Win32 and OpenGL setup preference

Started by
3 comments, last by GBGames 21 years, 7 months ago
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?
-------------------------GBGames' Blog: An Indie Game Developer's Somewhat Interesting ThoughtsStaff Reviewer for Game Tunnel
Advertisement
I''d have to see all your code to know what''s causing the slowdown on XP.

First, don''t use NULL instead of 0 unless YOU have defined NULL to be 0.

Second, WM_QUIT is not sent to the hWnd to the window that posted the quit message, so you have to use 0 as the second param if you''re using it to break out of the message loop.

About our other issues, I don''t really see a clear question. Basically, certain code needs to be called before the window is created, and certain code needs to be called after the window is created, but the absolute location is not really crucial. I personally detach as much of my processing from the WndProc as possible, simply creating and initializing from WinMain, and shutting down from the same once all the processing is done. The only thing my WndProc does is PostQuitMessage(0) in response to WM_CLOSE.

Later,
ZE.

//email me.//zealouselixir software.//msdn.//n00biez.//
miscellaneous links

[twitter]warrenm[/twitter]

I will make a comment about the slow down. I have heard rumors that windows is conspiring against OpenGl and they made it where OpenGl runs slower dont know if bill gates planed this but it is true OpenGL run about half the frame rate as similar directX games. You need to get the newest drivers for your card and go to opengl.org to ask the people there because I heard there is a windows creak that fixes the OpenGL creak Microsoft cam up with.
Pardon me, but WTF are you talking about? Microsoft may not be all over OpenGL, but they aren''t conspiring against it either, at least not in the way you suggest. If the issue really was driver related, it would be the fault of the driver creator, not of Microsoft.

Oh, and what''s a ''creak''?

Later,
ZE.

//email me.//zealouselixir software.//msdn.//n00biez.//
miscellaneous links

[twitter]warrenm[/twitter]

Not the case at all. I have used the programs that every tutorial I found mentioned, and they all run perfectly fine. Something was definitely wrong with my code itself. It just becomes more apparant in WinXP. The program running by itself in Win98 on my 300MHz laptop doesn''t have any noticeable run time issues, but when running the debug version from within VC++ 6.0, I do see Access Violation come up in the debug window. It concerned me but I didn''t see any problems until I tried to run it in WinXP, in which the program ran slowly.
Other OpenGL program that basically open a window and make it ready for OpenGL work perfectly fine in WinXP. My code makes it seem like the program is frozen most of the time. When I try to move the window, it does move...just five seconds later. Other windows move with no noticeable problems.
So MS is not out to get OpenGL...just my program! B-)
But seriously, I am going through some code and trying to determine what the problem is. Thanks for the help though!
-------------------------GBGames' Blog: An Indie Game Developer's Somewhat Interesting ThoughtsStaff Reviewer for Game Tunnel

This topic is closed to new replies.

Advertisement