Sign in to follow this  
rsood

OpenGL GLUT problem, or something else?

Recommended Posts

Hi, I recently decided to learn OpenGL. I have a copy of the OpenGL Programming Guide (4th edition), which uses GLUT. My first program I took pretty much straight from the first code example in the book (with some minor modification to get it to compile); here's the code:
#include <Gl\glut.h>

void WinDisplay(void){
    glClear(GL_COLOR_BUFFER_BIT);
    glColor3f(1.0, 1.0, 1.0);
    glBegin(GL_POLYGON);
    glVertex3f(0.25, 0.25, 0.0);
    glVertex3f(0.75, 0.25, 0.0);
    glVertex3f(0.75, 0.75, 0.0);
    glVertex3f(0.25, 0.75, 0.0);
    glEnd();
    glFlush();
}

void (*winDisplayFunc)(void) = &WinDisplay;

void initGlutWin(void){
    glClearColor(0.0, 1.0, 1.0, 0.0);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0);
}

int main(int argc, char* *argv){
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
    glutInitWindowSize(800, 600);
    glutInitWindowPosition(1, 1);
    glutCreateWindow(argv[0]);
    initGlutWin();
    glutDisplayFunc(winDisplayFunc);
    glutMainLoop();

return 0;
}

I encountered several problems when trying to run this. At first the program would always crash when glutDisplayFunc was passed the display function. This happened even when the code inside WinDisplay was commented out. I couldn't figure out what the problem was, so I downgraded my version of GLUT from the 3.7.6 that I had gotten on the maintainer's page to 3.7beta which I found on opengl.org (don't ask me why I thought this would work). I then got a new error upon running the program; a message box which read something like "Procedure entry point for SetPixelFormat could not be located in opengl.dll". I looked at what I could of opengl32.lib; it has a function wglSetPixelFormat but no SetPixelFormat. I then looked at the code of GLUT, and in glutint.h it has a line "#define SetPixelFormat wglSetPixelFormat". It was inside another ifdef though so it made me wonder if somewhere else in the code there was a reference to SetPixelFormat that didn't get replaced be wglSetPixelFormat when it was compiled. I haven't looked into that yet, because I've been trying to get my code to work, and if that was the problem, I'm thinking I would have to recompile GLUT (I use Borland C++ 5.5 rather than MSVC++, so that would probably be pretty time consuming). However, I also googled the problem and it seemed like other people who apparently weren't using GLUT were having the same issue (Procedure entry point for SetPixelFormat not found in opengl.dll) So is it a GLUT problem or isn't it? I downgraded again to GLUT 3.6 and now the program runs fine, but I'd still like to know what the problems were caused by. Thanks for any help.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Which version of the operating system are you using?
The OpenGL32.dll is the original one form Microsoft.
If so try upgrade it upgrading the video driver of your graphic adapter.

cheers

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Moreover at the end of the display function put a GlutPostRedisplay call.
The glFlush() seems to useless.

cheers

Share this post


Link to post
Share on other sites
Thanks for the replies.

I am using Windows XP, I just had to rename a copy of opengl32.dll to opengl.dll or the program complained about not being able to find opengl.dll. I also just reinstalled the operating system not too long ago and did all the updates, so the device driver for the graphics card should be the latest.

I think I see what you're saying with glutPostRedisplay (if I understand correctly, that posts a message to have the window update its contents), but would that really cause the program to crash if that function is not located in the WinDisplay function (that's the problem I was having when I was using GLUT 3.7.6)? I would think the window just wouldn't update its display.

I'm going to rephrase my question. Has anyone using GLUT 3.7.6 or 3.7beta encountered the same problems I have (program crashes when display function is passed to glutDisplayFunc, or a procedure entry point not being found in opengl.dll)? If so, what was the cause or how did you fix it? My program does work fine with GLUT 3.6.

Share this post


Link to post
Share on other sites
Renaiming opengl32.dll is not a good idea.
My advice is to download and install the most recent Driver for your 3D graphic card and to switch upon freeglut or OpenGLUT. GLUT is not maintained from a long time.
At present time I'm using freeglut.
Kind regards

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this