Académique Documents
Professionnel Documents
Culture Documents
Manjunath CR
Session : Jan09-May09
Programming 2D
Point can be in
2D : p(x,y) 3D : p(x,y,z)
3D can represented as
Z=0 -> p(x,y,0) Triplet p=(x,y,z) or a column matrix
Manjunath CR
OpenGL
OpenGL is a software interface that allows the programmer to create 2D and 3D graphics images OpenGL is independent of the hardware, operating, and windowing systems in use OpenGL functions in a client/server environment OpenGL functions (which are called commands) are designed to provide 2D and 3D graphics with the emphasis on 3D
Manjunath CR
Session : Jan09-May09
OpenGL
OpenGLs Atoms: Vertices a point is called a vertex user coordinates: possibly infinite drawing pad vertices (plural of vertex) are always 3D can also be used as 2D general form: glVertex* examples: glVertex2i(GLint x, GLint y) glVertex3f(GLfloat x, GLfloat y, GLfloat z) glVertex3fv(GLfloat[] vertex)
Manjunath CR
06CS65 CG&V - Unit - II Graphics programming 4
Session : Jan09-May09
OpenGL
Manjunath CR
Session : Jan09-May09
OpenGL
Manjunath CR
Session : Jan09-May09
OpenGl
glBegin(GL POINTS); glVertex2f(x1,y1); glVertex2f(x2,y2); glEnd(); glBegin(GL LINES); glVertex2f(x1,y1); glVertex2f(x2,y2); glEnd();
Manjunath CR
06CS65 CG&V - Unit - II Graphics programming 7
Session : Jan09-May09
Graphics function
Manjunath CR
Session : Jan09-May09
State changing
Transformation functions Attribute functions
Manjunath CR
Session : Jan09-May09
OpenGL Interface
Manjunath CR
10
Session : Jan09-May09
Manjunath CR
11
Session : Jan09-May09
Manjunath CR
12
Session : Jan09-May09
Geometric primitives
are specified in the problem domain : points, lines polygons, curves and surfaces
Manjunath CR
13
Session : Jan09-May09
Line segment
Polylines
Manjunath CR
14
Session : Jan09-May09
polygon
Polygon : object has a border that can be described by a line loop The performance of the GP can characterized by no of polygons per second that can be rendered
Rendering in 2 ways
Edges Its interior with solid color or a pattern
3 properties of polygon
Simple, convex & flat
Manjunath CR
06CS65 CG&V - Unit - II Graphics programming 15
Session : Jan09-May09
Filling the Polygon Interior (2D) To be filled, polygons have to be: simple and convex. A simple polygon has a well-defined interior
Convex polygon: All points on the line segment between any 2 points inside the polygon are inside the polygon.
Manjunath CR
16
Session : Jan09-May09
Polygon Types The appearance of polygons depends on the attributes that have been set before
Manjunath CR
17
Session : Jan09-May09
Polygon Strips
Manjunath CR
18
Session : Jan09-May09
Manjunath CR
19
Session : Jan09-May09
Text
Manjunath CR
20
Session : Jan09-May09
Stroke text
can be treated like all other graphics objects. Computer Graphics If the character define by a closed boundary we can fill it Advantages,
it can be defined to have all the details of any other objects It can be manipulated by standard transformation Viewed like any other graphical primitives
Manjunath CR
21
Session : Jan09-May09
Defining a full 128 or 256 character stroke, can be complex & font can take more memory , processing time Standard postscript fonts are defined by polynomial curves
Postscript can be used for high or low resolution application
Manjunath CR
22
Session : Jan09-May09
Raster text
Simple & fast
Manjunath CR
23
Session : Jan09-May09
Characters are defined as rectangles of bits called bit block Each block defines a single character by a pattern of 0 and 1 bits in the block Raster character can be placed in the frame buffer rapidly by a bit-block-transfer (bitblt) operation
Manjunath CR
24
Session : Jan09-May09
To increase the size of the character by replicating or duplicating pixels Transformation is not possible
Manjunath CR
25
Session : Jan09-May09
Stroke and bitmap character are created from other primitives openGl does not have a text a primitive
GLUT library provides few predefined bitmap and stroke Placed at present raster position on the display
glRasterPos2i(rx, ry);
glutBitmapCharacter(GLUT BITMAP 8 BY 13, k); rx += glutBitmapWidth(GLUT BITMAP 8 BY 13, k) K = no of ascii character
Manjunath CR
06CS65 CG&V - Unit - II Graphics programming 26
Session : Jan09-May09
Attributes
Is a property that determines how a geometrics primitives is rendered
EX: Color , thickness of the line, pattern filling the polygons
Manjunath CR
27
Session : Jan09-May09
Color
Tristimulus values
Additive & subtractive color
Color solid
Manjunath CR
28
Session : Jan09-May09
Manjunath CR
29
Session : Jan09-May09
RGB color From programmer view, 2 approaches RGB color model Indexed color model
Manjunath CR
30
Session : Jan09-May09
RGB color
Each color component stored separately in the frame buffer Usually 8 bits per component in buffer Note in glColor3f the color values range from 0.0 (none) to 1.0 (all), while in glColor3ub the values range from 0 to 255
3byte 1 for each color
Manjunath CR
31
Session : Jan09-May09
- A-alpha:- opacity(A=1) or
Manjunath CR
32
Session : Jan09-May09
Indexed color
Colors are indices into tables of RGB value Requires less memory
indices usually 8 bits not as important now
Memory inexpensive Need more colors for shading
Manjunath CR
33
Session : Jan09-May09
Viewing
Manjunath CR
34
Session : Jan09-May09
OpenGL places a camera at the origin pointing in the negative z direction The default viewing volume is a box centered at the origin with sides of length 2
Manjunath CR
35
Session : Jan09-May09
Manjunath CR
36
Session : Jan09-May09
Defining a relation between objects and camera Projection 2D-viewing (just clipping): viewing/clipping rectangle
Manjunath CR
37
Session : Jan09-May09
Using glOrtho
void glOrtho(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble near, GLdouble far) void gluOrtho2D(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top)
Manjunath CR
38
Session : Jan09-May09
Matrix Mode
2 important matrices
Model-view projection
Manjunath CR
39
Session : Jan09-May09
Matrix Mode
Two- and Three-dimensional Viewing In glOrtho(left, right, bottom, top,near, far) the near and far distances are measured from the camera
Two-dimensional vertex commands place all vertices in the plane z=0 If the application is in two dimensions, we can use the function
gluOrtho2D(left,right,bottom,top)
In two dimensions, the view or clipping volume becomes a clipping window
Manjunath CR
06CS65 CG&V - Unit - II Graphics programming 40
Session : Jan09-May09
Control Functions
GLUT functions
glutInit allows application to get command line arguments and initializes system glutInitDisplayMode requests properties for the window (the rendering context)
RGB color Single buffering Properties logically ORed together
Session : Jan09-May09
glutCreateWindow create window simple glutDisplayFunc display callback glutMainLoop enter infinite event loop
with
title
Manjunath CR
42
Session : Jan09-May09
#include <GL/glut.h> int main(int argc, char** argv) { glutInit(&argc,argv); glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB); glutInitWindowSize(500,500); glutInitWindowPosition(0,0); glutCreateWindow("simple"); glutDisplayFunc(mydisplay); init(); glutMainLoop(); }
Manjunath CR
43
Session : Jan09-May09
Manjunath CR
44
Session : Jan09-May09
Program structure
Most OpenGL programs have a similar structure that consists of the following functions
main():
defines the callback functions opens one or more windows with the required properties enters event loop (last executable statement)
callbacks
Display function Input and window functions
Manjunath CR
06CS65 CG&V - Unit - II Graphics programming 45