Professional Documents
Culture Documents
Introduction To OPEN GL
Introduction To OPEN GL
OpenGL is graphic software (API) which allows us to create 2D or 3D high quality images
and animations i.e. Main purpose of OpenGL is rendering (process of generating image
from a model or from scene). OpenGL is an API (Software Interface to the graphics
Hardware)
Graphic/image
OpenGL is platform (OS) independent( Applications programs can run on windows and Linux) , Hardware
independent (will run on PC’s, workstation, super computer), Open source software (free).
Uses any on the programming language like c,C++, java, Python for operating
Preprocessor Directives
main function()
{
….
…
}
#include<GL/glut.h> //Preprocessor Directive
void display()
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(0.0f,0.0f,0.0f);
glPointSize(20);
glBegin(GL_POINTS);
glVertex2i(0,0);
glEnd();
glFlush();
}
void init()
{
glClearColor(1.0,1.0,1.0,0.0); //set the background color of the window
glColor3f(1.0,1.0,1.0); //set the background color of the window
//glPointSize(4.0); // point size default is 1.0
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0,640.0,0.0,480.0); //window origin //clipping window or normal window or viewing window
}
glutDisplayFunc(display); This function gives picture definition to the display window. It is first and most important event call back function.
init();
glutMainLoop();
}
pre-processor Directives
GL, GLU, GLUT [GLX,AGL,WGL]: OpenGL can be accessed by application program directly through functions in
these 3 libraries.
Graphics Library (GL): Core library of OpenGL which contains basic functions/primitive functions. Functions in GL library
begins with gl
Graphics Library Utility (GLU) : contains functions for setting up viewing and projection matrices.
Graphics Library toolkit (GLUT): contains functions to manage window system. All GLUT functions start with prefix glut.
0)
Note: instead of including GL, GLU, GLUT separately we use GL/glut.h
To display our graphical object/output on the screen we need to use window (clipping window). Five
routines/functions are used to initialize window.
i. glutIit(&argc, argv)
This function initialize the GLUT and this function should be called before other GLUT functions.
2. glutInitDisplayMode : It is used to specify refresh buffer and colour modes.
glutInitDisplayMode(GLUT_single|GLUT_RGB)
3. glutCreteWindow(char *string);
4. glutInitWindowPosition(int x,int y)
Displays window that we created will be in some default position and size. By using this function we can specify the
position/location of the window with reference to the display screen whose origin is at left top corner.
Example
glutInitWindowPosition(50,100)
Example: glutInitWindowSize(400,300);
For this create an object/image/picture using OpenGL functions and pass this picture definition as argument to the
glutDisplayFunc() i.e. glutDisplayFunc(function_name); //here function_name is diplay()
This function gives picture definition to the display window. It is first and most important event call back function.
Note: Whenever GLUT determines the window contents need to be redisplayed then glutDisplayFun() is executed.
glClearColor(r,g,b,alpha); alpha=0 it is transparent object, 1=opaque object. This glClearColor function assigns a
color to display window after glClear openGL function is called. i.e.
glClear(GL_COLOR_BUFFER_BIT); is called.
Here GL_COLOR_BUFFER_BIT is an openGL symbolic constant which specifies that it is the bit value in the
color buffer (refresh buffer) that is to be set to the values indicated in the glClearColor function
Representing 2D or 3D objects
Now we want to tell openGL that how we want to project our picture onto the display window [viewing]
glOrtho2d(L,R,B,T);