GL context and matrix operations (Win32)

Hello!

In my program I perform scene rotation when pressing corresponding keys. AFAIK prior to calling GL commands, an operable GL context must be made current, so in my rotating procedure I get HDC for my window first, then get beforehand created HGLRC context for the given HDC, call matrix transformation functions and release both context in reverse order it were acquired.

The procedure code looks like the following:

void rotate_orient(bool dir,float* axis)
{
	HDC hdc;
	HGLRC hrc;

	hdc=GetDC(hWnd);
	wglMakeCurrent(hdc,hrc);
	glMatrixMode(GL_MODELVIEW);
	glRotatefv((dir?1:-1)*DELTA_ANGLE,cur_rot_axis); 
	store_orient(); 
	wglMakeCurrent(NULL,NULL);
	ReleaseDC(hWnd,hdc);
}
 

However, glMatrixMode gives an GL_INVALID_OPERATION error, which seems to me because of unproper context acquiring (although wglMakeCurrent returns TRUE). When I tried to declare hrc as static, wglMakeCurrent returned FALSE.
Do you have any idea how to fix it?

Thanks for your answers!

You’re passing an uninitialized variable to wglMakeCurrent. The last parameter is the rendering context you want to make current, but since it’s not initialized, it’s not a valid rendering context.

Oops… I really should have RTFM first. Anyway thanks for your help.