I´m Andreu and I´m getting started with OpenGL. My operating system is Mac OS 10.6 and I´m using Netbeans to write my C++ code.
I found this code in a Computer Graphics textbook. However, I have many compilation errors and I´ve been surfing literally a myriad of forums and I don´t know what to do.
#include <iostream> #include <stdio.h> #include <OpenGL/gl.h> void myinit(){ glClearColor(1.0,1.0,1.0,1.0); glColor3f(1.0,0.0,0.0); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluOrtho2D(0.0,50.0,0.0,50.0); glMatrixMode(GL_MODELVIEW); } void display(){ GLfloat vertices[3][2]={{0.0,0.0},{25.0,50.0},{50.0,0.0}}; int i, j, k; int rand(); GLfloat p[2]={7.5,5.0}; glClear(GL_COLOR_BUFFER_BIT); glBegin(GL_POINTS); for(k=0; k<5000; k++){ j=rand()*3; p[0]=(p[0]+vertices[j][0])/2.0; p[1]=(p[1]+vertices[j][1])/2.0; glVertex2fv(p); } glEnd(); glFlush(); } int main(int argc, char** argv) { glutInit(&argc,argv); glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); glutInitWindowSize(500,500); glutInitWindowPosition(0,0); glutCreateWindow("Sierpinski Gasket"); glutDisplayFunc(display); myinit(); glutMainLoop(); }
My compilation errors are:
main.cpp: In function 'void myinit()': main.cpp:13: error: 'gluOrtho2D' was not declared in this scope main.cpp: In function 'int main(int, char**)': main.cpp:38: error: 'glutInit' was not declared in this scope main.cpp:39: error: 'GLUT_SINGLE' was not declared in this scope main.cpp:39: error: 'GLUT_RGB' was not declared in this scope main.cpp:39: error: 'glutInitDisplayMode' was not declared in this scope main.cpp:40: error: 'glutInitWindowSize' was not declared in this scope main.cpp:41: error: 'glutInitWindowPosition' was not declared in this scope main.cpp:42: error: 'glutCreateWindow' was not declared in this scope main.cpp:43: error: 'glutDisplayFunc' was not declared in this scope main.cpp:45: error: 'glutMainLoop' was not declared in this scope make[2]: *** [build/Debug/GNU-MacOSX/main.o] Error 1 make[1]: *** [.build-conf] Error 2 make: *** [.build-impl] Error 2
I´d appreciate your help very much. I will attach my code in case it is necessary.
Thank you.