Jump to content
  • Advertisement
Sign in to follow this  

OpenGL OpenGL and MFC

This topic is 2324 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 been trying to use opengl in a mfc dialog box. I accomplished the task in the first dialog box. But if I open another dialog box from my main dialog box, I'm not able to use opengl in it. I have used the same method for opengl in the 2nd dialog box also, but it is not displaying anything. Could anyone please help me with it.

Thank you

Share this post

Link to post
Share on other sites
each thread in your process can only have 1 active context at the time, either use multiple render threads (one per context) or call wglMakeCurrent to switch context before you try to render to it.

If your problem is caused by something else you might want to post a minimal example that produces the same flawed result (or your current code if its reasonably small) Edited by SimonForsman

Share this post

Link to post
Share on other sites
thank you for your help.... but i have already used wglMakeCurrent function.... m not facing any error... its just that i am not able to render opengl in my 2nd window....

Share this post

Link to post
Share on other sites

but i have already used wglMakeCurrent function....

How are you using it? Are you calling it each time a dialog becomes active, making sure to use the context associated with that dialog? If you don't show any code, all anyone can do is guess.

Share this post

Link to post
Share on other sites
actually the code s big... i have used many classes.... this is the part where i have used wglMakeCurrent

void COpenGL::Init(HDC the_device_context)
// Initialise OpenGL

// Get a DC for the OpenGL render window
m_hDC = the_device_context;

// Set the pixel format for this DC
sizeof (PIXELFORMATDESCRIPTOR), // strcut size
1, // Version number
PFD_DRAW_TO_WINDOW | // Flags, draw to a window,
PFD_DOUBLEBUFFER, // double buffered
PFD_TYPE_RGBA, // RGBA pixel values
32, // 32-bit color
0, 0, 0, // RGB bits & shift sizes.
0, 0, 0, // Don't care about them
0, 0, // No alpha buffer info
0, 0, 0, 0, 0, // No accumulation buffer
32, // 32-bit depth buffer
0, // No stencil buffer
0, // No auxiliary buffers
PFD_MAIN_PLANE, // Layer type
0, // Reserved (must be 0)
0, // No layer mask
0, // No visible mask
0 // No damage mask

int nMyPixelFormatID = ChoosePixelFormat( m_hDC, &pfd );

SetPixelFormat( m_hDC, nMyPixelFormatID, &pfd );

// get a render context for OpenGL
m_hRC = wglCreateContext(m_hDC);
wglMakeCurrent (m_hDC, m_hRC);

this is the initialization of my opengl class........ whatelse is required please let me know....

Share this post

Link to post
Share on other sites
you need to call wglMakeCurrent whenever you switch between your contexts. (so twice per frame if you got 2 OpenGL render contexts or device contexts). (only calling it on initialization would just make the last initialized RC/DC active). Edited by SimonForsman

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!