🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Tutorial 1 problem

Started by
4 comments, last by gan 18 years, 4 months ago
Hi all, I'm trying to advance my C++ skills past the "Intro" books, and decided to give the NeHe tutorials a try. I typed up the first tutorial, compiled, linked, and built it. Then when I run the program one of the error catchers trips. "Can't create a GL rendering context." from this code:
	if (!(hRC=wglCreateContext(hDC))) // Are we able to get a rendering context?
	{
		KillGLWindow(); //Reset the display
		MessageBox(NULL,"Can't create a GL rendering context.", "ERROR", MB_OK | MB_ICONEXCLAMATION);
		return FALSE;
	}
Can anyone explain what's going on and how to fix it? Thanks
Advertisement
Quote: Original post by enigma555

"Can't create a GL rendering context."

from this code:

	if (!(hRC=wglCreateContext(hDC))) // Are we able to get a rendering context?	{		KillGLWindow(); //Reset the display		MessageBox(NULL,"Can't create a GL rendering context.", "ERROR", MB_OK | MB_ICONEXCLAMATION);		return FALSE;	}


Thanks


I think it's because : (hRC=wglCreateContext(hDC))= false, this happened could be a lot of reason, maybe you need to get the last error.
wglCreateContext
GetLastError

Thanks for helping!

OK. I added in a GetLastError() line and with a breakpoint got error# 2000 which says that the pixel format is invalid.

Here is the code relating to that section.

	static PIXELFORMATDESCRIPTOR pfd= //pfd tells windows how we want things to be	{		sizeof(PIXELFORMATDESCRIPTOR), // size of this pixel format descriptor			1, // Version number			PFD_DRAW_TO_WINDOW | //Format must support window			PFD_SUPPORT_OPENGL | //Format must support OpenGL			PFD_DOUBLEBUFFER, //Must support double buffering			PFD_TYPE_RGBA, //Request an RGBA format			bits, //select our 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, //Accumulation bits ignored			16, //16Bit Z-Buffer (Depth Buffer)			0, //No Stencil buffer			0, //No auxiliary buffer			PFD_MAIN_PLANE, //Main drawing layer			0, //Reserved			0, 0, 0 //Layer Masks Ignored	};	if (!(hDC=GetDC(hWnd))) //Did we get a device context?	{		KillGLWindow(); //Reset the display		MessageBox(NULL,"Can't create a GL device context.", "ERROR", MB_OK | MB_ICONEXCLAMATION);		return FALSE;	}	if (!(PixelFormat=ChoosePixelFormat(hDC, &pfd))) //Did windows find a matching pixel format?	{		KillGLWindow(); //Reset the display		MessageBox(NULL,"Can't set the PixelFormat.", "ERROR", MB_OK | MB_ICONEXCLAMATION);		return FALSE;	}	if (!(hRC=wglCreateContext(hDC))) // Are we able to get a rendering context?	{		ertest=GetLastError();		KillGLWindow(); //Reset the display		MessageBox(NULL,"Can't create a GL rendering context.", "ERROR", MB_OK | MB_ICONEXCLAMATION);		return FALSE;	}


How do I get the scrollable window?
Bleh. Found the problem. I must have looked right past the part of code where it set the pixel format.

Thanks for showing me that error checking command! I appreciate it!
I don't think I've ever experienced that much joy from displaying a black screen!
Quote: Original post by enigma555

How do I get the scrollable window?


Window class

This topic is closed to new replies.

Advertisement