Thursday, February 20, 2014

Installing openGL in Linux Mint / Ubuntu for Graphics Lab


Installing openGL in Linux Mint / Ubuntu for Graphics Lab
This is fairly simple actually.

All you have to do is to install the following things in your Linux distro.

sudo apt-get install freeglut3
sudo apt-get install freeglut3-dev
sudo apt-get install binutils-gold
And you are done :)

Here is a sample code for you:



/*
 * File:   main.cpp
 * Author: lordamit
 *
 * Created on July 9, 2012, 12:53 PM
 */

#include <GL/glut.h>
using namespace std;

void draw(void) {
   
    //set Background color
    glClearColor(1, 0, 0, 1);
    glClear(GL_COLOR_BUFFER_BIT);
    //Draw color
    glFlush();

}

//Main program

int main(int argc, char **argv) {

    glutInit(&argc, argv);
   
    glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
   
    //set window position
    glutInitWindowPosition(50, 25);
   
    //set window size
    glutInitWindowSize(500, 250);
   
    //set window name
    glutCreateWindow("My window");
   
    //Call to the drawing function
    glutDisplayFunc(draw);
   
    glutMainLoop();
    return 0;
}

Save this file using name program.c and compile it using
gcc -lGL -lglut program.c -o program

And execute it using
./program

You are done!

No comments:

Post a Comment