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 !