PDA

View Full Version : Using OpenGL to render in multiple Views of a same Window



tauseef_xavi
03-29-2017, 08:52 AM
Hi!

I am working on a MFC Project. Within my application Ih vae Multiple Views (CView). I am already rendering 3D content in one of the views. Now I am trying to render 2D images within another View using OpenGL. But I am getting Invalid Operation in the second view.


void CImageMainView::InitializeOpenGL()
{
m_pDC = new CClientDC(this);
m_hDC = m_pDC->GetSafeHdc();

SetupPixelFormat();
m_hRC = ::wglCreateContext(m_hDC);

BOOL ret = ::wglMakeCurrent(m_hDC, m_hRC);
if(!ret){
printf("Error making current context\n");
}
printf("wglMakeCurrent ");
CheckGLError();
GetOpenGLExtendedInformation();
::wglMakeCurrent(NULL, NULL);
printf("wglMakeCurrent to null");
CheckGLError();

return;
}

void CImageMainView::SetupPixelFormat()
{
static PIXELFORMATDESCRIPTOR pfd =
{
sizeof(PIXELFORMATDESCRIPTOR), // size of this pfd
1, // version number
PFD_DRAW_TO_WINDOW | // support window
PFD_SUPPORT_OPENGL | // support OpenGL
PFD_DOUBLEBUFFER, // double buffered
PFD_TYPE_RGBA, // RGBA type
24, // 24-bit color depth
0, 0, 0, 0, 0, 0, // color bits ignored
0, // no alpha buffer
0, // shift bit ignored
0, // no accumulation buffer
0, 0, 0, 0, // accum bits ignored
32, // 32-bit z-buffer
0, // no stencil buffer
0, // no auxiliary buffer
PFD_MAIN_PLANE, // main layer
0, // reserved
0, 0, 0 // layer masks ignored
};

m_PixelFormat = ::ChoosePixelFormat(m_hDC, &pfd);
::SetPixelFormat(m_hDC, m_PixelFormat, &pfd);

return;
}

Dark Photon
03-30-2017, 07:11 AM
I am getting Invalid Operation in the second view.

So where exactly do you see a GL error? What have you done to try and determine which call is throwing the GL_INVALID_OPERATION? Which call is that? Have you stepped through the code to ensure that it seems to be performing properly prior to the GL error being thrown?

Your comments for the field values in the PIXELFORMATDESCRIPTOR appear to be out-of-sync with the fields, but given the values you specify that's just a code readability hit, not a functional hit.

So you are requesting a 24-bit color 32-bit depth double-buffered window. On your driver, are you for sure getting a valid pixel format back for that? I ask because here on the latest NVidia GL drivers (with a recent GPU, in Windows), I do not see 24-bit color nor 32-bit depth listed as options for the valid pixel formats. Try requesting a 24-bit depth. If not that, try 32-bit color + 24-bit depth.