From 3694605b23b1019488844bf448d461eacc69077f Mon Sep 17 00:00:00 2001 From: cnlohr Date: Wed, 22 Mar 2017 00:12:31 -0400 Subject: Update RawDraw to version that can at least support OpenGL if we want it. --- redist/CNFGWinDriver.c | 71 ++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 66 insertions(+), 5 deletions(-) (limited to 'redist/CNFGWinDriver.c') diff --git a/redist/CNFGWinDriver.c b/redist/CNFGWinDriver.c index a029419..c5da925 100644 --- a/redist/CNFGWinDriver.c +++ b/redist/CNFGWinDriver.c @@ -13,7 +13,6 @@ static HWND lsHWND; static HDC lsWindowHDC; static HDC lsHDC; - #ifdef RASTERIZER #include "CNFGRasterizer.h" @@ -32,14 +31,34 @@ static void InternalHandleResize(); #endif +#ifdef CNFGOGL +#include +static HGLRC hRC=NULL; +static void InternalHandleResize() { } +void CNFGSwapBuffers() +{ + SwapBuffers(lsWindowHDC); +} +#endif + void CNFGGetDimensions( short * x, short * y ) { + static int lastx, lasty; + RECT window; + GetClientRect( lsHWND, &window ); + bufferx = ( window.right - window.left); + buffery = ( window.bottom - window.top); + if( bufferx != lastx || buffery != lasty ) + { + lastx = bufferx; + lasty = buffery; + InternalHandleResize(); + } *x = bufferx; *y = buffery; } - void CNFGUpdateScreenWithBitmap( unsigned long * data, int w, int h ) { RECT r; @@ -126,9 +145,49 @@ void CNFGSetup( const char * name_of_window, int width, int height ) hInstance, NULL); //no parameters to pass - lsWindowHDC = GetDC( lsHWND ); +#ifdef CNFGOGL + //From NeHe + static PIXELFORMATDESCRIPTOR pfd = + { + sizeof(PIXELFORMATDESCRIPTOR), + 1, + PFD_DRAW_TO_WINDOW | + PFD_SUPPORT_OPENGL | + PFD_DOUBLEBUFFER, + PFD_TYPE_RGBA, + 32, + 0, 0, 0, 0, 0, 0, + 0, + 0, + 0, + 0, 0, 0, 0, + 16, + 0, + 0, + PFD_MAIN_PLANE, + 0, + 0, 0, 0 + }; + GLuint PixelFormat = ChoosePixelFormat( lsWindowHDC, &pfd ); + if( !SetPixelFormat( lsWindowHDC, PixelFormat, &pfd ) ) + { + MessageBox( 0, "Could not create PFD for OpenGL Context\n", 0, 0 ); + exit( -1 ); + } + if (!(hRC=wglCreateContext(lsWindowHDC))) // Are We Able To Get A Rendering Context? + { + MessageBox( 0, "Could not create OpenGL Context\n", 0, 0 ); + exit( -1 ); + } + if(!wglMakeCurrent(lsWindowHDC,hRC)) // Try To Activate The Rendering Context + { + MessageBox( 0, "Could not current OpenGL Context\n", 0, 0 ); + exit( -1 ); + } +#endif + lsHDC = CreateCompatibleDC( lsWindowHDC ); lsBitmap = CreateCompatibleBitmap( lsWindowHDC, bufferx, buffery ); SelectObject( lsHDC, lsBitmap ); @@ -182,6 +241,7 @@ void CNFGHandleInput() } } +#ifndef CNFGOGL #ifndef RASTERIZER @@ -237,8 +297,7 @@ void CNFGClearFrame() DeleteObject( lsClearBrush ); lsClearBrush = CreateSolidBrush( CNFGBGColor ); SelectObject( lsHDC, lsClearBrush ); - - FillRect( lsHDC, &r, lsClearBrush ); + FillRect( lsHDC, &r, lsClearBrush); } void CNFGTackPoly( RDPoint * points, int verts ) @@ -287,3 +346,5 @@ void CNFGSwapBuffers() void CNFGInternalResize( short bufferx, short buffery ) { } #endif +#endif + -- cgit v1.2.3