Tuesday, June 2, 2015

Summary of Feedback Received for CG Course Conduction

After the completion of CG Course, students were asked to fill up Feedback Form.

Link to Feedback Form

A total of 33 students replied with the feedback. Below are the summary of responses received from the students:






Saturday, April 25, 2015

CG Seminar

Seminar was given to students on the following topics:
  1. What is GPU? CPU vs GPU
  2. How Touch Screen works?
  3. Texture Mapping in OpenGL
  4. How z-buffer Algorithm works?
  5. How Ball Mouse and Optical Mouse work?
  6. Interfaces to Three Dimensional Applications
  7. Projections and Shadows
  8. How to display Text in OpenGL?
Students actively participated in the seminar and the content delivered in the seminar was satisfactory.

I would like to thank each of the students who presented the seminar topics and also to the students who attended the seminar with enthusiasm. 

Following are the PPT links of seminar topics:
  1. What is GPU? CPU vs GPU - by Nithin Santhosh [USN: 2SD12CS063] + A video that demonstrates difference between CPU vs GPU
  2. Texture Mapping in OpenGL - by Manas Nayak [USN: 2SD12CS049] 
  3. How Touch Screen Works? - by Varun Parwatikar [USN: 2SD12CS133]
  4. Interfaces to Three Dimensional Applications - by Deepa Sangati [USN: 2SD12CS030]
  5. How to Display Text in OpenGL? - by Pooja Naik [USN: 2SD12CS065] + OpenGL code to demonstrate display of Texts in OpenGL
  6. Projections and Shadows - by Himaja Byale [USN: 2SD12CS041]
  7. How z-buffer Algorithm Works? - by Pooja Kesari [USN: 2SD12CS069]
  8. How Ball Mouse and Optical Mouse Work? - by Ankit Kaneri [USN: 2SD12CS014]

Friday, April 17, 2015

Notes on Basic Raster Graphics Algorithms for drawing 2D primitives

Contents in the notes are taken from the following resources:

Refer the following notes:

Thursday, April 9, 2015

CG Lab Termworks


Following link contains list of CG Lab termworks, based on which, final lab evaluation would be conducted during last week of April

Go through these termworks and implement the same on your own.

In-case of any doubts/clarifications, feel free to approach me during college hours.


These termworks cover the following CG Concepts:
  • Input interaction and menus
  • Generating Fractals
  • 2D and 3D Object Transformations
  • Specification of Projections
  • Positioning and Orienting the Camera
  • Lighting and material specifications

Friday, March 27, 2015

Lighting in OpenGL

To use lighting in OpenGL, we must keep several things in mind.

We have to first enable lighting by using glEnable(GL_LIGHTING)

OpenGL supports maximum of 8 light sources named from GL_LIGHT0 to GL_LIGHT7.

By default, when a lighting in enabled in OpenGL, only one light source is enabled, and it is situated along +ve Z-axis and emits WHILTE AMBIENT light.

We have to enable the light sources by using glEnable() function. 
For example, the following code enables GL_LIGHT0:

glEnable(GL_LIGHT0);
Output of Enabling Single Light Source
Once lighting is enabled, color of the object is immediately replaced by color of the light sources.
In OpenGL, we can position the light sources along the principal axes as well as specify the types of light sources.

Types of Light Sources in OpenGL:

Light Sources in OpenGL can be categorized into three types:
  • Ambient Light Source: This light source has same intensity throughout the scene. Hence mathematically, intensity of ambient light is a constant value, and hence objects look dull in the scene due to ambient light source.
Effect of Ambient Light on Object
To specify an ambient light source in OpenGL, we need to first specify the color of ambient intensity and then need to apply it to light source. 

For example:

float ambient_light0[] = {1.0, 1.0, 1.0, 0.0};
glLightfv(GL_LIGHT0, GL_AMBIENT, ambient_light0);

First three elements of ambient_light0 array specify a low intensity WHITE light (we can specify values between 0 to 255, 0 being least intense and 255 being highest intense). 

Fourth element signifies BLENDING value and is used where-in multiple light interactions are involved. But to see the effect, we need to enable BLENDING option.

glLightfv() function is used to specify the types of light sources. The above code specifies ambient light source for GL_LIGHT0.
  • Diffuse Light Source: Diffuse light source is treated as a point light source that emits light equally in all directions. The intensity of a point light source is inversely proportional to square of the distance between the source and the surface. Objects tend to have high contrast due to diffuse lights. Also objects tend to look either darker or brighter. Hence to compensate high contrasting effect, we usually add ambient light also to a scene.
Specification of Diffuse Light Source in OpenGL:

float diffuse_light0[] = {50.0, 0.0, 0.0, 0.0};
glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse_light0);

Effect of Diffuse Light on Object

  • Specular Light Source: Specular light source is a spotlight and is characterized by a narrow range of angles through which light is emitted. Specular lights specify how the object shines when light is incident on the object. But to get dramatic effects, we must also specify material properties for the object of interest.

Specification of Specular Light Source in OpenGL:

float specular_light0[] = {50.0, 0.0, 0.0, 0.0};
glLightfv(GL_LIGHT0, GL_SPECULAR, specular_light0);

Effect of Specular Light on Object

Positioning Light Sources in OpenGL:

Light Sources in OpenGL can be positioned along X, Y and Z-axis respectively.

Position of the light source is specified with a four element array.

First three elements specify the position of the light source.
(1, 0, 0) positions light source along X-axis.
(0, 1, 0) positions light source along Y-axis.
(0, 0, 1) positions light source along Z-axis.

Fourth element specifies whether a light source is at INFINITE distant from the object or not. Value of 0 signifies an INFINITE distant light source and value of 1 signifies a FINITE distant light source.

The following code positions RED DIFFUSE infinite distant light source along X-axis, BLUE AMBIENT finite distant light source along Y-axis and GREEN SPECULAR infinite distant light source along Z-axis:

float light0_position[] = {1, 0, 0, 0};
float light0_diffuse[] = {50, 0, 0, 0};
float light1_position[] = {0, 6, 0, 1};
float light1_ambient[] = {0, 0, 50, 0};
float light2_position[] = {0, 0, 1, 0};
float light2_specular[] = {0, 50, 0, 0};

glLightfv(GL_LIGHT0, GL_POSITION, light0_position);
glLightfv(GL_LIGHT0, GL_DIFFUSE, light0_diffuse);
glLightfv(GL_LIGHT1, GL_POSITION, light1_position);
glLightfv(GL_LIGHT1, GL_AMBIENT, light1_ambient);
glLightfv(GL_LIGHT2, GL_POSITION, light2_position);
glLightfv(GL_LIGHT2, GL_SPECULAR, light2_specular);

Effect of Three Light Sources

Material Specifications in OpenGL:

The glMaterialfv function specifies material parameters for the lighting model.

The following code specifies Ambient Reflection value of 0.25 to the material:

float material_ambient[] = {0.25, 0.25, 0.25, 1.0};
glMaterialfv(GL_FRONT, GL_AMBIENT, material_ambient);

The function glMaterialfv() takes three arguments. Meaning of each of the arguments is explained below:

First argument specifies the face or faces that are being updated. It must have one of the following values:
  • GL_FRONT
  • GL_BACK
  • GL_FRONT_AND_GL_BACK
Second argument specifies the material parameter of the face or faces being updated. The parameters that can be specified using glMaterialfv, and their interpretations by the lighting equation, are as follows:
  • GL_AMBIENT: The fourth parameter must contain four floating-point values that specify the ambient RGBA reflectance of the material. Integer values are mapped linearly such that the most positive represent-able value maps to 1.0, and the most negative represent-able value maps to -1.0. Floating-point values are mapped directly. Neither integer nor floating-point values are clamped. The default ambient reflectance for both front-facing and back-facing materials is (0.2, 0.2, 0.2, 1.0).
  • GL_DIFFUSE: The fourth parameter must contain four floating-point values that specify the diffuse RGBA reflectance of the material. Integer values are mapped linearly such that the most positive represent-able value maps to 1.0, and the most negative represent-able value maps to -1.0. Floating-point values are mapped directly. Neither integer nor floating-point values are clamped. The default diffuse reflectance for both front-facing and back-facing materials is (0.8, 0.8, 0.8, 1.0).
  • GL_SPECULAR: The fourth parameter must contain four floating-point values that specify the specular RGBA reflectance of the material. Integer values are mapped linearly such that the most positive represent-able value maps to 1.0, and the most negative represent-able value maps to -1.0. Floating-point values are mapped directly. Neither integer nor floating-point values are clamped. The default specular reflectance for both front-facing and back-facing materials is (0.0, 0.0, 0.0, 1.0).
  • GL_EMISSION: The fourth parameter must contain four floating-point values that specify the RGBA emitted light intensity of the material. Integer values are mapped linearly such that the most positive represent-able value maps to 1.0, and the most negative represent-able value maps to -1.0. Floating-point values are mapped directly. Neither integer nor floating-point values are clamped. The default emission intensity for both front-facing and back-facing materials is (0.0, 0.0, 0.0, 1.0).
  • GL_SHININESS: The fourth parameter is a single integer value that specifies the RGBA specular exponent of the material. Integer values are mapped directly. Only values in the range [0, 127] are accepted. The default specular exponent for both front-facing and back-facing materials is 0.
  • GL_AMBIENT_AND_DIFFUSE: Equivalent to calling glMaterial twice with the same parameter values, once with GL_AMBIENT and once with GL_DIFFUSE.
  • GL_COLOR_INDEXES: The fourth parameter must contain three floating-point values that specify the color indexes for ambient, diffuse, and specular lighting. These three values, and GL_SHININESS, are the only material values used by the color-index mode lighting equation.
OpenGL Code that demonstrates specification of light sources, positioning of light sources along principal axes and also specifies material properties to the object TEAPOT:

1:  #include<stdio.h>  
2:  #include<math.h>  
3:  #include<GL/glut.h>  
4:  void myInit()  
5:  {  
6:     glClearColor(0.0, 0.0, 0.0, 0.0);  
7:     glColor3f(1.0, 0.0, 0.0);  
8:     glMatrixMode(GL_PROJECTION);  
9:     glLoadIdentity();  
10:     glOrtho(-2.0, 2.0, -2.0, 2.0, -2.0, 2.0);    // set viewing volume to 2 X 2 X 2  
11:     glMatrixMode(GL_MODELVIEW);  
12:     glEnable(GL_LIGHT0);  
13:     glEnable(GL_LIGHT1);  
14:     glEnable(GL_LIGHT2);  
15:     float light0_position[] = {1, 0, 0, 0};  
16:     float light0_diffuse[] = {50, 0, 0, 0};  
17:     float light1_position[] = {0, 1, 0, 0};  
18:     float light1_ambient[] = {0, 0, 50, 0};  
19:     float light2_position[] = {0, 0, 1, 0};  
20:     float light2_specular[] = {0, 50, 0, 0};  
21:     glLightfv(GL_LIGHT0, GL_POSITION, light0_position);  
22:     glLightfv(GL_LIGHT0, GL_DIFFUSE, light0_diffuse);  
23:     glLightfv(GL_LIGHT1, GL_POSITION, light1_position);  
24:     glLightfv(GL_LIGHT1, GL_AMBIENT, light1_ambient);  
25:     glLightfv(GL_LIGHT2, GL_POSITION, light2_position);  
26:     glLightfv(GL_LIGHT2, GL_SPECULAR, light2_specular);  
27:     float material_ambient[] = {0.25, 0.25, 0.25, 1.0};  
28:     float material_diffuse[] = {0.8, 0.8, 0.8, 1.0};  
29:     float material_specular[] = {0.8, 0.8, 0.8, 1.0};  
30:     float shininess = 50;  
31:     glMaterialfv(GL_FRONT, GL_AMBIENT, material_ambient);  
32:     glMaterialfv(GL_FRONT, GL_DIFFUSE, material_diffuse);  
33:     glMaterialfv(GL_FRONT, GL_SPECULAR, material_specular);  
34:     glMaterialf(GL_FRONT, GL_SHININESS, shininess);  
35:  }  
36:  void display()  
37:  {  
38:     glRotatef(-0.1, 1.0, 1.0, 1.0);  
39:     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );   
40:     glutSolidTeapot(1.0);  
41:     glFlush();  
42:  }  
43:  int main(int argc, char **argv)  
44:  {  
45:    glutInit(&argc, argv);  
46:    glutInitDisplayMode(GLUT_SINGLE | GLUT_DEPTH | GLUT_RGB );  
47:    glutInitWindowSize(500, 500);  
48:    glutInitWindowPosition(0, 0);  
49:    glutCreateWindow("Lighting in OpenGL");  
50:    glutDisplayFunc(display);  
51:    glutIdleFunc(display);  
52:    glEnable(GL_DEPTH_TEST);  
53:    glEnable(GL_LIGHTING);  
54:    myInit();  
55:    glutMainLoop();  
56:  return 0;  
57:  }  

Output



Tuesday, March 17, 2015

Sample OpenGL Program



1:  #include<stdio.h>  
2:  #include<GL/glut.h>  
3:  void myInit()  
4:  {  
5:     glClearColor(1.0, 1.0, 1.0, 1.0);  
6:     glColor3f(1.0, 0.0, 0.0);  
7:     glMatrixMode(GL_PROJECTION);  
8:     glLoadIdentity();  
9:     gluOrtho2D(0.0, 10.0, 0.0, 10.0);  
10:    glMatrixMode(GL_MODELVIEW);  
11:  }  
12:  void display()  
13:  {  
14:     glClear(GL_COLOR_BUFFER_BIT);  
15:     glBegin(GL_LINES);  
16:      glVertex2f(1.0, 1.0);  
17:      glVertex2f(9.0, 9.0);  
18:     glEnd();  
19:     glFlush();  
20:  }  
21:  int main(int argc, char **argv)  
22:  {  
23:    glutInit(&argc, argv);  
24:    glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE);  
25:    glutInitWindowSize(400, 300);  
26:    glutInitWindowPosition(100, 100);  
27:    glutCreateWindow("My First Example");  
28:    glutDisplayFunc(display);  
29:    myInit();  
30:    glutMainLoop();  
31:    return 0;  
32:  }  

This program draws line between two points (1,1) and (9,9) 

Output:


Line 2 includes header file glut.h present in GL folder. Inclusion of glut.h is mandatory as it contains function declarations that are necessary for compilation. Functions available under glut.h can internally call glu.h and gl.h headers. gl.h is a core header file which provides core functionality features for OpenGL. Functions available in glu.h file internally call functions from gl.h header. Functions starting with glut keyword belong to glut.h header file; similar statements can be made for functions belonging to glu.h and gl.h header files. All function names of OpenGL use Camel Casing convention except for the first keyword.

Let's analyze the code from main() function:

Line 23 specifies glutInit() function[this function belongs to glut.h header, as it starts with keyword glut]. This function specifies the interaction between the window system and OpenGL.

Line 24 specifies the usage of RGB coloring mode and usage of SINGLE buffered display. We can also specify DOUBLE, that specifies double buffered display.

Line 25 specifies width and height of the window as 400 and 300 pixels respectively.

Line 26 positions the window in (100, 100) measured from IV-quadrant.

Line 27 gives the name for the window.

Line 28 registers a display callback function myDisplay(), that is invoked automatically whenever there is a need for window refresh.

Line 30 enters the GLUT event processing loop. This routine is called at most once in a GLUT program. Once called, this routine will never return. It will call as necessary any callbacks that have been registered.

Now let's focus our attention on myInit() function:

Line 5 specifies the background color for the window. First three arguments specify the normalized intensity values for RED, GREEN and BLUE colors. Fourth argument specifies ALPHA value, that sets the transparency for the window. To use the fourth argument, BLENDING has to be enabled. In this example, solid window with white color is rendered.

Line 6 specifies the color of the primitives in RGB values. In this example, primitives are drawn with red color. Note that color is an attribute of the primitive and is part of OpenGL state. This means that once the attribute is set, it will be active throughout program execution.

Line 7 changes the matrix from MODELVIEW to PROJECTION. OpenGL supports two types of matrices of order 4X4 (also called as homogeneous coordinate system matrices). MODELVIEW matrix specifies transformation of primitives as well as positioning and orienting the camera. PROJECTION matrix specifies the type of projection (parallel or perspective).

Line 8 loads 4X4 identity matrix to PROJECTION matrix.

Line 9 specifies that the program is using orthographic projection (a type of parallel projection) and also specifies the area of 2D view rectangle. First and third argument values specify (left, bottom) point and second and fourth argument values specify (right, top) point of the view rectangle. Note that this function internally calls glOrtho() function, which specifies 3D vew volume with (near, far) values as ZERO.

VIEW VOLUME specification using glOrtho()

Line 10 switches back the matrix from PROJECTION to MODELVIEW. Note that it is important to use MODELVIEW matrix for modeling objects, as these specifications are part of MODELVIEW transformations.

Let's briefly discuss myDisplay() function:

Line 14 clears the buffer flag. This function can clear all types of buffer flags supported by OpenGL. In this example, color buffer flag is cleared (reset).

Line 15 draws lines between pair of vertices such that no lines share a common point. Specification of vertices have to be done between glBegin() and glEnd() functions. OpenGL has many options to be passed to glBegin() function:

  • GL_POINTS - each vertex specification is displayed at a size of at-least one pixel (we can change the size of the pixel using glPointSize() function)
  • GL_LINE_STRIP - connects successive vertices to form successive line segments. But this option does not join last vertex with first
  • GL_LINE_LOOP - same as GL_LINE_LOOP but connects last vertex with first and hence forms a line loop
  • GL_POLYGON - the edges are the same as they would be if we used GL_LINE_LOOP; however the interior of the polygon is filled according to the color state (this can to be specified using glColor3f() function)
  • GL_TRIANGLES - successive groups of three vertices are interpreted as triangles
  • GL_QUADS - successive groups of four vertices are interpreted as quadrilaterals
  • GL_TRIANGLE_STRIP - each additional vertex is combined with the previous two vertices to define a new triangle
  • GL_QUAD_STRIP - to new vertices with the previous two vertices are combined to define a new quadrilateral
  • GL_TRIANGLE_FAN - fixes the first vertex and next successive pairs of vertices determine the triangles

glBegin() options

Lines 16-17 specifies two 2D points with the coordinates (1, 1) and (9, 9) [these values are specified in Object Coordinate System].

Line 19 empties all supported buffers of OpenGL (like network buffer, graphics accelerator, etc), causing all issued commands to be executed as quickly as they are accepted by the actual rendering engine. Though this execution may not be completed in any particular time period, it does complete in finite time.


OpenGL Handbook

CAT Result Analysis


Following is the Result Analysis for each CAT as well as CAM. This post will be updated after every CAT. Final CAM will be updated after the end of all CAT and once CTA is awarded.


CG PPTs


The following PPTs are taken from Edward Angel PPTs

These PPTs are modified according to the requirements of the syllabus and flow.
Some of the concepts are also taken from

  • Computer Graphics Using OpenGL, F.S. Hill, Jr., 2nd Edition, Pearson Education
  • Advanced Graphics Programming Using OpenGL, Tom McReynolds and David Blythe, Elsevier Inc
  1. Introduction-1
  2. Introduction-2
  3. Introduction-3
  4. OpenGL-1
  5. OpenGL-2
  6. OpenGL-3
  7. Input Interaction-1
  8. Input Interaction-2
  9. Input Interaction-3
  10. Viewing-1
  11. Viewing-2
  12. Viewing-3
  13. Viewing-4
  14. Lighting and Shading
New PPTs will be uploaded as and when the contents are covered in the class.

CG Worksheets

Following documents contain the details of the contents covered in each class, classes missed, labs held, labs missed (both A & B divisions).

These documents will be updated after each class/lab.
  1. Class and Lab Worksheet A Div  
  2. Class Worksheet B Div

Lab Attendance Sheets

Following document contains Computer Graphics Laboratory Attendance Sheets.

This document is updated after every lab.

CAT Marks List and Attendance

Following documents contain CAT Marks Distribution and also attendance details of each class (both A & B Divisions).

Documents will be updated after every class.
  1. CAT Marks List and Attendance Status A Div
  2. Attendance B Div

Notes on Linear Algebra and Affine Transformations

This document contains notes on Linear Algebra and Affine Transformations.

Contents are taken from the following books:

  1. Computer Graphics Using OpenGL, F.S. Hill, Jr., 2nd Edition, Pearson Education [3rd, 4th Chapter]
  2. Interactive Computer Graphics A Top-Down Approach Using OpenGL, Edward Angel, 5th Edition, Pearson [4th Chapter]

Computer Graphics Syllabus