04.10.10 - Installing OpenGL/Glut libraries in Ubuntu

Steps to install, link and run OpenGL/Glut programs in Ubuntu

The first step is to install the development libraries of OpenGL/Glut in Ubuntu:
sudo apt-get install freeglut3 freeglut3-dev
For newer versions of Ubuntu (>= 11.10) you have to install another package because the linker does't link anymore.
sudo apt-get install binutils-gold
Create a test file (test.c):
#include <GL/glut.h>

//Drawing funciton
void draw(void)
{
  //Background color
  glClearColor(0,1,0,1);
  glClear(GL_COLOR_BUFFER_BIT );
  //Draw order
  glFlush();
}

//Main program
int main(int argc, char **argv)
{
  glutInit(&argc, argv);
  //Simple buffer
  glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB );
  glutInitWindowPosition(50,25);
  glutInitWindowSize(500,250);
  glutCreateWindow("Green window");
  //Call to the drawing function
  glutDisplayFunc(draw);
  glutMainLoop();
  return 0;
}
Compile the file linking the OpenGL/Glut libraries:
gcc -lGL -lglut test.c -o test
Via: Ubuntuforums
More news about:  ubuntu
Tags:  c,  linux,  OpenGL,  Glut,  gcc

Comments

  • Gravatar
    05.12.10 - 05:42  Richard

    Hi Thanks for the great information on OpenGL in Ubuntu. Very helpful. (The black background in your text boxes is not good though with black text as it is difficult to see/read it! A different colour combo would help!). I like your site - thanks & best wishes

  • 05.12.10 - 08:46  kiwwito
    Thanks for your comment!

    The next version of kiwwito (comming soon) will change the black background. Thanks again for the advice.
  • Gravatar
    16.01.12 - 02:15  Jeremy

    Unfortunately: something is wrong with the ubuntu glut library: it doesn't link properly anymore!

  • 17.01.12 - 09:49  kiwwito
    Solved! I've updated the article for Ubuntu 11.10. Lot of thanks!
  • Gravatar
    27.01.12 - 06:09  Paul

    I keep getting E: Invalid operation binutils-gold I'm also getting undefined reference for all of the gl commands I try to use.

  • 27.01.12 - 10:06  kiwwito
    Are you sure that you have Ubuntu 11.10?
  • Gravatar
    27.01.12 - 01:52  Amogh

    use "sudo apt-get install binutils-gold". Missing install.

  • 27.01.12 - 10:23  kiwwito
    Thanks, fixed!

Comment