mirror of
https://github.com/FunkyFr3sh/cnc-ddraw.git
synced 2025-03-15 06:04:49 +01:00
show opengl unavailable warning
This commit is contained in:
parent
f5b661dc1b
commit
fa54189259
@ -24,6 +24,8 @@
|
||||
#define CUTSCENE_WIDTH 640
|
||||
#define CUTSCENE_HEIGHT 400
|
||||
|
||||
extern char OpenglVersion[];
|
||||
|
||||
struct IDirectDrawImpl;
|
||||
struct IDirectDrawImplVtbl;
|
||||
struct IDirectDrawSurfaceImpl;
|
||||
|
@ -46,6 +46,10 @@ typedef struct IDirectDrawSurfaceImpl
|
||||
DWORD lPitch;
|
||||
DWORD lXPitch;
|
||||
|
||||
PBITMAPINFO bmi;
|
||||
HBITMAP bitmap;
|
||||
HDC hDC;
|
||||
|
||||
} IDirectDrawSurfaceImpl;
|
||||
|
||||
struct IDirectDrawSurfaceImplVtbl
|
||||
|
@ -22,6 +22,7 @@
|
||||
#include "surface.h"
|
||||
#include "paletteshader.h"
|
||||
|
||||
char OpenglVersion[128];
|
||||
|
||||
BOOL detect_cutscene();
|
||||
DWORD WINAPI render_soft_main(void);
|
||||
@ -33,6 +34,14 @@ DWORD WINAPI render_main(void)
|
||||
HGLRC hRC = wglCreateContext(ddraw->render.hDC);
|
||||
BOOL madeCurrent = hRC && wglMakeCurrent(ddraw->render.hDC, hRC);
|
||||
|
||||
char *glversion = (char *)glGetString(GL_VERSION);
|
||||
if (glversion)
|
||||
{
|
||||
strncpy(OpenglVersion, glversion, sizeof(OpenglVersion));
|
||||
const char deli[2] = " ";
|
||||
strtok(OpenglVersion, deli);
|
||||
}
|
||||
|
||||
if (!madeCurrent || (ddraw->autorenderer && glGetError() != GL_NO_ERROR))
|
||||
{
|
||||
if (madeCurrent)
|
||||
|
@ -58,14 +58,15 @@ DWORD WINAPI render_soft_main(void)
|
||||
{
|
||||
Sleep(500);
|
||||
|
||||
PBITMAPINFO bmi = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD) * 256);
|
||||
|
||||
bmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
|
||||
bmi->bmiHeader.biWidth = ddraw->width;
|
||||
bmi->bmiHeader.biHeight = -ddraw->height;
|
||||
bmi->bmiHeader.biPlanes = 1;
|
||||
bmi->bmiHeader.biBitCount = ddraw->bpp;
|
||||
bmi->bmiHeader.biCompression = BI_RGB;
|
||||
DWORD warningEndTick = timeGetTime() + (15 * 1000);
|
||||
char warningText[512] = { 0 };
|
||||
if (OpenglVersion[0])
|
||||
{
|
||||
snprintf(
|
||||
warningText, sizeof(warningText),
|
||||
"-WARNING- Using slow software rendering, please update your graphics card driver (%s)",
|
||||
strlen(OpenglVersion) > 10 ? "" : OpenglVersion);
|
||||
}
|
||||
|
||||
DWORD tick_start = 0;
|
||||
DWORD tick_end = 0;
|
||||
@ -107,7 +108,18 @@ DWORD WINAPI render_soft_main(void)
|
||||
{
|
||||
if (ddraw->primary->palette && ddraw->primary->palette->data_rgb == NULL)
|
||||
{
|
||||
ddraw->primary->palette->data_rgb = &bmi->bmiColors[0];
|
||||
ddraw->primary->palette->data_rgb = &ddraw->primary->bmi->bmiColors[0];
|
||||
}
|
||||
|
||||
if (warningText[0])
|
||||
{
|
||||
if (timeGetTime() < warningEndTick)
|
||||
{
|
||||
RECT rc = { 0, 0, ddraw->width, ddraw->height };
|
||||
DrawText(ddraw->primary->hDC, warningText, -1, &rc, DT_NOCLIP | DT_CENTER);
|
||||
}
|
||||
else
|
||||
warningText[0] = 0;
|
||||
}
|
||||
|
||||
if ((ddraw->render.width != ddraw->width || ddraw->render.height != ddraw->height) &&
|
||||
@ -117,13 +129,13 @@ DWORD WINAPI render_soft_main(void)
|
||||
ddraw->render.hDC, ddraw->render.viewport.x, ddraw->render.viewport.y,
|
||||
ddraw->render.viewport.width, ddraw->render.viewport.height,
|
||||
0, 0, ddraw->width, ddraw->height, ddraw->primary->surface,
|
||||
bmi, DIB_RGB_COLORS, SRCCOPY);
|
||||
ddraw->primary->bmi, DIB_RGB_COLORS, SRCCOPY);
|
||||
}
|
||||
else if (!(ddraw->vhack && detect_cutscene()))
|
||||
{
|
||||
SetDIBitsToDevice(
|
||||
ddraw->render.hDC, 0, 0, ddraw->width, ddraw->height, 0, 0, 0,
|
||||
ddraw->height, ddraw->primary->surface, bmi, DIB_RGB_COLORS);
|
||||
ddraw->height, ddraw->primary->surface, ddraw->primary->bmi, DIB_RGB_COLORS);
|
||||
}
|
||||
|
||||
}
|
||||
@ -131,14 +143,14 @@ DWORD WINAPI render_soft_main(void)
|
||||
{
|
||||
if (ddraw->primary->palette && ddraw->primary->palette->data_rgb == NULL)
|
||||
{
|
||||
ddraw->primary->palette->data_rgb = &bmi->bmiColors[0];
|
||||
ddraw->primary->palette->data_rgb = &ddraw->primary->bmi->bmiColors[0];
|
||||
}
|
||||
|
||||
StretchDIBits(
|
||||
ddraw->render.hDC, ddraw->render.viewport.x, ddraw->render.viewport.y,
|
||||
ddraw->render.viewport.width, ddraw->render.viewport.height,
|
||||
0, ddraw->height-400, CUTSCENE_WIDTH, CUTSCENE_HEIGHT, ddraw->primary->surface,
|
||||
bmi, DIB_RGB_COLORS, SRCCOPY);
|
||||
ddraw->primary->bmi, DIB_RGB_COLORS, SRCCOPY);
|
||||
|
||||
if (ddraw->primary->palette && !ddraw->incutscene)
|
||||
{
|
||||
@ -165,7 +177,5 @@ DWORD WINAPI render_soft_main(void)
|
||||
SetEvent(ddraw->render.ev);
|
||||
}
|
||||
|
||||
HeapFree(GetProcessHeap(), 0, bmi);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
@ -53,8 +53,13 @@ ULONG __stdcall ddraw_surface_Release(IDirectDrawSurfaceImpl *This)
|
||||
}
|
||||
if(This->surface)
|
||||
{
|
||||
HeapFree(GetProcessHeap(), 0, This->surface);
|
||||
DeleteObject(This->bitmap);
|
||||
DeleteDC(This->hDC);
|
||||
}
|
||||
|
||||
if (This->bmi)
|
||||
HeapFree(GetProcessHeap(), 0, This->bmi);
|
||||
|
||||
if(This->palette)
|
||||
{
|
||||
IDirectDrawPalette_Release(This->palette);
|
||||
@ -486,9 +491,29 @@ HRESULT __stdcall ddraw_CreateSurface(IDirectDrawImpl *This, LPDDSURFACEDESC lpD
|
||||
|
||||
if(Surface->width && Surface->height)
|
||||
{
|
||||
Surface->bmi = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD) * 256);
|
||||
Surface->bmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
|
||||
Surface->bmi->bmiHeader.biWidth = Surface->width;
|
||||
Surface->bmi->bmiHeader.biHeight = -Surface->height;
|
||||
Surface->bmi->bmiHeader.biPlanes = 1;
|
||||
Surface->bmi->bmiHeader.biBitCount = Surface->bpp;
|
||||
Surface->bmi->bmiHeader.biCompression = BI_RGB;
|
||||
|
||||
int i;
|
||||
for (i = 0; i < 256; i++)
|
||||
{
|
||||
Surface->bmi->bmiColors[i].rgbRed = i;
|
||||
Surface->bmi->bmiColors[i].rgbGreen = i;
|
||||
Surface->bmi->bmiColors[i].rgbBlue = i;
|
||||
Surface->bmi->bmiColors[i].rgbReserved = 0;
|
||||
}
|
||||
|
||||
Surface->lXPitch = Surface->bpp / 8;
|
||||
Surface->lPitch = Surface->width * Surface->lXPitch;
|
||||
Surface->surface = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, Surface->lPitch * Surface->height * Surface->lXPitch);
|
||||
|
||||
Surface->hDC = CreateCompatibleDC(ddraw->render.hDC);
|
||||
Surface->bitmap = CreateDIBSection(Surface->hDC, Surface->bmi, DIB_RGB_COLORS, (void **)&Surface->surface, NULL, 0);
|
||||
SelectObject(Surface->hDC, Surface->bitmap);
|
||||
}
|
||||
|
||||
printf(" Surface = %p (%dx%d@%d)\n", Surface, (int)Surface->width, (int)Surface->height, (int)Surface->bpp);
|
||||
|
Loading…
x
Reference in New Issue
Block a user