1
0
mirror of https://github.com/FunkyFr3sh/cnc-ddraw.git synced 2025-03-14 22:03:27 +01:00

Initialize OpenGL and clear the screen to blue on update

This commit is contained in:
Toni Spets 2010-10-17 10:53:01 +03:00
parent f1e2bb8dc5
commit ad037e718c
5 changed files with 79 additions and 2 deletions

View File

@ -1,5 +1,5 @@
all:
i586-mingw32msvc-gcc -Wall -Wl,--enable-stdcall-fixup -shared -s -o ddraw.dll main.c palette.c surface.c ddraw.def
i586-mingw32msvc-gcc -Wall -Wl,--enable-stdcall-fixup -shared -s -o ddraw.dll main.c palette.c surface.c ddraw.def -lgdi32 -lopengl32
clean:
rm -f ddraw.dll

39
main.c
View File

@ -67,6 +67,9 @@ HRESULT ddraw_SetDisplayMode(void *_This, DWORD width, DWORD height, DWORD bpp)
This->height = height;
This->bpp = bpp;
MoveWindow(This->hWnd, 0, 0, This->width, This->height, TRUE);
SetWindowLong(This->hWnd, GWL_STYLE, WS_CAPTION | WS_POPUPWINDOW | WS_VISIBLE);
return DD_OK;
}
@ -132,8 +135,12 @@ fakeDirectDraw iface =
null //WaitForVerticalBlank
};
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
HRESULT WINAPI DirectDrawCreate(GUID FAR* lpGUID, LPDIRECTDRAW FAR* lplpDD, IUnknown FAR* pUnkOuter)
{
WNDCLASS wc;
printf("DirectDrawCreate(lpGUID=%p, lplpDD=%p, pUnkOuter=%p)\n", lpGUID, lplpDD, pUnkOuter);
fakeDirectDrawObject *This = (fakeDirectDrawObject *)malloc(sizeof(fakeDirectDrawObject));
@ -142,5 +149,37 @@ HRESULT WINAPI DirectDrawCreate(GUID FAR* lpGUID, LPDIRECTDRAW FAR* lplpDD, IUnk
printf(" This = %p\n", This);
*lplpDD = (LPDIRECTDRAW)This;
This->hInstance = GetModuleHandle( 0 );
/* create dummy window */
wc.style = CS_OWNDC;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = This->hInstance;
wc.hIcon = LoadIcon( NULL, IDI_APPLICATION );
wc.hCursor = LoadCursor( NULL, IDC_ARROW );
wc.hbrBackground = 0;
wc.lpszMenuName = NULL;
wc.lpszClassName = "cnc-ddraw";
RegisterClass( &wc );
This->hWnd = CreateWindow("cnc-ddraw", "cnc-ddraw", 0, 0, 0, 0, 0, NULL, NULL, This->hInstance, NULL );
return DD_OK;
}
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_CLOSE:
PostQuitMessage( 0 );
case WM_CREATE:
case WM_DESTROY:
case WM_KEYDOWN:
return 0;
default:
return DefWindowProc( hWnd, message, wParam, lParam );
}
}

5
main.h
View File

@ -19,6 +19,8 @@
#include <windows.h>
#include "ddraw.h"
#include <GL/gl.h>
#include <GL/glu.h>
typedef struct
{
@ -60,6 +62,9 @@ typedef struct
DWORD height;
DWORD bpp;
HINSTANCE hInstance;
HWND hWnd;
} fakeDirectDrawObject;
#endif

View File

@ -70,6 +70,7 @@ HRESULT ddraw_CreateSurface(void *_This, LPDDSURFACEDESC lpDDSurfaceDesc, LPDIRE
Surface->Functions = &siface;
/* private stuff */
Surface->hDC = NULL;
Surface->bpp = This->bpp;
Surface->surface = NULL;
Surface->caps = 0;
@ -78,8 +79,27 @@ HRESULT ddraw_CreateSurface(void *_This, LPDDSURFACEDESC lpDDSurfaceDesc, LPDIRE
{
if(lpDDSurfaceDesc->ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE)
{
PIXELFORMATDESCRIPTOR pfd;
printf("Creating primary surface and initializing OpenGL\n");
Surface->width = This->width;
Surface->height = This->height;
Surface->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 = 24;
pfd.cDepthBits = 16;
pfd.iLayerType = PFD_MAIN_PLANE;
SetPixelFormat( Surface->hDC, ChoosePixelFormat( Surface->hDC, &pfd ), &pfd );
Surface->hRC = wglCreateContext( Surface->hDC );
wglMakeCurrent( Surface->hDC, Surface->hRC );
}
dump_ddscaps(lpDDSurfaceDesc->ddsCaps.dwCaps);
@ -183,11 +203,21 @@ HRESULT ddraw_surface_Lock(void *_This, LPRECT lpDestRect, LPDDSURFACEDESC lpDDS
return DD_OK;
}
HRESULT ddraw_surface_Unlock(void *This, LPVOID lpRect)
HRESULT ddraw_surface_Unlock(void *_This, LPVOID lpRect)
{
fakeDirectDrawSurfaceObject *This = (fakeDirectDrawSurfaceObject *)_This;
#if _DEBUG
printf("DirectDrawSurface::Unlock(This=%p, lpRect=%p)\n", This, lpRect);
#endif
if(This->caps & DDSCAPS_PRIMARYSURFACE)
{
/* clearing the screen for now */
glClearColor( 0.0f, 0.0f, 255.0f, 0.0f );
glClear( GL_COLOR_BUFFER_BIT );
SwapBuffers( This->hDC );
}
return DD_OK;
}

View File

@ -75,6 +75,9 @@ typedef struct
DWORD caps;
void *surface;
HDC hDC;
HGLRC hRC;
ULONG Ref;
} fakeDirectDrawSurfaceObject;