Jump to content
  • Advertisement
Sign in to follow this  
Seroja

OpenGL WGL weird behavior

This topic is 4795 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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!

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!