Crash on Window Creation

Hi All,

I’m just getting started with GLUT and I’m simply trying to run the first tutorial program in the OpenGL Programming Guide Redbook. The example is the window that draws a white rectangle and black background (Example 1.2).

The program crashes on the call to:
glutCreateWindow (“hello”);

The break references this line in glut.h (line 503):
static int APIENTRY glutCreateWindow_ATEXIT_HACK(const char *title) { return __glutCreateWindowWithExit(title, exit); }

I’m running Vista Ultimate 64-bit.

I’m new to GLUT and OpenGL and have no idea what’s wrong… Please help!

Anthony

Here’s the code:

#include <windows.h>
#include <gl/glut.h>
#include <gl/gl.h>

void display(void)
{
/* clear all pixels */
glClear (GL_COLOR_BUFFER_BIT);

/* draw white polygon (rectangle) with corners at

  • (0.25, 0.25, 0.0) and (0.75, 0.75, 0.0)
    */
    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();

/* don’t wait!

  • start processing buffered OpenGL routines
    */
    glFlush ();
    }

void init (void)
{
/* select clearing (background) color */
glClearColor (0.0, 0.0, 0.0, 0.0);

/* initialize viewing values */
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0);
}

/*

  • Declare initial window size, position, and display mode
  • (single buffer and RGBA). Open window with “hello”
  • in its title bar. Call initialization routines.
  • Register callback function to display graphics.
  • Enter main loop and process events.
    /
    int main(int argc, char
    * argv)
    {
    glutInit(&argc, argv);
    glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
    glutInitWindowSize (250, 250);
    glutInitWindowPosition (100, 100);
    glutCreateWindow (“hello”);
    init ();
    glutDisplayFunc(display);
    glutMainLoop();
    return 0; /* ISO C requires main to return int. */
    }

You may try to put this before including glut.h :
#define GLUT_DISABLE_ATEXIT_HACK

If this does not help, try with freeglut, which is drop-in replacement for glut but better maintained.

Thanks for the reply, but it didn’t work. Just giving me syntax errors on compile now:

1>c:\program files\microsoft sdks\windows\v6.0a\include\gl\glut.h(503) : error C2059: syntax error : ‘(’
1>c:\program files\microsoft sdks\windows\v6.0a\include\gl\glut.h(503) : error C2143: syntax error : missing ‘;’ before ‘{’
1>c:\program files\microsoft sdks\windows\v6.0a\include\gl\glut.h(503) : error C2447: ‘{’ : missing function header (old-style formal list?)

I’ll try freeglut…

So… I’ve been trying to get this thing to work with freeglut and still the same issue. I’ve tried 3 different IDE’s, 3 different computers. I can get it to work on my XP 32bit notebook and strangely another desktop which is nearly identical to this one (same processor, similar graphics card, also 64bit). I can literally copy the same code from one PC to another (same versions of glut, VC++, etc…) and it won’t work.

Please does anyone know what’s going on? I’m getting frustrated!!!

Anthony

I can literally copy the same code from one PC to another and it won’t work.

If you take the working compiled exe (and its dlls too !) to the other PC, does it also crash ?
This test will allow to find whether the problem is within the compilation env or the running env.

What do you mean, the dlls? If I remember there was a glut dll I had to put in my system folder, but that was the same file on both computers from the beginning.

Just copying the exe gives me the same problem…