Professional Documents
Culture Documents
- Geometrical Objects
- Circle
- Ellipse
- Rectangle
- Polygons, Polylines
- Transformations – 2D
- Windowing and Viewport
- Mapping of Objects
- Projections
- Rendering
- Light Effects
- Shades and Shadows
- Textures
- Ray Tracing
- Illumination
III SOFTWARE STANDARDS
1. GKS (Graphics Kernel System) 1984 : First software 7. Java 3D : Produce 3D web displays
standard accepted by ISO including ANSI --- First 2D
then extended to 3D 8. RenderMan Interface by Pixar Corporation:
Produces scenes by using lightning models
2. PHIGS (Programmer’s Hierarchical Interactive
Graphics System): 9. Mathematica (provides Graphics Libraries)
• It was extension of GKS.
• New features like rendering, colour 10. Matlab (provides Graphics Libraries)
specifications, picture manipulation were
added. 11. Maple (provides Graphics Libraries)
Tip: An application programming interface (API) is a set of routines, protocols, and tools for building software applications.
OpenGL Architecture
OpenGL Hierarchy
• GL (Graphic Library)
• Lowest level: vertex, matrix manipulation
• Eg:- glVertex3f(point.x, point.y, point.z)
Function names are prefixed with gl and each Component name with a Capital letter
Eg:
glBegin(with set of primitives)
glBegin(GL_LINES);
glClear()
glVertex2i(180,15);
glEnd()
glVertex2i(10,145);
glCopyPixel()
glEnd();
glPolygonMode()
Eg:
GL_2D
GL_RGB
GL_POLYGON
DATA TYPES
Special built-in data types are there in OpenGL
Eg:
GLbyte
GLshort
GLint
GLfloat
GLdouble
GLboolean
OpenGL WINDOW
To create any graphics display/object using OpenGL, we first need to setup a DISPLAY WINDOW
(rectangular area where our picture will be displayed)
50
300
400
glutDisplayFunc(lineSegment);
All Display Windows we have created are activated by using the following function:
glutMainLoop();
It must be put at the last in the program
Positioning a Window
glutInitWindowPosition(50,100);
initial
Specifying the Window Size:
glutInitWindowSize(400, 300);
glClearColor(GL_COLOR_BUFFER_BIT);
Setting Object Color:
glColor3f(0.0, 0.4, 0.2);
indicates that we are specifying 3 RGB color components using floating point values
To Display Line Segment (say) in 2D, we still have to use 3D viewing operations.
glMatrixMode(GL_PROJECTION);
X Values Y Values
OpenGL Program to plot a line
#include<iostream>
#include<GL/glut.h>
void init()
{ glClearColor(0.0, 0.0, 0.0, 0.0); // Set display window colour to white
glMatrixMode(GL_PROJECTION); // Set Projection Parameters
gluOrtho2D(0.0, 250.0, 0.0, 150.0); //Values of xMin, yMin, xMax, yMax
}
void Line()
{ glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0, 1.0, 1.0);
glBegin(GL_LINES);
glVertex2i(180,15);
glVertex2i(10,145);
glEnd();
glFlush();
} Output
int main(int agc, char** argv)
{ glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(400, 300);
glutInitWindowPosition(50, 100);
glutCreateWindow(“Line Drawing");
init();
glutDisplayFunc(Line);
glutMainLoop();
return 0;
}
Anoder Code Example
void Display()
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0, 1.0, 0.0);
glBegin(GL_POLYGON);
glVertex2f(-0.5, -0.5);
glVertex2f(-0.5, 0.5);
glVertex2f(0.5, 0.5);
glVertex2f(0.5, -0.5);
glEnd();
glFlush();
}
….