Jump to content
  • Advertisement
Sign in to follow this  

Setting Up OpenGL

This topic is 3929 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Ok, I have recently started learning C++ and OpenGL so I can start making my owns games which something I have always wanted to do since I starting taking computer programming classes in High School. I have a pretty good grasps on the basics of C++ and enough to follow the basics of OpenGL. I know that I should really learn a lot more C++ before I dabble to far into OpenGL but after a while, making useless console programs after useless console programs, you get a little bored and you start asking yourself what the heck does this have to do with making video games. So I starting looking at graphical APIs, that I was going to have to learn at some point and decided to look at openGL and I hope it works out but I have a lot of questions and issue that I would really appreciate it if you guys could help me out. First of all, I have tried many different tutorials and tried to use their code and it never ends up compiling. first it was the header files but I fixed that, then it was windows.h messing things up, then apprently it was the compiler but then I switched compilers and I was getting the same messages. Anyway I have finally settled for a tutorial that I want to use and here is the inital code that wont compile. (I'm using Dev-C++ on Windows XP)
#include <GL/gl.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);
        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);

/*  don't wait!  
 *  start processing buffered OpenGL routines 
    glFlush ();

void init (void) 
/*  select clearing (background) color       */
    glClearColor (0.0, 0.0, 0.0, 0.0);

/*  initialize viewing values  */
    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 ();
    return 0;   /* ISO C requires main to return int. */

When compiled I get this error
  [Linker error] undefined reference to `gluPerspective@32' 
  ld returned 1 exit status 
 C:\Dev-Cpp\Makefile.win [Build Error]  [LearninGL.exe] Error 1 

I did switch compilers a few times and yet I got the same error each time. However I did see that in DevC++ you can open an openGL template base where code can be modified and used bti it is much more complicated than the code above, and I will no be able to follow this tutorial correctly if I can not use the code above Ill prolly post some more questions in here once I start working on it again, so thanks to anyone who can help me set this up!

Share this post

Link to post
Share on other sites
Do you need to do #include<glu32.lib> and have that file in the include folder of the compiler?

Also when i downloaded the OpenGL SDK the only libraries it came with were glu and opengl so where do I get glu32?

Share this post

Link to post
Share on other sites
Not to hijack the thread completely but seeing as I too am having issues getting OpenGL to work correctly...

I'm attempting to run it with code::blocks and over SDL according to Lazy Foo's tutorial. However when I attempt to compile I don't get any errors in my code itself, instead I just get this:

undefined reference to `glClearColor@16'
undefined reference to `glMatrixMode@4'

and a bunch more just like it.

Any help would be appreciated.

Share this post

Link to post
Share on other sites
You need to link to the libraries correctly.

Go to Project->Project Options->Parameters.

In the "Linker" box, type: "-lopengl32 -lglu32" without the quotation marks.

See if that helps!

Share this post

Link to post
Share on other sites
I can find the file I was previously using so I made a different one using the same code and now I am getting this error

1 C:\Dev-Cpp\Window!.cpp In file included from Window!.cpp
50 C:\Dev-Cpp\include\GL\glut.h redeclaration of C++ built-in type `short'
C:\Dev-Cpp\Makefile.win [Build Error] [Window!.o] Error 1

Also i dont have a library called glu32. Isnt that causing something?

Share this post

Link to post
Share on other sites
I recently compiled openGL + GLUT in Code::Blocks, i don't know if it will work out with Dev-cpp but what i did was:

Add this line to the linker.
-lopengl32 -lglu32 -lglut32

But even with that i got the same "redeclaration of C++ built-in type `short'" linker error.

I solved adding:


at the beginning of my main.cpp
Also, i think you have to add #include <windows.h> before including gl.h or glut.h

Hope that helps.

Share this post

Link to post
Share on other sites
Well, an MMOFPS of course!

lol, j/k. I guess I would start with a relatively easy game like pong/breakout clone. I'm really sure, just something easy.

Share this post

Link to post
Share on other sites

I finally got the code to work, or YOU guys finally got the code to work. Im so excited I cant wait to start making some interactive programs....NOW WITH GRAPHICS!!!!

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!