Problems With First Tutorial

It’s sad when you copy/paste code and can’t get it to work . I tried to compile the first segment of code from “The Red Book”, but it didn’t work. It’s gotta be something wrong with setting up the workspace. Unfortunetely, the book gives no information on how to set up the code in the compiler. Anyway, here is the error message and the code.

Compiling…
MessinAround.cpp
c:\program files\microsoft visual studio\vc98\include\gl\gl.h(1152) : error C2144: syntax error : missing ‘;’ before type ‘void’
c:\program files\microsoft visual studio\vc98\include\gl\gl.h(1152) : error C2501: ‘WINGDIAPI’ : missing storage-class or type specifiers
c:\program files\microsoft visual studio\vc98\include\gl\gl.h(1152) : fatal error C1004: unexpected end of file found
Error executing cl.exe.

3DGL.exe - 3 error(s), 0 warning(s)

Here is the code from the tutorial.

#include <GL/gl.h>
#include <GL/glut.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. */
    }

if memory serves correctly, the windows.h needs to be included (before the GL/ headers).

other than that, make sure you have the proper libraries (opengl32.lib and glut32.lib) in your linker list – it’ll more than likely be your next error

[This message has been edited by dallas (edited 01-14-2001).]

Yeah i tried the code in my compiler and i got the same problem. But adding

#include <windows.h>

should fix your problem.

Thanks, yeah, that fixed it.

actually the whole point of glut is to be platform independant

remove gl\gl.h and just include gl\glut.h

glut automatically includes glu.h and gl.h