Archived

This topic is now archived and is closed to further replies.

Tompa

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

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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 pfd

1, // version number


PFD_DRAW_TO_WINDOW | // support window

PFD_SUPPORT_OPENGL | // support OpenGL

PFD_DOUBLEBUFFER, // double buffered


PFD_TYPE_RGBA, // RGBA type

32, // n-bit 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, // accum bits ignored

32, // n-bit z-buffer

0, // no stencil buffer

0, // no auxiliary buffer

PFD_MAIN_PLANE, // main layer

0, // reserved

0, 0, 0 // layer masks ignored

};



Share this post


Link to post
Share on other sites
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!

Share this post


Link to post
Share on other sites