1) Here is the various stages of the tetrahedron:

Size: px
Start display at page:

Download "1) Here is the various stages of the tetrahedron:"

Transcription

1 Andrew Yenalavitch Homework 3 CSE Winter ) ( 20 points ) Write a shader program that renders a colored tetrahedron, which gradually shrinks to a point and expands back to its original shape. While it is shrinking and expanding, the color of the tetrahedron changes. 2) ( 20 points ) Write a shader program that uses texture techniques to paste 6 different images on the 6 faces of a cube. The cube rotates and changes size from time to time. 1) Here is the various stages of the tetrahedron:

2 I started with my code from lab 8 (the color changing hexagon) and modified it so that it displays a tetrahedron, and scales in addition to changing colors. To draw the tetrahedron, I used glutsolidtetrahedron and rotated it so that the edges would be more visible: glpushmatrix(); glrotatef(30, 0,1,0); glutsolidtetrahedron(); glpopmatrix();

3 To achieve the scaling effect, I took the "r" variable I used in lab 9 to achieve the color changing effect, and plugged it into a mat4 scaling matrix. I limit "r" to be no less than 0. As the tetrahedron shrinks, its color transitions from red to blue. As the tetrahedron grows to full scale, its color transitions from blue to red. float r = 0; float b = 0; r = r * sin ( * time ); if (r < 0) r = 0; b = r; mat4 ScalarMatrix = mat4( r, 0.0, 0.0, 0.0, 0.0, r, 0.0, 0.0, 0.0, 0.0, r, 0.0, 0.0, 0.0, 0.0, 1.0 ); I also added in shader lighting effects from the brick shader example program. The light position is passed in from the application as a uniform: gluniform3f(glgetuniformlocation(programobject, "LightPosition"), 0.0, 0.0, 4.0); This position is used by the vertex shader in various lighting calculations: vec3 ecposition = vec3 (gl_modelviewmatrix * gl_vertex); vec3 tnorm = normalize(gl_normalmatrix * gl_normal); vec3 lightvec = normalize(lightposition - ecposition); vec3 reflectvec = reflect(-lightvec, tnorm); vec3 viewvec = normalize(-ecposition); float diffuse = max(dot(lightvec, tnorm), 0.0); float spec = 0.0; if (diffuse > 0.0) spec = max(dot(reflectvec, viewvec), 0.0); spec = pow(spec, 16.0); LightIntensity = DiffuseContribution * diffuse + SpecularContribution * spec; and the resulting light intensity is passed to the fragement shader with the "LightIIntensity" varrying variable. Full source code: //lab9.cpp #include <stdlib.h> #include <stdio.h> #include <string.h> #include <fcntl.h> #include <sys/types.h> #include <unistd.h>

4 #define GLEW_STATIC 1 #include <GL/glew.h> #include <GL/glu.h> #include <GL/glut.h> using namespace std; /* Global handles for the currently active program object, with its two shader objects */ GLuint programobject = 0; GLuint vertexshaderobject = 0; GLuint fragmentshaderobject = 0; static GLint win = 0; //GLfloat angle = 0; GLuint timeparam; int readshadersource(char *filename, GLchar **shader ) // Allocate memory to hold the source of our shaders. FILE *fp; int count, pos, shadersize; fp = fopen( filename, "r"); if (!fp ) return 0; pos = (int) ftell ( fp ); fseek ( fp, 0, SEEK_END ); shadersize = ( int ) ftell ( fp ) - pos; fseek ( fp, 0, SEEK_SET ); //move to end //calculates file size //rewind to beginning if ( shadersize <= 0 ) printf("shader %s empty\n", filename); return 0; shadersize += 1; *shader = (GLchar *) malloc( shadersize); // Read the source code count = (int) fread(*shader, 1, shadersize, fp); (*shader)[count] = '\0'; if (ferror(fp)) count = 0; fclose(fp); return 1; // public int installshaders(const GLchar *vertex, const GLchar *fragment) GLint vertcompiled, fragcompiled; // status values GLint linked; // Create a vertex shader object and a fragment shader object

5 vertexshaderobject = glcreateshader(gl_vertex_shader); fragmentshaderobject = glcreateshader(gl_fragment_shader); // Load source code strings into shaders, compile and link glshadersource(vertexshaderobject, 1, &vertex, NULL); glshadersource(fragmentshaderobject, 1, &fragment, NULL); glcompileshader(vertexshaderobject); glgetshaderiv(vertexshaderobject, GL_COMPILE_STATUS, &vertcompiled); glcompileshader( fragmentshaderobject ); glgetshaderiv( fragmentshaderobject, GL_COMPILE_STATUS, &fragcompiled); if (!vertcompiled!fragcompiled) return 0; // Create a program object and attach the two compiled shaders programobject = glcreateprogram(); glattachshader( programobject, vertexshaderobject); glattachshader( programobject, fragmentshaderobject); // Link the program object gllinkprogram(programobject); glgetprogramiv(programobject, GL_LINK_STATUS, &linked); if (!linked) return 0; // Install program object as part of current state gluseprogram(programobject); gluniform3f(glgetuniformlocation(programobject, "LightPosition"), 0.0, 0.0, 4.0); return 1; int init(void) const char *version; GLchar *VertexShaderSource, *FragmentShaderSource; int loadstatus = 0; version = (const char *) glgetstring(gl_version); if (version[0]!= '2' version[1]!= '.') printf("this program requires OpenGL 2.x, found %s\n", version); // exit(1); gldepthfunc(gl_less); glenable(gl_depth_test); glclearcolor(1.0f, 1.0f, 1.0f, 1.0f); readshadersource("movingv.vert", &VertexShaderSource ); readshadersource("tests.frag", &FragmentShaderSource ); loadstatus = installshaders(vertexshadersource, FragmentShaderSource); timeparam = glgetuniformlocation ( programobject, "time" ); return loadstatus;

6 static void Reshape(int width, int height) glviewport(0, 0, width, height); glmatrixmode(gl_projection); glloadidentity(); glfrustum(-1.0, 1.0, -1.0, 1.0, 5.0, 25.0); glmatrixmode(gl_modelview); glloadidentity(); gltranslatef(0.0f, 0.0f, -15.0f); void CleanUp(void) gldeleteshader(vertexshaderobject); gldeleteshader(fragmentshaderobject); gldeleteprogram(programobject); glutdestroywindow(win); static void Idle(void) gluniform1f( timeparam, glutget ( GLUT_ELAPSED_TIME ) ); //angle += 0.01; glutpostredisplay(); static void Key(unsigned char key, int x, int y) switch(key) case 27: CleanUp(); exit(0); break; glutpostredisplay(); void display(void) GLfloat vec[4]; glclear(gl_color_buffer_bit GL_DEPTH_BUFFER_BIT); glclearcolor( 1.0, 1.0, 1.0, 0.0 ); //get white background color glcolor3f ( 1, 0, 0 ); //red, this will have no effect if shader is loaded glpushmatrix(); glrotatef(30, 0,1,0); glutsolidtetrahedron(); glpopmatrix(); glutswapbuffers(); glflush(); int main(int argc, char *argv[]) int success = 0;

7 glutinit(&argc, argv); glutinitwindowposition( 0, 0); glutinitwindowsize(500, 500); glutinitdisplaymode(glut_rgb GLUT_DOUBLE GLUT_DEPTH); win = glutcreatewindow(argv[0]); glutreshapefunc(reshape); glutkeyboardfunc(key); glutdisplayfunc(display); glutidlefunc(idle); // Initialize the "OpenGL Extension Wrangler" library glewinit(); success = init(); if ( success ) glutmainloop(); return 0; //movingv.vert uniform float time; //value provided by application program uniform vec3 LightPosition; const float SpecularContribution = 0.3; const float DiffuseContribution = SpecularContribution; varying float LightIntensity; varying vec4 Color; void main(void) vec3 ecposition = vec3 (gl_modelviewmatrix * gl_vertex); vec3 tnorm = normalize(gl_normalmatrix * gl_normal); vec3 lightvec = normalize(lightposition - ecposition); vec3 reflectvec = reflect(-lightvec, tnorm); vec3 viewvec = normalize(-ecposition); float diffuse = max(dot(lightvec, tnorm), 0.0); float spec = 0.0; if (diffuse > 0.0) spec = max(dot(reflectvec, viewvec), 0.0); spec = pow(spec, 16.0); LightIntensity = DiffuseContribution * diffuse + SpecularContribution * spec; float r = 0; float b = 0; r = r * sin ( * time ); if (r < 0) r = 0; b = r; mat4 ScalarMatrix = mat4( r, 0.0, 0.0, 0.0, 0.0, r, 0.0, 0.0,

8 0.0, 0.0, r, 0.0, 0.0, 0.0, 0.0, 1.0 ); Color = vec4(r, 0, b, 1.0); gl_position = gl_modelviewprojectionmatrix * ScalarMatrix * gl_vertex; //tests.frag varying vec4 Color; varying float LightIntensity; void main(void) Color *= LightIntensity; gl_fragcolor = Color; 2) Here is the cube rotating at full size from 2 different angles:

9 Here is the cube scaled to half size after 10 seconds: I started with the simpletex program used in lab 9 to texture the octagon and modified it to work with multiple textures. These texture names are hard-coded into the program: char faces[][20] = "front.png", "back.png", "right.png", "left.png", "top.png", "bottom.png" ; And these names are used to initialize the various texture parameters: void init2dtexture() glgentextures(6, texname); for ( int i = 0; i < 6; ++i ) GLubyte *teximage = maketeximage( faces[i] ); if (!teximage ) printf("\nerror reading %s \n", faces[i] ); exit(1); glbindtexture(gl_texture_2d, texname[i]); //now we work on texname gltexparameteri(gl_texture_2d, GL_TEXTURE_WRAP_S, GL_REPEAT); gltexparameteri(gl_texture_2d, GL_TEXTURE_WRAP_T, GL_REPEAT); 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, iwidth, iheight, 0, GL_RGBA, GL_UNSIGNED_BYTE, teximage); delete teximage; Instead of an octagon, these 6 different PNG files were mapped to a cube using the technique provided by Dr. Yu from lab 9. Here is an example of one of the faces: glbegin ( GL_POLYGON ); //back face gltexcoord2f (0,0); glvertex3f (0,0,0); gltexcoord2f (1,0); glvertex3f (1,0,0);

10 gltexcoord2f (1,1); glvertex3f (1,1,0); gltexcoord2f (0,1); glvertex3f (0,1,0); glend(); Every ten seconds, the cube toggles between full size and half size. To achieve this, I used a gluttimerfunc callback function named mytimer that toggles the value of the variable "scalar" between 1.0 and 0.5. void mytimer(int id) // timer callback cout << "Timer just went off" << endl; if (scalar == 1.0) scalar = 0.5; else scalar = 1.0; glutpostredisplay(); // request redraw gluttimerfunc(10000, mytimer, 0); // reset timer for 10 seconds This value is passed to the vertex shader as a uniform and placed in the scaling matrix "ScalarMatrix". This matrix is then used to scale the shader. mat4 ScalarMatrix = mat4( scalar, 0.0, 0.0, 0.0, 0.0, scalar, 0.0, 0.0, 0.0, 0.0, scalar, 0.0, 0.0, 0.0, 0.0, 1.0 ); gl_position = gl_modelviewprojectionmatrix * RotationMatrix * ScalarMatrix * gl_vertex; In addition to the timed scaling, the cube is also rotating. To achieve this, I increment the "angle" variable in the idle function and pass this to the vertex shader as a uniform. gluniform1f( angleparam, angle ); angle += 0.01; The vertex shader finds the sine and cosine of this angle and creates 2 rotational matrices, "ZRotationMatrix" and "YRotationMatrix", which are multiplied together to form "RotationMatrix". This matrix is used to rotate the shader. float c = cos( angle ); float s = sin( angle ); mat4 ZRotationMatrix = mat4( c, -s, 0.0, 0.0, s, c, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0 ); mat4 YRotationMatrix = mat4( c, 0.0, s, 0.0, 0, 1, 0.0, 0.0, -s, 0.0, c, 0.0, 0.0, 0.0, 0.0, 1.0 ); mat4 RotationMatrix = ZRotationMatrix * YRotationMatrix;

11 gl_position = gl_modelviewprojectionmatrix * RotationMatrix * ScalarMatrix * gl_vertex; Full source code: //simpletex.cpp #include <stdlib.h> #include <stdio.h> #include <string.h> #include <fcntl.h> #include <sys/types.h> #include <unistd.h> #include <cmath> #include <iostream> #define GLEW_STATIC 1 #include <GL/glew.h> #include <GL/glu.h> #include <GL/glut.h> #include "imageio.h" using namespace std; /* Global handles for the currently active program object, with its two shader objects */ GLfloat angle = 0; GLfloat angleparam = 0; GLfloat scalar = 1.0; GLfloat scalarparam = 0; GLuint programobject = 0; GLuint vertexshaderobject = 0; GLuint fragmentshaderobject = 0; static GLint win = 0; int anglex= 0, angley = 0, anglez = 0; int objecttype = 0; static GLuint texname[6]; int iwidth = 64, iheight = 64; char faces[][20] = "front.png", "back.png", "right.png", "left.png", "top.png", "bottom.png" ; //rotation angles /* static GLubyte checkimage[iheight][iwidth][3]; void makecheckimage(void) int i, j, c; for (i = 0; i < iwidth; i++) for (j = 0; j < iheight; j++) c = ((((i&0x8)==0)^((j&0x8))==0))*255; checkimage[i][j][0] = (GLubyte) c; checkimage[i][j][1] = (GLubyte) c; checkimage[i][j][2] = (GLubyte) c;

12 */ GLubyte* maketeximage( char *loadfile ) int i, j, c, width, height; GLubyte *teximage; teximage = loadimagergba( (char *) loadfile, &width, &height); iwidth = width; iheight = height; return teximage; void init2dtexture() glgentextures(6, texname); for ( int i = 0; i < 6; ++i ) GLubyte *teximage = maketeximage( faces[i] ); if (!teximage ) printf("\nerror reading %s \n", faces[i] ); exit(1); glbindtexture(gl_texture_2d, texname[i]); //now we work on texname gltexparameteri(gl_texture_2d, GL_TEXTURE_WRAP_S, GL_REPEAT); gltexparameteri(gl_texture_2d, GL_TEXTURE_WRAP_T, GL_REPEAT); 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, iwidth, iheight, 0, GL_RGBA, GL_UNSIGNED_BYTE, teximage); delete teximage; int readshadersource(char *filename, GLchar **shader ) // Allocate memory to hold the source of our shaders. FILE *fp; int count, pos, shadersize; fp = fopen( filename, "r"); if (!fp ) return 0; pos = (int) ftell ( fp ); fseek ( fp, 0, SEEK_END ); shadersize = ( int ) ftell ( fp ) - pos; fseek ( fp, 0, SEEK_SET ); //move to end //calculates file size //rewind to beginning if ( shadersize <= 0 ) printf("shader %s empty\n", filename); return 0; *shader = (GLchar *) malloc( shadersize + 1); // Read the source code count = (int) fread(*shader, 1, shadersize, fp); (*shader)[count] = '\0'; if (ferror(fp))

13 count = 0; fclose(fp); return 1; // public int installshaders(const GLchar *vertex, const GLchar *fragment) GLint vertcompiled, fragcompiled; // status values GLint linked; // Create a vertex shader object and a fragment shader object vertexshaderobject = glcreateshader(gl_vertex_shader); fragmentshaderobject = glcreateshader(gl_fragment_shader); // Load source code strings into shaders, compile and link glshadersource(vertexshaderobject, 1, &vertex, NULL); glshadersource(fragmentshaderobject, 1, &fragment, NULL); glcompileshader(vertexshaderobject); glgetshaderiv(vertexshaderobject, GL_COMPILE_STATUS, &vertcompiled); glcompileshader( fragmentshaderobject ); glgetshaderiv( fragmentshaderobject, GL_COMPILE_STATUS, &fragcompiled); if (!vertcompiled!fragcompiled) return 0; // Create a program object and attach the two compiled shaders programobject = glcreateprogram(); glattachshader( programobject, vertexshaderobject); glattachshader( programobject, fragmentshaderobject); // Link the program object gllinkprogram(programobject); glgetprogramiv(programobject, GL_LINK_STATUS, &linked); if (!linked) return 0; // Install program object as part of current state gluseprogram(programobject); // Set up initial uniform values gluniform3f(glgetuniformlocation(programobject, "LightPosition"), 2.0, 2.0, 4.0); gluniform1i(glgetuniformlocation(programobject, "texhandle"), 0); return 1; int init(void) const char *version;

14 GLchar *VertexShaderSource, *FragmentShaderSource; int loadstatus = 0; version = (const char *) glgetstring(gl_version); if (version[0] < '2' version[1]!= '.') printf("this program requires OpenGL >= 2.x, found %s\n", version); exit(1); gldepthfunc(gl_less); glenable(gl_depth_test); glclearcolor(1.0f, 1.0f, 1.0f, 1.0f); readshadersource("simpletex.vert", &VertexShaderSource ); readshadersource("simpletex.frag", &FragmentShaderSource ); loadstatus = installshaders(vertexshadersource, FragmentShaderSource); angleparam = glgetuniformlocation ( programobject, "angle" ); scalarparam = glgetuniformlocation ( programobject, "scalar" ); init2dtexture(); return loadstatus; void mytimer(int id) // timer callback cout << "Timer just went off" << endl; if (scalar == 1.0) scalar = 0.5; else scalar = 1.0; glutpostredisplay(); // request redraw gluttimerfunc(10000, mytimer, 0); // reset timer for 10 seconds static void Reshape(int w, int h) float vp = 0.8f; float aspect = (float) w / (float) h; glviewport(0, 0, w, h); glmatrixmode(gl_projection); glloadidentity(); glviewport(0, 0, w, h); glmatrixmode(gl_projection); glloadidentity(); // glortho(-1.0, 1.0, -1.0, 1.0, -10.0, 10.0); glfrustum(-vp, vp, -vp / aspect, vp / aspect, 3, 10.0); glmatrixmode(gl_modelview); glloadidentity(); gltranslatef(0.0, 0.0, -5.0); void CleanUp(void) gldeleteshader(vertexshaderobject); gldeleteshader(fragmentshaderobject); gldeleteprogram(programobject); glutdestroywindow(win); static void Idle(void)

15 gluniform1f( angleparam, angle ); angle += 0.01; gluniform1f( scalarparam, scalar ); glutpostredisplay(); static void Key(unsigned char key, int x, int y) switch(key) case 27: CleanUp(); exit(0); break; case 'x': anglex = ( anglex + 3 ) % 360; break; case 'X': anglex = ( anglex - 3 ) % 360; break; case 'y': angley = ( angley + 3 ) % 360; break; case 'Y': angley = ( angley - 3 ) % 360; break; case 'z': anglez = ( anglez + 3 ) % 360; break; case 'Z': anglez = ( anglez - 3 ) % 360; break; case 'r': anglex = angley = anglez = 0; break; case 't': objecttype = (objecttype + 1 ) % 3; break; glutpostredisplay(); void display(void) GLfloat vec[4]; glclear(gl_color_buffer_bit GL_DEPTH_BUFFER_BIT); glclearcolor( 1.0, 1.0, 1.0, 0.0 ); //get white background color glpushmatrix(); glrotatef( anglex, 1.0, 0.0, 0.0); glrotatef( angley, 0.0, 1.0, 0.0); glrotatef( anglez, 0.0, 0.0, 1.0); //rotate the cube along x-axis //rotate along y-axis //rotate along z-axis //glactivetexture(gl_texture0); glenable(gl_texture_2d); //glbindtexture(gl_texture_2d, texname); glbindtexture(gl_texture_2d, texname[0]); glbegin ( GL_POLYGON ); //back face gltexcoord2f (0,0); glvertex3f (0,0,0); gltexcoord2f (1,0); glvertex3f (1,0,0); gltexcoord2f (1,1);

16 glvertex3f (1,1,0); gltexcoord2f (0,1); glvertex3f (0,1,0); glend(); glbindtexture(gl_texture_2d, texname[1]); glbegin ( GL_POLYGON ); // front face gltexcoord2f (0,0); glvertex3f (0,0,1); gltexcoord2f (1,0); glvertex3f (1,0,1); gltexcoord2f (1,1); glvertex3f (1,1,1); gltexcoord2f (0,1); glvertex3f (0,1,1); glend(); glbindtexture(gl_texture_2d, texname[2]); glbegin ( GL_POLYGON ); // right face gltexcoord2f (0,0); glvertex3f (1,0,1); gltexcoord2f (1,0); glvertex3f (1,0,0); gltexcoord2f (1,1); glvertex3f (1,1,0); gltexcoord2f (0,1); glvertex3f (1,1,1); glend(); glbindtexture(gl_texture_2d, texname[3]); glbegin ( GL_POLYGON ); // left face gltexcoord2f (0,0); glvertex3f (0,0,1); gltexcoord2f (1,0); glvertex3f (0,0,0); gltexcoord2f (1,1); glvertex3f (0,1,0); gltexcoord2f (0,1); glvertex3f (0,1,1); glend(); glbindtexture(gl_texture_2d, texname[4]); glbegin ( GL_POLYGON ); // top face gltexcoord2f (0,0); glvertex3f (0,1,0); gltexcoord2f (1,0); glvertex3f (0,1,1); gltexcoord2f (1,1); glvertex3f (1,1,1); gltexcoord2f (0,1); glvertex3f (1,1,0); glend(); glbindtexture(gl_texture_2d, texname[5]); glbegin ( GL_POLYGON ); // bottom face gltexcoord2f (0,0); glvertex3f (0,0,0); gltexcoord2f (1,0); glvertex3f (0,0,1); gltexcoord2f (1,1); glvertex3f (1,0,1); gltexcoord2f (0,1); glvertex3f (1,0,0); glend(); glpopmatrix(); glutswapbuffers(); glflush(); gldisable(gl_texture_2d);

17 int main(int argc, char *argv[]) int success = 0; glutinit(&argc, argv); glutinitwindowposition( 0, 0); glutinitwindowsize(500, 500); glutinitdisplaymode(glut_rgb GLUT_DOUBLE GLUT_DEPTH); win = glutcreatewindow(argv[0]); glutreshapefunc(reshape); glutkeyboardfunc(key); glutdisplayfunc(display); gluttimerfunc(10000, mytimer, 0); glutidlefunc(idle); // Initialize the "OpenGL Extension Wrangler" library glewinit(); success = init(); if ( success ) glutmainloop(); return 0; //simpletex.vert uniform float angle; uniform float scalar; //value provided by application program //value provided by application program void main(void) gl_texcoord[0] = gl_multitexcoord0; float c = cos( angle ); float s = sin( angle ); mat4 ZRotationMatrix = mat4( c, -s, 0.0, 0.0, s, c, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0 ); mat4 YRotationMatrix = mat4( c, 0.0, s, 0.0, 0, 1, 0.0, 0.0, -s, 0.0, c, 0.0, 0.0, 0.0, 0.0, 1.0 ); mat4 XRotationMatrix = mat4( 1.0, 0.0, 0.0, 0.0, 0.0, c, -s, 0.0, 0.0, s, c, 0.0, 0.0, 0.0, 0.0, 1.0 ); mat4 ScalarMatrix = mat4( scalar, 0.0, 0.0, 0.0, 0.0, scalar, 0.0, 0.0, 0.0, 0.0, scalar, 0.0,

18 0.0, 0.0, 0.0, 1.0 ); mat4 RotationMatrix = ZRotationMatrix * YRotationMatrix; gl_position = gl_modelviewprojectionmatrix * RotationMatrix * ScalarMatrix * gl_vertex; //simpletex.frag uniform sampler2d texhandle; void main (void) vec3 lightcolor = vec3 (texture2d(texhandle, gl_texcoord[0].st)); gl_fragcolor = vec4 (lightcolor, 1.0); And here are the source images used for the sides: back.png bottom.png

19 front.png left.png

20 right.png top.png Evaluation: I successfully completed all parts of the homework and am giving myself 40 points.

1)Write a shader program that renders a regular pentagon with textured image like the one shown below.

1)Write a shader program that renders a regular pentagon with textured image like the one shown below. Andrew Yenalavitch CSE520 Winter 2015 Quiz 2 Report 1)Write a shader program that renders a regular pentagon with textured image like the one shown below. Use the following provided image for the texture:

More information

Philip Calderon CSE 520 Lab 3 Color Shader

Philip Calderon CSE 520 Lab 3 Color Shader Philip Calderon CSE 520 Lab 3 Color Shader Summary: The purpose of lab 4 is to produce a pyramid tetrahedron that we are able to rotate it when clicked. Part 1: Color Tetrahedron Part 2: Rotation to show

More information

Erik Anchondo cse 520 lab 4

Erik Anchondo cse 520 lab 4 Erik Anchondo 2-6-19 cse 520 lab 4 1. Wrote a glsl program that displays a colored tetrahedron. The tetrahedron starts to rotate on the x axis when the mouse button is clicked once. If the mouse button

More information

2a. The triangles scale increases (expands) when the 'e' key is pressed and decreases (contracts) when the 'c' key is pressed.

2a. The triangles scale increases (expands) when the 'e' key is pressed and decreases (contracts) when the 'c' key is pressed. Erik Anchondo 1-29-19 cse 520 lab 3 1. Wrote a shader program to display three colored triangles, with one of each triangle being red, green, and blue. The colors change which triangle they are applied

More information

1. Write a shader program that animates the morphing of Figure 'A' to Figure 'B' and back.

1. Write a shader program that animates the morphing of Figure 'A' to Figure 'B' and back. Karl Zachary Maier CSE 520 Homework 1 1. Write a shader program that animates the morphing of Figure 'A' to Figure 'B' and back. /* morph.cpp */ #include #include #include

More information

Yazhuo Liu Homework 3

Yazhuo Liu Homework 3 Yazhuo Liu Homework 3 Write a shader program that renders a colored tetrahedron, which gradually shrinks to a point and expands back to its original shape. While it is shrinking and expanding, the color

More information

An Introduction to 3D Computer Graphics, Stereoscopic Image, and Animation in OpenGL and C/C++ Fore June

An Introduction to 3D Computer Graphics, Stereoscopic Image, and Animation in OpenGL and C/C++ Fore June An Introduction to 3D Computer Graphics, Stereoscopic Image, and Animation in OpenGL and C/C++ Fore June Appendix D OpenGL Shading Language (GLSL) D.1 Extending OpenGL The OpenGL architecture we have presented

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

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

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

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

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

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

Stored Texture Shaders

Stored Texture Shaders Stored Texture Shaders 157 Preparing for Texture Access These steps are the same when using a shader as when using fixed functionality Make a specific texture unit active by calling glactivetexture Create

More information

Chapter 9 Texture Mapping An Overview and an Example Steps in Texture Mapping A Sample Program Specifying the Texture Texture Proxy Replacing All or

Chapter 9 Texture Mapping An Overview and an Example Steps in Texture Mapping A Sample Program Specifying the Texture Texture Proxy Replacing All or Chapter 9 Texture Mapping An Overview and an Example Steps in Texture Mapping A Sample Program Specifying the Texture Texture Proxy Replacing All or Part of a Texture Image One Dimensional Textures Using

More information

Information Coding / Computer Graphics, ISY, LiTH GLSL. OpenGL Shading Language. Language with syntax similar to C

Information Coding / Computer Graphics, ISY, LiTH GLSL. OpenGL Shading Language. Language with syntax similar to C GLSL OpenGL Shading Language Language with syntax similar to C Syntax somewhere between C och C++ No classes. Straight ans simple code. Remarkably understandable and obvious! Avoids most of the bad things

More information

Preparing for Texture Access. Stored Texture Shaders. Accessing Texture Maps. Vertex Shader Texture Access

Preparing for Texture Access. Stored Texture Shaders. Accessing Texture Maps. Vertex Shader Texture Access Stored Texture Shaders Preparing for Texture Access These steps are the same when using a shader as when using fixed functionality Make a specific texture unit active by calling glactivetexture Create

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

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

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

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

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

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

// 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. Review of Last Demo. Methodology for Lecture. Geometry Basic Setup. Outline. Foundations of Computer Graphics (Fall 2012)

To Do. Review of Last Demo. Methodology for Lecture. Geometry Basic Setup. Outline. Foundations of Computer Graphics (Fall 2012) Foundations of Computer Graphics (Fall 2012) CS 184, Lecture 8: OpenGL 2 http://inst.eecs.berkeley.edu/~cs184 To Do Continue working on HW 2. Can be difficult Class lectures, programs primary source Can

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

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

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

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 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

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

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

This Lecture. Why OpenGL? Introduction to OpenGL. Programmer s View

This Lecture. Why OpenGL? Introduction to OpenGL. Programmer s View Foundations of Computer Graphics Overview and Motivation This Lecture Introduction to OpenGL and simple demo code mytest1.cpp ; you compiled mytest3.cpp for HW 0 I am going to show (and write) actual code

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

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

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

Computer Graphics (CS 543) Lecture 3b: Shader Setup & GLSL Introduction

Computer Graphics (CS 543) Lecture 3b: Shader Setup & GLSL Introduction Computer Graphics (CS 543) Lecture 3b: Shader Setup & GLSL Introduction Prof Emmanuel Agu Computer Science Dept. Worcester Polytechnic Institute (WPI) OpenGL function format function name gluniform3f(x,y,z)

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

Lecture 22 Sections 8.8, 8.9, Wed, Oct 28, 2009

Lecture 22 Sections 8.8, 8.9, Wed, Oct 28, 2009 s The s Lecture 22 Sections 8.8, 8.9, 8.10 Hampden-Sydney College Wed, Oct 28, 2009 Outline s The 1 2 3 4 5 The 6 7 8 Outline s The 1 2 3 4 5 The 6 7 8 Creating Images s The To create a texture image internally,

More information

To Do. Demo: Surreal (HW 3) This Lecture. Introduction to OpenGL. Outline. Foundations of Computer Graphics (Spring 2012)

To Do. Demo: Surreal (HW 3) This Lecture. Introduction to OpenGL. Outline. Foundations of Computer Graphics (Spring 2012) Foundations of Computer Graphics (Spring 2012) CS 184, Lecture 6: OpenGL 1 http://inst.eecs.berkeley.edu/~cs184 To Do HW 1 due on Thu Must find partners for HW 2 (if problems, speak to TAs during section).

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

compatibility mode core mode

compatibility mode core mode Using the GLUT This document provides a more detailed description of the minimum steps necessary to write build and execute an OpenGL 3D application that runs on the three desktop platforms Windows, OSX

More information

RECITATION - 1. Ceng477 Fall

RECITATION - 1. Ceng477 Fall RECITATION - 1 Ceng477 Fall 2007-2008 2/ 53 Agenda General rules for the course General info on the libraries GLUT OpenGL GLUI Details about GLUT Functions Probably we will not cover this part 3/ 53 General

More information

... Print PROGRAMS\Final Project final\planes\planeshoot.c 1

... Print PROGRAMS\Final Project final\planes\planeshoot.c 1 ... Print PROGRAMS\Final Project final\planes\planeshoot.c 1 1 #include 2 #include 3 #include 4 #include 5 #include 6 #include

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

Rendering Pipeline/ OpenGL

Rendering Pipeline/ OpenGL Chapter 2 Basics of Computer Graphics: Your tasks for the weekend Piazza Discussion Group: Register Post review questions by Mon noon Use private option, rev1 tag Start Assignment 1 Test programming environment

More information

Information Coding / Computer Graphics, ISY, LiTH GLSL. OpenGL Shading Language. Language with syntax similar to C

Information Coding / Computer Graphics, ISY, LiTH GLSL. OpenGL Shading Language. Language with syntax similar to C GLSL OpenGL Shading Language Language with syntax similar to C Syntax somewhere between C och C++ No classes. Straight ans simple code. Remarkably understandable and obvious! Avoids most of the bad things

More information

CS 432 Interactive Computer Graphics

CS 432 Interactive Computer Graphics CS 432 Interactive Computer Graphics Lecture 7 Part 2 Texture Mapping in OpenGL Matt Burlick - Drexel University - CS 432 1 Topics Texture Mapping in OpenGL Matt Burlick - Drexel University - CS 432 2

More information

Comp 410/510 Computer Graphics Spring Programming with OpenGL Part 3: Shaders

Comp 410/510 Computer Graphics Spring Programming with OpenGL Part 3: Shaders Comp 410/510 Computer Graphics Spring 2018 Programming with OpenGL Part 3: Shaders Objectives Basic shaders - Vertex shader - Fragment shader Programming shaders with GLSL Finish first program void init(void)

More information

CS 4204 Computer Graphics

CS 4204 Computer Graphics CS 4204 Computer Graphics OpenGL Basics Yong Cao Virginia Tech References: 2001 Siggraph, An Interactive Introduction to OpenGL Programming, Dave Shreiner,Ed Angel, Vicki Shreiner Official Presentation

More information

Programming with OpenGL Part 3: Three Dimensions

Programming with OpenGL Part 3: Three Dimensions Programming with OpenGL Part 3: Three Dimensions Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico Objectives Develop a more sophisticated

More information

Transformation, Input and Interaction. Hanyang University

Transformation, Input and Interaction. Hanyang University Transformation, Input and Interaction Hanyang University Transformation, projection, viewing Pipeline of transformations Standard sequence of transforms Cornell CS4620 Fall 2008 Lecture 8 3 2008 Steve

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

Computer Graphics Introduction to OpenGL

Computer Graphics Introduction to OpenGL Computer Graphics 2015 3. Introduction to OpenGL Hongxin Zhang State Key Lab of CAD&CG, Zhejiang University 2015-09-28 2. 2D Graphics Algorithms (cont.) Rasterization Computer Graphics @ ZJU Hongxin Zhang,

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

An Introduction to 3D Computer Graphics, Stereoscopic Image, and Animation in OpenGL and C/C++ Fore June

An Introduction to 3D Computer Graphics, Stereoscopic Image, and Animation in OpenGL and C/C++ Fore June An Introduction to 3D Computer Graphics, Stereoscopic Image, and Animation in OpenGL and C/C++ Fore June Chapter 19 OpenGL Shading Language (GLSL) 19.1 Extending OpenGL The OpenGL architecture we have

More information

Information Coding / Computer Graphics, ISY, LiTH. OpenGL! ! where it fits!! what it contains!! how you work with it 11(40)

Information Coding / Computer Graphics, ISY, LiTH. OpenGL! ! where it fits!! what it contains!! how you work with it 11(40) 11(40) Information Coding / Computer Graphics, ISY, LiTH OpenGL where it fits what it contains how you work with it 11(40) OpenGL The cross-platform graphics library Open = Open specification Runs everywhere

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

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

Computer Graphics Programming

Computer Graphics Programming Computer Graphics Programming Graphics APIs Using MFC (Microsoft Foundation Class) in Visual C++ Programming in Visual C++ GLUT in Windows and Unix platform Overview and Application Graphics APIs Provide

More information

Letterkenny Institute of Technology

Letterkenny Institute of Technology Letterkenny Institute of Technology BSc in Computing in Games Development Subject: Computer Graphics for Games Programming 2 Level: 7 Date: January 2008 Examiners: Dr. J.G. Campbell Dr. M.D.J. McNeill

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

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

Computer Graphics (CS 4731) Lecture 11: Implementing Transformations. Prof Emmanuel Agu. Computer Science Dept. Worcester Polytechnic Institute (WPI)

Computer Graphics (CS 4731) Lecture 11: Implementing Transformations. Prof Emmanuel Agu. Computer Science Dept. Worcester Polytechnic Institute (WPI) Computer Graphics (CS 47) Lecture : Implementing Transformations Prof Emmanuel Agu Computer Science Dept. Worcester Polytechnic Institute (WPI) Objectives Learn how to implement transformations in OpenGL

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

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

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

Lecture 09: Shaders (Part 1)

Lecture 09: Shaders (Part 1) Lecture 09: Shaders (Part 1) CSE 40166 Computer Graphics Peter Bui University of Notre Dame, IN, USA November 9, 2010 OpenGL Rendering Pipeline OpenGL Rendering Pipeline (Pseudo-Code) 1 f o r gl_vertex

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

CSE 4431/ M Advanced Topics in 3D Computer Graphics. TA: Margarita Vinnikov

CSE 4431/ M Advanced Topics in 3D Computer Graphics. TA: Margarita Vinnikov CSE 4431/5331.03M Advanced Topics in 3D Computer Graphics TA: Margarita Vinnikov mvinni@cse.yorku.ca What do we need to do to use shaders in our program? Shaders Work flow For multiple shaders 1. Create

More information

Objectives. Programming with OpenGL Part 5: More GLSL. Program Object. Reading a Shader. Shader Reader. Linking Shaders with Application

Objectives. Programming with OpenGL Part 5: More GLSL. Program Object. Reading a Shader. Shader Reader. Linking Shaders with Application Objectives Programming with OpenGL Part : More GLSL CS Interactive Computer Graphics Prof. David E. Breen Department of Computer Science Coupling shaders to applications - Reading - Compiling - Linking

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

Chapter 13 Selection and Feedback

Chapter 13 Selection and Feedback OpenGL Programming Guide (Addison-Wesley Publishing Company) Chapter 13 Selection and Feedback Chapter Objectives After reading this chapter, you ll be able to do the following: Create applications that

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

yahoo.com

yahoo.com What is the workshop about? We use software such as AutoCAD, 3D Studio, Maya and many others for a host of applications ranging from Technical Drawings to Machine Design to Game Making to Special Effects

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

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

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

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

Teacher Assistant : Tamir Grossinger Reception hours: by - Building 37 / office -102 Assignments: 4 programing using

Teacher Assistant : Tamir Grossinger   Reception hours: by  - Building 37 / office -102 Assignments: 4 programing using Teacher Assistant : Tamir Grossinger email: tamirgr@gmail.com Reception hours: by email - Building 37 / office -102 Assignments: 4 programing using C++ 1 theoretical You can find everything you need in

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

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

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

Andrew Yenalavitch Homework 1 CSE Fall 2014

Andrew Yenalavitch Homework 1 CSE Fall 2014 Andrew Yenalavitch Homework 1 CSE 420 - Fall 2014 1.) ( 20 points ) In the class, we have discussed how to draw a line given by y = m x + b using Besenham's algorithm with m 1. Extend the algorithm to

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

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

Computer Graphics (CS 4731) Lecture 11: Implementing Transformations. Prof Emmanuel Agu. Computer Science Dept. Worcester Polytechnic Institute (WPI)

Computer Graphics (CS 4731) Lecture 11: Implementing Transformations. Prof Emmanuel Agu. Computer Science Dept. Worcester Polytechnic Institute (WPI) Computer Graphics (CS 47) Lecture : Implementing Transformations Prof Emmanuel Agu Computer Science Dept. Worcester Polytechnic Institute (WPI) Objectives Learn how to implement transformations in OpenGL

More information

Some advantages come from the limited environment! No classes. Stranight ans simple code. Remarkably. Avoids most of the bad things with C/C++.

Some advantages come from the limited environment! No classes. Stranight ans simple code. Remarkably. Avoids most of the bad things with C/C++. GLSL OpenGL Shading Language Language with syntax similar to C Syntax somewhere between C och C++ No classes. Stranight ans simple code. Remarkably understandable and obvious! Avoids most of the bad things

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

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

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

Vertex & Fragment shaders

Vertex & Fragment shaders Vertex & Fragment shaders The next big step in graphics hardware Adds programmability to the previously fixed rendering pipeline The OpenGL Shading Language (a.k.a. GLSL, glslang) Vertex shaders: programs

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

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

Lecture 07: Buffers and Textures

Lecture 07: Buffers and Textures Lecture 07: Buffers and Textures CSE 40166 Computer Graphics Peter Bui University of Notre Dame, IN, USA October 26, 2010 OpenGL Pipeline Today s Focus Pixel Buffers: read and write image data to and from

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

This Lecture. Introduction to OpenGL. Outline. Why OpenGL? Programmer s View. Foundations of Computer Graphics

This Lecture. Introduction to OpenGL. Outline. Why OpenGL? Programmer s View. Foundations of Computer Graphics Foundations of Computer Graphics Overview and Motivation This Lecture Introduction to OpenGL and simple demo code mytest1.cpp ; you compiled mytest3.cpp for HW 0 I am going to show (and write) actual code

More information