I am setting up OpenGL in a base template code for myself so that I don''t have to worry about setting it up every time I start a project.
However I noticed that the code I used to have, when running the program through VC++ 6.0, will say something about access violations in the debug window. The program runs fine in Win98, but in WinXP I noticed that it runs very slowly.
The program is a simple window with a black background...and that''s it! So something is screwy.
I then compiled the NeHe tutorial that also sets up a window with a plain background only. It runs fine in both OSes.
So clearly there was something wrong with my code. I basically took the basic code that was in OpenGL Game Programming and apparantly in my modifications to make a basic window I messed up something bad enough that it acts buggy but not bad enough to cause an error.
I was comparing the different Win32/OpenGL tutorials and found that in my code I was using hwnd in my PeekMessages() function while in NeHe''s code he was not. Rather NeHe used NULL in its place:
// My code
PeekMessage(&msg, hwnd, NULL,NULL,PM_REMOVE);
//NeHe''s code
PeekMessage(&msg, NULL,0,0,PM_REMOVE);
Why the disparity in the code?
Also while comparing other tutorials I noticed that the rendering contexts are wglCreated and wglDeleted in slightly different ways.
One tutorial I read created separate functions for doing so:
// PIXELFORMATDESCRIPTOR pfd is defined in this function
// and then the render context is created and set
void EnableOpenGL(HWND hWnd, HDC * hDC, HGLRC * hRC);
// deletes the current context and releases hDC
void DisableOpenGL(HWND hWnd, HDC hDC, HGLRC hRC);
What is interesting is that it calls EnableOpenGL() right before the main loop that every program had in common. The WndProc in that tutorial returned 0 for the WM_CREATE and WM_CLOSE messages. The WM_CLOSE message also PostQuitMessage(0) before returning 0. After the program exits the main loop, there were two functions called:
DisableOpenGL() and DestroyWindow() which had parameters but I won''t type them out here.
Another tutorial creates the context and such in the WndProc callback function, after the message WM_CREATE is sent to the program. That tutorial releases the context when WM_CLOSE is sent.
Now in general from reading this I see what they all have in common and they aren''t much different at all, but I would like to know if anyone has a preference or if one offers an advantage over the other?