Thread: Problems in getting OpenGL to work

  1. #1
    Registered User
    Join Date
    Dec 2005
    Posts
    29

    Problems in getting OpenGL to work

    Hello,

    I've been trying to get OpenGL to work for weeks now, and it's just not happening. Could someone please help me get it to work?

    I am using the MinGW C compiler and have the following files in the correct folders within the MinGW folder:

    opengl32.lib
    glu32.lib
    glut32.lib
    gl.h
    glu.h
    glut.h

    In system folder:
    opengl32.dll
    glu32.dll
    glut32.dll

    The following is the code that I am trying to get to work...

    I'm fairly sure I'm not compiling it properly....but here it is anyway:

    (This it not my code, it is from 'THE RED BOOK', and I just want to see if opengl is working before I start coding)

    Code:
    #include <windows.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 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;   /* ANSI C requires main to return int. */
    }
    Thanks in advance,

    Stuart

  2. #2
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    You should post this in the Game Programming forum, where you might have more replies.
    I am using the MinGW C compiler and have the following files in the correct folders within the MinGW folder:
    Code:
    opengl32.lib
    glu32.lib
    glut32.lib
    gl.h
    glu.h
    glut.h
    You need to add them to your project or link to them (the libraries), just having them in the right place isn't enough.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  3. #3
    User
    Join Date
    Jan 2006
    Location
    Canada
    Posts
    499
    I found that out the hard way when I was using DirectDraw. The stupid thing just wouldn't compile. I had no Internet at that time, so I used Microsoft technical support (ugh). You sit on the phone for ages, and then I felt so dumb when they told me to add the DirectX libraries to the link list.

  4. #4
    Registered User
    Join Date
    Dec 2005
    Posts
    29
    I didn't put it in game programming,as I'm not going to be programming a game! But I see your point.

    I compile using the following

    gcc hello.c -o hello -lopengl32 -lglu32 -lglut32 -lglut

    i still get 3 errors though, and can't work out what library I am missing.

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Of course, not actually saying what the errors are will of course lead to a speedy answer

  6. #6
    Registered User
    Join Date
    Dec 2005
    Posts
    29
    C:\DOCUM~1\EVESHA~1\LOCALS~1\Temp/ccIlbaaa.o(.text+0x1c):hello.c:
    undefined reference to '__glutCreateWithExit@12'

    C:\DOCUM~1\EVESHA~1\LOCALS~1\Temp/ccIlbaaa.o(.text+0x3c):hello.c:
    undefined reference to '__glutCreateWindowsWithExit@8'


    C:\DOCUM~1\EVESHA~1\LOCALS~1\Temp/ccIlbaaa.o(.text+0x5c):hello.c:
    undefined reference to '__glutCreateMenuWithExit@8'

    collect2: ld returned 1 exit status

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. OpenGL problems
    By Mecha in forum Game Programming
    Replies: 5
    Last Post: 01-07-2004, 08:21 PM
  2. OpenGL lighting problems
    By sirSolarius in forum Game Programming
    Replies: 0
    Last Post: 12-01-2003, 09:11 PM
  3. Input Problems and C# (CSharp) Tutorials
    By Grayson_Peddie in forum C# Programming
    Replies: 4
    Last Post: 02-27-2003, 10:45 PM
  4. OpenGL .dll vs video card dll
    By Silvercord in forum Game Programming
    Replies: 14
    Last Post: 02-12-2003, 07:57 PM
  5. OpenGL and Windows
    By sean345 in forum Game Programming
    Replies: 5
    Last Post: 06-24-2002, 10:14 PM