void OpenGLWindow::CreateOGLWindow(int mode, HINSTANCE hInstance, WNDPROC windowsProcedure)
{
/* Create Window */
try{
// add in resolution switching and a switch/case statement for mode
CreateBaseWindow(hInstance, windowsProcedure, CS_HREDRAW | CS_VREDRAW, WS_OVERLAPPEDWINDOW | WS_SYSMENU, 100, 100, 800, 600);
}
catch(BaseWindowError bwe)
{
throw OpenGLWindowError(KString("Unable to create base window: ") + bwe.errorMsg, KString("CreateOGLWindow -> ") + bwe.triggerMethod,
KString("OpenGLWindow -> ") + bwe.triggerClass, KString(__FILE__) + KString(" -> ") + bwe.sourceFile, __LINE__);
}
/* Get Device Context */
window_hDC = GetDC(window_hWnd);
if(window_hDC == NULL)
throw OpenGLWindowError("Unable to get device context", "CreateOGLWindow", "OpenGLWindow", __FILE__, __LINE__);
/* Describe Pixel Format */
PIXELFORMATDESCRIPTOR pfd =
{
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, // 24-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
16, // 32-bit z-buffer
0, // no stencil buffer
0, // no auxiliary buffer
PFD_MAIN_PLANE, // main layer
0, // reserved
0, 0, 0 // layer masks ignored
};
/* Get and Set Pixel Format*/
int format = 0;
format = ChoosePixelFormat(window_hDC, &pfd);
if(format == 0)
throw OpenGLWindowError("Could not find pixel format", "CreateOGLWindow", "OpenGLWindow", __FILE__, __LINE__);
if(!SetPixelFormat( window_hDC, format, &pfd ))
throw OpenGLWindowError("Could not set pixel format", "CreateOGLWindow", "OpenGLWindow", __FILE__, __LINE__);
/* Get Rendering Context */
render_hRC = wglCreateContext( window_hDC );
if(render_hRC == NULL)
throw OpenGLWindowError("Could not get rendering context", "CreateOGLWindow", "OpenGLWindow", __FILE__, __LINE__);
/* Make Context Current*/
if(!wglMakeCurrent( window_hDC, render_hRC ))
throw OpenGLWindowError("Could not make rendering context current", "CreateOGLWindow", "OpenGLWindow", __FILE__, __LINE__);
/* Set Viewport */
RECT rect; // rectangle of window
GetWindowRect(window_hWnd, &rect);
glViewport(0, 0, rect.right - rect.left, rect.bottom - rect.top);
/* Set Projection and View */
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
Problem with Choosing Pixel Format
I''m having a problem with creating an OpenGL window. What happens is that regardless of what my pixel format description is, ChoosePixelFormat always returns zero. Everything before that point works perfectly. I''ve tried several PFDs, including ones that work from downloaded tutorial/example source. Any ideas as to what is causing my problems? Thanks.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement