mirror of
https://github.com/FunkyFr3sh/cnc-ddraw.git
synced 2025-03-15 06:04:49 +01:00
Move some render init stuff out of render main loop
This commit is contained in:
parent
afdc334935
commit
3e594b10c6
29
main.c
29
main.c
@ -379,6 +379,8 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
||||
|
||||
HRESULT __stdcall ddraw_SetCooperativeLevel(IDirectDrawImpl *This, HWND hWnd, DWORD dwFlags)
|
||||
{
|
||||
PIXELFORMATDESCRIPTOR pfd;
|
||||
|
||||
printf("DirectDraw::SetCooperativeLevel(This=%p, hWnd=0x%08X, dwFlags=0x%08X)\n", This, (unsigned int)hWnd, (unsigned int)dwFlags);
|
||||
|
||||
/* Red Alert for some weird reason does this on Windows XP */
|
||||
@ -397,6 +399,20 @@ HRESULT __stdcall ddraw_SetCooperativeLevel(IDirectDrawImpl *This, HWND hWnd, DW
|
||||
SetWindowLong(This->hWnd, GWL_WNDPROC, (LONG)WndProc);
|
||||
}
|
||||
|
||||
if(!This->render.hDC)
|
||||
{
|
||||
This->render.hDC = GetDC(This->hWnd);
|
||||
|
||||
memset(&pfd, 0, sizeof(PIXELFORMATDESCRIPTOR));
|
||||
pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR);
|
||||
pfd.nVersion = 1;
|
||||
pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
|
||||
pfd.iPixelType = PFD_TYPE_RGBA;
|
||||
pfd.cColorBits = ddraw->render.bpp ? ddraw->render.bpp : ddraw->mode.dmBitsPerPel;
|
||||
pfd.iLayerType = PFD_MAIN_PLANE;
|
||||
SetPixelFormat( This->render.hDC, ChoosePixelFormat( This->render.hDC, &pfd ), &pfd );
|
||||
}
|
||||
|
||||
return DD_OK;
|
||||
}
|
||||
|
||||
@ -443,6 +459,18 @@ ULONG __stdcall ddraw_Release(IDirectDrawImpl *This)
|
||||
LeaveCriticalSection(&This->cs);
|
||||
}
|
||||
|
||||
if(This->render.hDC)
|
||||
{
|
||||
ReleaseDC(This->hWnd, This->render.hDC);
|
||||
This->render.hDC = NULL;
|
||||
}
|
||||
|
||||
if(This->render.ev)
|
||||
{
|
||||
CloseHandle(This->render.ev);
|
||||
ddraw->render.ev = NULL;
|
||||
}
|
||||
|
||||
DeleteCriticalSection(&This->cs);
|
||||
|
||||
/* restore old wndproc, subsequent ddraw creation will otherwise fail */
|
||||
@ -532,6 +560,7 @@ HRESULT WINAPI DirectDrawCreate(GUID FAR* lpGUID, LPDIRECTDRAW FAR* lplpDD, IUnk
|
||||
}
|
||||
|
||||
InitializeCriticalSection(&This->cs);
|
||||
This->render.ev = CreateEvent(NULL, TRUE, FALSE, NULL);
|
||||
|
||||
/* load configuration options from ddraw.ini */
|
||||
char cwd[MAX_PATH];
|
||||
|
3
main.h
3
main.h
@ -54,6 +54,9 @@ typedef struct IDirectDrawImpl
|
||||
int bpp;
|
||||
int filter;
|
||||
|
||||
HDC hDC;
|
||||
int *tex;
|
||||
|
||||
HANDLE thread;
|
||||
BOOL run;
|
||||
HANDLE ev;
|
||||
|
24
render.c
24
render.c
@ -23,29 +23,16 @@
|
||||
DWORD WINAPI render_main(void)
|
||||
{
|
||||
int i,j;
|
||||
PIXELFORMATDESCRIPTOR pfd;
|
||||
HDC hDC;
|
||||
HGLRC hRC;
|
||||
|
||||
hDC = GetDC(ddraw->hWnd);
|
||||
|
||||
int tex_width = 1024;
|
||||
int tex_height = 1024;
|
||||
float scale_w = 1.0f;
|
||||
float scale_h = 1.0f;
|
||||
int *tex = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, tex_width * tex_height * sizeof(int));
|
||||
|
||||
memset(&pfd, 0, sizeof(PIXELFORMATDESCRIPTOR));
|
||||
pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR);
|
||||
pfd.nVersion = 1;
|
||||
pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
|
||||
pfd.iPixelType = PFD_TYPE_RGBA;
|
||||
pfd.cColorBits = ddraw->render.bpp ? ddraw->render.bpp : ddraw->mode.dmBitsPerPel;
|
||||
pfd.iLayerType = PFD_MAIN_PLANE;
|
||||
SetPixelFormat( hDC, ChoosePixelFormat( hDC, &pfd ), &pfd );
|
||||
|
||||
hRC = wglCreateContext( hDC );
|
||||
wglMakeCurrent( hDC, hRC );
|
||||
hRC = wglCreateContext( ddraw->render.hDC );
|
||||
wglMakeCurrent( ddraw->render.hDC, hRC );
|
||||
|
||||
DWORD tick_start;
|
||||
DWORD tick_end;
|
||||
@ -61,8 +48,6 @@ DWORD WINAPI render_main(void)
|
||||
frame_len = 1000.0f / ddraw->render.maxfps;
|
||||
}
|
||||
|
||||
ddraw->render.ev = CreateEvent(NULL, TRUE, FALSE, NULL);
|
||||
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, tex_width, tex_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, tex);
|
||||
glViewport(0, 0, ddraw->render.width, ddraw->render.height);
|
||||
|
||||
@ -114,7 +99,7 @@ DWORD WINAPI render_main(void)
|
||||
glTexCoord2f(0,scale_h); glVertex2f(-1, -1);
|
||||
glEnd();
|
||||
|
||||
SwapBuffers(hDC);
|
||||
SwapBuffers(ddraw->render.hDC);
|
||||
|
||||
if(ddraw->render.maxfps > 0)
|
||||
{
|
||||
@ -130,12 +115,9 @@ DWORD WINAPI render_main(void)
|
||||
}
|
||||
|
||||
HeapFree(GetProcessHeap(), 0, tex);
|
||||
CloseHandle(ddraw->render.ev);
|
||||
ddraw->render.ev = NULL;
|
||||
|
||||
wglMakeCurrent(NULL, NULL);
|
||||
wglDeleteContext(hRC);
|
||||
ReleaseDC(ddraw->hWnd, hDC);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user