Game Cookies

October 8, 2007

OpenGL and FreeBSD

Filed under: code, development, rant — nippysaurus @ 4:27 pm

I have always wanted to do everything cross platform but when you dont know what youre doing and dont have much time it tends to be the last thing on your mind. So a few weeks ago I wrote a simple windows application (using OpenGL) to easily display points in 3D space instead of having to draw it on paper (doing vector maths at university at the moment). I also happen to have just set up a computer with FreeBSD (and GNOME).

So here I go all brave wanting to implement my work in FreeBSD but oh boy what a mission. Firstly, where the heck are the OpenGL libraries (and GLU, and GLUT)? I googled for about an hour and finally discovered that they are in /usr/X11R6/include and /usr/X11R6/lib. Yipee! I dont know if they were installed with Xorg or with xorg-libraries-7.3 port. I don’t care at this point.

So I find a tutorial on the web somewhere and paste all the code into a cpp file. Now I have not compiled c++ from a command line ages now. Compiling from the command line is an art! Anyways, this is the code I hacked together.

#include <GL/glut.h>

void displayCB(void)
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0, 1.0, 1.0);
glBegin(GL_POLYGON);
glVertex2i(200,125);
glVertex2i(100,375);
glVertex2i(300,375);
glEnd();
glFlush();
}

void keyCB(unsigned char key, int x, int y)
{
//if( key == 'q' ) exit(0);
}

int main(int argc, char* argv[])
{
int Window;
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB);
glutInitWindowSize(400,500);
Window = glutCreateWindow("Triangle");
/* From here the current window is set */
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
gluOrtho2D(0.0f, 400.0f, 0.0f, 500.0f);
glutDisplayFunc(displayCB);
glutKeyboardFunc(keyCB);
glutMainLoop();
return 0;
}

I had to escape that exit() function because for some reason it was not compiling.

So getting this far was a bit of a nightmare, but on top of all this I could not remember the g++ arguments to use! Without an IDE you need to specify include and library locations. Back to google! What I came up with was the following command to compile that file.

g++ -I/usr/X11R6/include -L/usr/X11R6/lib -lGL -lGLU -lglut main.cpp

Happy coding 🙂

2 Comments »

  1. Hey there!

    This is a great piece of code. I was just looking for that! It helps me get to start gl programming in FreeBSD 🙂 thx

    Comment by WuXorT — November 26, 2007 @ 10:34 am

  2. np buddy 🙂 If you have any troubles with it, post here and I will get back to you.

    Comment by nippysaurus — November 26, 2007 @ 12:19 pm


RSS feed for comments on this post. TrackBack URI

Leave a comment

Create a free website or blog at WordPress.com.