COMPSCI 373 S1 C - Assignment 2 Sample Solution

Size: px
Start display at page:

Download "COMPSCI 373 S1 C - Assignment 2 Sample Solution"

Transcription

1 COMPSCI 373 S1 C Assignment 2 Sample Solution 1 of 17 Computer Science COMPSCI 373 S1 C - Assignment 2 Sample Solution This assignment is worth % of your final grade. 1. 3D Modelling and Texture Mapping with OpenGL (29 Marks) In this question you will create a little game containing a plane with grass, 20 flowers, Easter eggs falling from the sky, a robot with a basket at the end of its arm and a reflecting mirror. The objective of the game is to catch the Easter eggs with the basket. If you hit an egg with the rim of the basket or if you miss it the egg gets smashed [please feel free to extend the game and add appropriate sound effects ;-) ]. The game finishes after 50 eggs have been smashed. Download the file Ass2.zip which contains a.net solution including all necessary source files. Unzip the files and compile and run them. You should see a grass covered plane, 20 flowers, a non-reflecting mirror, and Easter eggs falling from the sky. NOTE: In order to make debugging easier and improve the understanding of texture maps, all texture images are stored in Portable Pixel Map format (ppm). This format is very inefficient to load and your program might take a long time to load when run in DEBUG mode. You can avoid this by compiling your program in RELEASE mode. (a) [2 marks] When playing the finished game you will find that it is hard to catch eggs since it is difficult to perceive the exact 3D position of an egg and where it will land. Implement the method drawpath() in the CEgg class, which draws a line from the centre of each egg to the ground. A line is coloured blue (0.3, 0.3, 1.0) if the distance to the ground is larger than 3 units, orange (1.0, 0.5, 0.3) if the distance is between 1.5 and 3 units and yellow (1.0, 1.0, 0.3) otherwise. Visibility of the lines is toggled by pressing the h key (already implemented). After completing this exercise your programs should look similar to the screen shot on the right: Solution: The path is defined as a simple line segment orthogonal to the ground (xz)-plane and hence is given by the position of an egg and its position with the y-coordinate set to 0. void CEgg::drawPath() if (position[1]>3) glcolor3f(0.3f, 0.3f, 1.0f); else if (position[1]>1.5) glcolor3f(1.0f, 0.5f, 0.3f); else glcolor3f(1.0f, 1.0f, 0.3f); glbegin(gl_lines); glvertex3fv(position); glvertex3f(position[0],0,position[2]); glend();

2 COMPSCI 373 S1 C Assignment 2 Sample Solution 2 of 17 (b) [6 Marks] Define the robot shown in the image below. The robot has three arms with lengths armlength and at the tip of the 3 rd arm it has a torus which is always parallel to the ground plane. The outer radius of the torus is basketradius and its inner radius is rimradius. The bottom arm is perpendicular to the ground plane and centered at the origin. The whole robot is rotated by an angle φ (phi) around its centre axis. The second arm is rotated by the angle θ (theta) with respect to the bottom arm and the third arm is rotated by 2θ with respect to the second arm as illustrated in the figure below. At the end of this exercise your robot should look like in the picture below. Note that the keys a, s, w and z are used to modify the angles φ and θ, i.e. at the end of this exercise you should be able to move the robot using these keys. NOTE: For this exercise it is sufficient to use matrix operations (translation, rotation, scaling, push, pop) and two solid objects defined in GLUT. In order to make it easier for you to test your implementation I have defined a variable basketcentre which gives you the point at the centre of the torus. You can check your code by drawing this point and by verifying that it is indeed in the centre of the basket rim of the robot. Solution: It is easiest to construct the robot using a bottom-up approach. i.e. start with the bottom arm of the robot and implement the rotation around its axis. By defining this rotation first it will be applied to all subsequent components, which is exactly what we want. Next we implement the middle arm of the robot. Note that the scaling and translation only apply to this arm (i.e. we use glpushmatrix() and gl PopMatrix()), whereas the rotation applies to this arm and all components connected to it (i.e. the top arm and the basket). Finally we define the top arm and the basket connected to it.

3 COMPSCI 373 S1 C Assignment 2 Sample Solution 3 of 17 void CRobot::draw() glenable(gl_normalize); glmaterialfv(gl_front, GL_SPECULAR, mat_specular); glmaterialfv(gl_front, GL_SHININESS, no_shininess); glmaterialfv(gl_front, GL_AMBIENT_AND_DIFFUSE, mat_ambient_and_diffuse); // rotate the whole robot glpushmatrix(); glrotatef(phi, 0, 1, 0); // bottom robot arm glpushmatrix(); glscalef(bottomarmwidth, armlength, bottomarmwidth); gltranslatef(0, 0.5, 0); glutsolidcube(1.0); glpopmatrix(); // Transformations moving the middle arm and the top arm attached to it glpushmatrix(); gltranslatef(0, armlength, 0); glrotatef(theta, 0, 0, 1); // middle robot arm glpushmatrix(); glscalef(toparmwidth, armlength, toparmwidth); gltranslatef(0, 0.5, 0); glutsolidcube(1.0); glpopmatrix(); // Transformations moving the top arm and basket relative to the middle arm gltranslatef(0, armlength, 0); glrotatef(180-2*theta, 0, 0, 1); // top robot arm glpushmatrix(); glscalef(toparmwidth, armlength, toparmwidth); gltranslatef(0, 0.5, 0); glutsolidcube(1.0); glpopmatrix(); // ring and basket at the top of the arm gltranslatef(0, armlength, 0); glrotatef(-90+theta, 0, 0, 1); gltranslatef(0, basketradius, 0); glrotatef(-90,0,1,0); glutsolidtorus(rimradius, basketradius, 16, 16); _drawbasket(); glpopmatrix(); glpopmatrix(); gldisable(gl_normalize); glflush(); (c) [6 Marks] Complete the function _drawbasket() and add it to the draw method of the CRobot class so that it draws a basket defined as a surface of revolution. Please precompute the vertices of the basket s surface in the method _initbasketsurface of the CRobot class and draw the surface using quad strips as indicated in the figure below. Since we later on use texture mapping for the basket it s not necessary to define surface normals. You must define the surface of revolution yourself using GLUT commands or other geometry libraries gives automatically zero marks. The dimensions and number of vertices of the surface are defined in the code by constants explained in the illustration below.

4 COMPSCI 373 S1 C Assignment 2 Sample Solution 4 of 17 HINT: For this question it is easiest to use a quarter ellipsoid for the profile curve! Note that you will change the profile curve in part (h) of this question, so it is recommended to design your code accordingly. At the end of this step your scene should look similar to that in the image below. Solution: We use the formula in the lecture notes to create the basket by rotating a quarter ellipses around the z-axis, i.e. the axis of the resulting torus is aligned with the z-axis. This is practical because the torus defining the ring of the basket is also by default aligned with the z-axis. The surface of revolution is defined by creating first a profile curve c(t)=(x(t),0,z(t)) which is obtained by taking the equation of an ellipsoid with the major axis basketheight and the minor axis basketradius. Then x( t) basketradius *sin(0.5πt ) c ( t) = 0 = 0 t [0,1] ( ) *cos(0.5 ) z t basketheight πt The surface of revolution is obtained by rotating each point of the profile curve around the z-axis, i.e. ( basketradius *sin(0.5πt )) cos 2πs ( basketradius *sin(0.5πt )) sin 2πs s, [0,1] x( t)cos 2πs p ( s, t) = x( t)sin 2πs = t ( ) * cos(0.5 ) z t basketheight πt

5 COMPSCI 373 S1 C Assignment 2 Sample Solution 5 of 17 Note that we don t need the surface normals since later on we texture map this surface. The resulting code is: // initialise vertices basket int i,j; double z,r; for(i=0;i<num_longitudinal_vertices;i++) z=basketheight*cos(pi/2*((double) i/(num_longitudinal_vertices-1))); r=basketradius*sin(pi/2*((double) i/(num_longitudinal_vertices-1))); for(j=0;j<num_circumferentiall_vertices;j++) vertices[i][j][0]=(float) (cos(2*pi*j/(double) (NUM_CIRCUMFERENTIALL_VERTICES-1))*r); vertices[i][j][1]=(float) (sin(2*pi*j/(double) (NUM_CIRCUMFERENTIALL_VERTICES-1))*r); vertices[i][j][2]=(float) z; and the draw method is void CRobot::_drawBasket() glshademodel(gl_flat); int i,j; for(i=0;i<num_longitudinal_vertices-1;i++) glbegin(gl_quad_strip); for(j=0;j<num_circumferentiall_vertices;j++) glvertex3fv(vertices[i][j]); glvertex3fv(vertices[i+1][j]); glend(); glshademodel(gl_smooth); (d) [5 marks] Use texture mapping to draw the basket at the end of the robot arm. Complete the missing code so that it loads the texture map Net.pgm and maps it onto the basket. Note that the program contains already a routine to load a texture of type Portable Pixel Map (ppm) - a Portable Gray Map (pgm) is defined similarly but has only one byte per pixel (a greyscale value in the range 0 to 255). Note that the texture image has been constructed such that the pixels on its left and ride side are identical. Consequently you should map the horizontal direction of the image onto the circumferential direction of the basket s surface in order to get a continuous texture. At the end of this step your scene should look something like this:

6 COMPSCI 373 S1 C Assignment 2 Sample Solution 6 of 17 Solution: Change the initialization procedures so that suitable texture coordinates are computed. The texture coordinates map the texture around the basket similarly to wrapping a paper around a cylinder. Note that the texture image will get distorted towards the apex of the basket, i.e. the black lines in it converge, which is exactly what we want to have for a realistic basket. // initialise vertices basket int i,j; double z,r; for(i=0;i<num_longitudinal_vertices;i++) z=basketheight*cos(pi/2*((double) i/(num_longitudinal_vertices-1))); r=basketradius*sin(pi/2*((double) i/(num_longitudinal_vertices-1))); for(j=0;j<num_circumferentiall_vertices;j++) vertices[i][j][0]=(float) (cos(2*pi*j/(double) (NUM_CIRCUMFERENTIALL_VERTICES-1))*r); vertices[i][j][1]=(float) (sin(2*pi*j/(double) (NUM_CIRCUMFERENTIALL_VERTICES-1))*r); vertices[i][j][2]=(float) z; texture_coordinates[i][j][1]=(double) i/(num_longitudinal_vertices-1); texture_coordinates[i][j][0]=(double) j/(num_circumferentiall_vertices-1);

7 COMPSCI 373 S1 C Assignment 2 Sample Solution 7 of 17 Next we complete the function for the texture initialization. It s easiest to define the texture map in the RGBA format we discussed in the lecture, i.e. the gray scale values of the input image are used as red, green and blue components of the texture image. void CRobot::_initTexture() // load net texture ifstream texturefile; char* filename="net.pgm"; texturefile.open(filename, ios::in); if (texturefile.fail()) displaymessage(error_message, "CRobot()::CRobot(): could not open file %s",filename); skipline(texturefile); texturefile >> texturewidth; texturefile >> textureheight; int numrgbvalues; texturefile >> numrgbvalues; texture = new GLubyte[textureWidth*textureHeight*4]; int k,l,c; for(k=0;k<textureheight;k++) for(l=0;l<texturewidth;l++) texturefile >> c; texture[(k*texturewidth+l)*4]=(glubyte) c; texture[(k*texturewidth+l)*4+1]=(glubyte) c; texture[(k*texturewidth+l)*4+2]=(glubyte) c; texture[(k*texturewidth+l)*4+3]=(glubyte) 255; texturefile.close(); glbindtexture(gl_texture_2d, texname); gltexparameteri(gl_texture_2d, GL_TEXTURE_MAG_FILTER, GL_LINEAR); gltexparameteri(gl_texture_2d, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glteximage2d(gl_texture_2d, 0, GL_RGBA, texturewidth, textureheight, 0, GL_RGBA, GL_UNSIGNED_BYTE, texture); delete[] texture; In order to draw the basket we must define the appropriate texture coordinates for each vertex in the draw() method: glenable(gl_texture_2d); glbindtexture(gl_texture_2d, texname); gltexenvf(gl_texture_env, GL_TEXTURE_ENV_MODE, GL_REPLACE); int i,j; for(i=0;i<num_longitudinal_vertices-1;i++) glbegin(gl_quad_strip); for(j=0;j<num_circumferentiall_vertices;j++) gltexcoord2fv(texture_coordinates[i][j]); glvertex3fv(vertices[i][j]); gltexcoord2fv(texture_coordinates[i+1][j]); glvertex3fv(vertices[i+1][j]); glend();

8 COMPSCI 373 S1 C Assignment 2 Sample Solution 8 of 17 (e) [3 marks] Modify your code such that white pixels in the texture image become transparent. In order to do this you have to set the fourth coordinate (the alpha value ) of all white pixels to 0. You also have to enable blending and alpha testing which is done by inserting the lines glenable(gl_blend) glblendfunc(gl_src_alpha, GL_ONE_MINUS_SRC_ALPHA); glalphafunc(gl_greater, 0.9f); glenable(gl_alpha_test); before performing the texture mapping. You don t need to understand blending and alpha testing, but if you are interested feel free to read more about it in the OpenGL programming guide. Don t forget to disable blending and alpha testing at the end of the draw method. After implementing this step your scene should look something like this: like this: Solution: Change the line assigning the transparency value during texture loading to if (c==255) texture[(k*texturewidth+l)*4+3]=(glubyte) 0; else texture[(k*texturewidth+l)*4+3]=(glubyte) 255; Before drawing the texture add glshademodel(gl_flat); glenable(gl_blend); glblendfunc(gl_src_alpha, GL_ONE_MINUS_SRC_ALPHA); glalphafunc(gl_greater, 0.9f); glenable(gl_alpha_test); and after drawing the texture add gldisable(gl_alpha_test); gldisable(gl_blend); gldisable(gl_texture_2d); glshademodel(gl_smooth);

9 COMPSCI 373 S1 C Assignment 2 Sample Solution 9 of 17 (f) [3 marks] Modify your code so that you can zoom in and out of the scene using the +/= and -/_ keys, respectively. In order to do that you have to change one parameter of the gluperspective function and you have to set the projection matrix whenever you change that parameter. After implementing this step you should be able to obtain pictures like this: Solution: We first add the keys for zooming to the event handling routine. A zoom is achieved by changing the field-of-view (fov). A smaller fov value has the effect that the view frustum is narrower. i.e. smaller part of the scene is projected onto the view plane and the objects in that region appear enlarged. It makes sense to limit the fov value in order to avoid unnatural distortions. void handlekeypress(unsigned char key, int x, int y) // keep the method unchanged and add the two lines below if ((key=='+') (key=='=')) if (fov>1) fov/=1.05; _initview(); glutpostredisplay(); if ((key=='-') (key=='_')) if (fov<70) fov*=1.05; _initview(); glutpostredisplay(); (g) [4 marks] Modify the _initbasketsurface method of the CRobot class so that the profile curve is a Hermite curve defined by: p1 = p(0) = (basketheight, 0) // start point p4 = p(1) = (0, basketradius) // end point r1 = p'(0) = (0, 2*basketRadius) // tangent at start point r4 = p'(0) = (2*basketHeight, 0) // tangent at end point After this change the basket will look similar to the results of part (b) as illustrated below:

10 COMPSCI 373 S1 C Assignment 2 Sample Solution 10 of 17 Change the code so that the end tangent is rotated by the angle basketshapeangle, i.e. the new end tangent is ( -2*basketHeight*cos(2*Pi*basketShapeAngle/360.0), -2*basketHeight*sin(2*Pi*basketShapeAngle/360.0) ) Modify the event handling so that pressing the r key increases the angle basketshapeangle by one. After this change pressing the r key will allow you to rotate the end tangent around the end point resulting in the shapes illustrated below: Solution: We define a 2D profile curve (x(t), z(t)) using a Hermite curve define by the given points and tangents: x( t) c( t) = = H1(t) p1 + H 2 (t) p 4 + H 3 (t) v1 + H 4 (t) v 4 z( t) basketheight 0 = H1(t) + H 2 (t) + H 0 basketradius - 2 basketheight cos + H 4 (t) - 2 basketheight sin ( 2π basketshapeangle/360) ( 2π basketshapeangle/360) 3 0 (t) 2 basketradius t [0,1] where H 1 (t),, H 4 (t) are the Hermite basis functions (see lecture notes). Since the parameter space is the same as for the quarter ellipsoid we can define the surface-of-revolution by replacing x(t) and z(t) of the quarter ellipsoid with the values from the above Hermite curve:

11 COMPSCI 373 S1 C Assignment 2 Sample Solution 11 of 17 // Hermite basis functions defined at the start of Robot.cpp double H0(const double t)return t*t*(2*t-3)+1; double H1(const double t)return t*t*(3-2*t); double H2(const double t)return t*t*(t-2)+t; double H3(const double t)return t*t*(t-1); // Hermite curve representing profile curve of the basket CVec2df CRobot::_basketSilhouetteHermiteCurve(double t) CVec2df p1(basketheight, 0); CVec2df p4(0, basketradius); CVec2df r1(0, 2*basketRadius); CVec2df r4(-2*basketheight*cos(2*pi*basketshapeangle/360.0), - 2*basketHeight*sin(2*Pi*basketShapeAngle/360.0)); return H0(t)*p1+H1(t)*p4+H2(t)*r1+H3(t)*r4; // Computation of the surface of revolution // Note that only the lines for computing z and r are changed void CRobot::_initBasketSurface() // initialise vertices basket int i,j; double z,r; for(i=0;i<num_longitudinal_vertices;i++) CVec2df p=_basketsilhouettehermitecurve((double) z=p[0]; r=p[1]; for(j=0;j<num_circumferentiall_vertices;j++) vertices[i][j][0]=(float) (cos(2*pi*j/(double) (NUM_CIRCUMFERENTIALL_VERTICES-1))*r); vertices[i][j][1]=(float) (sin(2*pi*j/(double) (NUM_CIRCUMFERENTIALL_VERTICES-1))*r); vertices[i][j][2]=(float) z; texture_coordinates[i][j][1]=(double) i/(num_longitudinal_vertices-1); texture_coordinates[i][j][0]=(double) j/(num_circumferentiall_vertices-1); Now we only need to add a routine for event handling: // In ass1main.cpp void handlekeypress(unsigned char key, int x, int y) // keep the method unchanged and add the line below if ((key=='r') (key=='r')) robot.updatebasketshape(); // In Robot.cpp (add the function prototype to Robot.h) void CRobot::updateBasketShape() basketshapeangle+=1.0; if (basketshapeangle>360) basketshapeangle-=360.0; _initbasketsurface(); glutpostredisplay();

12 COMPSCI 373 S1 C Assignment 2 Sample Solution 12 of Bezier Surfaces (16 Marks) The famous Utah teapot (rendered by the GLUT function glutsolidteapot) is defined by Bezier surfaces [ In this exercise you will model and render the lid of the teapot. One quarter section of the lid is defined by 2 Bezier patches with 4x4 control points. The complete lid can be defined rendering the same patch 4 times with appropriate rotation commands. The control points and Bezier patches of one quarter of the teapot are defined in the file teapot_lid.txt. The surface consists of two Bezier patches. Each patch has 4x4 control points. However, only 22 different control points are required since the patches share control points at the common boundary and since some control points are repeated (e.g. at the tip). (a) [5 Marks] render the two cubic Bezier surfaces using a wireframe. You can write the program from scratch or modify the example program ParametricSurfaceNET from the course web page (recommended). Change the program that way that the default number of subdivision for rendering the surface is 4 (i.e. 4x4 polygons for each surface patch) and that you can increase/decrease the number of subdivisions using + / - keys. Below are some screenshots with 1,4 and 20 subdivisions and the control points rendered in blue. You don t need to render the control points, but it might make debugging easier (you might want to toggle the display of control points). Remember that Bezier surfaces and surfaces of revolution are both parametric surface and you can use the same code to display them once you have the formula for p(s,t). (b) [7 marks] Extend the program such that the surface is rendered using Gouraud shaded polygons. In order to do this you must compute vertex normals (see lecture notes chapter 6).. Note that the first control point of the first patch is repeated four times and hence the resulting mesh polygons are triangles and one of the partial derivatives is zero. Therefore you have to treat this case separately and use instead the normal (0,0,1). Extend the program such that the user can toggle between wireframe and surface representation using the l and s keys. The resulting surface (with 10 subdivisions) should look as follows.

13 COMPSCI 373 S1 C Assignment 2 Sample Solution 13 of 17 (c) [3 marks] Rendering the mesh by computing the polygon vertices in the display method is extremely slow. A much faster way is to use so-called display lists. Each time you change the object you want to display you define all OpenGL commands for rendering it into a display list. When you then display this object you just call the resulting display list, which executes the corresponding OpenGl commands without having to execute again all the equations necessary for computing the points and normals you display. In order to use display lists you have to change your program as follows: 1. Add a new variable displaylistid of type GLuint to the program. 2. In the initialization define displaylistid=glgenlists(1); which generates a unique ID for that display list. 3. Write a new method generatedisplaylist() which looks as follows void generatedisplaylist() glnewlist(displaylistid, GL_COMPILE); // render the Bezier patches, i.e. compute vertices // and normals for surface points and display them glendlist(); 4. Call this method once before you display the object for the first time (e.g. in the init() method) and call it each time you change the definition of the object (i.e. when you change the number of subdivisions for rendering the mesh) 5. In the display method render the object by calling its display list, i.e. use glcalllist(displaylistid); everytime you want to display the object defined in the display list (d) [1] Extend the program such that it displays the entire teapot lid. The easiest way to achieve this is by using the method/display list for the quarter teapot and just rotating it appropriately. The resulting images using wireframe and surface rendering should look as follows:

14 COMPSCI 373 S1 C Assignment 2 Sample Solution 14 of 17 Solution: // ***************************************************************************** // * A program to display the lid of the Utah Teapot defined by Bezier Patches * // * (c) May 2011, Burkhard Wuensche * // ***************************************************************************** // // Use 'l' to render the mesh // Use 's' to render the surface // Use '+'/'-' To increase/decrease subdivision level // Use 'c' to toggle the display of the control points #include <windows.h> #include <gl/gl.h> #include <gl/glu.h> #include <gl/glut.h> #include "Trackball.h" #include "Lighting.h" #include "Geometry.h" const int windowwidth=600; const int windowheight=600; double basis1(double t) return (1-t)*(1-t)*(1-t); double basis2(double t) return 3*(1-t)*(1-t)*t; double basis3(double t) return 3*(1-t)*t*t; double basis4(double t) return t*t*t; double db1dt(double t) return -3*(1-t)*(1-t); double db2dt(double t) return 3*(1-t)*(1-3*t); double db3dt(double t) return 3*t*(2-3*t); double db4dt(double t) return 3*t*t; typedef double (*basisfunctiontype)(double); basisfunctiontype bezierbasisfunction[]=&basis1,&basis2,&basis3,&basis4; basisfunctiontype bezierbasisfunctionderivative[]=&db1dt,&db2dt,&db3dt,&db4dt; typedef enum LINE_MODE, SURFACE_MODE RENDER_OPTION; RENDER_OPTION current_render_option=surface_mode; bool show_control_points=true; int numsegments=4; GLuint displaylistid; const int numvertices=22; CVec3df vertices[numvertices]= CVec3df(0,0,3.15f), CVec3df(0.8f,0,3.15f), CVec3df(0.8f,-0.45f,3.15f), CVec3df(0.45f,-0.8f,3.15f), CVec3df(0,-0.8f,3.15f), CVec3df(0,0,2.85f), CVec3df(0.2f,0,2.7f), CVec3df(0.2f,-0.112f,2.7f), CVec3df(0.112f,-0.2f,2.7f), CVec3df(0,-0.2f,2.7f), CVec3df(0.4f,0,2.55f), CVec3df(0.4f,-0.224f,2.55f), CVec3df(0.224f,-0.4f,2.55f), CVec3df(0,-0.4f,2.55f), CVec3df(1.3f,0,2.55f), CVec3df(1.3f,-0.728f,2.55f), CVec3df(0.728f,-1.3f,2.55f), CVec3df(0,-1.3f,2.55f), CVec3df(1.3f,0,2.4f), CVec3df(1.3f,-0.728f,2.4f), CVec3df(0.728f,-1.3f,2.4f), CVec3df(0,-1.3f,2.4f) ; const int NUM_PATCHES=2; const int BEZIER_ORDER=4; // use 4th order Bezier curves in both parameter directions int ctr_points[num_patches][bezier_order][bezier_order] = 0,0,0,0,1,2,3,4,5,5,5,5,6,7,8,9, 6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21;

15 COMPSCI 373 S1 C Assignment 2 Sample Solution 15 of 17 // material properties GLfloat mat_specular[4]; GLfloat mat_ambient_and_diffuse[4]; GLfloat mat_shininess[1]; CTrackball trackball; CLighting lighting; CVec3df _bicubicbezierpatchpoint(int k, double s, double t) int i,j; CVec3df p(0,0,0); for(i=0;i<bezier_order;i++) for(j=0;j<bezier_order;j++) p+=vertices[ctr_points[k][i][j]]*bezierbasisfunction[i](s) *bezierbasisfunction[j](t); return p; CVec3df _bicubicbezierpatchnormal(int k, double s, double t) int i,j; CVec3df dpdt(0,0,0); CVec3df dpds(0,0,0); for(i=0;i<bezier_order;i++) for(j=0;j<bezier_order;j++) dpdt+=vertices[ctr_points[k][i][j]]*bezierbasisfunction[i](s) *bezierbasisfunctionderivative[j](t); dpds+=vertices[ctr_points[k][i][j]]*bezierbasisfunctionderivative[i](s) *bezierbasisfunction[j](t); CVec3df n=cross(dpdt,dpds); if (dpdt.length()< dpds.length()< ) n.setvector(0,0,1); else n.normalisedestructivenoerror(); return n; void generatedisplaylist() int i,j,k; double s,t; CVec3df v[5][10]; glnewlist(displaylistid, GL_COMPILE); for(k=0;k<num_patches;k++) for(i=0;i<numsegments;i++) glbegin(gl_quad_strip); for(j=0;j<=numsegments;j++) s=(double) i/(double) numsegments; t=(double) j/(double) numsegments; glnormal3fv(_bicubicbezierpatchnormal(k,s,t).getarray()); glvertex3fv(_bicubicbezierpatchpoint(k,s,t).getarray()); s=(double) (i+1)/(double) numsegments; glnormal3fv(_bicubicbezierpatchnormal(k,s,t).getarray()); glvertex3fv(_bicubicbezierpatchpoint(k,s,t).getarray()); glend(); glendlist(); void display(void) glmatrixmode( GL_MODELVIEW ); // Set the view matrix... glloadidentity(); //... to identity. glulookat(0,0,6, 0,0,0, 0,1,0); // camera is on the z-axis trackball.tbmatrix(); // rotate scene using the trackball glclear( GL_COLOR_BUFFER_BIT GL_DEPTH_BUFFER_BIT); glenable(gl_normalize); glfrontface(gl_cw); if (current_render_option==line_mode) glpolygonmode(gl_front_and_back, GL_LINE);

16 COMPSCI 373 S1 C Assignment 2 Sample Solution 16 of 17 else glpolygonmode(gl_front_and_back, GL_FILL); glpushmatrix(); gltranslatef(0, 0, -3.0f); glpushmatrix(); glcalllist(displaylistid); glrotatef(90,0,0,1); glcalllist(displaylistid); glrotatef(90,0,0,1); glcalllist(displaylistid); glrotatef(90,0,0,1); glcalllist(displaylistid); glpopmatrix(); if (show_control_points) int i; glpointsize(5.0); gldisable(gl_lighting); glcolor3f(0.0, 0.0, 1.0); glbegin(gl_points); for(i=0;i<numvertices;i++) glvertex3fv(vertices[i].getarray()); glend(); glenable(gl_lighting); glpopmatrix(); glflush (); glutswapbuffers(); void init(void) // select clearing color (for glclear) glclearcolor (1,1,1,1); // RGB-value for black // enable depth buffering glenable(gl_depth_test); // initialize view (simple orthographic projection) glmatrixmode(gl_projection); glloadidentity(); gluperspective(33,1,2,10); trackball.tbinit(glut_left_button); // material properties mat_ambient_and_diffuse[0]=0.8; // red material... mat_ambient_and_diffuse[1]=0.0; mat_ambient_and_diffuse[2]=0.0; mat_ambient_and_diffuse[3]=1; mat_specular[0]=0.8f; //... with white highlights mat_specular[1]=0.8f; // if light source is reflected mat_specular[2]=0.8f; // on the material surface. mat_specular[3]=1; mat_shininess[0]=100; glmaterialfv(gl_front, GL_SPECULAR, mat_specular); glmaterialfv(gl_front, GL_AMBIENT_AND_DIFFUSE, mat_ambient_and_diffuse); glmaterialfv(gl_front, GL_SHININESS, mat_shininess); // enable shading and lighting lighting.enable(); glshademodel(gl_smooth); void reshape(int width, int height ) // Called at start, and whenever user resizes component int size = min(width, height); glviewport(0, 0, size, size); // Largest possible square trackball.tbreshape(width, height); void handlemousemotion(int x, int y) trackball.tbmotion(x, y); void handlemouseclick(int button, int state, int x, int y)

17 COMPSCI 373 S1 C Assignment 2 Sample Solution 17 of 17 trackball.tbmouse(button, state, x, y); void handlekeyboardevent(unsigned char key, int x, int y) switch (key) case 'l': current_render_option=line_mode; glutpostredisplay(); break; case 's': current_render_option=surface_mode; glutpostredisplay(); break; case 'c': show_control_points=!show_control_points; glutpostredisplay(); break; case '+': if (numsegments<100) numsegments++; generatedisplaylist(); glutpostredisplay(); break; case '-': if (numsegments>1) numsegments--; generatedisplaylist(); glutpostredisplay(); break; default: trackball.tbkeyboard(key); // create a double buffered colour window int main(int argc, char** argv) glutinit(&argc, argv); glutinitdisplaymode(glut_double GLUT_RGB GLUT_DEPTH); glutinitwindowsize(windowwidth, windowheight); glutinitwindowposition(100, 100); glutcreatewindow("lid of the \"Utah Teapot\""); init (); // initialise view displaylistid=glgenlists(1); generatedisplaylist(); glutmousefunc(handlemouseclick); // Set function to handle mouse clicks glutmotionfunc(handlemousemotion); // Set function to handle mouse motion glutkeyboardfunc(handlekeyboardevent); // Set function to handle keyboard input glutdisplayfunc(display); // Set function to draw scene glutreshapefunc(reshape); // Set function called if window gets resized glutmainloop(); return 0;

COMPSCI 372 S2 C - Assignment 2 Due Date: Monday 22nd September 2008, 9.30pm

COMPSCI 372 S2 C - Assignment 2 Due Date: Monday 22nd September 2008, 9.30pm COMPSCI 372 S2 C - Assignment 2 1 of 8 Computer Science COMPSCI 372 S2 C - Assignment 2 Due Date: Monday 22nd September 2008, 9.30pm This assignment is worth 6.25% of your final grade. In this assignment

More information

Books, OpenGL, GLUT, GLUI, CUDA, OpenCL, OpenCV, PointClouds, and G3D

Books, OpenGL, GLUT, GLUI, CUDA, OpenCL, OpenCV, PointClouds, and G3D Books, OpenGL, GLUT, GLUI, CUDA, OpenCL, OpenCV, PointClouds, and G3D CS334 Spring 2012 Daniel G. Aliaga Department of Computer Science Purdue University Computer Graphics Pipeline Geometric Primitives

More information

Books, OpenGL, GLUT, CUDA, OpenCL, OpenCV, PointClouds, G3D, and Qt

Books, OpenGL, GLUT, CUDA, OpenCL, OpenCV, PointClouds, G3D, and Qt Books, OpenGL, GLUT, CUDA, OpenCL, OpenCV, PointClouds, G3D, and Qt CS334 Fall 2015 Daniel G. Aliaga Department of Computer Science Purdue University Books (and by now means complete ) Interactive Computer

More information

// double buffering and RGB glutinitdisplaymode(glut_double GLUT_RGBA); // your own initializations

// double buffering and RGB glutinitdisplaymode(glut_double GLUT_RGBA); // your own initializations #include int main(int argc, char** argv) { glutinit(&argc, argv); Typical OpenGL/GLUT Main Program // GLUT, GLU, and OpenGL defs // program arguments // initialize glut and gl // double buffering

More information

To Do. Computer Graphics (Fall 2008) Course Outline. Course Outline. Methodology for Lecture. Demo: Surreal (HW 3)

To Do. Computer Graphics (Fall 2008) Course Outline. Course Outline. Methodology for Lecture. Demo: Surreal (HW 3) Computer Graphics (Fall 2008) COMS 4160, Lecture 9: OpenGL 1 http://www.cs.columbia.edu/~cs4160 To Do Start thinking (now) about HW 3. Milestones are due soon. Course Course 3D Graphics Pipeline 3D Graphics

More information

FAKULTI TEKNOLOGI MAKLUMAT DAN KOMUNIKASI BITM INTERACTIVE COMPUTER GRAPHICS LAB SESSION 4. C++ - OpenGL

FAKULTI TEKNOLOGI MAKLUMAT DAN KOMUNIKASI BITM INTERACTIVE COMPUTER GRAPHICS LAB SESSION 4. C++ - OpenGL FAKULTI TEKNOLOGI MAKLUMAT DAN KOMUNIKASI BITM 3213 - INTERACTIVE COMPUTER GRAPHICS LAB SESSION 4 C++ - OpenGL Part 1- C++ - Texture Mapping 1. Download texture file and put it into your current folder

More information

C OMPUTER G RAPHICS Thursday

C OMPUTER G RAPHICS Thursday C OMPUTER G RAPHICS 2017.04.27 Thursday Professor s original PPT http://calab.hanyang.ac.kr/ Courses Computer Graphics practice3.pdf TA s current PPT not uploaded yet GRAPHICS PIPELINE What is Graphics

More information

Basic Graphics Programming

Basic Graphics Programming 15-462 Computer Graphics I Lecture 2 Basic Graphics Programming Graphics Pipeline OpenGL API Primitives: Lines, Polygons Attributes: Color Example January 17, 2002 [Angel Ch. 2] Frank Pfenning Carnegie

More information

Precept 2 Aleksey Boyko February 18, 2011

Precept 2 Aleksey Boyko February 18, 2011 Precept 2 Aleksey Boyko February 18, 2011 Getting started Initialization Drawing Transformations Cameras Animation Input Keyboard Mouse Joystick? Textures Lights Programmable pipeline elements (shaders)

More information

Lectures OpenGL Introduction

Lectures OpenGL Introduction Lectures OpenGL Introduction By Tom Duff Pixar Animation Studios Emeryville, California and George Ledin Jr Sonoma State University Rohnert Park, California 2004, Tom Duff and George Ledin Jr 1 What is

More information

QUESTION 1 [10] 2 COS340-A October/November 2009

QUESTION 1 [10] 2 COS340-A October/November 2009 2 COS340-A QUESTION 1 [10] a) OpenGL uses z-buffering for hidden surface removal. Explain how the z-buffer algorithm works and give one advantage of using this method. (5) Answer: OpenGL uses a hidden-surface

More information

C++ is Fun Part 13 at Turbine/Warner Bros.! Russell Hanson

C++ is Fun Part 13 at Turbine/Warner Bros.! Russell Hanson C++ is Fun Part 13 at Turbine/Warner Bros.! Russell Hanson Syllabus 1) First program and introduction to data types and control structures with applications for games learning how to use the programming

More information

Graphics Programming

Graphics Programming Graphics Programming 3 rd Week, 2011 OpenGL API (1) API (application programming interface) Interface between an application program and a graphics system Application Program OpenGL API Graphics Library

More information

1 /* 4 C:\opencv\build\include. 6 C:\opencv\build\x86\vc10\lib

1 /* 4 C:\opencv\build\include. 6 C:\opencv\build\x86\vc10\lib 1 1. Program 1 OpenCV (OpenCV Sample001) 1 /* 2 - > - > - >VC++ 3 ( ) 4 C:\opencv\build\include 5 ( ) 6 C:\opencv\build\x86\vc10\lib 7 - > - > - > - > 8 (240 O p e n C V ) 9 opencv_core240d.lib 10 opencv_imgproc240d.lib

More information

Duc Nguyen CSE 420 Computer Graphics 10/10/2018 Homework 1

Duc Nguyen CSE 420 Computer Graphics 10/10/2018 Homework 1 Duc Nguyen CSE 420 Computer Graphics 10/10/2018 Homework 1 1. The endpoints of a given line are (0, 0) and (18, 6). Compute the first 4 values of y manually using Bresenham's Line Algorithm as x steps

More information

UNIT 7 LIGHTING AND SHADING. 1. Explain phong lighting model. Indicate the advantages and disadvantages. (Jun2012) 10M

UNIT 7 LIGHTING AND SHADING. 1. Explain phong lighting model. Indicate the advantages and disadvantages. (Jun2012) 10M UNIT 7 LIGHTING AND SHADING 1. Explain phong lighting model. Indicate the advantages and disadvantages. (Jun2012) 10M Ans: Phong developed a simple model that can be computed rapidly It considers three

More information

Lecture 5: Viewing. CSE Computer Graphics (Fall 2010)

Lecture 5: Viewing. CSE Computer Graphics (Fall 2010) Lecture 5: Viewing CSE 40166 Computer Graphics (Fall 2010) Review: from 3D world to 2D pixels 1. Transformations are represented by matrix multiplication. o Modeling o Viewing o Projection 2. Clipping

More information

CS559: Computer Graphics. Lecture 12: OpenGL Li Zhang Spring 2008

CS559: Computer Graphics. Lecture 12: OpenGL Li Zhang Spring 2008 CS559: Computer Graphics Lecture 12: OpenGL Li Zhang Spring 2008 Reading Redbook Ch 1 & 2 So far: 3D Geometry Pipeline Model Space (Object Space) Rotation Translation Resizing World Space M Rotation Translation

More information

Hierarchical Modeling: Tree of Transformations, Display Lists and Functions, Matrix and Attribute Stacks,

Hierarchical Modeling: Tree of Transformations, Display Lists and Functions, Matrix and Attribute Stacks, Hierarchical Modeling: Tree of Transformations, Display Lists and Functions, Matrix and Attribute Stacks, Hierarchical Modeling Hofstra University 1 Modeling complex objects/motion Decompose object hierarchically

More information

OpenGL for dummies hello.c #include int main(int argc, char** argv) { glutinit(&argc, argv); glutinitdisplaymode (GLUT_SINGLE GLUT_RGB); glutinitwindowsize (250, 250); glutinitwindowposition

More information

Introduction to OpenGL

Introduction to OpenGL Introduction to OpenGL Banafsheh Azari http://www.uni-weimar.de/cms/medien/cg.html What You ll See Today What is OpenGL? Related Libraries OpenGL Command Syntax B. Azari http://www.uni-weimar.de/cms/medien/cg.html

More information

Graphics Programming. August 31, Programming of the Sierpinski gasket. Programming with OpenGL and C/C++

Graphics Programming. August 31, Programming of the Sierpinski gasket. Programming with OpenGL and C/C++ Computer Graphics Graphics Programming August 31, 2005 Contents Our Goal in This Chapter Programming of the Sierpinski gasket How To? Programming with OpenGL and C/C++ OpenGL API (Application Programmer

More information

Lectures Transparency Case Study

Lectures Transparency Case Study Lectures Transparency Case Study By Tom Duff Pixar Animation Studios Emeryville, California and George Ledin Jr Sonoma State University Rohnert Park, California 2004, Tom Duff and George Ledin Jr 1 How

More information

Modeling with Transformations

Modeling with Transformations Modeling with Transformations Prerequisites This module requires some understanding of 3D geometry, particularly a sense of how objects can be moved around in 3-space. The student should also have some

More information

Introduction to Computer Graphics with OpenGL/GLUT

Introduction to Computer Graphics with OpenGL/GLUT Introduction to Computer Graphics with OpenGL/GLUT What is OpenGL? A software interface to graphics hardware Graphics rendering API (Low Level) High-quality color images composed of geometric and image

More information

OpenGL/GLUT Intro. Week 1, Fri Jan 12

OpenGL/GLUT Intro. Week 1, Fri Jan 12 University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2007 Tamara Munzner OpenGL/GLUT Intro Week 1, Fri Jan 12 http://www.ugrad.cs.ubc.ca/~cs314/vjan2007 News Labs start next week Reminder:

More information

Computer graphics Labs: OpenGL (1/3) Geometric transformations and projections

Computer graphics Labs: OpenGL (1/3) Geometric transformations and projections University of Liège Department of Aerospace and Mechanical engineering Computer graphics Labs: OpenGL (1/3) Geometric transformations and projections Exercise 1: Geometric transformations (Folder transf

More information

Computer graphics MN1

Computer graphics MN1 Computer graphics MN1 http://www.opengl.org Todays lecture What is OpenGL? HowdoI useit? Rendering pipeline Points, vertices, lines, polygons Matrices and transformations Lighting and shading Code examples

More information

CS559: Computer Graphics. Lecture 12: OpenGL Transformation Li Zhang Spring 2008

CS559: Computer Graphics. Lecture 12: OpenGL Transformation Li Zhang Spring 2008 CS559: Computer Graphics Lecture 2: OpenGL Transformation Li Zhang Spring 28 Today Transformation in OpenGL Reading Chapter 3 Last time Primitive Details glpolygonmode(glenum face, GLenum mode); face:

More information

Computer graphics MN1

Computer graphics MN1 Computer graphics MN1 http://www.opengl.org Todays lecture What is OpenGL? How do I use it? Rendering pipeline Points, vertices, lines,, polygons Matrices and transformations Lighting and shading Code

More information

Modeling Transform. Chapter 4 Geometric Transformations. Overview. Instancing. Specify transformation for objects 李同益

Modeling Transform. Chapter 4 Geometric Transformations. Overview. Instancing. Specify transformation for objects 李同益 Modeling Transform Chapter 4 Geometric Transformations 李同益 Specify transformation for objects Allow definitions of objects in own coordinate systems Allow use of object definition multiple times in a scene

More information

GL_COLOR_BUFFER_BIT, GL_PROJECTION, GL_MODELVIEW

GL_COLOR_BUFFER_BIT, GL_PROJECTION, GL_MODELVIEW OpenGL Syntax Functions have prefix gl and initial capital letters for each word glclearcolor(), glenable(), glpushmatrix() glu for GLU functions glulookat(), gluperspective() constants begin with GL_,

More information

API for creating a display window and using keyboard/mouse interations. See RayWindow.cpp to see how these are used for Assignment3

API for creating a display window and using keyboard/mouse interations. See RayWindow.cpp to see how these are used for Assignment3 OpenGL Introduction Introduction OpenGL OpenGL is an API for computer graphics. Hardware-independent Windowing or getting input is not included in the API Low-level Only knows about triangles (kind of,

More information

Basic Graphics Programming

Basic Graphics Programming CSCI 480 Computer Graphics Lecture 2 Basic Graphics Programming January 11, 2012 Jernej Barbic University of Southern California http://www-bcf.usc.edu/~jbarbic/cs480-s12/ Graphics Pipeline OpenGL API

More information

Computer Graphics. Transformations. CSC 470 Computer Graphics 1

Computer Graphics. Transformations. CSC 470 Computer Graphics 1 Computer Graphics Transformations CSC 47 Computer Graphics 1 Today s Lecture Transformations How to: Rotate Scale and Translate 2 Introduction An important concept in computer graphics is Affine Transformations.

More information

Computer graphics MN1

Computer graphics MN1 Computer graphics MN1 Hierarchical modeling Transformations in OpenGL glmatrixmode(gl_modelview); glloadidentity(); // identity matrix gltranslatef(4.0, 5.0, 6.0); glrotatef(45.0, 1.0, 2.0, 3.0); gltranslatef(-4.0,

More information

Source code: #include <iostream>

Source code: #include <iostream> Andrew Yenalavitch Homework 4 CSE 520 - Winter 2015 1. ( 10 points ) Write a program that finds the knot vector ( u 0,..., u n-1 ) of a B-spline. It asks for 'number of control points' and 'degree of spline'

More information

Assignment 1. Simple Graphics program using OpenGL

Assignment 1. Simple Graphics program using OpenGL Assignment 1 Simple Graphics program using OpenGL In this assignment we will use basic OpenGL functions to draw some basic graphical figures. Example: Consider following program to draw a point on screen.

More information

COMPUTER GRAPHICS LAB # 3

COMPUTER GRAPHICS LAB # 3 COMPUTER GRAPHICS LAB # 3 Chapter 2: COMPUTER GRAPHICS by F.S HILLs. Initial steps in drawing figures (polygon, rectangle etc) Objective: Basic understanding of simple code in OpenGL and initial steps

More information

Lecture 4 of 41. Lab 1a: OpenGL Basics

Lecture 4 of 41. Lab 1a: OpenGL Basics Lab 1a: OpenGL Basics William H. Hsu Department of Computing and Information Sciences, KSU KSOL course pages: http://snipurl.com/1y5gc Course web site: http://www.kddresearch.org/courses/cis636 Instructor

More information

11/1/13. Basic Graphics Programming. Teaching Assistant. What is OpenGL. Course Producer. Where is OpenGL used. Graphics library (API)

11/1/13. Basic Graphics Programming. Teaching Assistant. What is OpenGL. Course Producer. Where is OpenGL used. Graphics library (API) CSCI 420 Computer Graphics Lecture 2 Basic Graphics Programming Teaching Assistant Yijing Li Office hours TBA Jernej Barbic University of Southern California Graphics Pipeline OpenGL API Primitives: Lines,

More information

Drawing Primitives. OpenGL basics

Drawing Primitives. OpenGL basics CSC 706 Computer Graphics / Dr. N. Gueorguieva 1 OpenGL Libraries Drawing Primitives OpenGL basics OpenGL core library OpenGL32 on Windows GL on most unix/linux systems (libgl.a) OpenGL Utility Library

More information

Assignment #6 2D Vector Field Visualization Arrow Plot and LIC

Assignment #6 2D Vector Field Visualization Arrow Plot and LIC Assignment #6 2D Vector Field Visualization Arrow Plot and LIC Due Oct.15th before midnight Goal: In this assignment, you will be asked to implement two visualization techniques for 2D steady (time independent)

More information

Introduction to OpenGL

Introduction to OpenGL Introduction to OpenGL Tutorial 1: Create a window and draw a 2D square Introduction: The aim of the first tutorial is to introduce you to the magic world of graphics based on the OpenGL and GLUT APIs.

More information

1 (Practice 1) Introduction to OpenGL

1 (Practice 1) Introduction to OpenGL 1 (Practice 1) Introduction to OpenGL This first practical is intended to get you used to OpenGL command. It is mostly a copy/paste work. Try to do it smartly by tweaking and messing around with parameters,

More information

Using OpenGL with CUDA

Using OpenGL with CUDA Using OpenGL with CUDA Installing OpenGL and GLUT; compiling with nvcc Basics of OpenGL and GLUT in C Interoperability between OpenGL and CUDA OpenGL = Open Graphic Library creation of 3D graphic primitives

More information

6. Make use of glviewport() to display two sine curves on the same screen, one on the

6. Make use of glviewport() to display two sine curves on the same screen, one on the Duc Nguyen CSE-420: Computer Graphics 10/17/18 1. Modify lines.cpp to display lines in the following patterns: a. a long dash and a dot, (.. ) b. two close dots followed by a distant dot (...... ) 2. Modify

More information

Lecture 3. Understanding of OPenGL programming

Lecture 3. Understanding of OPenGL programming Lecture 3 Understanding of OPenGL programming What is OpenGL GL: stands for Graphic Library Software interface for rendering purposes for 2D or 3D geometric data objects. Various Pieces gl: The basic libraries.

More information

Display Lists in OpenGL

Display Lists in OpenGL Display Lists in OpenGL Display lists are a mechanism for improving performance of interactive OpenGL applications. A display list is a group of OpenGL commands that have been stored for later execution.

More information

3D computer graphics: geometric modeling of objects in the computer and rendering them

3D computer graphics: geometric modeling of objects in the computer and rendering them SE313: Computer Graphics and Visual Programming Computer Graphics Notes Gazihan Alankus, Spring 2012 Computer Graphics 3D computer graphics: geometric modeling of objects in the computer and rendering

More information

Outline. Other Graphics Technology. OpenGL Background and History. Platform Specifics. The Drawing Process

Outline. Other Graphics Technology. OpenGL Background and History. Platform Specifics. The Drawing Process Outline 433-380 Graphics and Computation Introduction to OpenGL OpenGL Background and History Other Graphics Technology Drawing Viewing and Transformation Lighting GLUT Resources Some images in these slides

More information

Graphics and Computation Introduction to OpenGL

Graphics and Computation Introduction to OpenGL 433-380 Graphics and Computation Introduction to OpenGL Some images in these slides are taken from The OpenGL Programming Manual, which is copyright Addison Wesley and the OpenGL Architecture Review Board.

More information

DONALD HOUSE: CPSC 8170, FALL 2018 DESIGN OF A REAL-TIME ANIMATION PROGRAM

DONALD HOUSE: CPSC 8170, FALL 2018 DESIGN OF A REAL-TIME ANIMATION PROGRAM DONALD HOUSE: CPSC 8170, FALL 2018 DESIGN OF A REAL-TIME ANIMATION PROGRAM DEMO MODEL-VIEW-CONTROLLER DESIGN canonical.cpp The main program canonical.cpp acts as the controller, directing Model and actions

More information

20 GLuint objects; 36 Scale += 0.1; 37 break; 38 case GLUT_KEY_DOWN:

20 GLuint objects; 36 Scale += 0.1; 37 break; 38 case GLUT_KEY_DOWN: 1 1. 1 #include 2 #include 3 Program 1 (OpenGL Sample016) 4 // 5 static int MouseX = 0; // X 6 static int MouseY = 0; // Y 7 static float SpinX = 0; // X 8 static float SpinY = 0;

More information

Announcements OpenGL. Computer Graphics. Spring CS4815

Announcements OpenGL. Computer Graphics. Spring CS4815 Computer Graphics Spring 2017-2018 Outline 1 2 Tutes and Labs Tute02, vector review (see matrix) Week02 lab Lab Marking 10 labs in total each lab worth 3% of overall grade marked on attendance and completion

More information

Announcements OpenGL. Computer Graphics. Autumn 2009 CS4815

Announcements OpenGL. Computer Graphics. Autumn 2009 CS4815 Computer Graphics Autumn 2009 Outline 1 Labs 2 Labs Outline 1 Labs 2 Labs Labs Week02 lab Marking 8 10 labs in total each lab worth 2 3% of overall grade marked on attendance and completion of lab completed

More information

2 Transformations and Homogeneous Coordinates

2 Transformations and Homogeneous Coordinates Brief solutions to Exam in Computer Graphics Time and place: 08:00 3:00 Tuesday March 7, 2009, Gimogatan 4, sal Grades TD388: 3: 20pts; 4: 26pts; 5: 34pts. Glossary API Application Programmer s Interface.

More information

Programming using OpenGL: A first Introduction

Programming using OpenGL: A first Introduction Programming using OpenGL: A first Introduction CMPT 361 Introduction to Computer Graphics Torsten Möller Machiraju/Zhang/Möller 1 Today Overview GL, GLU, GLUT, and GLUI First example OpenGL functions and

More information

CMSC 425: Lecture 4 More about OpenGL and GLUT Tuesday, Feb 5, 2013

CMSC 425: Lecture 4 More about OpenGL and GLUT Tuesday, Feb 5, 2013 CMSC 425: Lecture 4 More about OpenGL and GLUT Tuesday, Feb 5, 2013 Reading: See any standard reference on OpenGL or GLUT. Basic Drawing: In the previous lecture, we showed how to create a window in GLUT,

More information

Introduction to MS Visual C/C++

Introduction to MS Visual C/C++ 3/4/2002 Burkhard Wünsche Introduction to C/C++ Page 1 of 9 0. Introduction: Introduction to MS Visual C/C++ This tutorial gives a simple introduction to MS Visual C/C++ with an emphasis on OpenGL graphics

More information

Methodology for Lecture

Methodology for Lecture Basic Geometry Setup Methodology for Lecture Make mytest1 more ambitious Sequence of steps Demo Review of Last Demo Changed floor to all white, added global for teapot and teapotloc, moved geometry to

More information

Grafica Computazionale

Grafica Computazionale Grafica Computazionale lezione36 Informatica e Automazione, "Roma Tre" June 3, 2010 Grafica Computazionale: Lezione 33 Textures Introduction Steps in Texture Mapping A Sample Program Texturing algorithms

More information

BOUNCING BALL IMRAN IHSAN ASSISTANT PROFESSOR

BOUNCING BALL IMRAN IHSAN ASSISTANT PROFESSOR COMPUTER GRAPHICS LECTURE 07 BOUNCING BALL IMRAN IHSAN ASSISTANT PROFESSOR WWW.IMRANIHSAN.COM /* * GL07BouncingBall.cpp: A ball bouncing inside the window */ #include // for MS Windows #include

More information

IntMu.Lab5. Download all the files available from

IntMu.Lab5. Download all the files available from IntMu.Lab5 0. Download all the files available from http://www.dee.isep.ipp.pt/~jml/intmu/lab5: wget http://www.dee.isep.ipp.pt/~jml/intmu/lab5/makefile make getall Analyze the program windmill.c. Compile

More information

Scientific Visualization Basics

Scientific Visualization Basics Scientific Visualization Basics Aiichiro Nakano Collaboratory for Advanced Computing & Simulations Dept. of Computer Science, Dept. of Physics & Astronomy, Dept. of Chemical Engineering & Materials Science,

More information

Cameras (and eye) Ideal Pinhole. Real Pinhole. Real + lens. Depth of field

Cameras (and eye) Ideal Pinhole. Real Pinhole. Real + lens. Depth of field Cameras (and eye) Ideal Pinhole Real Pinhole Real + lens Depth of field 1 Z-buffer How do we draw objects? Polygon Based Fast Raytracing Ray/Object intersections Slow Copyright Pixar 2 Raytracing for each

More information

OpenGL refresher. Advanced Computer Graphics 2012

OpenGL refresher. Advanced Computer Graphics 2012 Advanced Computer Graphics 2012 What you will see today Outline General OpenGL introduction Setting up: GLUT and GLEW Elementary rendering Transformations in OpenGL Texture mapping Programmable shading

More information

Modeling Objects by Polygonal Approximations. Linear and Affine Transformations (Maps)

Modeling Objects by Polygonal Approximations. Linear and Affine Transformations (Maps) Modeling Objects by Polygonal Approximations Define volumetric objects in terms of surfaces patches that surround the volume Each surface patch is approximated set of polygons Each polygon is specified

More information

Announcement. Homework 1 has been posted in dropbox and course website. Due: 1:15 pm, Monday, September 12

Announcement. Homework 1 has been posted in dropbox and course website. Due: 1:15 pm, Monday, September 12 Announcement Homework 1 has been posted in dropbox and course website Due: 1:15 pm, Monday, September 12 Today s Agenda Primitives Programming with OpenGL OpenGL Primitives Polylines GL_POINTS GL_LINES

More information

Interaction. CSCI 480 Computer Graphics Lecture 3

Interaction. CSCI 480 Computer Graphics Lecture 3 CSCI 480 Computer Graphics Lecture 3 Interaction January 18, 2012 Jernej Barbic University of Southern California Client/Server Model Callbacks Double Buffering Hidden Surface Removal Simple Transformations

More information

Ulf Assarsson Department of Computer Engineering Chalmers University of Technology

Ulf Assarsson Department of Computer Engineering Chalmers University of Technology Ulf Assarsson Department of Computer Engineering Chalmers University of Technology 1. I am located in room 4115 in EDIT-huset 2. Email: 3. Phone: 031-772 1775 (office) 4. Course assistant: Tomas Akenine-Mőller

More information

Graphics Pipeline & APIs

Graphics Pipeline & APIs Graphics Pipeline & APIs CPU Vertex Processing Rasterization Fragment Processing glclear (GL_COLOR_BUFFER_BIT GL_DEPTH_BUFFER_BIT); glpushmatrix (); gltranslatef (-0.15, -0.15, solidz); glmaterialfv(gl_front,

More information

Fundamental Types of Viewing

Fundamental Types of Viewing Viewings Fundamental Types of Viewing Perspective views finite COP (center of projection) Parallel views COP at infinity DOP (direction of projection) perspective view parallel view Classical Viewing Specific

More information

Interaction Computer Graphics I Lecture 3

Interaction Computer Graphics I Lecture 3 15-462 Computer Graphics I Lecture 3 Interaction Client/Server Model Callbacks Double Buffering Hidden Surface Removal Simple Transformations January 21, 2003 [Angel Ch. 3] Frank Pfenning Carnegie Mellon

More information

OpenGL Tutorial. Ceng 477 Introduction to Computer Graphics

OpenGL Tutorial. Ceng 477 Introduction to Computer Graphics OpenGL Tutorial Ceng 477 Introduction to Computer Graphics Adapted from: http://www.cs.princeton.edu/courses/archive/spr06/cos426/assn3/opengl_tutorial.ppt OpenGL IS an API OpenGL IS nothing more than

More information

Lectures Display List

Lectures Display List Lectures Display List By Tom Duff Pixar Animation Studios Emeryville, California and George Ledin Jr Sonoma State University Rohnert Park, California 2004, Tom Duff and George Ledin Jr 1 What is it? What

More information

ERKELEY DAVIS IRVINE LOS ANGELES RIVERSIDE SAN DIEGO SAN FRANCISCO EECS 104. Fundamentals of Computer Graphics. OpenGL

ERKELEY DAVIS IRVINE LOS ANGELES RIVERSIDE SAN DIEGO SAN FRANCISCO EECS 104. Fundamentals of Computer Graphics. OpenGL ERKELEY DAVIS IRVINE LOS ANGELES RIVERSIDE SAN DIEGO SAN FRANCISCO SANTA BARBARA SANTA CRUZ EECS 104 Fundamentals of Computer Graphics OpenGL Slides courtesy of Dave Shreine, Ed Angel and Vicki Shreiner

More information

Computer Graphics Course 2005

Computer Graphics Course 2005 Computer Graphics Course 2005 Introduction to GLUT, GLU and OpenGL Administrative Stuff Teaching Assistant: Rony Goldenthal Reception Hour: Wed. 18:00 19:00 Room 31 (Ross 1) Questions: E-mail: cg@cs Newsgroups:

More information

Visualizing Molecular Dynamics

Visualizing Molecular Dynamics Visualizing Molecular Dynamics Aiichiro Nakano Collaboratory for Advanced Computing & Simulations Department of Computer Science Department of Physics & Astronomy Department of Chemical Engineering & Materials

More information

Computer Graphics, Chapt 08

Computer Graphics, Chapt 08 Computer Graphics, Chapt 08 Creating an Image Components, parts of a scene to be displayed Trees, terrain Furniture, walls Store fronts and street scenes Atoms and molecules Stars and galaxies Describe

More information

OpenGL Transformations

OpenGL Transformations OpenGL Transformations R. J. Renka Department of Computer Science & Engineering University of North Texas 02/18/2014 Introduction The most essential aspect of OpenGL is the vertex pipeline described in

More information

Programming with OpenGL Part 2: Complete Programs Computer Graphics I, Fall

Programming with OpenGL Part 2: Complete Programs Computer Graphics I, Fall Programming with OpenGL Part 2: Complete Programs 91.427 Computer Graphics I, Fall 2008 1 1 Objectives Refine first program Alter default values Introduce standard program structure Simple viewing 2-D

More information

CSC 240 Computer Graphics. Fall 2015 Smith College

CSC 240 Computer Graphics. Fall 2015 Smith College CSC 240 Computer Graphics Fall 2015 Smith College Outline: 11/9 Stacks revisited Shading (using normal vectors) Texture Mapping Final quiz If time: robot with two arms White background slides from Eitan

More information

Graphics Pipeline & APIs

Graphics Pipeline & APIs 3 2 4 Graphics Pipeline & APIs CPU Vertex Processing Rasterization Processing glclear (GL_COLOR_BUFFER_BIT GL_DEPTH_BUFFER_BIT); glpushmatrix (); gltranslatef (-0.15, -0.15, solidz); glmaterialfv(gl_front,

More information

Computer Graphics. OpenGL

Computer Graphics. OpenGL Computer Graphics OpenGL What is OpenGL? OpenGL (Open Graphics Library) is a library for computer graphics It consists of several procedures and functions that allow a programmer to specify the objects

More information

Computer Graphics (Basic OpenGL)

Computer Graphics (Basic OpenGL) Computer Graphics (Basic OpenGL) Thilo Kielmann Fall 2008 Vrije Universiteit, Amsterdam kielmann@cs.vu.nl http://www.cs.vu.nl/ graphics/ Computer Graphics (Basic OpenGL, Input and Interaction), ((57))

More information

CS418 OpenGL & GLUT Programming Tutorial (I) Presented by : Wei-Wen Feng 1/30/2008

CS418 OpenGL & GLUT Programming Tutorial (I) Presented by : Wei-Wen Feng 1/30/2008 CS418 OpenGL & GLUT Programming Tutorial (I) Presented by : Wei-Wen Feng 1/30/2008 2008/2/3 Slide 2 I Am Your TA Name : Wei-Wen Wen Feng 4th Year Graduate Student in Graphics I will be Holding discussion/tutorial

More information

Lecture 2 2D transformations Introduction to OpenGL

Lecture 2 2D transformations Introduction to OpenGL Lecture 2 2D transformations Introduction to OpenGL OpenGL where it fits what it contains how you work with it OpenGL parts: GL = Graphics Library (core lib) GLU = GL Utilities (always present) GLX, AGL,

More information

OpenGL: Open Graphics Library. Introduction to OpenGL Part II. How do I render a geometric primitive? What is OpenGL

OpenGL: Open Graphics Library. Introduction to OpenGL Part II. How do I render a geometric primitive? What is OpenGL OpenGL: Open Graphics Library Introduction to OpenGL Part II CS 351-50 Graphics API ( Application Programming Interface) Software library Layer between programmer and graphics hardware (and other software

More information

Ulf Assarsson Department of Computer Engineering Chalmers University of Technology

Ulf Assarsson Department of Computer Engineering Chalmers University of Technology Ulf Assarsson Department of Computer Engineering Chalmers University of Technology Tracing Photons One way to form an image is to follow rays of light from a point source finding which rays enter the lens

More information

3.2 Hierarchical Modeling

3.2 Hierarchical Modeling Fall 2018 CSCI 420: Computer Graphics 3.2 Hierarchical Modeling Hao Li http://cs420.hao-li.com 1 Importance of shadows Source: UNC 2 Importance of shadows Source: UNC 3 Importance of shadows Source: UNC

More information

Lecture 2 CISC440/640 Spring Department of Computer and Information Science

Lecture 2 CISC440/640 Spring Department of Computer and Information Science Lecture 2 CISC440/640 Spring 2015 Department of Computer and Information Science Today s Topic The secrets of Glut-tony 2 So let s do some graphics! For the next week or so this is your world: -1 1-1 1

More information

Comp 410/510 Computer Graphics Spring Programming with OpenGL Part 2: First Program

Comp 410/510 Computer Graphics Spring Programming with OpenGL Part 2: First Program Comp 410/510 Computer Graphics Spring 2017 Programming with OpenGL Part 2: First Program Objectives Refine the first program Introduce a standard program structure - Initialization Program Structure Most

More information

1.2 Basic Graphics Programming

1.2 Basic Graphics Programming Fall 2018 CSCI 420: Computer Graphics 1.2 Basic Graphics Programming Hao Li http://cs420.hao-li.com 1 Last time Last Time Story Computer Graphics Image Last Time 3D Printing 3D Capture Animation Modeling

More information

by modifying the glutinitwindowsize() function you can change the screen size to whatever you please.

by modifying the glutinitwindowsize() function you can change the screen size to whatever you please. Zoe Veale Lab 2 Draw2 part 1: I edited the glutinitwindowsize() function tom change the size of my screen window. int main(int argc, char** argv) glutinit(&argc, argv); //initialize toolkit glutinitdisplaymode

More information

Order of Transformations

Order of Transformations Order of Transformations Because the same transformation is applied to many vertices, the cost of forming a matrix M=ABCD is not significant compared to the cost of computing Mp for many vertices p Note

More information

Exercise 1 Introduction to OpenGL

Exercise 1 Introduction to OpenGL Exercise 1 Introduction to OpenGL What we are going to do OpenGL Glut Small Example using OpenGl and Glut Alexandra Junghans 2 What is OpenGL? OpenGL Two Parts most widely used and supported graphics API

More information

Introduction to OpenGL: Part 2

Introduction to OpenGL: Part 2 Introduction to OpenGL: Part 2 Introduction to OpenGL: Part 2 A more complex example recursive refinement Introduction to OpenGL: Part 2 A more complex example recursive refinement Can OpenGL draw continuous

More information

Graphics Hardware and OpenGL

Graphics Hardware and OpenGL Graphics Hardware and OpenGL Ubi Soft, Prince of Persia: The Sands of Time What does graphics hardware have to do fast? Camera Views Different views of an object in the world 1 Camera Views Lines from

More information

Computer Graphics. Chapter 10 Three-Dimensional Viewing

Computer Graphics. Chapter 10 Three-Dimensional Viewing Computer Graphics Chapter 10 Three-Dimensional Viewing Chapter 10 Three-Dimensional Viewing Part I. Overview of 3D Viewing Concept 3D Viewing Pipeline vs. OpenGL Pipeline 3D Viewing-Coordinate Parameters

More information