Author Topic: OpenGL using gl/glut.h header file  (Read 214 times)

Offline biotech54

  • Single posting newcomer
  • *
  • Posts: 9
OpenGL using gl/glut.h header file
« on: October 19, 2017, 03:12:12 am »
I'm trying to get a simple openGL program to compile.  I read a prior post that i needed to add dll, header, and lib files, and i thought i did it correctly.  All the directories have changed since this post 12 years ago.  I still cannot get it to compile.  We are using the gl/glut.h header file.  I'm taking a class at a local university on OpenGL.  I asked my professor if he could figure out how to use codeblocks, and he tried for 15 minutes, and couldnt figure it out.  He advised me to abandon codeblocks and use visualstudio instead.  I would prefer to use codeblocks if possible.

I'm using windows 7, compiling with GCC compiler, C language.

I tried getting openMP to work with codeblocks recently without any luck, despite help from this forum.  I spent 6 weeks studying openMP, couldn't get a simple hello world program to compile, which really sucks.  I'm hoping this won't be a repeat.

This is the simple program, given by the professor.  Compiler error gives "undefined reference to" all the opengl functions.
Any help is appreciated:

#include <gl/glut.h>      // (or others, depending on the system in use)

void init (void)
{
    glClearColor (1.0, 1.0, 1.0, 0.0);  // Set display-window color to white.

    glMatrixMode (GL_PROJECTION);       // Set projection parameters.
    gluOrtho2D (0.0, 200.0, 0.0, 150.0);
}

void lineSegment (void)
{
    glClear (GL_COLOR_BUFFER_BIT);  // Clear display window.

    glColor3f (0.0, 0.0, 1.0);      // Set line segment color to red.
    glBegin (GL_LINES);
        glVertex2i (180, 15);       // Specify line-segment geometry.
        glVertex2i (10, 145);
    glEnd ( );

    glFlush ( );     // Process all OpenGL routines as quickly as possible.
}

void main (int argc, char** argv)
{
    glutInit (&argc, argv);                         // Initialize GLUT.
    glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);   // Set display mode.
    glutInitWindowPosition (50, 100);   // Set top-left display-window position.
    glutInitWindowSize (400, 300);      // Set display-window width and height.
    glutCreateWindow ("An Example OpenGL Program"); // Create display window.

    init ( );                            // Execute initialization procedure.
    glutDisplayFunc (lineSegment);       // Send graphics to display window.
    glutMainLoop ( );                    // Display everything and wait.
}



Offline stahta01

  • Lives here!
  • ****
  • Posts: 5969
    • My Best Post
Re: OpenGL using gl/glut.h header file
« Reply #1 on: October 19, 2017, 03:39:07 am »
http://wiki.codeblocks.org/index.php/FAQ-Compiling_(errors)#Q:_How_do_I_troubleshoot_a_compiler_problem.3F

Post a full re-build log.
And, post your compiler version.

Edit: I suggest you find a support site for the Compiler you are using; since, it sounds like your instructor does not wish to support MinGW GCC. And, this site does not support any compiler.

Tim S.
« Last Edit: October 19, 2017, 05:29:15 am by stahta01 »
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 32 bit.
On Debian Testing, compiling CB Trunk against wxWidgets 3.0.2.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline blauzahn

  • Multiple posting newcomer
  • *
  • Posts: 70
Re: OpenGL using gl/glut.h header file
« Reply #2 on: October 19, 2017, 06:53:58 am »
Have you tried the wizard (file | new | project | opengl project)?