Professional Documents
Culture Documents
OpenGL Basics For Sample Program
OpenGL Basics For Sample Program
(21CSL66)
1
COMPUTER GRAPHICS AND IMAGE PROCESSING LABORATORY
(21CSL66)
2
COMPUTER GRAPHICS AND IMAGE PROCESSING LABORATORY
(21CSL66)
PART-A
3
COMPUTER GRAPHICS AND IMAGE PROCESSING LABORATORY
(21CSL66)
PART-A
7.Write a Program to read a digital image. Split and display image into 4 quadrants, up, down, right
and left.
8.Write a program to show rotation, scaling, and translation on an image.
9.Read an image and extract and display low-level features such as edges, textures using filtering
techniques.
10. Write a program to blur and smoothing an image.
11.Write a program to contour an image.
12.Write a program to detect a face/s in an image.
4
COMPUTER GRAPHICS AND IMAGE PROCESSING LABORATORY
(21CSL66)
PART-B
Student should develop a mini project and it should be demonstrate in the laboratory
examination,
(During the practical exam: the students should demonstrate and answer
Viva-Voce)
5
OpenGL
What is OpenGL
OpenGL is a software interface to graphics hardware.
Graphics rendering API
Rendering?–converting geometric or
mathematical object descriptions into frame
buffer values.
high-quality color images composed of geometric
and image primitives
window system independent
operating system independent
This interface consists of 150 distinct commands they are
used to specify the object and operations needed to produce
interactive 2D & 3D graphics application.
Currently there are 3 major graphics APIs currently
being used right now.
GLX
Abstractions
GLUT
Windowing toolkit (key, mouse handler, window events)
GLU
• Viewing –perspective/orthographic
• Image scaling, polygon tessellation
• Sphere, cylinders, quadratic surfaces
GL
glVertex3fv( v )
GL_LINES
GL_POLYGON
GL_LINE_STRIP GL_LINE_LOOP
GL_POINTS
GL_TRIANGLES
GL_QUADS
GL_QUAD_STRIP
GL_TRIANGLE_STRIP GL_TRIANGLE_FAN
12
GL_POINTS each vertex is displayed as one
pixel
GL_LINES Takes successive pair of
vertices(lines are disconnected)
GL_LINE_STRIP Successive vertices are
connected
GL_LINE_LOOP polyline are closed.
POLYGON
Polygon is an object that has
1.Border that can be describe by line
loop.
2.Defined interiors.
3 properties of a polygon
Simple, Convex, Flat
If no two edges of a polygon cross each other it’s a
simple polygon.
convex non-convex
Data types supported in OpenGL
Suffix Data Type Typical Corresponding C- OpenGL Type
Language Type Definition
b 8-bit integer signed char GLbyte
Functions:
glFunction: glBegin, glClear, glVertex, …
Constants:
GL_CONSTANT: GL_2D, GL_LINE
Datatypes:
GLtype: GLbyte, GLint, GLfloat
Example
glClearColor(1.0,1.0,1.0,0.0);// Background color
glMatrixMode(GL_PROJECTION); // Set transformation
glLoadIdentity;
gluOrtho2D(0, 200, 0, 150);
void display(void)
{
glClear( GL_COLOR_BUFFER_BIT);
glColor3f(1.0, 0.0, 0.0);
glBegin(GL_LINES);
glVertex3f(2.0, 4.0, 0.0);
glVertex3f(8.0, 4.0, 0.0);
glEnd();
glFlush();
}
24
The following is a main program that works for most graphics applications
#include <GL/glut.h>
void main(int *argc, char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
glutInitWindowSize(500,500);
glutInitWindowPosition(0,0);
glutCreateWindow(“ Sample program”);
glutdisplayFunc(display);
myinit();
glutMainLoop();
}
25
Example
Example 3D
// Set color
Note:
• Objects are drawn in the current local axis-frame;
• With transformations this frame can be changed.