CG1 Labs Wei Li. Back Face Culling // enable back-face culling glEnable( GL_CULL_FACE ); // orientation of front-facing polygons glFrontFace( GL_CCW );

Slides:



Advertisements
Similar presentations
2 COEN Computer Graphics I Evening’s Goals n Discuss the fundamentals of lighting in computer graphics n Analyze OpenGL’s lighting model n Show.
Advertisements

1 Understanding of OpenGL TA: Dong Hyun Jeong Instructor : Dr. Kalpathi Subramanian Texture Mapping.
TEXTURE MAPPING JEFF CHASTINE 1. TEXTURE MAPPING Applying an image (or a texture ) to geometry 2D images (rectangular) 3D images (volumetric – such as.
OpenGL Texture Mapping
Virtual Realism LIGHTING AND SHADING. Lighting & Shading Approximate physical reality Ray tracing: Follow light rays through a scene Accurate, but expensive.
1 MAE152 Computer Graphics for Scientists and Engineers Lighting in OpenGL.
OpenGL Son of the Survival Guide. Last Time on OpenGL Windowing … glut Rendering Primatives Transformations Projections State Management.
MAT 594CM S2010Fundamentals of Spatial ComputingAngus Forbes Overview Today: - Make sure everyone is set up with an OpenGL environment - OpenGL basics:
CS 4731: Computer Graphics Lecture 16: Illumination Models Part 2 Emmanuel Agu.
Hidden Surfaces and Shading CS BSP Tree T1T1 T2T2 E if (f 1 (E) < 0) then draw T 1 draw T 2 else draw T 2 draw T 1 f 1 (p) = 0 is the.
1 Lecture 12 Texture Mapping uploading of the texture to the video memory the application of the texture onto geometry.
Computer Graphics (Fall 2004) COMS 4160, Lecture 11: OpenGL 2
Illumination and Shading
Lighting & Material. Example 1/5 #include ” glut.h ” void display(); void reshape(int, int); void lighting(); int main(int argc, char** argv) { glutInit(&argc,
Illumination and Shading. Illumination (Lighting) Model the interaction of light with surface points to determine their final color and brightness OpenGL.
Development of Interactive 3D Virtual World Applications
1 Graphics CSCI 343, Fall 2013 Lecture 20 Lighting and Shading III.
Texturing in OpenGL Lab #7. Creating Textures glEnable ( GL_TEXTURE_2D ); GLuint myTex; glGenTextures ( 1, (GLuint*) &myTex ); glBindTexture ( GL_TEXTURE_2D,
Texture Mapping. To add surface details… World of Warcraft, Blizzard Inc. More polygons (slow and hard to handle small details) Less polygons but with.
Shading and Illumination. OpenGL Shading Without ShadingWith Shading.
Hank Childs, University of Oregon
2IV60 Computer Graphics set 10: Texture mapping Jack van Wijk TU/e.
1 SIC / CoC / Georgia Tech MAGIC Lab Rossignac Textures and shadows  Generation  Mipmap  Texture coordinates,
Module 04 – Texture mapping, Texture filtering, Lighting and Blending Module 04 Texture mapping, Texture filtering, Lighting and Blending.
Texture Mapping. Introduction What is Texture Mapping? Types of Texture Mapping –1D, 2D and 3D SDL and OpenGL.
Computer Graphics Ben-Gurion University of the Negev Fall 2012.
CS 4363/6353 TEXTURE MAPPING PART II. WHAT WE KNOW We can open image files for reading We can load them into texture buffers We can link that texture.
Hank Childs, University of Oregon Nov. 5th, 2014 CIS 441/541: Introduction to Computer Graphics Lecture 11: 2D textures, lighting and materials.
Programming for Virtual Reality Applications Projection in OpenGL Lighting and Shading Lecture 17.
CS380 LAB IV OpenGL Jonghyeob Lee Reference1. [OpenGL course slides by Rasmus Stenholt] Reference2. [
Lecture 9: Lighting and Shading 1  Principles of Interactive Graphics  CMSCD2012  Dr David England, Room 718,  ex 2271
Lecture 14 Shading models 1.Shading Constant Shading (to be implemented) Gouraud Shading Phong Shading 2.Light and shading with OpenGL 1.
08 |Lighting and Shading Eriq Muhammad Adams J |
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Shading I Ed Angel Professor of Computer Science, Electrical and Computer Engineering,
Texture Mapping Drawing Pictures on Polygons. Texture Mapping.
TEXTURES & OTHER GOODIES Computer Graphics. glTexCoord2f(...); + =
Computer Science Term 1, 2006 Tutorial 2 Assignment 3 – The Virtual World.
CG Summary: OpenGL Shading andTextures Angel, Chapters 5, 7; “Red Book” slides from AW, red book, etc. CSCI 6360/4360.
OpenGL Color and Lighting 2003 Spring Keng Shih-Ling.
2 COEN Computer Graphics I Evening’s Goals n Discuss displaying and reading image primitives n Describe texture mapping n Discuss OpenGL modes and.
OpenGL Lighting Jian-Liang Lin 2002 Hidden-Surface Removal -1 Original Code: while (1) { get_viewing_point_from_mouse_position(); glClear(GL_COLOR_BUFFER_BIT);
Intro to OpenGL: Vertices and Drawing
1 Graphics CSCI 343, Fall 2015 Lecture 25 Texture Mapping.
Details of Texture Mapping Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Monday, December 1, 2003.
1 Geometric Transformations-II Modelling Transforms By Dr.Ureerat Suksawatchon.
Illumination CSE 410. Basic steps of lighting Enable smooth shading Set global ambient light glShadeModel(GL_SMOOTH); glEnable(GL_NORMALIZE); GLfloat.
CS559: Computer Graphics Lecture 16: Shading and OpenGL Li Zhang Spring 2008.
Texture Mapping CEng 477 Introduction to Computer Graphics.
CSC Graphic Programming Lecture 2 OpenGL Lightning.
Illumination and Shading. Illumination (Lighting) Model the interaction of light with surface points to determine their final color and brightness OpenGL.
Lecture 6 Lighting. Introduction What is light? How do we percept colors? Lights in OpenGL.
1 Dr. Scott Schaefer Lighting. 2/49 Lighting/Illumination Color is a function of how light reflects from surfaces to the eye Global illumination accounts.
CSC Graphics Programming
Shading To determine the correct shades of color on the surface of graphical objects.
Lecture 16: Shading and OpenGL Li Zhang Spring 2008
Texture Mapping We can improve the realism of graphics models by mapping a texture pattern (image) onto the modeled object surface. We refer to this technique.
Illumination and Shading
@ 2017 by Jim X. Chen George Mason University
Texture Mapping Part II
Open GL: Colors and Lighting
OpenGL Texture Mapping
Lighting and Shading Lab 8:.
o عَلَّمَهُ الْبَيَانَ
Illumination and Shading
Lighting – Light Sources
Computer Graphics Practical Lesson 6
OpenGL Texture Mapping
Lighting and Shading Lab 8:.
OpenGL Texture Mapping
Programming Textures Lecture 15 Fri, Sep 28, 2007.
Presentation transcript:

CG1 Labs Wei Li

Back Face Culling // enable back-face culling glEnable( GL_CULL_FACE ); // orientation of front-facing polygons glFrontFace( GL_CCW ); … draw something … glFrontFace( GL_CW ); … draw something …

Lighting // enable lighting glEnable(GL_LIGHTING); // enable first light source glEnable(GL_LIGHT0); … setup light source attributes … … setup surface material attributes … … draw meshes …

Light Source Type Point Light : ( 5.30, 8.60, 2.07, 1 ) Parallel Light: ( 0.46, 0.69, 0.54, 0 ) Spot Light: angle Attenuation: 1 / ( ax 2 + bx + c )

Shading Component Diffuse Specular Ambient

Diffuse

Specular

Normal

Result

// light source attributes GLfloat LightAmbient[] = { 0.4f, 0.4f, 0.4f, 1.0f }; GLfloat LightDiffuse[] = { 0.3f, 0.3f, 0.3f, 1.0f }; GLfloat LightSpecular[] = { 0.4f, 0.4f, 0.4f, 1.0f }; GLfloat LightPosition[] = { 5.0f, 5.0f, 5.0f, 1.0f }; glLightfv(GL_LIGHT0, GL_AMBIENT, LightAmbient ); glLightfv(GL_LIGHT0, GL_DIFFUSE, LightDiffuse ); glLightfv(GL_LIGHT0, GL_SPECULAR, LightSpecular); glLightfv(GL_LIGHT0, GL_POSITION, LightPosition); – Shininess specifies how small the highlights are

// surface material attributes GLfloat material_Ka[] = { 0.11f, 0.06f, 0.11f, 1.0f }; GLfloat material_Kd[] = { 0.43f, 0.47f, 0.54f, 1.0f }; GLfloat material_Ks[] = { 0.33f, 0.33f, 0.52f, 1.0f }; GLfloat material_Ke[] = { 0.10f, 0.00f, 0.10f, 1.0f }; GLfloat material_Se = 10; glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, material_Ka); glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, material_Kd); glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, material_Ks); glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, material_Ke); glMaterialf (GL_FRONT_AND_BACK, GL_SHININESS, material_Se);

Draw Polygon with Normals glBegin( GL_POLYGON ); // vertex 1 glNormal3f( nx1, ny1, nz1 ); glVertex3f( x1, y1, z1 ); // vertex 2 glNormal3f( nx2, ny2, nz2 ); glVertex3f( x2, y2, z2 ); … glEnd();

Gen Texture // gen texture Gluint tex = 0; glGenTextures ( 1, &tex ); // Load Texture Image Int sizex = 512; Int sizey = 512; unsigned char *pixels = new unsigned char[ sizex * sizey * 3 ]; // RGB … load image data to pixel buffer … glBindTexture( GL_TEXTURE_2D, tex ); glTexImage2D( GL_TEXTURE_2D,// target 0,// level GL_RGBA8,// internal format sizex, sizey,// texture size 0,// border GL_RGB,// image format GL_UNSIGNED_BYTE, // image data type pixels // pointer to image pixel buffer ); glBindTexture( GL_TEXTURE_2D, 0 );

Use Texture // enable texture mapping and bind texture glEnable( GL_TEXTURE_2D ); glBindTexture( GL_TEXTURE_2D, tex ); // setup texture filter glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); // draw polygon with texture coordinate … // disable texture mapping and unbind texture glBindTexture( GL_TEXTURE_2D, 0 ); glDisable( GL_TEXTURE_2D );

GL_NEAREST vs GL_LINEAR

Draw Polygon with Texture Coordinate glBegin( GL_POLYGON ); // vertex 1 glTexCoord2f( s1, t1 ); glVertex3f( x1, y1, z1 ); // vertex 2 glTexCoord2f( s2, t2 ); glVertex3f( x2, y2, z2 ); … glEnd();

Delete Texture glDeleteTextures( 1, &tex ); tex = 0;

Spherical Coordinates Pitch ( around right axis ) Yaw ( around gravity axis )

Model –.d File should start from “data”, no preceding space, like “ data” – Indices start from 1 or 0 C++ – C++ is not like C# or Java which has garbage collector – so if you "new" something, remember to "delete" it – // array – int *indices = new int[ 128 ]; – delete[] indices; – Indices = NULL; – // instance – vec3 *vp = new vec3; – delete vp; – vp = NULL; – For simple instance, you can just define it in this way – vec3 v;

OpenGL Matrix glMatrixMode( GL_MODELVIEW ); // ? glLoadIdentity();// I glTranslatef();// I * T glRotatef();// I * T * R glPushMatrix();// I * T * R -> stack – glMultMatrix();// I * T * R * M – … – glVertex3f();// I * T * R * M * v – … glPopMatrix();// stack -> I * T * R glVertex3f();// I * T *R * v Column Major vs. Row Major