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


OpenGL Win32 and OpenGL setup preference

Recommended Posts

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?

Share this post

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


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

Share this post

Link to post
Share on other sites
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 to ask the people there because I heard there is a windows creak that fixes the OpenGL creak Microsoft cam up with.

Share this post

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


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

Share this post

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

Share this post

Link to post
Share on other sites

  • Partner Spotlight

  • Forum Statistics

    • Total Topics
    • Total Posts
  • Similar Content

    • By xhcao
      Before using void glBindImageTexture(    GLuint unit, GLuint texture, GLint level, GLboolean layered, GLint layer, GLenum access, GLenum format), does need to make sure that texture is completeness. 
    • By cebugdev
      hi guys, 
      are there any books, link online or any other resources that discusses on how to build special effects such as magic, lightning, etc. in OpenGL? i mean, yeah most of them are using particles but im looking for resources specifically on how to manipulate the particles to look like an effect that can be use for games,. i did fire particle before, and I want to learn how to do the other 'magic' as well.
      Like are there one book or link(cant find in google) that atleast featured how to make different particle effects in OpenGL (or DirectX)? If there is no one stop shop for it, maybe ill just look for some tips on how to make a particle engine that is flexible enough to enable me to design different effects/magic 
      let me know if you guys have recommendations.
      Thank you in advance!
    • By dud3
      How do we rotate the camera around x axis 360 degrees, without having the strange effect as in my video below? 
      Mine behaves exactly the same way spherical coordinates would, I'm using euler angles.
      Tried googling, but couldn't find a proper answer, guessing I don't know what exactly to google for, googled 'rotate 360 around x axis', got no proper answers.
      The video shows the difference between blender and my rotation:
    • By Defend
      I've had a Google around for this but haven't yet found some solid advice. There is a lot of "it depends", but I'm not sure on what.
      My question is what's a good rule of thumb to follow when it comes to creating/using VBOs & VAOs? As in, when should I use multiple or when should I not? My understanding so far is that if I need a new VBO, then I need a new VAO. So when it comes to rendering multiple objects I can either:
      * make lots of VAO/VBO pairs and flip through them to render different objects, or
      * make one big VBO and jump around its memory to render different objects. 
      I also understand that if I need to render objects with different vertex attributes, then a new VAO is necessary in this case.
      If that "it depends" really is quite variable, what's best for a beginner with OpenGL, assuming that better approaches can be learnt later with better understanding?
    • By test opty
      Hello all,
      On my Windows 7 x64 machine I wrote the code below on VS 2017 and ran it.
      #include <glad/glad.h>  #include <GLFW/glfw3.h> #include <std_lib_facilities_4.h> using namespace std; void framebuffer_size_callback(GLFWwindow* window , int width, int height) {     glViewport(0, 0, width, height); } //****************************** void processInput(GLFWwindow* window) {     if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS)         glfwSetWindowShouldClose(window, true); } //********************************* int main() {     glfwInit();     glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);     glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);     glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);     //glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);     GLFWwindow* window = glfwCreateWindow(800, 600, "LearnOpenGL", nullptr, nullptr);     if (window == nullptr)     {         cout << "Failed to create GLFW window" << endl;         glfwTerminate();         return -1;     }     glfwMakeContextCurrent(window);     if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress))     {         cout << "Failed to initialize GLAD" << endl;         return -1;     }     glViewport(0, 0, 600, 480);     glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);     glClearColor(0.2f, 0.3f, 0.3f, 1.0f);     glClear(GL_COLOR_BUFFER_BIT);     while (!glfwWindowShouldClose(window))     {         processInput(window);         glfwSwapBuffers(window);         glfwPollEvents();     }     glfwTerminate();     return 0; }  
      The result should be a fixed dark green-blueish color as the end of here. But the color of my window turns from black to green-blueish repeatedly in high speed! I thought it might be a problem with my Graphics card driver but I've updated it and it's: NVIDIA GeForce GTX 750 Ti.
      What is the problem and how to solve it please?
  • Popular Now