Original Post
Ok, I've just started on OpenGL and I'm already having problems. My attempt to create a tester OpenGL window has failed. I just want a prog that'll create an OpenGL window.
I'm working in VC++ 6, on Windows XP. Here's my rough code:
#include <windows.h>
#include <GL\GL.h>
#include <GL\GLU.h>
#include <GL\GLaux.h>
HGLRC hRC=NULL;
LRESULT WINAPI MsgProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam )
{
switch( msg )
{
case WM_DESTROY:
PostQuitMessage( 0 );
return 0;
}
return DefWindowProc( hWnd, msg, wParam, lParam );
}
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
// TODO: Place code here.
// Set up a WNDCLASSEX class to store information about the style of window to be created
WNDCLASSEX wc = { sizeof(WNDCLASSEX), CS_OWNDC | CS_HREDRAW | CS_VREDRAW, MsgProc, 0L,
0L, GetModuleHandle(NULL), NULL, NULL, NULL, NULL,
"OpenGL Test", NULL };
RegisterClassEx(&wc);
HWND hWnd = CreateWindow( "OpenGL Test", "OpenGL Test 1", WS_OVERLAPPEDWINDOW, 200, 200, 300, 300,
NULL, NULL, NULL, NULL);
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
16, // 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
};
HDC hDC = GetDC(hWnd);
DescribePixelFormat(hDC, GetPixelFormat(hDC), sizeof(PIXELFORMATDESCRIPTOR), &pfd);
GLuint PixelFormat = ChoosePixelFormat(hDC, &pfd);
if(!SetPixelFormat(hDC, PixelFormat, &pfd))
{
hRC = wglCreateContext(hDC);
wglMakeCurrent(hDC, hRC);
ShowWindow(hWnd, SW_SHOWNORMAL);
MSG msg;
ZeroMemory(&msg, sizeof(MSG));
GetMessage(&msg, hWnd, NULL, NULL);
while (msg.message != WM_QUIT)
{
TranslateMessage(&msg);
DispatchMessage(&msg);
GetMessage(&msg, hWnd, NULL, NULL);
}
}
wglMakeCurrent(NULL,NULL);
wglDeleteContext(hRC);
ReleaseDC(hWnd,hDC);
DestroyWindow(hWnd);
UnregisterClass("OpenGl Test", hInstance);
return 0;
}
I know the program fails at "SetPixelFormat(hDC, PixelFormat, &pfd))".
So, is it my code? Is it XP? Or what? Please help!!
[edited by - Dougie on March 27, 2004 9:37:28 AM]