CS380 LAB IV OpenGL Jonghyeob Lee Reference1. [OpenGL course slides by Rasmus Stenholt] Reference2. [http://nehe.gamedev.net/]http://nehe.gamedev.net/

Slides:



Advertisements
Similar presentations
Hofstra University1 Texture Motivation: to model realistic objects need surface detail: wood grain, stone roughness, scratches that affect shininess, grass,
Advertisements

Texture Mapping. Texturing  process that modifies the appearance of each point on a surface using an image or function  any aspect of appearance can.
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
MAT 594CM S2010Fundamentals of Spatial ComputingAngus Forbes Overview Today: - Make sure everyone is set up with an OpenGL environment - OpenGL basics:
Hofstra University1 Texture Motivation: to model realistic objects need surface detail: wood grain, stone roughness, scratches that affect shininess, grass,
CSC345: Advanced Graphics & Virtual Environments
OpenGL Texture Mapping
OpenGL Texture Mapping Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico.
1 Lecture 12 Texture Mapping uploading of the texture to the video memory the application of the texture onto geometry.
OpenGL Texture Mapping April 16, Angel: Interactive Computer Graphics 3E © Addison-Wesley 2002 Basic Stragegy Three steps to applying a texture.
CS 4731: Computer Graphics Lecture 17: Texturing Emmanuel Agu.
Texture Mapping A way of adding surface details Two ways can achieve the goal:  Surface detail polygons: create extra polygons to model object details.
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 in OpenGL.
Computer Graphics Texture Mapping Eriq Muhammad Adams
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
2IV60 Computer Graphics set 10: Texture mapping Jack van Wijk TU/e.
Lecture 8: Texture Mapping 1  Principles of Interactive Graphics  CMSCD2012  Dr David England, Room 718,  ex 2271
Texture Mapping. Scope Buffers Buffers Various of graphics image Various of graphics image Texture mapping Texture mapping.
Texture Mapping. Introduction What is Texture Mapping? Types of Texture Mapping –1D, 2D and 3D SDL and OpenGL.
Texture Mapping Course: Computer Graphics Presented by Fan Chen
Computer Graphics Ben-Gurion University of the Negev Fall 2012.
An Interactive Introduction to OpenGL Programming Ed Angel
Imaging and Raster Primitives Vicki Shreiner. 2 Jobs Andrew Giles Andrew Giles Chuck Fultz Chuck Fultz SIGGraph - SIGGraph.
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.
Lecture 27: Texture Mapping Li Zhang Spring 2008
Texture Mapping. 2 Motivation A typical modern graphics card can handle 10s of millions of polygons a second. How many individual blades of grass are.
OpenGL Texture Mapping. 2 Objectives Introduce the OpenGL texture functions and options.
Texture Mapping Angel Angel: Interactive Computer Graphics5E © Addison-Wesley
CG1 Labs Wei Li. Back Face Culling // enable back-face culling glEnable( GL_CULL_FACE ); // orientation of front-facing polygons glFrontFace( GL_CCW );
CS 480/680 Computer Graphics OpenGL Texture Mapping Dr. Frederick C Harris, Jr. Fall 2011.
Texture Mapping in OpenGL. Texture Mapping Imaging we are “pasting” a picture onto a model  Which part of the picture will be pasted onto which part.
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.
October 9, 2002Serguei A. Mokhov, 1 COMP471 – Computer Graphics OpenGL: Texture Mapping.
Texture Mapping. 2 3 Loading Textures void glTexImage2D (GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border,
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
Computing & Information Sciences Kansas State University Lecture 12 of 42CIS 636/736: (Introduction to) Computer Graphics CIS 636/736 Computer Graphics.
Computer Graphics Bing-Yu Chen National Taiwan University.
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.
Lighting Dave Shreiner. 2 Lighting Principles Lighting simulates how objects reflect light Lighting simulates how objects reflect light material composition.
第三课. Overview of this Section Concept of Texture Mapping ( 纹理映射 ) 2D Texture 3D Texture Environment Mapping Bump Mapping Others OpenGL Implementation.
1 Chapter 7 Texture Mapping. 2 The Limits of Geometric Modeling Although graphics cards can render over 10 million polygons per second, that number is.
Texture Mapping CEng 477 Introduction to Computer Graphics.
CSC Graphics Programming
Madhulika (18010), Assistant Professor, LPU.
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.
OpenGL Texture Mapping
Advanced Graphics Algorithms Ying Zhu Georgia State University
Advanced Graphics Algorithms Ying Zhu Georgia State University
OpenGL Texture Mapping
Introduction to Computer Graphics with WebGL
Computer Graphics, Lee Byung-Gook, Dongseo Univ.
Assignment 3b Q&A.
3D Game Programming Texture Mapping
Lighting and Materials
Computer Graphics Practical Lesson 6
OpenGL Texture Mapping
OpenGL Texture Mapping
Programming Textures Lecture 15 Fri, Sep 28, 2007.
3D Game Programming Texture Mapping
OpenGL Texture Mapping
Presentation transcript:

CS380 LAB IV OpenGL Jonghyeob Lee Reference1. [OpenGL course slides by Rasmus Stenholt] Reference2. [

Goal Introduce OpenGL programming Help you do CS380 homework by yourself 2

Notice Use Noah board for your questions ( 3

Outline Lighting and Materials Texture Mapping 4

5 Lighting and Materials Why is this important?  Geometry is only one third of rendering  Lights and materials make up the other two  Unlit objects tend to look dull and artificial In OpenGL, lights and materials are connected  Light interacts with materials  Materials must be assigned to geometry to benefit from lighting

6 Lighting Principles The result of lighting depends on various factors  Material composition of object  Light colour and position  Global lighting parameters ambient light two sided lighting Lighting can be done in both RGBA and indexed color mode

7 OpenGL Lighting Lighting is computed per-vertex The lighting model is called Phong shading Lighting properties  Diffuse  Specular  Ambient

8 Lighting Normals define how a surface reflects light  glNormal3f( x, y, z ) Normals can be defined per-vertex  Just like colours The current normal is used to compute lighting contributions  The angles between the normal and light directions are used  Use unit normals for proper lighting Some transformations affect a normal’s length glEnable( GL_NORMALIZE ) or glEnable( GL_RESCALE_NORMAL )

9 Light Properties The command for setting lighting properties  glLightfv(light, property, value);  light specifies which light Multiple lights, starting with GL_LIGHT0 glGetIntegerv( GL_MAX_LIGHTS, &n ); The maximum number of lights is usually 8  Properties colors position and type attenuation  Light color properties GL_AMBIENT GL_DIFFUSE GL_SPECULAR

10 Types of Lights OpenGL supports two types of lights  Local (Point) light sources  Infinite (Directional) light sources Type of light controlled by w coordinate  Usually w=1 for a point light

11 Turning on the Lights First you must tell OpenGL that lighting should be used glEnable( GL_LIGHTING ); Then each light can be individually turned on/off glEnable( GL_LIGHT n );

Load a solid teapot Tutorials 12 void display() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_MODELVIEW); glutSolidTeapot(0.5); glFlush(); }

Tutorials Add a light on previous scene 13 void display() { glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); float light_pos[] = {-2, 2, 2, 1}; float light_Ka[] = {0, 0, 0, 1}; float light_Kd[] = {1, 1, 1, 1}; float light_Ks[] = {1, 1, 1, 1}; glLightfv(GL_LIGHT0, GL_POSITION, light_pos); glLightfv(GL_LIGHT0, GL_AMBIENT, light_Ka); glLightfv(GL_LIGHT0, GL_DIFFUSE, light_Kd); glLightfv(GL_LIGHT0, GL_SPECULAR, light_Ks); … }

14 Material Properties Define the surface properties of a primitive glMaterialfv( face, property, value );  Separate materials for front and back GL_DIFFUSE Base color GL_SPECULAR Highlight Color GL_AMBIENT Low-light Color GL_EMISSION Glow Color GL_SHININESS Surface Smoothness

Tutorials Add a materials on front 15 void display() { float material_Ka[] = {0.11, 0.06, 0.11, 1.00}; float material_Kd[] = {0.43, 0.47, 0.54, 1.00}; float material_Ks[] = {0.33, 0.33, 0.52, 1.00}; float material_Ke[] = {0.00, 0.00, 0.00, 0.00}; float material_Se[] = {10}; glMaterialfv(GL_FRONT, GL_AMBIENT, material_Ka); glMaterialfv(GL_FRONT, GL_DIFFUSE, material_Kd); glMaterialfv(GL_FRONT, GL_SPECULAR, material_Ks); glMaterialfv(GL_FRONT, GL_EMISSION, material_Ke); glMaterialfv(GL_FRONT, GL_SHININESS, material_Se); }

Tutorials Compare three teapots 16

17 Texture Mapping Applying a 1-D, 2-D, or 3-D image to geometric primitives  Texture coordinates are called (s,t,r,q) Uses of texturing  Simulating materials  Reducing geometric complexity  Reflections  Advanced surface properties

18 Texture Mapping s t x y z image geometry screen

19 Applying Textures The short version 1. Specify a texture image 1. Read or generate image 2. Assign to texture 3. Enable texturing 2. Specify texture parameters 1. Wrapping 1. How texture edges are handled 2. Filtering 1. How texture sampling is handled 3. Assign texture coordinates to vertices

20 Generating a Texture Identifier Generate texture names glGenTextures( n, *texIds );  A texture name is just an integer  The texture name is assigned to some texture data later on Example unsigned int texName; glGenTextures(1, &texname)

21 Binding Textures Bind textures before using glBindTexture( target, id );  Binding a texture means assigning a certain texture id to a certain kind of texture  The valid kinds of textures are GL_TEXTURE_1D GL_TEXTURE_2D GL_TEXTURE_3D Example glBindTexture( GL_TEXTURE_2D, texName );

22 Filter Modes  Handles the sampling mode of the texture  Minification or magnification Handles when the texture to screen mapping is not 1:1  Special mipmap minification filters Wrap Modes  Handles texture lookups outside the texture’s edges  Clamping Copies data from the edge of the texture  Repeating Tiles the texture Texture Functions  How to mix primitive’s color with texture’s color Blend Modulate Replace Texture Application Methods

23 Filter Modes TexturePolygon MagnificationMinification PolygonTexture Example: glTexParameteri( target, type, mode );

24 Wrapping Mode Example: glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP ) glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT ) texture s t GL_CLAMP wrapping GL_REPEAT wrapping

25 Based on parametric texture coordinates Texture coordinates are assigned to vertices  Just like colours and normals The n-D to 3-D mapping is the responsibility of the programmer/modeller glTexCoord*() specified at each vertex s t Mapping Texture

26 Texture Mapping 0, 01, 0 (0.4, 0.2) (0.8, 0.4) A BC a b c 1, 1 0, 1 (s, t) = (0.2, 0.8) Texture SpaceObject Space

Tutorials Make checkerboard texture 27 int i, j, c; for (i = 0; i < 64; i++) { for (j = 0; j < 64; 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; checkImage[i][j][3] = (GLubyte) 255; }

Tutorials Assign texture 28 glGenTextures(1, &texName); glBindTexture(GL_TEXTURE_2D, 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_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 64, 64, 0, GL_RGBA, GL_UNSIGNED_BYTE, checkImage);

Tutorials Texture mapping onto rectangle 29 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glEnable(GL_TEXTURE_2D); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL); glBindTexture(GL_TEXTURE_2D, texName); glBegin(GL_QUADS); glTexCoord2f(0.0, 0.0); glVertex3f(-0.5, -0.5, 0.0); glTexCoord2f(0.0, 1.0); glVertex3f(0.5, -0.5, 0.0); glTexCoord2f(1.0, 1.0); glVertex3f(0.5, 0.5, 0.0); glTexCoord2f(1.0, 0.0); glVertex3f(-0.5, 0.5, 0.0); glEnd(); glFlush(); glDisable(GL_TEXTURE_2D);

Q&A Any questions? 30