mirror of
https://github.com/FunkyFr3sh/cnc-ddraw.git
synced 2025-03-15 06:04:49 +01:00
Use power-of-two texture in OpenGL, optimize rendering, add bpp selection into ini
This commit is contained in:
parent
d245af34bb
commit
4b3b799106
5
main.c
5
main.c
@ -454,6 +454,11 @@ HRESULT WINAPI DirectDrawCreate(GUID FAR* lpGUID, LPDIRECTDRAW FAR* lplpDD, IUnk
|
||||
{
|
||||
This->render->height = 400;
|
||||
}
|
||||
This->render->bpp = GetPrivateProfileIntA("ddraw", "bpp", 24, ini_path);
|
||||
if(This->render->bpp != 16 && This->render->bpp != 24 && This->render->bpp != 32)
|
||||
{
|
||||
This->render->bpp = 24;
|
||||
}
|
||||
|
||||
GetPrivateProfileStringA("ddraw", "filter", tmp, tmp, sizeof(tmp), ini_path);
|
||||
if(tolower(tmp[0]) == 'l' || tolower(tmp[3]) == 'l')
|
||||
|
1
main.h
1
main.h
@ -52,6 +52,7 @@ typedef struct IDirectDrawImpl
|
||||
int maxfps;
|
||||
int width;
|
||||
int height;
|
||||
int bpp;
|
||||
int filter;
|
||||
|
||||
HANDLE thread;
|
||||
|
@ -30,6 +30,7 @@ struct render_ddraw_impl
|
||||
int maxfps;
|
||||
int width;
|
||||
int height;
|
||||
int bpp;
|
||||
int filter;
|
||||
|
||||
HANDLE thread;
|
||||
@ -55,6 +56,7 @@ struct render_ddraw_impl render_ddraw =
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
|
||||
NULL,
|
||||
TRUE,
|
||||
|
@ -30,6 +30,7 @@ struct render_opengl_impl
|
||||
int maxfps;
|
||||
int width;
|
||||
int height;
|
||||
int bpp;
|
||||
int filter;
|
||||
|
||||
HANDLE thread;
|
||||
@ -53,6 +54,7 @@ struct render_opengl_impl render_opengl =
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
|
||||
NULL,
|
||||
TRUE,
|
||||
@ -83,15 +85,18 @@ DWORD WINAPI render_opengl_main(IDirectDrawSurfaceImpl *surface)
|
||||
|
||||
hDC = GetDC(ddraw->hWnd);
|
||||
|
||||
int *glTex = malloc(surface->width * surface->height * sizeof(int));
|
||||
int tex_width = 1024;
|
||||
int tex_height = 1024;
|
||||
float scale_w = (float)surface->width/tex_width;
|
||||
float scale_h = (float)surface->height/tex_height;
|
||||
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 = 24;
|
||||
pfd.cDepthBits = 16;
|
||||
pfd.cColorBits = render_opengl.bpp;
|
||||
pfd.iLayerType = PFD_MAIN_PLANE;
|
||||
SetPixelFormat( hDC, ChoosePixelFormat( hDC, &pfd ), &pfd );
|
||||
|
||||
@ -114,6 +119,22 @@ DWORD WINAPI render_opengl_main(IDirectDrawSurfaceImpl *surface)
|
||||
|
||||
render_opengl.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, render_opengl.width, render_opengl.height);
|
||||
|
||||
if(render_opengl.filter)
|
||||
{
|
||||
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
|
||||
}
|
||||
else
|
||||
{
|
||||
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
|
||||
}
|
||||
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
|
||||
while(render_opengl.run)
|
||||
{
|
||||
if(render_opengl.maxfps > 0)
|
||||
@ -126,32 +147,17 @@ DWORD WINAPI render_opengl_main(IDirectDrawSurfaceImpl *surface)
|
||||
{
|
||||
for(j=0; j<surface->width; j++)
|
||||
{
|
||||
glTex[i*surface->width+j] = surface->palette->data_bgr[((unsigned char *)surface->surface)[i*surface->lPitch + j*surface->lXPitch]];
|
||||
tex[i*surface->width+j] = surface->palette->data_bgr[((unsigned char *)surface->surface)[i*surface->lPitch + j*surface->lXPitch]];
|
||||
}
|
||||
}
|
||||
|
||||
glViewport(0, 0, render_opengl.width, render_opengl.height);
|
||||
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, surface->width, surface->height, 0, GL_RGBA, GL_UNSIGNED_BYTE, glTex);
|
||||
|
||||
if(render_opengl.filter)
|
||||
{
|
||||
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
|
||||
}
|
||||
else
|
||||
{
|
||||
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
|
||||
}
|
||||
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, surface->width, surface->height, GL_RGBA, GL_UNSIGNED_BYTE, tex);
|
||||
|
||||
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);
|
||||
glTexCoord2f(0,0); glVertex2f(-1, 1);
|
||||
glTexCoord2f(scale_w,0); glVertex2f( 1, 1);
|
||||
glTexCoord2f(scale_w,scale_h); glVertex2f( 1, -1);
|
||||
glTexCoord2f(0,scale_h); glVertex2f(-1, -1);
|
||||
glEnd();
|
||||
|
||||
SwapBuffers(hDC);
|
||||
@ -171,7 +177,7 @@ DWORD WINAPI render_opengl_main(IDirectDrawSurfaceImpl *surface)
|
||||
|
||||
CloseHandle(render_opengl.ev);
|
||||
|
||||
free(glTex);
|
||||
free(tex);
|
||||
|
||||
wglMakeCurrent(NULL, NULL);
|
||||
wglDeleteContext(hRC);
|
||||
|
Loading…
x
Reference in New Issue
Block a user