WGL weird behavior

Started by
0 comments, last by Seroja 18 years, 10 months ago
I have made a whole routine to set up and handle OpenGL context on windows. Almost everything works well, but almost... 1) SetPixelFormat: The usual way of setting pixel format would be: hPix = ChoosePixelFormat(hDC, PixFmt) SetPixelFormat(hDC, hPix, PixFmt) hGLRC = wglCreateContext(hDC) wglMakeCurrent(hDC, hGLRC) However, it doesn't. If I run it this way, SetPixelFormat won't actually set it, but won't generate an error as well. Thus, wglCreateContext will raise error 2000 (invalid pixel format) and hGLRC will be 0. I have found my way around this: hPix = ChoosePixelFormat(hDC, PixFmt) wglCreateContext(hDC) ' This was added SetPixelFormat(hDC, hPix, PixFmt) hGLRC = wglCreateContext(hDC) wglMakeCurrent(hDC, hGLRC) The first wglCreateContext raises error 2000, but after that, SetPixelFormat works successfully and the second wglCreateContext returns a valid handle. Any idea why it works this way? I think it shouldn't, am I missing something important? 2) wglSwapBuffers: I'm trying to implement pausing to the rendering. That is, after the main loop has been initiated, if the window is hidden (e.g. Alt-Tabbing) the rendering should pause. I've tried doing it by just doing nothing in the loop. That didn't work, wglSwapBuffers just didn't actually do anything after I unpaused - the screen stopped getting updated. It does work if during pause I continue to swap buffers, but I don't like that. I found out that it is somehow related to glClear. If during the loop I call glClear(GL_COLOR_BUFFER_BIT + GL_DEPTH_BUFFER_BIT), without calling wglSwapBuffers during pause, I can unpause later. However, I don't like it either, and it takes about a second to reactivate (not immediate) in that way. Has anyone had those problems before? Any help? Thanks in advance!
Advertisement
Finally figured out #2 by myself. I used .Net Drawing.Graphics to get the handle to the device context. At the beginning the handle didn't work at all, later I managed to fix it. It seemed to work, but it still gave the bug of SwapBuffers. Returning to Win32 API - GetDC fixed it.

I still have no idea about #1. Any help?

This topic is closed to new replies.

Advertisement