From 9fb38f56959cd8a6d64c8e9ff0d034b1aefb5215 Mon Sep 17 00:00:00 2001 From: lecoanet Date: Tue, 21 Sep 2004 08:40:25 +0000 Subject: One more attempt towards a truly working GL initialization code. --- generic/tkZinc.c | 133 ++++++++++++++++++++++++++++--------------------------- 1 file changed, 67 insertions(+), 66 deletions(-) (limited to 'generic') diff --git a/generic/tkZinc.c b/generic/tkZinc.c index 6465a31..21221d0 100644 --- a/generic/tkZinc.c +++ b/generic/tkZinc.c @@ -992,72 +992,7 @@ InitRendering1(ZnWInfo *wi) ZnGLContext gl_context; if (wi->render) { -# ifdef _WIN32 - /* - * Look for a matching context already available. - */ - ce = ZnGetGLContext(wi->dpy); - if (ce) { - gl_context = ce->context; - ce->hwnd = Tk_GetHWND(Tk_WindowId(wi->win)); - ce->hdc = GetDC(ce->hwnd); - ZnListAdd(ce->widgets, &wi, ZnListTail); - SetPixelFormat(ce->hdc, ce->ipixel, &ce->pfd); - } - else { - ce = ZnMalloc(sizeof(ZnGLContextEntry)); - ce->hwnd = Tk_GetHWND(Tk_WindowId(wi->win)); - ce->hdc = GetDC(ce->hwnd); - ce->widgets = ZnListNew(1, sizeof(ZnWInfo *)); - ZnListAdd(ce->widgets, &wi, ZnListTail); - - memset(&ce->pfd, 0, sizeof(PIXELFORMATDESCRIPTOR)); - ce->pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR); - ce->pfd.nVersion = 1; - ce->pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER; - ce->pfd.iPixelType = PFD_TYPE_RGBA; - ce->pfd.cRedBits = 8; - ce->pfd.cGreenBits = 8; - ce->pfd.cBlueBits = 8; - ce->pfd.cAlphaBits = 8; - ce->pfd.cStencilBits = 8; - ce->pfd.iLayerType = PFD_MAIN_PLANE; - ce->ipixel = ChoosePixelFormat(ce->hdc, &ce->pfd); - /*printf("ipixel=%d dwFlags=0x%x req=0x%x iPixelType=%d hdc=%d\n", - ce->ipixel, ce->pfd.dwFlags, - PFD_DRAW_TO_WINDOW|PFD_SUPPORT_OPENGL|PFD_DOUBLEBUFFER, - ce->pfd.iPixelType==PFD_TYPE_RGBA, - ce->hdc);*/ - if (!ce->ipixel || - (ce->pfd.cRedBits != 8) || (ce->pfd.cGreenBits != 8) || (ce->pfd.cBlueBits != 8) || - (ce->pfd.cStencilBits != 8)) { - fprintf(stderr, "ChoosePixelFormat failed\n"); - } - - if (SetPixelFormat(ce->hdc, ce->ipixel, &ce->pfd) == TRUE) { - gl_context = wglCreateContext(ce->hdc); - if (gl_context) { - ce->context = gl_context; - ce->dpy = wi->dpy; - ce->max_tex_size = 64; /* Minimum value is always valid */ - ce->max_line_width = 1; - ce->max_point_width = 1; - ce->next = gl_contexts; - gl_contexts = ce; - } - else { - fprintf(stderr, "wglCreateContext failed\n"); - ZnFree(ce); - } - } - else { - ZnFree(ce); - } - } - ReleaseDC(ce->hwnd, ce->hdc); - -# else /* _WIN32 */ - +# ifndef _WIN32 XVisualInfo *gl_visual = NULL; Colormap colormap = 0; @@ -1144,10 +1079,76 @@ static void InitRendering2(ZnWInfo *wi) { ZnGLContextEntry *ce; + ZnGLContext gl_context; GLfloat r[2]; /* Min, Max */ GLint i[1]; if (wi->render) { +# ifdef _WIN32 + /* + * Look for a matching context already available. + */ + ce = ZnGetGLContext(wi->dpy); + if (ce) { + gl_context = ce->context; + ce->hwnd = Tk_GetHWND(Tk_WindowId(wi->win)); + ce->hdc = GetDC(ce->hwnd); + ZnListAdd(ce->widgets, &wi, ZnListTail); + SetPixelFormat(ce->hdc, ce->ipixel, &ce->pfd); + } + else { + ce = ZnMalloc(sizeof(ZnGLContextEntry)); + ce->hwnd = Tk_GetHWND(Tk_WindowId(wi->win)); + ce->hdc = GetDC(ce->hwnd); + ce->widgets = ZnListNew(1, sizeof(ZnWInfo *)); + ZnListAdd(ce->widgets, &wi, ZnListTail); + + memset(&ce->pfd, 0, sizeof(PIXELFORMATDESCRIPTOR)); + ce->pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR); + ce->pfd.nVersion = 1; + ce->pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER; + ce->pfd.iPixelType = PFD_TYPE_RGBA; + ce->pfd.cRedBits = 8; + ce->pfd.cGreenBits = 8; + ce->pfd.cBlueBits = 8; + ce->pfd.cAlphaBits = 8; + ce->pfd.cStencilBits = 8; + ce->pfd.iLayerType = PFD_MAIN_PLANE; + ce->ipixel = ChoosePixelFormat(ce->hdc, &ce->pfd); + /*printf("ipixel=%d dwFlags=0x%x req=0x%x iPixelType=%d hdc=%d\n", + ce->ipixel, ce->pfd.dwFlags, + PFD_DRAW_TO_WINDOW|PFD_SUPPORT_OPENGL|PFD_DOUBLEBUFFER, + ce->pfd.iPixelType==PFD_TYPE_RGBA, + ce->hdc);*/ + if (!ce->ipixel || + (ce->pfd.cRedBits != 8) || (ce->pfd.cGreenBits != 8) || (ce->pfd.cBlueBits != 8) || + (ce->pfd.cStencilBits != 8)) { + fprintf(stderr, "ChoosePixelFormat failed\n"); + } + + if (SetPixelFormat(ce->hdc, ce->ipixel, &ce->pfd) == TRUE) { + gl_context = wglCreateContext(ce->hdc); + if (gl_context) { + ce->context = gl_context; + ce->dpy = wi->dpy; + ce->max_tex_size = 64; /* Minimum value is always valid */ + ce->max_line_width = 1; + ce->max_point_width = 1; + ce->next = gl_contexts; + gl_contexts = ce; + } + else { + fprintf(stderr, "wglCreateContext failed\n"); + ZnFree(ce); + } + } + else { + ZnFree(ce); + } + } + ReleaseDC(ce->hwnd, ce->hdc); +#endif + ce = ZnGLMakeCurrent(wi->dpy, wi); glGetFloatv(ZN_GL_LINE_WIDTH_RANGE, r); ce->max_line_width = r[1]; -- cgit v1.1