Trouble with OpenGL tutorial
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: Trouble with OpenGL tutorial

  1. #1
    Join Date
    Jul 2007
    Posts
    33

    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

  2. #2
    Join Date
    Jun 2007
    Location
    MA-USA
    Posts
    247

    Re: Trouble with OpenGL tutorial

    First start with a new console project.
    Then add your files to the project.

    glut.h is not a dev-standard header file.
    so glut.h should reside in project folder.
    #include "glut.h"

    optionally you can put it in the /include/gl folder.
    #include <gl/glut.h>

    libglut32.a is a dev-standard lib file, so just link your project to it.

  3. #3
    Join Date
    Jul 2007
    Posts
    33

    Re: Trouble with OpenGL tutorial

    I think I'm getting the same errors. I'm pretty sure that I'm linking the library to the project correctly, and I changed the GLUT header to #include<GL/glut.h>, making sure that the glut.h was in the GL folder.

    here is the latest compile log:
    Code:
    Compiler: Default compiler
    Building Makefile: "C:\Andy's Old Computer Files\Andy's Programs\OpenGL examples\Makefile.win"
    Executing  make...
    make.exe -f "C:\Andy's Old Computer Files\Andy's Programs\OpenGL examples\Makefile.win" all
    g++.exe -D__DEBUG__ -c "Sierpinski gasket.cpp" -o "Sierpinski gasket.o" -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"    -g3
    
    g++.exe -D__DEBUG__ "Sierpinski gasket.o"  -o "Sierpinski Gasket.exe" -L"lib" C:/Dev-Cpp/lib/libglut32.a  -g3 
    
    Sierpinski gasket.o(.text+0x11c): In function `glutInit_ATEXIT_HACK':
    C:/Dev-Cpp/Bin/../lib/gcc/mingw32/3.4.2/../../../../include/GL/glut.h:486: undefined reference to `__glutInitWithExit'
    Sierpinski gasket.o(.text+0x137): In function `glutCreateWindow_ATEXIT_HACK':
    C:/Dev-Cpp/Bin/../lib/gcc/mingw32/3.4.2/../../../../include/GL/glut.h:503: undefined reference to `__glutCreateWindowWithExit'
    
    Sierpinski gasket.o(.text+0x153): In function `glutCreateMenu_ATEXIT_HACK':
    C:/Dev-Cpp/Bin/../lib/gcc/mingw32/3.4.2/../../../../include/GL/glut.h:549: undefined reference to `__glutCreateMenuWithExit'
    Sierpinski gasket.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'
    Sierpinski gasket.o(.text+0x1a5):C:/Andy's Old Computer Files/Andy's Programs/OpenGL examples/Sierpinski gasket.cpp:9: undefined reference to `_imp__glColor3f'
    Sierpinski gasket.o(.text+0x1b3):C:/Andy's Old Computer Files/Andy's Programs/OpenGL examples/Sierpinski gasket.cpp:11: undefined reference to `_imp__glMatrixMode'
    
    Sierpinski gasket.o(.text+0x1ba):C:/Andy's Old Computer Files/Andy's Programs/OpenGL examples/Sierpinski gasket.cpp:12: undefined reference to `_imp__glLoadIdentity'
    Sierpinski gasket.o(.text+0x1f4):C:/Andy's Old Computer Files/Andy's Programs/OpenGL examples/Sierpinski gasket.cpp:13: undefined reference to `_imp__glOrtho'
    Sierpinski gasket.o(.text+0x202):C:/Andy's Old Computer Files/Andy's Programs/OpenGL examples/Sierpinski gasket.cpp:14: undefined reference to `_imp__glMatrixMode'
    Sierpinski gasket.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'
    Sierpinski gasket.o(.text+0x261):C:/Andy's Old Computer Files/Andy's Programs/OpenGL examples/Sierpinski gasket.cpp:30: undefined reference to `rand()'
    Sierpinski gasket.o(.text+0x2c8):C:/Andy's Old Computer Files/Andy's Programs/OpenGL examples/Sierpinski gasket.cpp:35: undefined reference to `_imp__glBegin'
    Sierpinski gasket.o(.text+0x2d6):C:/Andy's Old Computer Files/Andy's Programs/OpenGL examples/Sierpinski gasket.cpp:36: undefined reference to `_imp__glVertex2fv'
    Sierpinski gasket.o(.text+0x2dd):C:/Andy's Old Computer Files/Andy's Programs/OpenGL examples/Sierpinski gasket.cpp:37: undefined reference to `_imp__glEnd'
    Sierpinski gasket.o(.text+0x2ee):C:/Andy's Old Computer Files/Andy's Programs/OpenGL examples/Sierpinski gasket.cpp:39: undefined reference to `_imp__glFlush'
    Sierpinski gasket.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'
    Sierpinski gasket.o(.text+0x34e):C:/Andy's Old Computer Files/Andy's Programs/OpenGL examples/Sierpinski gasket.cpp:47: undefined reference to `glutInitWindowSize'
    Sierpinski gasket.o(.text+0x362):C:/Andy's Old Computer Files/Andy's Programs/OpenGL examples/Sierpinski gasket.cpp:48: undefined reference to `glutInitWindowPosition'
    Sierpinski gasket.o(.text+0x37a):C:/Andy's Old Computer Files/Andy's Programs/OpenGL examples/Sierpinski gasket.cpp:50: undefined reference to `glutDisplayFunc'
    Sierpinski gasket.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
    
    make.exe: *** ["Sierpinski] Error 1
    
    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
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center