-
March 14th, 2009, 03:19 PM
#1
Trouble with OpenGL tutorial
I'm new to OpenGL. I'm reading the book Interactive Computer Graphics with OpenGL (Angel). As a test of the concepts taught in the book, I tried compiling the first example program, only to find that I get all sorts of errors. The program is supposed to display a Sierpinski gasket composed of a given number of points on the screen. I'm compiling with DevC++. I've downloaded the GLUT header file, so I don't think that that is the problem.
Any help would be greatly appreciated.
Thanks
Andy
Code:
#include<iostream>
#include<glut.h>
using namespace std;
void myinit(void)
{
//attributes
glClearColor(1.0,1.0,1.0,0.0);//white background
glColor3f(1.0,0.0,0.0);//draw in red
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0.0,500.0,0.0,500.0,-100.0,100.0);
glMatrixMode(GL_MODELVIEW);
//sets up viewing
}
void display(void)
{
typedef GLfloat point2[2];//define a 2-coordinate point data type
point2 vertices[3]={{0.0,0.0},{250.0,500.0},{500.0,0.0}};
//creates an arbitrary triangle
static point2 p={75.0,50.0};
//sets an initial point within the triangle
glClear(GL_COLOR_BUFFER_BIT);//clear the window
int j,k;
int rand(); //random number generator
for(k=0;k<5000;k++)
{
j=rand()%3;
//pick a random vertex from 0,1,2
p[0]=(p[0]+vertices[j][0])/2;
p[1]=(p[1]+vertices[j][1])/2;
//computes next point in sequence
glBegin(GL_POINTS);//plot points
glVertex2fv(p);
glEnd();
}
glFlush();
}
int main(int argc, char **argv)
{
//Standard GLUT initialization
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);//default, not needed
glutInitWindowSize(500,500);
glutInitWindowPosition(0,0);//place window at top left of display
glutCreateWindow("Sierpinski Gasket");//window title
glutDisplayFunc(display);//display callback invoked when opened
myinit(); //set attributes
glutMainLoop(); //enter event loop
return 1;
}
And here is the compile log, which may or may not be helpful
Code:
Compiler: Default compiler
Executing g++.exe...
g++.exe "C:\Andy's Old Computer Files\Andy's Programs\OpenGL examples\Sierpinski gasket.cpp" -o "C:\Andy's Old Computer Files\Andy's Programs\OpenGL examples\Sierpinski gasket.exe" -g3 -I"lib\gcc\mingw32\3.4.2\include" -I"include\c++\3.4.2\backward" -I"include\c++\3.4.2\mingw32" -I"include\c++\3.4.2" -I"include" -L"lib" -g3
C:\DOCUME~1\ANDYBA~1\LOCALS~1\Temp/ccwNaaaa.o(.text+0x11c): In function `glutInit_ATEXIT_HACK':
C:/Dev-Cpp/Bin/../lib/gcc/mingw32/3.4.2/../../../../include/glut.h:486: undefined reference to `__glutInitWithExit'
C:\DOCUME~1\ANDYBA~1\LOCALS~1\Temp/ccwNaaaa.o(.text+0x137): In function `glutCreateWindow_ATEXIT_HACK':
C:/Dev-Cpp/Bin/../lib/gcc/mingw32/3.4.2/../../../../include/glut.h:503: undefined reference to `__glutCreateWindowWithExit'
C:\DOCUME~1\ANDYBA~1\LOCALS~1\Temp/ccwNaaaa.o(.text+0x153): In function `glutCreateMenu_ATEXIT_HACK':
C:/Dev-Cpp/Bin/../lib/gcc/mingw32/3.4.2/../../../../include/glut.h:549: undefined reference to `__glutCreateMenuWithExit'
C:\DOCUME~1\ANDYBA~1\LOCALS~1\Temp/ccwNaaaa.o(.text+0x184): In function `Z6myinitv':
C:/Andy's Old Computer Files/Andy's Programs/OpenGL examples/Sierpinski gasket.cpp:8: undefined reference to `_imp__glClearColor'
C:\DOCUME~1\ANDYBA~1\LOCALS~1\Temp/ccwNaaaa.o(.text+0x1a5):C:/Andy's Old Computer Files/Andy's Programs/OpenGL examples/Sierpinski gasket.cpp:9: undefined reference to `_imp__glColor3f'
C:\DOCUME~1\ANDYBA~1\LOCALS~1\Temp/ccwNaaaa.o(.text+0x1b3):C:/Andy's Old Computer Files/Andy's Programs/OpenGL examples/Sierpinski gasket.cpp:11: undefined reference to `_imp__glMatrixMode'
C:\DOCUME~1\ANDYBA~1\LOCALS~1\Temp/ccwNaaaa.o(.text+0x1ba):C:/Andy's Old Computer Files/Andy's Programs/OpenGL examples/Sierpinski gasket.cpp:12: undefined reference to `_imp__glLoadIdentity'
C:\DOCUME~1\ANDYBA~1\LOCALS~1\Temp/ccwNaaaa.o(.text+0x1f4):C:/Andy's Old Computer Files/Andy's Programs/OpenGL examples/Sierpinski gasket.cpp:13: undefined reference to `_imp__glOrtho'
C:\DOCUME~1\ANDYBA~1\LOCALS~1\Temp/ccwNaaaa.o(.text+0x202):C:/Andy's Old Computer Files/Andy's Programs/OpenGL examples/Sierpinski gasket.cpp:14: undefined reference to `_imp__glMatrixMode'
C:\DOCUME~1\ANDYBA~1\LOCALS~1\Temp/ccwNaaaa.o(.text+0x246): In function `Z7displayv':
C:/Andy's Old Computer Files/Andy's Programs/OpenGL examples/Sierpinski gasket.cpp:25: undefined reference to `_imp__glClear'
C:\DOCUME~1\ANDYBA~1\LOCALS~1\Temp/ccwNaaaa.o(.text+0x261):C:/Andy's Old Computer Files/Andy's Programs/OpenGL examples/Sierpinski gasket.cpp:30: undefined reference to `rand()'
C:\DOCUME~1\ANDYBA~1\LOCALS~1\Temp/ccwNaaaa.o(.text+0x2c8):C:/Andy's Old Computer Files/Andy's Programs/OpenGL examples/Sierpinski gasket.cpp:35: undefined reference to `_imp__glBegin'
C:\DOCUME~1\ANDYBA~1\LOCALS~1\Temp/ccwNaaaa.o(.text+0x2d6):C:/Andy's Old Computer Files/Andy's Programs/OpenGL examples/Sierpinski gasket.cpp:36: undefined reference to `_imp__glVertex2fv'
C:\DOCUME~1\ANDYBA~1\LOCALS~1\Temp/ccwNaaaa.o(.text+0x2dd):C:/Andy's Old Computer Files/Andy's Programs/OpenGL examples/Sierpinski gasket.cpp:37: undefined reference to `_imp__glEnd'
C:\DOCUME~1\ANDYBA~1\LOCALS~1\Temp/ccwNaaaa.o(.text+0x2ee):C:/Andy's Old Computer Files/Andy's Programs/OpenGL examples/Sierpinski gasket.cpp:39: undefined reference to `_imp__glFlush'
C:\DOCUME~1\ANDYBA~1\LOCALS~1\Temp/ccwNaaaa.o(.text+0x33a): In function `main':
C:/Andy's Old Computer Files/Andy's Programs/OpenGL examples/Sierpinski gasket.cpp:46: undefined reference to `glutInitDisplayMode'
C:\DOCUME~1\ANDYBA~1\LOCALS~1\Temp/ccwNaaaa.o(.text+0x34e):C:/Andy's Old Computer Files/Andy's Programs/OpenGL examples/Sierpinski gasket.cpp:47: undefined reference to `glutInitWindowSize'
C:\DOCUME~1\ANDYBA~1\LOCALS~1\Temp/ccwNaaaa.o(.text+0x362):C:/Andy's Old Computer Files/Andy's Programs/OpenGL examples/Sierpinski gasket.cpp:48: undefined reference to `glutInitWindowPosition'
C:\DOCUME~1\ANDYBA~1\LOCALS~1\Temp/ccwNaaaa.o(.text+0x37a):C:/Andy's Old Computer Files/Andy's Programs/OpenGL examples/Sierpinski gasket.cpp:50: undefined reference to `glutDisplayFunc'
C:\DOCUME~1\ANDYBA~1\LOCALS~1\Temp/ccwNaaaa.o(.text+0x384):C:/Andy's Old Computer Files/Andy's Programs/OpenGL examples/Sierpinski gasket.cpp:52: undefined reference to `glutMainLoop'
collect2: ld returned 1 exit status
Execution terminated
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|