Well Hello People, now I wan't to tell you how to install OpenGL on linux ubuntu. But first, you must to know what is OpenGL? OpenGL is a abbreviation from Open Graphic Library, which is one API, that is a library consists of various functions and usually used to draw a 2D or 3D object. Okay guys follow me to install it.
Open your terminal
This will update your apt database to the most recent available packages.
This installs the necessary development tools for building source code.
This installs the development libraries and headers for freeglut.
okay you already to install it now you follow me to running it.
Open your Notepad++/Notepadqq/Text Editor
#include
#include
#include
void userdraw(void);
void drawDot(float x, float y)
{
glBegin(GL_POINTS);
glVertex2f(x,y);
glEnd();
}
void drawLine (float x1, float y1, float x2, float y2)
{
glBegin(GL_LINES);
glVertex2f(x1,y1);
glVertex2f(x2,y2);
glEnd();
}
void setColor(float red, float green, float blue)
{
glColor3f(red,green,blue);
}
void userdraw(void)
{
glPointSize(4);
setColor(1.,1.,1.);
drawDot(100,40); //point
drawLine(1,1,100,100);//line
glBegin(GL_POLYGON); //polygon
glVertex2f(210,260);
glVertex2f(260,260);
glVertex2f(260,210);
glEnd();
glBegin(GL_LINE_STRIP); //polyline
glVertex2f(110,160);
glVertex2f(110,110);
glVertex2f(160,110);
glEnd();
}
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT);
userdraw();
glFlush();
}
void main(int argc, char **argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(640,480);
glutInitWindowPosition(100,150);
glutCreateWindow("My First Open Graphic Library");
glClearColor(0.0,0.0,0.0,0.0);
gluOrtho2D(0.,640.,0.0,480.0);
glutDisplayFunc(display);
glutMainLoop();
}
Explanation:
#include <GL/glut.h> // a package from OpenGL.
void userdraw(void); //Here is the place to draw.
void drawDot(float x, float y) //function to draw points based on x and y coordinates. If on therethe data type is float, on glVertex2f(x,y);. if on void drawDot(float x, float y) the data type is intiger like this void drawDot(int x, int y), you must change glVertex2f(x,y); to glVertex2i(x,y);. if on the data type is double you must change glVertex2f(x,y); to glVertex2d(x,y);.
void drawLine (float x1, float y1, float x2, float y2) //function to draw lines on your project.
void setColor(float red, float green, float blue) //color settings for dots or lines .
glPointSize(4); //to settings you dots or lines sizes.
setColor(1.,1.,1.); // to set your color.
drawDot(100,40); //the point will be at the coordinates x 100 and the y coordinates 40.
glClearColor(0.0,0.0,0.0,0.0);//for background color.
-lGL -lGLU -lglut -lm to call glut package.
-o for name output your program
okay guys until here i told you how to Install OpenGL on Linux Ubuntu and Running it. see you on the next tutorial.