PDA

View Full Version : Problems With First Tutorial



SilentStrike
01-14-2001, 04:23 PM
It's sad when you copy/paste code and can't get it to work http://www.opengl.org/discussion_boards/ubb/wink.gif. 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. */
}

dallas
01-14-2001, 04:39 PM
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 http://www.opengl.org/discussion_boards/ubb/smile.gif

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

ninja770
01-15-2001, 03:38 PM
Yeah i tried the code in my compiler and i got the same problem. But adding

#include <windows.h>

should fix your problem.

SilentStrike
01-15-2001, 04:05 PM
Thanks, yeah, that fixed it.

krisvh
01-16-2001, 08:45 AM
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