PROGRAM 7
Program using OpenGL functions, to draw a simple
shaded scene consisting of a tea pot on a table. Define
suitably the position and properties of the light source
along with the properties of surfaces of the solid
object used in the scene.
#include <GL/glut.h>
void wall (double thickness)
{
//draw thin wall with top = xz-plane, corner at origin
glPushMatrix();
glTranslated (0.5, 0.5 * thickness, 0.5);
glScaled (1.0, thickness, 1.0);
glutSolidCube (1.0);
glPopMatrix();
}
After
transformation
void tableLeg (double thick, double len) //draw one table leg
{
glPushMatrix();
glTranslated (0, len/2, 0);
glScaled (thick, len, thick);
glutSolidCube (1.0);
glPopMatrix();
}
1
23
4
floor
//draw the table - a top and four legs, draw the top first
void table (double topWid, double topThick, double legThick, double legLen)
{
glPushMatrix();
glTranslated (0, legLen, 0);
glScaled(topWid, topThick, topWid);
glutSolidCube (1.0); // table top
glPopMatrix();
double dist = topWid/2.0 - legThick/2.0;
glPushMatrix();
glTranslated (dist, 0, dist);
tableLeg (legThick, legLen); // 1
glTranslated (0.0, 0.0, -2 * dist);
tableLeg (legThick, legLen); // 2
glTranslated (-2*dist, 0, 2 *dist);
tableLeg (legThick, legLen); // 3
glTranslated(0, 0, -2*dist);
tableLeg (legThick, legLen); // 4
glPopMatrix();
}
1
23
4
floor
Table top
void displaySolid ()
{
//set properties of the surface material
GLfloat mat_ambient[] = {1.0, 0.0, 0.0, 1.0};
GLfloat mat_diffuse[] = {1.0, 1.0, 0.0, 1.0};
GLfloat mat_specular[] = {0.0, 1.0, 0.0, 1.0};
GLfloat mat_shininess[] = {50.0};
glMaterialfv (GL_FRONT, GL_AMBIENT, mat_ambient);
glMaterialfv (GL_FRONT, GL_DIFFUSE, mat_diffuse);
glMaterialfv (GL_FRONT, GL_SPECULAR, mat_specular);
glMaterialfv (GL_FRONT, GL_SHININESS, mat_shininess);
//set the light source properties
GLfloat lightIntensity[] = {1.0, 1.0, 1.0, 1.0};
GLfloat light_position[] = {2.0, 6.0, 3.0, 0.0};
glLightfv (GL_LIGHT0, GL_POSITION, light_position);
glLightfv (GL_LIGHT0, GL_DIFFUSE, lightIntensity);
10CSL67 CG LAB PROGRAM 7
10CSL67 CG LAB PROGRAM 7
10CSL67 CG LAB PROGRAM 7
//set the camera
glMatrixMode (GL_PROJECTION);
glLoadIdentity();
glOrtho (-1.0, 1.0, -1.0, 1.0, 0.1, 100.0);
glMatrixMode (GL_MODELVIEW);
glLoadIdentity();
gluLookAt (2.0, 1.0, 2.0, 0.0, 0.1, 0.0, 0.0, 1.0, 0.0);
//start drawing
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// delete the next 5 push and pop statements
glPushMatrix();
glTranslated (0.6, 0.38, 0.5); // position of tea pot
glRotated (30, 0, 1, 0);
glutSolidTeapot (0.08); // 0.08 = size of the tea pot
glPopMatrix ();
Original image without rotation
After rotation
// delete the next 3 push and pop statements
glPushMatrix();
glTranslated (0.4, 0, 0.4);
table (0.6, 0.02, 0.02, 0.3); //table
glPopMatrix();
wall (0.02); // floor
glPushMatrix();
glRotated (90.0, 0.0, 0.0, 1.0);
wall (0.02); // left
glPopMatrix();
glPushMatrix();
glRotated (-90.0, 1.0, 0.0, 0.0);
wall (0.02); // right
glPopMatrix();
glFlush();
}
void main (int argc, char ** argv)
{
glutInit (&argc, argv);
glutInitDisplayMode (GLUT_SINGLE|GLUT_RGB|GLUT_DEPTH);
glutInitWindowSize (500, 500);
glutCreateWindow ("tea pot on a table");
glutDisplayFunc (displaySolid);
glEnable (GL_LIGHTING);
glEnable (GL_LIGHT0);
glEnable (GL_DEPTH_TEST);
glEnable (GL_NORMALIZE);
glutMainLoop();
}

More Related Content

PDF
10CSL67 CG LAB PROGRAM 8
PDF
10CSL67 CG LAB PROGRAM 10
TXT
Ass day2 1_checkerboard...copy in cpp
PDF
The Ring programming language version 1.5.3 book - Part 65 of 184
PDF
The Ring programming language version 1.9 book - Part 65 of 210
PDF
The Ring programming language version 1.6 book - Part 57 of 189
PPT
Working with Callbacks
PDF
The Ring programming language version 1.5.2 book - Part 54 of 181
10CSL67 CG LAB PROGRAM 8
10CSL67 CG LAB PROGRAM 10
Ass day2 1_checkerboard...copy in cpp
The Ring programming language version 1.5.3 book - Part 65 of 184
The Ring programming language version 1.9 book - Part 65 of 210
The Ring programming language version 1.6 book - Part 57 of 189
Working with Callbacks
The Ring programming language version 1.5.2 book - Part 54 of 181

What's hot (20)

PPTX
Oprerator overloading
PPTX
Oops in c++
PDF
Oopsprc1c
PDF
The Ring programming language version 1.5.1 book - Part 53 of 180
DOCX
Caropro
TXT
Efek daun
PPT
ARTDM 170, Week13: Processing
PDF
Proga 0601
PDF
The Ring programming language version 1.7 book - Part 59 of 196
KEY
cocos2d 事例編 HungryMasterの実装から
PDF
The Ring programming language version 1.5.2 book - Part 63 of 181
PDF
Ios13 bluetooth-dualshock4
PDF
The Ring programming language version 1.5.2 book - Part 53 of 181
PDF
ARM 7 LPC 2148 lecture
PDF
The Ring programming language version 1.6 book - Part 59 of 189
PPTX
Better performance through Superscalarity
PDF
The Ring programming language version 1.6 book - Part 56 of 189
PDF
The Ring programming language version 1.8 book - Part 61 of 202
PDF
551 pd fsam_fayed_ring_doc_1.5.2
Oprerator overloading
Oops in c++
Oopsprc1c
The Ring programming language version 1.5.1 book - Part 53 of 180
Caropro
Efek daun
ARTDM 170, Week13: Processing
Proga 0601
The Ring programming language version 1.7 book - Part 59 of 196
cocos2d 事例編 HungryMasterの実装から
The Ring programming language version 1.5.2 book - Part 63 of 181
Ios13 bluetooth-dualshock4
The Ring programming language version 1.5.2 book - Part 53 of 181
ARM 7 LPC 2148 lecture
The Ring programming language version 1.6 book - Part 59 of 189
Better performance through Superscalarity
The Ring programming language version 1.6 book - Part 56 of 189
The Ring programming language version 1.8 book - Part 61 of 202
551 pd fsam_fayed_ring_doc_1.5.2
Ad

Viewers also liked (18)

PDF
10CSL67 CG LAB PROGRAM 2
PDF
10CSL67 CG LAB PROGRAM 6
PPTX
Executive Original Single GPS Vendor Migration Project Overview
PDF
Reference Letter
PDF
Vivansaa Logo.PDF
PPTX
Paula andrea álvarez vásquez
PPTX
Facebook Insights for Outsiders - Men in Web
DOC
KAREN-RESUME
PDF
PUEDE EL CRISTIANO BEBER ALCOHOL CON MODERACION
PDF
10CSL67 CG LAB PROGRAM 1
PDF
10CSL67 CG LAB PROGRAM 3
PDF
10CSL67 CG LAB PROGRAM 5
PDF
Why Youth SCEAL
PPT
Contrucción de subjetividades
PDF
10CSL67 CG LAB PROGRAM 4
DOC
Cover rpp
DOCX
PPTX
LeadSquared Overview for Education Industry
10CSL67 CG LAB PROGRAM 2
10CSL67 CG LAB PROGRAM 6
Executive Original Single GPS Vendor Migration Project Overview
Reference Letter
Vivansaa Logo.PDF
Paula andrea álvarez vásquez
Facebook Insights for Outsiders - Men in Web
KAREN-RESUME
PUEDE EL CRISTIANO BEBER ALCOHOL CON MODERACION
10CSL67 CG LAB PROGRAM 1
10CSL67 CG LAB PROGRAM 3
10CSL67 CG LAB PROGRAM 5
Why Youth SCEAL
Contrucción de subjetividades
10CSL67 CG LAB PROGRAM 4
Cover rpp
LeadSquared Overview for Education Industry
Ad

Similar to 10CSL67 CG LAB PROGRAM 7 (20)

DOCX
computer graphics opengl programs for cse students
PDF
The Ring programming language version 1.6 book - Part 164 of 189
DOCX
Robot Motion Source code
DOCX
openGl example
PDF
The Ring programming language version 1.5.4 book - Part 119 of 185
PDF
The Ring programming language version 1.6 book - Part 151 of 189
PDF
The Ring programming language version 1.5.1 book - Part 134 of 180
PDF
The Ring programming language version 1.5.4 book - Part 110 of 185
PDF
The Ring programming language version 1.8 book - Part 178 of 202
PDF
The Ring programming language version 1.5 book - Part 18 of 31
PDF
The Ring programming language version 1.5.4 book - Part 114 of 185
PDF
The Ring programming language version 1.5.4 book - Part 109 of 185
PDF
The Ring programming language version 1.5.4 book - Part 146 of 185
PDF
The Ring programming language version 1.5.2 book - Part 135 of 181
PDF
The Ring programming language version 1.6 book - Part 131 of 189
PDF
The Ring programming language version 1.5.2 book - Part 148 of 181
PDF
The Ring programming language version 1.6 book - Part 150 of 189
PDF
The Ring programming language version 1.8 book - Part 159 of 202
PDF
The Ring programming language version 1.5.3 book - Part 143 of 184
PDF
The Ring programming language version 1.7 book - Part 182 of 196
computer graphics opengl programs for cse students
The Ring programming language version 1.6 book - Part 164 of 189
Robot Motion Source code
openGl example
The Ring programming language version 1.5.4 book - Part 119 of 185
The Ring programming language version 1.6 book - Part 151 of 189
The Ring programming language version 1.5.1 book - Part 134 of 180
The Ring programming language version 1.5.4 book - Part 110 of 185
The Ring programming language version 1.8 book - Part 178 of 202
The Ring programming language version 1.5 book - Part 18 of 31
The Ring programming language version 1.5.4 book - Part 114 of 185
The Ring programming language version 1.5.4 book - Part 109 of 185
The Ring programming language version 1.5.4 book - Part 146 of 185
The Ring programming language version 1.5.2 book - Part 135 of 181
The Ring programming language version 1.6 book - Part 131 of 189
The Ring programming language version 1.5.2 book - Part 148 of 181
The Ring programming language version 1.6 book - Part 150 of 189
The Ring programming language version 1.8 book - Part 159 of 202
The Ring programming language version 1.5.3 book - Part 143 of 184
The Ring programming language version 1.7 book - Part 182 of 196

Recently uploaded (20)

PDF
Accra-Kumasi Expressway - Prefeasibility Report Volume 1 of 7.11.2018.pdf
PDF
August -2025_Top10 Read_Articles_ijait.pdf
PPTX
Software Engineering and software moduleing
PDF
Artificial Superintelligence (ASI) Alliance Vision Paper.pdf
PDF
distributed database system" (DDBS) is often used to refer to both the distri...
PDF
Level 2 – IBM Data and AI Fundamentals (1)_v1.1.PDF
PPTX
Current and future trends in Computer Vision.pptx
PDF
III.4.1.2_The_Space_Environment.p pdffdf
PDF
Abrasive, erosive and cavitation wear.pdf
PDF
null (2) bgfbg bfgb bfgb fbfg bfbgf b.pdf
PDF
Soil Improvement Techniques Note - Rabbi
PDF
22EC502-MICROCONTROLLER AND INTERFACING-8051 MICROCONTROLLER.pdf
PPTX
Feature types and data preprocessing steps
PPT
Total quality management ppt for engineering students
PDF
SMART SIGNAL TIMING FOR URBAN INTERSECTIONS USING REAL-TIME VEHICLE DETECTI...
PPTX
6ME3A-Unit-II-Sensors and Actuators_Handouts.pptx
PDF
Influence of Green Infrastructure on Residents’ Endorsement of the New Ecolog...
PPTX
Amdahl’s law is explained in the above power point presentations
PPTX
Information Storage and Retrieval Techniques Unit III
PDF
UNIT no 1 INTRODUCTION TO DBMS NOTES.pdf
Accra-Kumasi Expressway - Prefeasibility Report Volume 1 of 7.11.2018.pdf
August -2025_Top10 Read_Articles_ijait.pdf
Software Engineering and software moduleing
Artificial Superintelligence (ASI) Alliance Vision Paper.pdf
distributed database system" (DDBS) is often used to refer to both the distri...
Level 2 – IBM Data and AI Fundamentals (1)_v1.1.PDF
Current and future trends in Computer Vision.pptx
III.4.1.2_The_Space_Environment.p pdffdf
Abrasive, erosive and cavitation wear.pdf
null (2) bgfbg bfgb bfgb fbfg bfbgf b.pdf
Soil Improvement Techniques Note - Rabbi
22EC502-MICROCONTROLLER AND INTERFACING-8051 MICROCONTROLLER.pdf
Feature types and data preprocessing steps
Total quality management ppt for engineering students
SMART SIGNAL TIMING FOR URBAN INTERSECTIONS USING REAL-TIME VEHICLE DETECTI...
6ME3A-Unit-II-Sensors and Actuators_Handouts.pptx
Influence of Green Infrastructure on Residents’ Endorsement of the New Ecolog...
Amdahl’s law is explained in the above power point presentations
Information Storage and Retrieval Techniques Unit III
UNIT no 1 INTRODUCTION TO DBMS NOTES.pdf

10CSL67 CG LAB PROGRAM 7

  • 1. PROGRAM 7 Program using OpenGL functions, to draw a simple shaded scene consisting of a tea pot on a table. Define suitably the position and properties of the light source along with the properties of surfaces of the solid object used in the scene.
  • 2. #include <GL/glut.h> void wall (double thickness) { //draw thin wall with top = xz-plane, corner at origin glPushMatrix(); glTranslated (0.5, 0.5 * thickness, 0.5); glScaled (1.0, thickness, 1.0); glutSolidCube (1.0); glPopMatrix(); } After transformation
  • 3. void tableLeg (double thick, double len) //draw one table leg { glPushMatrix(); glTranslated (0, len/2, 0); glScaled (thick, len, thick); glutSolidCube (1.0); glPopMatrix(); } 1 23 4 floor
  • 4. //draw the table - a top and four legs, draw the top first void table (double topWid, double topThick, double legThick, double legLen) { glPushMatrix(); glTranslated (0, legLen, 0); glScaled(topWid, topThick, topWid); glutSolidCube (1.0); // table top glPopMatrix(); double dist = topWid/2.0 - legThick/2.0; glPushMatrix(); glTranslated (dist, 0, dist); tableLeg (legThick, legLen); // 1 glTranslated (0.0, 0.0, -2 * dist); tableLeg (legThick, legLen); // 2 glTranslated (-2*dist, 0, 2 *dist); tableLeg (legThick, legLen); // 3 glTranslated(0, 0, -2*dist); tableLeg (legThick, legLen); // 4 glPopMatrix(); } 1 23 4 floor Table top
  • 5. void displaySolid () { //set properties of the surface material GLfloat mat_ambient[] = {1.0, 0.0, 0.0, 1.0}; GLfloat mat_diffuse[] = {1.0, 1.0, 0.0, 1.0}; GLfloat mat_specular[] = {0.0, 1.0, 0.0, 1.0}; GLfloat mat_shininess[] = {50.0}; glMaterialfv (GL_FRONT, GL_AMBIENT, mat_ambient); glMaterialfv (GL_FRONT, GL_DIFFUSE, mat_diffuse); glMaterialfv (GL_FRONT, GL_SPECULAR, mat_specular); glMaterialfv (GL_FRONT, GL_SHININESS, mat_shininess); //set the light source properties GLfloat lightIntensity[] = {1.0, 1.0, 1.0, 1.0}; GLfloat light_position[] = {2.0, 6.0, 3.0, 0.0}; glLightfv (GL_LIGHT0, GL_POSITION, light_position); glLightfv (GL_LIGHT0, GL_DIFFUSE, lightIntensity);
  • 9. //set the camera glMatrixMode (GL_PROJECTION); glLoadIdentity(); glOrtho (-1.0, 1.0, -1.0, 1.0, 0.1, 100.0); glMatrixMode (GL_MODELVIEW); glLoadIdentity(); gluLookAt (2.0, 1.0, 2.0, 0.0, 0.1, 0.0, 0.0, 1.0, 0.0); //start drawing glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // delete the next 5 push and pop statements glPushMatrix(); glTranslated (0.6, 0.38, 0.5); // position of tea pot glRotated (30, 0, 1, 0); glutSolidTeapot (0.08); // 0.08 = size of the tea pot glPopMatrix (); Original image without rotation After rotation
  • 10. // delete the next 3 push and pop statements glPushMatrix(); glTranslated (0.4, 0, 0.4); table (0.6, 0.02, 0.02, 0.3); //table glPopMatrix(); wall (0.02); // floor glPushMatrix(); glRotated (90.0, 0.0, 0.0, 1.0); wall (0.02); // left glPopMatrix(); glPushMatrix(); glRotated (-90.0, 1.0, 0.0, 0.0); wall (0.02); // right glPopMatrix(); glFlush(); }
  • 11. void main (int argc, char ** argv) { glutInit (&argc, argv); glutInitDisplayMode (GLUT_SINGLE|GLUT_RGB|GLUT_DEPTH); glutInitWindowSize (500, 500); glutCreateWindow ("tea pot on a table"); glutDisplayFunc (displaySolid); glEnable (GL_LIGHTING); glEnable (GL_LIGHT0); glEnable (GL_DEPTH_TEST); glEnable (GL_NORMALIZE); glutMainLoop(); }