From: John Tsiombikas Date: Fri, 31 Dec 2021 11:44:46 +0000 (+0200) Subject: fixed wgl context creation in miniglut: X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?p=andemo;a=commitdiff_plain;h=8c70193a723f9dfbea3655f336d10eff644d0f6f fixed wgl context creation in miniglut: - forgot to ask for an accelerated context - extra attributes added according to the glutInitDisplayMode flags, were written over the fixed ones at the start of the attr array. --- diff --git a/src/pc/miniglut.c b/src/pc/miniglut.c index 1919b64..1efbea3 100644 --- a/src/pc/miniglut.c +++ b/src/pc/miniglut.c @@ -15,6 +15,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ +#include #if defined(__unix__) #include @@ -49,7 +50,7 @@ static int have_netwm_fullscr(void); #include #define BUILD_WIN32 -static LRESULT CALLBACK handle_message(HWND win, unsigned int msg, WPARAM wparam, LPARAM lparam); +static HRESULT CALLBACK handle_message(HWND win, unsigned int msg, WPARAM wparam, LPARAM lparam); static HINSTANCE hinst; static HWND win; @@ -1268,6 +1269,7 @@ void glutSetKeyRepeat(int repmode) } #define WGL_DRAW_TO_WINDOW 0x2001 +#define WGL_ACCELERATION 0x2003 #define WGL_SUPPORT_OPENGL 0x2010 #define WGL_DOUBLE_BUFFER 0x2011 #define WGL_STEREO 0x2012 @@ -1280,6 +1282,7 @@ void glutSetKeyRepeat(int repmode) #define WGL_ACCUM_BITS 0x201d #define WGL_DEPTH_BITS 0x2022 #define WGL_STENCIL_BITS 0x2023 +#define WGL_FULL_ACCELERATION 0x2027 #define WGL_TYPE_RGBA 0x202b #define WGL_TYPE_COLORINDEX 0x202c @@ -1297,9 +1300,11 @@ static PROC wglGetPixelFormatAttribiv; static unsigned int choose_pixfmt(unsigned int mode) { unsigned int num_pixfmt, pixfmt = 0; - int attr[32] = { WGL_DRAW_TO_WINDOW, 1, WGL_SUPPORT_OPENGL, 1 }; + int attr[32] = { WGL_DRAW_TO_WINDOW, 1, WGL_SUPPORT_OPENGL, 1, + WGL_ACCELERATION, WGL_FULL_ACCELERATION }; + float fattr[2] = {0, 0}; - int *aptr = attr; + int *aptr = attr + 6; int *samples = 0; if(mode & GLUT_DOUBLE) { @@ -1334,7 +1339,7 @@ static unsigned int choose_pixfmt(unsigned int mode) } *aptr++ = 0; - while((!wglChoosePixelFormat(dc, attr, 0, 1, &pixfmt, &num_pixfmt) || !num_pixfmt) && samples && *samples) { + while((!wglChoosePixelFormat(dc, attr, fattr, 1, &pixfmt, &num_pixfmt) || !num_pixfmt) && samples && *samples) { *samples >>= 1; if(!*samples) { aptr[-3] = 0; @@ -1343,6 +1348,7 @@ static unsigned int choose_pixfmt(unsigned int mode) return pixfmt; } +static PIXELFORMATDESCRIPTOR pfd; static PIXELFORMATDESCRIPTOR tmppfd = { sizeof tmppfd, 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, 24, 8, 0, @@ -1418,7 +1424,7 @@ static int create_window_wglext(const char *title, int width, int height) if(!(pixfmt = choose_pixfmt(init_mode))) { panic("Failed to find suitable pixel format\n"); } - if(!SetPixelFormat(dc, pixfmt, &tmppfd)) { + if(!SetPixelFormat(dc, pixfmt, &pfd)) { panic("Failed to set the selected pixel format\n"); } if(!(ctx = wglCreateContext(dc))) { @@ -1453,7 +1459,6 @@ fail: static void create_window(const char *title) { int pixfmt; - PIXELFORMATDESCRIPTOR pfd = {0}; RECT rect; int width, height; @@ -1465,6 +1470,30 @@ static void create_window(const char *title) width = rect.right - rect.left; height = rect.bottom - rect.top; + memset(&pfd, 0, sizeof pfd); + pfd.nSize = sizeof pfd; + pfd.nVersion = 1; + pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER; + if(init_mode & GLUT_STEREO) { + pfd.dwFlags |= PFD_STEREO; + } + pfd.iPixelType = init_mode & GLUT_INDEX ? PFD_TYPE_COLORINDEX : PFD_TYPE_RGBA; + pfd.cColorBits = 24; + if(init_mode & GLUT_ALPHA) { + pfd.cAlphaBits = 8; + } + if(init_mode & GLUT_ACCUM) { + pfd.cAccumBits = 24; + } + if(init_mode & GLUT_DEPTH) { + pfd.cDepthBits = 24; + } + if(init_mode & GLUT_STENCIL) { + pfd.cStencilBits = 8; + } + pfd.iLayerType = PFD_MAIN_PLANE; + + if(create_window_wglext(title, width, height) == -1) { if(!(win = CreateWindow("MiniGLUT", title, WS_OVERLAPPEDWINDOW, @@ -1473,28 +1502,6 @@ static void create_window(const char *title) } dc = GetDC(win); - pfd.nSize = sizeof pfd; - pfd.nVersion = 1; - pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER; - if(init_mode & GLUT_STEREO) { - pfd.dwFlags |= PFD_STEREO; - } - pfd.iPixelType = init_mode & GLUT_INDEX ? PFD_TYPE_COLORINDEX : PFD_TYPE_RGBA; - pfd.cColorBits = 24; - if(init_mode & GLUT_ALPHA) { - pfd.cAlphaBits = 8; - } - if(init_mode & GLUT_ACCUM) { - pfd.cAccumBits = 24; - } - if(init_mode & GLUT_DEPTH) { - pfd.cDepthBits = 24; - } - if(init_mode & GLUT_STENCIL) { - pfd.cStencilBits = 8; - } - pfd.iLayerType = PFD_MAIN_PLANE; - if(!(pixfmt = ChoosePixelFormat(dc, &pfd))) { panic("Failed to find suitable pixel format\n"); } @@ -1525,7 +1532,7 @@ static void create_window(const char *title) reshape_pending = 1; } -static LRESULT CALLBACK handle_message(HWND win, unsigned int msg, WPARAM wparam, LPARAM lparam) +static HRESULT CALLBACK handle_message(HWND win, unsigned int msg, WPARAM wparam, LPARAM lparam) { static int mouse_x, mouse_y; int x, y, key; diff --git a/src/sdr.c b/src/sdr.c index cc577df..8e79cb5 100644 --- a/src/sdr.c +++ b/src/sdr.c @@ -101,6 +101,7 @@ unsigned int create_shader(const char *src, unsigned int sdr_type) glDeleteShader(sdr); sdr = 0; } + fflush(stderr); free(info_str); return sdr; @@ -269,6 +270,7 @@ int link_program(unsigned int prog) fprintf(stderr, info_str ? "linking failed: %s\n" : "linking failed\n", info_str); retval = -1; } + fflush(stderr); free(info_str); return retval;