Chapter 7 - 9 Final
Chapter 7 - 9 Final
Chapter 7
Modeling:
Define object in local coordinates
Place object in world coordinates (modeling
transformation)
Viewing:
Define camera parameters
Find object location in camera coordinates (viewing
transformation)
Projection: project object to the viewplane
Clipping: clip object to the view volume
Viewport transformation
Rasterization: rasterize object
2/18/23 Computer Graphics MTU – CS
Viewing Transformation
7
Matrix Modes
Matrix Mode (glMatrixMode)
ModelView Matrix (GL_MODELVIEW)
- Model related operations: glBegin, glEnd, glTranslate,
glRotate, glScale, gluLookAt…
Projection Matrix (GL_PROJECTION)
- Setup projection matrix: glViewport, gluPerspective/
glOrtho/ glFrustum…
glut routines
Cube glutWireCube(GLdouble size) glutSolidCube(GLdouble
size)
Tetrahedron glutWireTetrahedron() glutSolidTetrahedron()
Normal Vector
1. A normal vector (or normal) points in a direction
perpendicular to a surface (in general).
2. An object’s normal vectors define its orientation relative
to light sources. These vectors are used by OpenGL to
determine how much light the object receives at its vertices.
3.Lighting for vertices is calculated after MODELVIEW
transformation before PROJECTION transformation (vertex
shading) glBegin (GL_POLYGON);
glNormal3fv(n0);
glVertex3fv(v0);
glNormal3fv(n1);
glVertex3fv(v1);
glNormal3fv(n2);
glVertex3fv(v2);
glNormal3fv(n3);
glVertex3fv(v3);
2/18/23
glEnd();
Computer Graphics MTU – CS
Contd…
56
// A spotlight
glLightfv(GL_LIGHT1, GL_POSITION, position);
glLightfv(GL_LIGHT1, GL_DIFFUSE, diffuseRGBA);
glLightfv(GL_LIGHT1, GL_SPOT_DIRECTION,
spotDirection);
glLightf(GL_LIGHT1, GL_SPOT_CUTOFF, 45.0f);
glLightf(GL_LIGHT1, GL_SPOT_EXPONENT, 30.0f);
Parameters:
GL_LIGHT_MODEL_AMBIENT
- global RGBA ambient intensity
Parameters:
GL_AMBIENT, GL_DIFFUSE, GL_SPECULAR,
GL_EMISSION, GL_SHININESS
2/18/23 Computer Graphics MTU – CS
Drawing Example
Adding Lighting:
float lPos[] = {1.0,1.0,1.0,1.0};
glLightfv(GL_LIGHT0,GL_POSITION,lPos);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glShadeModel(GL_SMOOTH);
// Setup camera
// Draw objects
2/18/23 Computer Graphics MTU – CS
B. Shading in OpenGL
63
Left: Flat shading of a triangle mesh in OpenGL. Right: Gouraud shading. Note that the mesh
appears smooth, although the coarseness of the geometry is visible at the silhouettes of the mesh.
2/18/23 Computer Graphics MTU – CS
Contd…
64
Texture Procedures
- Textures may be defined procedurally. As input, a
procedure requires a point on the surface of an object,
and it outputs the surface albedo at that point.
Examples of procedural textures include
checkerboards, fractals, and noise.
Digital Images
- To map an arbitrary digital image to a surface, we can
define texture coordinates (u, v) ∈ [0, 1]2.
- For each point [u0, v0] in texture space, we get a point
in the corresponding image.