1
0
mirror of https://github.com/FunkyFr3sh/cnc-ddraw.git synced 2025-03-25 01:57:47 +01:00

Use game's own window for drawing, initial drawing with grayscale palette

This commit is contained in:
Toni Spets 2010-10-17 14:19:48 +03:00
parent ad037e718c
commit c3ed0a00b1
4 changed files with 57 additions and 28 deletions

26
main.c
View File

@ -51,9 +51,13 @@ HRESULT ddraw_GetCaps(void *This, LPDDCAPS lpDDDriverCaps, LPDDCAPS lpDDEmulCaps
return DD_OK; return DD_OK;
} }
HRESULT ddraw_SetCooperativeLevel(void *This, HWND hWnd, DWORD dwFlags) HRESULT ddraw_SetCooperativeLevel(void *_This, HWND hWnd, DWORD dwFlags)
{ {
fakeDirectDrawObject *This = (fakeDirectDrawObject *)_This;
printf("DirectDraw::SetCooperativeLevel(This=%p, hWnd=0x%08X, dwFlags=0x%08X)\n", This, (unsigned int)hWnd, (unsigned int)dwFlags); printf("DirectDraw::SetCooperativeLevel(This=%p, hWnd=0x%08X, dwFlags=0x%08X)\n", This, (unsigned int)hWnd, (unsigned int)dwFlags);
This->hWnd = hWnd;
return DD_OK; return DD_OK;
} }
@ -139,33 +143,15 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
HRESULT WINAPI DirectDrawCreate(GUID FAR* lpGUID, LPDIRECTDRAW FAR* lplpDD, IUnknown FAR* pUnkOuter) 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); printf("DirectDrawCreate(lpGUID=%p, lplpDD=%p, pUnkOuter=%p)\n", lpGUID, lplpDD, pUnkOuter);
fakeDirectDrawObject *This = (fakeDirectDrawObject *)malloc(sizeof(fakeDirectDrawObject)); fakeDirectDrawObject *This = (fakeDirectDrawObject *)malloc(sizeof(fakeDirectDrawObject));
This->Ref = 1; This->Ref = 1;
This->Functions = &iface; This->Functions = &iface;
This->hWnd = NULL;
printf(" This = %p\n", This); printf(" This = %p\n", This);
*lplpDD = (LPDIRECTDRAW)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; return DD_OK;
} }

1
main.h
View File

@ -62,7 +62,6 @@ typedef struct
DWORD height; DWORD height;
DWORD bpp; DWORD bpp;
HINSTANCE hInstance;
HWND hWnd; HWND hWnd;
} fakeDirectDrawObject; } fakeDirectDrawObject;

View File

@ -73,6 +73,7 @@ HRESULT ddraw_CreateSurface(void *_This, LPDDSURFACEDESC lpDDSurfaceDesc, LPDIRE
Surface->hDC = NULL; Surface->hDC = NULL;
Surface->bpp = This->bpp; Surface->bpp = This->bpp;
Surface->surface = NULL; Surface->surface = NULL;
Surface->glTex = NULL;
Surface->caps = 0; Surface->caps = 0;
if(lpDDSurfaceDesc->dwFlags & DDSD_CAPS) if(lpDDSurfaceDesc->dwFlags & DDSD_CAPS)
@ -114,7 +115,10 @@ HRESULT ddraw_CreateSurface(void *_This, LPDDSURFACEDESC lpDDSurfaceDesc, LPDIRE
if(Surface->width && Surface->height) if(Surface->width && Surface->height)
{ {
Surface->surface = malloc(Surface->width * Surface->height * Surface->bpp / 8); Surface->lPitch = Surface->width;
Surface->lXPitch = Surface->bpp / 8;
Surface->surface = malloc(Surface->width * Surface->height * Surface->lXPitch);
Surface->glTex = malloc(Surface->width * Surface->height * sizeof(int));
} }
printf(" Surface = %p (%dx%d@%d)\n", Surface, (int)Surface->width, (int)Surface->height, (int)Surface->bpp); printf(" Surface = %p (%dx%d@%d)\n", Surface, (int)Surface->width, (int)Surface->height, (int)Surface->bpp);
@ -133,8 +137,11 @@ HRESULT ddraw_surface_AddAttachedSurface(void *_This, LPDIRECTDRAWSURFACE lpDDSu
return DD_OK; return DD_OK;
} }
HRESULT ddraw_surface_Blt(void *This, LPRECT lpDestRect, LPDIRECTDRAWSURFACE lpDDSrcSurface, LPRECT lpSrcRect, DWORD dwFlags, LPDDBLTFX lpDDBltFx) HRESULT ddraw_surface_Blt(void *_This, LPRECT lpDestRect, LPDIRECTDRAWSURFACE lpDDSrcSurface, LPRECT lpSrcRect, DWORD dwFlags, LPDDBLTFX lpDDBltFx)
{ {
fakeDirectDrawSurfaceObject *This = (fakeDirectDrawSurfaceObject *)_This;
fakeDirectDrawSurfaceObject *Source = (fakeDirectDrawSurfaceObject *)lpDDSrcSurface;
printf("DirectDrawSurface::Blt(This=%p, lpDestRect=%p, lpDDSrcSurface=%p, lpSrcRect=%p, dwFlags=%d, lpDDBltFx=%p)\n", This, lpDestRect, lpDDSrcSurface, lpSrcRect, (int)dwFlags, lpDDBltFx); printf("DirectDrawSurface::Blt(This=%p, lpDestRect=%p, lpDDSrcSurface=%p, lpSrcRect=%p, dwFlags=%d, lpDDBltFx=%p)\n", This, lpDestRect, lpDDSrcSurface, lpSrcRect, (int)dwFlags, lpDDBltFx);
if(lpDestRect) if(lpDestRect)
{ {
@ -144,6 +151,8 @@ HRESULT ddraw_surface_Blt(void *This, LPRECT lpDestRect, LPDIRECTDRAWSURFACE lpD
{ {
printf(" src: l: %d t: %d r: %d b: %d\n", (int)lpSrcRect->left, (int)lpSrcRect->top, (int)lpSrcRect->right, (int)lpSrcRect->bottom); printf(" src: l: %d t: %d r: %d b: %d\n", (int)lpSrcRect->left, (int)lpSrcRect->top, (int)lpSrcRect->right, (int)lpSrcRect->bottom);
} }
/* FIXME: blit the correct areas */
memcpy(This->surface, Source->surface, This->width * This->height);
return DD_OK; return DD_OK;
} }
@ -197,25 +206,56 @@ HRESULT ddraw_surface_Lock(void *_This, LPRECT lpDestRect, LPDDSURFACEDESC lpDDS
#endif #endif
lpDDSurfaceDesc->dwSize = sizeof(DDSURFACEDESC); lpDDSurfaceDesc->dwSize = sizeof(DDSURFACEDESC);
lpDDSurfaceDesc->dwFlags = DDSD_LPSURFACE; lpDDSurfaceDesc->dwFlags = DDSD_LPSURFACE|DDSD_PITCH;
lpDDSurfaceDesc->lpSurface = This->surface; lpDDSurfaceDesc->lpSurface = This->surface;
lpDDSurfaceDesc->lPitch = This->lPitch;
return DD_OK; return DD_OK;
} }
HRESULT ddraw_surface_Unlock(void *_This, LPVOID lpRect) HRESULT ddraw_surface_Unlock(void *_This, LPVOID lpRect)
{ {
int i,j;
fakeDirectDrawSurfaceObject *This = (fakeDirectDrawSurfaceObject *)_This; fakeDirectDrawSurfaceObject *This = (fakeDirectDrawSurfaceObject *)_This;
#if _DEBUG #if _DEBUG
printf("DirectDrawSurface::Unlock(This=%p, lpRect=%p)\n", This, lpRect); printf("DirectDrawSurface::Unlock(This=%p, lpRect=%p)\n", This, lpRect);
#endif #endif
if(This->caps & DDSCAPS_PRIMARYSURFACE) if(This->caps & DDSCAPS_PRIMARYSURFACE)
{ {
/* clearing the screen for now */
glClearColor( 0.0f, 0.0f, 255.0f, 0.0f ); /* FIXME: temporary grayscale palette */
glClear( GL_COLOR_BUFFER_BIT ); int tmp_palette[256];
SwapBuffers( This->hDC ); for(i=0;i<256;i++)
{
tmp_palette[i] = (i<<16)|(i<<8)|i;
}
/* convert ddraw surface to opengl texture */
for(i=0; i<This->height; i++)
{
for(j=0; j<This->width; j++)
{
This->glTex[i*This->width+j] = tmp_palette[((unsigned char *)This->surface)[i*This->lPitch + j*This->lXPitch]];
}
}
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, This->width, This->height, 0, GL_RGBA, GL_UNSIGNED_BYTE, This->glTex);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
glEnable(GL_TEXTURE_2D);
glBegin(GL_TRIANGLE_FAN);
glTexCoord2f(0,0); glVertex2f(-1, 1);
glTexCoord2f(1,0); glVertex2f( 1, 1);
glTexCoord2f(1,1); glVertex2f( 1, -1);
glTexCoord2f(0,1); glVertex2f(-1, -1);
glEnd();
SwapBuffers(This->hDC);
} }
return DD_OK; return DD_OK;

View File

@ -73,10 +73,14 @@ typedef struct
DWORD height; DWORD height;
DWORD bpp; DWORD bpp;
DWORD caps; DWORD caps;
void *surface; void *surface;
DWORD lPitch;
DWORD lXPitch;
HDC hDC; HDC hDC;
HGLRC hRC; HGLRC hRC;
int *glTex;
ULONG Ref; ULONG Ref;