tomtetlaw -1 Posting Pro

When I try to call wglMakeCurrent, I get an access violation. My program only runs in one thread and one window, and I've got a valid device context and rendering context, I can't see what the problem is. I'm using VC++ 2010 and am running Widows 7 64-bit.

static HDC gl_devcontext;
static HGLRC gl_rcontext;

void _GL_Init (void)
{
	int pf;
	PIXELFORMATDESCRIPTOR pfd = {
		sizeof(PIXELFORMATDESCRIPTOR), 1,								
		PFD_DRAW_TO_WINDOW|PFD_SUPPORT_OPENGL|PFD_DOUBLEBUFFER, PFD_TYPE_RGBA, 32,								
		0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 32, 0, 0, PFD_MAIN_PLANE, 0, 0, 0, 0
	};

	gl_devcontext = GetDC (W_GetHandle());

	pf = ChoosePixelFormat (gl_devcontext, &pfd);
	if( !SetPixelFormat( gl_devcontext, pf, NULL ) )
		MessageBox (NULL, "Couldn't choose pixel format!", "Error", MB_OK);

	gl_rcontext = wglCreateContext( gl_devcontext );
	if( !wglMakeCurrent( gl_devcontext, gl_rcontext ) )
		MessageBox (NULL, "Couldn't set device context and rendering context!", "Error", MB_OK);
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.