PDA

View Full Version : wglMakeCurrent question



jdz_simon
10-17-2004, 02:50 AM
I am so bored for my OpenGL program---- just a little program.

I render my QUAD with a texture ,this is ONLY function of my program.
But ,but , I get error when I use wglMakeCurrent(NULL,NULL), the error information is "GL_INVALID_OPERATION" , the OnDraw function as follows:
void CMyView::init()
{
int n;
static PIXELFORMATDESCRIPTOR pfd=
{
sizeof(PIXELFORMATDESCRIPTOR),
1,
PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL |PFD_DOUBLEBUFFER,// Format Must Support OpenGL
PFD_TYPE_RGBA,
24,
0,0,0,0,0,0,
0,
0,
0,
0,0,0,0,
32,
0,
0,
PFD_MAIN_PLANE,
0,
0,0,0
};
m_hDC =::GetDC(m_hWnd);
int pixelformat;
if((pixelformat=ChoosePixelFormat(m_hDC,&pfd))==0)
{
MessageBox("ChoosePixelFormat failed");

}
if(SetPixelFormat(m_hDC,pixelformat,&pfd)==FALSE)
{
MessageBox("SetPixelFormat failed");

}

n=::GetPixelFormat(m_hDC);
::DescribePixelFormat(m_hDC,n,sizeof(pfd),&pfd);
hrc=wglCreateContext(m_hDC);
wglMakeCurrent(m_hDC,hrc);

GetClientRect(&m_oldRect);
glClearDepth(1.0f);

glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LESS);

::ReleaseDC(m_hWnd,m_hDC);

}
void CMyView::DrawScene()
{
m_hDC = ::GetDC(m_hWnd);
wglMakeCurrent(m_hDC,hrc);

glClearColor(0.0f, 0.0f, 1.0f, 1.0);
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

glLoadIdentity();

glFinish();

SwapBuffers(m_hDC);//wglGetCurrentDC());
wglMakeCurrent(NULL,NULL);
GLenum err = glGetError();
::ReleaseDC( m_hWnd, m_hDC);
}

I must release the hrc ,because I have another dialog wanted use another OpenGL RC for rendering . So, In order to eliminate the interference with the CMyView ,I think I need wglMakeCurrent(NULL,NULL), please Help me !!! Thanks a lot !

jdz_simon
10-17-2004, 03:14 AM
I comment out the sentence "wglMakeCurrent(NULL,NULL)", the return value of glGetError() is 0 ----Normal. I think wglMakeCurrent works wrong, but I can't solve it .

jdz_simon
10-17-2004, 05:01 PM
surely, I can solve it by myself , thanks

secnuop
10-17-2004, 08:35 PM
glGetError(), or any GL call for that matter, is invalid if there is no context current. Since there isn't a context current after wglMakeCurrent(NULL,NULL), you cannot call glGetError() to see if the operation succeeded.

Instead, check the return value from wglMakeCurrent(). If wglMakeCurrent() returns TRUE no error has occurred, otherwise an error has occurred and you can call GetLastError() to get more information.

See MSDN for more info.