Nehe lesson 1"Can't Create A GL Device Context."

Started by
3 comments, last by Tompa 20 years, 5 months ago
After doing this tutorial I get this error "Can''t Create A GL Device Context." This error is called like this: 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; // Return FALSE } What does GetDC do, why and when will it return false? Anyone?
Advertisement
GetDC() returns a handle to a device context of a window's client area. When it fails it returns a zero. You need that device context for creating a render context and for the SwapBuffers() function.

For all things windows, MSDN is your friend.

[edited by - microdot on October 23, 2003 5:27:29 AM]
<span class="smallfont">That is not dead which can eternal lieAnd with strange aeons even death may die.   -- "The Nameless City" - H. P. Lovecraft</span>
After a while now I realize that it's not the above code that gives me the error, it's a few lines below and it goes like this:
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; // Return FALSE
}

Does this make more sense for anyone?

Thanks for the MSDN hint by the way...

EDIT: My eyes are not whith me today... The error message in the topic is not the correct one... "Can't Create A GL Rendering Context." is the correct one. To be honest, I'm not sure if it was that fault to begin with... I might have fixed the first one, just to run into another...




[edited by - Tompa on October 23, 2003 5:47:35 AM]
hdc is a device context and it is used to draw on window

hrc is a rendering context and it is related to OpenGL

before create a hrc you need to choose the pixel format and set the pixel format for the hdc (that is describe bpp, Zbuffer depth, and other things).
I think you get an error (a false return) from SetPixelFormat()
or you pass a wrong pixelformat index to this function. See also ChoosePixelFormat() and checks that it returns an index != 0
Finally if you continue to get errors you can try to change your PIXELFORMATDESC...I use this as default (it works everywhere)(maybe)

static PIXELFORMATDESCRIPTOR defPFD = {sizeof(PIXELFORMATDESCRIPTOR),  // size of this pfd1,                              // version numberPFD_DRAW_TO_WINDOW |            // support windowPFD_SUPPORT_OPENGL |		// support OpenGLPFD_DOUBLEBUFFER,		// double bufferedPFD_TYPE_RGBA,                  // RGBA type32,                             // n-bit color depth0, 0, 0, 0, 0, 0,               // color bits ignored0,                              // no alpha buffer0,                              // shift bit ignored0,                              // no accumulation buffer0, 0, 0, 0,                     // accum bits ignored32,                             // n-bit z-buffer0,                              // no stencil buffer0,                              // no auxiliary bufferPFD_MAIN_PLANE,                 // main layer0,                              // reserved0, 0, 0                         // layer masks ignored};


THANK YOU!!!

As I said my eyes were not with me... I had totally missed to even call SetPixelFormat...
You made it come to my attention. Thanks again!
Now it works just like it should!

This topic is closed to new replies.

Advertisement