Errors on opengl code with c++

Hi everyone, I urgently need help on this opengl code I compiled with c++. It gives errors:


Error E2040 opengl_simple.cpp 1: Declaration terminated incorrectly
Error E2206 opengl_simple.cpp 5: Illegal character '#' (0x23)
Error E2206 opengl_simple.cpp 22: Illegal character '#' (0x23)
Error E2323 opengl_simple.cpp 44: Illegal number suffix
*** 4 errors in Compile ***



1. //
2. // ex2.1-simple --- opengl_simple.cpp : A visual C++ console application
3. //
4. // only need to add following include file:
5. #include "stdafx.h"
6. // the rest is the same as the linux version
7./****************************************************************************
********
8. simple.c
9. This program essentially opens a window, clears it, draws the object, and
flushes the drawing buffer. It then goes into an infinite loop accepting
events and calling the appropriate functions.
10.VERSION
11.v1.00 - Created 17/04/2003
12.COMPILE simple.c under Linux machines using:
13.> gcc simple.c -o simple -lGLU -lglut -lGL -lm
14.RUN:
15.> simple
16.*****************************************************************************
*******/
17.
18.#include <GL/glut.g>
19.
20.void mydisplay()
21.{
22. // Clear the window
23. glClear(GL_COLOR_BUFFER_BIT);
24.
25. // specify polygon to be drawn and vertices of polygon
26. glBegin(GL_POLYGON);
27. glVertex2f(-0.5, -0.5);
28. glVertex2f(-0.5, 0.5);
29. glVertex2f(0.5, 0.5);
30. glVertex2f(0.5, -0.5)
31. glEnd();
32. // Flush the buffer to force drawing of all objects thus far
33. glFlush();
34. }
35.////////////////////////////////////////////////////////////////////////
36.//
37.// MAIN PROGRAM
38.//
39.////////////////////////////////////////////////////////////////////////
40.int main(int argc, char** argv) {
41. //create window called simple
42. glutCreateWindow("simple");
43. // Assign mydisplay() to be the function called whenever a display
44. // event occurs, generally after a resize of expose event
45. glutDisplayFunc(mydisplay);
46. //Enter infinite loop calling 'mydisplay'
47. glutMainLoop();
48.
49. return 0;
50. }
Last edited on
#include <GL/glut.g>

Is there actually any such file as this?
[ code ] [ /code ] tags please.

And that's pretty weird. Did you really use the right compiler? The compiler complains the number sign is illegal, which it isn't. Also, it thinks in line 1 there is a declaration (which it isn't either)
Last edited on
This line

glVertex2f(0.5, -0.5)

is missing a terminating semi-colon, but once that's fixed and the included header actually exists, and the numbers are removed from the beginning of every line, it happily compiles and runs as far as throwing up on itself because glutCreateWindow is called without first calling glutInit.

Whatever the OP is compiling, it's not the code posted.
Last edited on
Topic archived. No new replies allowed.