Saturday, October 27, 2012

OpenGL and freeglut on Linux + Codeblocks

Hey everyone,
After long time I'm writing on this blog. Hope to keep things up from here onwards but cant promise.

This post is about doing OpenGL programming in codeblocks.

Codeblocks is a C/CPP IDE. Usually opengl c programming is done in this. Our lecturer, Ms. G. S. Makalanda ( Senior Lecturer) B.Sc.(Math)(SL), M.Sc.(Stat)(SL), M.Sc. (Comp. Sci.)(UK),  has asked us to install code-blocks in order to do C programming on opengl. Well everyone except me is working on windows pc's. This is my story, problems, solutions I found to overcome to run code successfully on codeblocks.

Codeblocks was in Ubuntu Software center so no problem in installing it. I guess there was opengl installed in default. When I create new opengl project, the sample code runs smoothly. But when I create a new glut project it says,  
CG/gluttest.o:gluttest.c:function display: error||undefined reference to 'glClear'|
CG/gluttest.o:gluttest.c:function display: error||undefined reference to 'glColor3f'|
CG/gluttest.o:gluttest.c:function display: error||undefined reference to 'glBegin'|
CG/gluttest.o:gluttest.c:function display: error||undefined reference to 'glVertex3f'|
CG/gluttest.o:gluttest.c:function display: error||undefined reference to 'glVertex3f'|
CG/gluttest.o:gluttest.c:function display: error||undefined reference to 'glVertex3f'|
CG/gluttest.o:gluttest.c:function display: error||undefined reference to 'glVertex3f'|
*some more references like same*
||=== Build finished: 33 errors, 0 warnings ===|
 like wise gives build error for each gl function. Other guys on windows pc had the same problem but they seems to fix it when they changed glut library. So I did some search and found that I have to install freeglut (linux version of the glut).



so I issued
sudo apt-get install freeglut3 freeglut3-dev
But still I couldn't create a new glut project in codeblocks. When creating glut project they codeblocks ask for the place that have glut installed (place header files and other libraries are). Usually in linux they are in /usr folder. So when I dirrect it the codeblocks say glut libraries are missing and asked me to try to append '.a' and '.so' to files.

Then I manually went to see /usr directory. In there, was /usr/include directory which contained all header files gcc needs. Among them there was GL directory in that I could find gl.h and glut.h. But in /usr/lib I couldn't find any of gllibs. So I searched and searched on web. Then user :-ToApolytoXaos (in Cyprus) in IRC chat room of codeblocks told me to go through wiki pages of codeblocks. Then as a result I again went to freeglut website and download it manually. Then I unziped the download and compiled & installed the source code of freeglut again through terminal. But still the problem existed.

What I did?

I looked through the unziped folder of freeglut. I found a hidden folder in freeglut/src/.lib inside the sourcecode which contained several compiled c objects and a zip file named libglut.a . I had a hunch "Hey these are the things that codeblocks keep repeating that says missing". So I thought to hack this around rather than solving in conventional way. So I did
sudo cp freeglut/src/.lib/* /usr/lib
Now problem seems to be solved. I could create a new glut project. But when I tried to run the sample glut program given in code::blocks seems to be giving error
||=== testing, Debug ===|
ld: error||cannot find -lXxf86vm|
||=== Build finished: 1 errors, 0 warnings ===|
 I was so frustrated. Then I went to IRC chat with totally frustrated feeling. Again kindly ToApolytoXaos came to help me. He sugested to install me few libraries. So I issued

sudo apt-get install libxmu-dev libxi-dev
sudo apt-get install libXxf86vm-dev
 Then the sample program ran smoothly. I was so happy. But problems didn't ended there to be honest. I had few typos in my own coding. But again ToApolypto helped me to find those. Finally here I am writing a blog post about this so no one ever will be frustrated as I am.

End of the post I would like to mention something.
"Never give up! If you are with linux, there is always a way! At least you have friends who can help you."

5 comments:

Anonymous said...

Same thing happened to me. Thanks for the help.

Unknown said...

thanks, my problem has been solved :)

Fernando said...

thank you brother ...Finally I can solved my problem ... greetings from mexico

Anonymous said...

That's exactly my problem. Thank you so much

Rbt618 said...

Here, in January 2020, and still this same problem is not resolved. I cannot get free-glut working with Ubuntu - Codeblocks. I'm at the point of just going back to Windows so I can write my programs and be done with it.