OpenGL and MFC

Started by
4 comments, last by SimonForsman 11 years, 10 months ago
Hello,
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
Advertisement
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)
[size="1"]I don't suffer from insanity, I'm enjoying every minute of it.
The voices in my head may not be real, but they have some good ideas!
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....

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.
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
static PIXELFORMATDESCRIPTOR pfd =
{
sizeof (PIXELFORMATDESCRIPTOR), // strcut size
1, // Version number
PFD_DRAW_TO_WINDOW | // Flags, draw to a window,
PFD_SUPPORT_OPENGL | // use OpenGL
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....
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).
[size="1"]I don't suffer from insanity, I'm enjoying every minute of it.
The voices in my head may not be real, but they have some good ideas!

This topic is closed to new replies.

Advertisement