how to start

hey guys
i am very new to opengl
but would like to learn a lot on it
But i have no idea where to start
so i searched and found out that i have to include the glut.h header in the code
i am going to use c++ with GNU’s g++ compiler in ubuntu
so i downloaded the header but i dont know where to paste the header in my hard disk so that i can use it in my program
please help

Maybe here:

Welcome to the fun world of Linux and openGL. That is great you want to learn. You should not have to manually copy any header files anywhere. Linux has synaptic to make installing everything a simple and easy hands-off task.

I suggest using glut to help your learning curve. In synaptic you can make sure it is installed by checking “freeglut3”.

As a test of your gcc tools, you should be able to run from a terminal “gcc --version” and see a response something like “gcc (Ubuntu 4.3.3-5ubuntu4) 4.3.3”. If that works then you are ready to try coding if not take a look at How to install GCC in Ubuntu Linux.

Since you are still in a terminal, type

gedit main.cpp &

and paste in the following code

//this shows one way to get FPS using an inprecise clock
//or to throttle the drawing rate to a fixed FPS with glutTimerFunc
//g++ main.cpp -lGL -lglut

#include <cstdlib>
#include <iostream>

//linux openGL headers
#include <GL/gl.h>
#include <GL/glut.h>

GLint gFramesPerSecond = 0;

void FPS(void) {
  static GLint Frames = 0;         // frames averaged over 1000mS
  static GLuint Clock;             // [milliSeconds]
  static GLuint PreviousClock = 0; // [milliSeconds]
  static GLuint NextClock = 0;     // [milliSeconds]

  Clock = glutGet(GLUT_ELAPSED_TIME); //has limited resolution, so average over 1000mS
  if ( Clock < NextClock ) return;

  gFramesPerSecond = Frames/1; // store the averaged number of frames per second

  PreviousClock = Clock;
  NextClock = Clock+1000; // 1000mS=1S in the future

void timer(int value)
  const int desiredFPS=120;
  glutTimerFunc(1000/desiredFPS, timer, ++value);

  //put your specific idle code here
  //... this code will run at desiredFPS
  char spinner[] = {'|','/','-','~','\\'};
  //end your specific idle code here

  FPS(); //only call once per frame loop to measure FPS 

void display() {
  glClearColor(0.0, 0.0, 0.0, 0.0);

  // Set the drawing color (RGB: WHITE)
  printf("FPS %d\r",gFramesPerSecond); fflush(stdout);


  glBegin(GL_LINE_STRIP); {


void init() {

void keyboard(unsigned char key, int x, int y)
   switch (key) {
      case 27:  // escape key

int main(int argc, char** argv) {
   glutInit(&argc, argv);
   glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB);
   glutCreateWindow("FPS test");



   return 0;

save it and then in the same terminal you opened earlier, compile your code using the command

g++ main.cpp -lGL -lglut

which will create an executable named a.out. Try it by typing in the terminal


which will pop up a openGL window with a rather boring box being drawn and in the terminal you will see a constantly updating FPS reading. Note you can throttle this up and down by adjusting the “desiredFPS=120” in the timer function. Press the <escape> key to exit and return back to the terminal.

Have fun on your learning journey. I look forward to seeing your future openGL creations :slight_smile: