Skip to main content
GameDev.net gamedev.net
🔒 Locked

Setting Up OpenGL

Started by CarlosNYM Oct 13, 2007 at 12:34 AM 8 replies 3.2k views
Original Post
CarlosNYM
CarlosNYM
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);
    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 (background) 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;   /* 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!
SimonForsman
SimonForsman
You need to link the glu32 library. (-lglu32)
[size="1"]I don't suffer from insanity, I'm enjoying every minute of it.
The voices in my head may not be real, but they have some good ideas!
CarlosNYM
CarlosNYM
Do you need to do #include 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?
Plethora
Plethora
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.

I'm working on a game!  It's called "Spellbook Tactics".  I'd love it if you checked it out, offered some feedback, etc.  I am very excited about my progress thus far and confident about future progress as well!   http://infinityelephant.wordpress.com
Hobbesian
Hobbesian
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!

CarlosNYM
CarlosNYM
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?
desdemian
desdemian
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:

#define GLUT_DISABLE_ATEXIT_HACK

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

Hope that helps.
Bye!
CarlosNYM
CarlosNYM
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.
CarlosNYM
CarlosNYM
YAY!!!!!!!!!!!!!!!!!!!!

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!!!!

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.