Monday, June 22, 2015

Computer Graphics - getting glut library


We need glut to practice all our code, because the code contains functions from the glut library...so to get the glut library, you need to type this in the terminal :

sudo apt-get install freeglut3-dev

Now, just to verify, try this code :

#include<GL/glut.h>

void myInit()
{
    glClearColor(1.0,1.0,1.0,0.0);
    glColor3f(1.0,0.0,0.0);
    glPointSize(1);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluOrtho2D(0.0,640.0,0.0,480.0);
}

void myDisplay()
{
    glClear(GL_COLOR_BUFFER_BIT);

    glBegin(GL_LINES);
        glVertex2d(100,100);
        glVertex2d(100,200);
    glEnd();

    glFlush();
}

int main(int argc,char* argv[])
{
    glutInit(&argc,argv);
    glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
    glutInitWindowSize(640,480);
    glutCreateWindow("First Exercise");
    glutDisplayFunc(myDisplay);
    myInit();
    glutMainLoop();
    return 1;
}

save the above code as sample.c

and to compile, type this in the terminal :

gcc sample.c -lGL -lGLU -lglut -o sample

( it's 'l' , that is, a small L after every hyphen )

and now to see the output, type the usual thing :

./sample

The output should appear in a new window, and the output is a red line at the left bottom of the window. This way you can verify that glut libraries are installed properly and that you can run programs which use glut library functions, good luck! :)

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.