Interactive Computer Graphics CS 418 – Spring 2015 Mesh Rendering, Transformation, Camera Viewing and Projection in OpenGL TA: Zhicheng Yan Sushma S Kini.

Slides:



Advertisements
Similar presentations
Vertex Buffer Objects, Vertex Array Objects, Pixel Buffer Objects.
Advertisements

Computer Graphics 2D & 3D Transformation.
02/17/05CISC640/440 OpenGL Tutorial1 OpenGL Tutorial CISC 640/440 Computer Graphics TA: Qi Li/Mani Thomas
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Building Models modified by Ray Wisman Ed Angel Professor of Computer Science,
1 Building Models. 2 Objectives Introduce simple data structures for building polygonal models ­Vertex lists ­Edge lists OpenGL vertex arrays.
Using GLU/GLUT Objects GLU/GLUT provides very simple object primitives glutWireCube glutWireCone gluCylinder glutWireTeapot.
CLASS 4 CS770/870. Translation Scale Multiplying Matrices. The R C rule What happens when we do two translates? What happens when we do two scales?
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.
 The success of GL lead to OpenGL (1992), a platform-independent API that was  Easy to use  Close enough to the hardware to get excellent performance.
Lab 1: OpenGL Tutorial CS 282. What’s the plan for today? Go over our framework code. Learn some basic OpenGL! Reveal Lab 1 Answer questions.
Meshes Dr. Scott Schaefer. 3D Surfaces Vertex Table.
Computer Graphics Ben-Gurion University of the Negev Fall 2012.
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Programming with OpenGL Part 2: Complete Programs Ed Angel Professor of Computer Science,
Objectives Learn to build arbitrary transformation matrices from simple transformations Learn to build arbitrary transformation matrices from simple transformations.
TA: Zhicheng Yan Sushma S Kini Mary Pietrowicz
1 OpenGL Basics A Graphics Standard ©Mel Slater, Anthony Steed
Modeling. Geometric Models  2D and 3D objects  Triangles, quadrilaterals, polygons  Spheres, cones, boxes  Surface characteristics  Color  Texture.
Fundamentals of Computer Graphics Part 4
Drawing Basic Graphics Primitives Lecture 4 Wed, Sep 3, 2003.
Open GL Programming Speaker: 彭任右 Date: 2005/10/3.
TWO DIMENSIONAL GEOMETRIC TRANSFORMATIONS CA 302 Computer Graphics and Visual Programming Aydın Öztürk
Triangulation Introduction to Computer Graphics and Animation (Principle of Computer Graphics) Rattapoom Waranusast.
2D Transformations.
Image Synthesis Rabie A. Ramadan, PhD 2. 2 Java OpenGL Using JOGL: Using JOGL: Wiki: You can download JOGL from.
Speeding Up Rendering After Deciding What to Draw.
Ch 2 Graphics Programming page 1 CSC 367 Coordinate Systems (2.1.2) Device coordinates, or screen coordinates (pixels) put limitations on programmers and.
CG1 Labs Wei Li. Back Face Culling // enable back-face culling glEnable( GL_CULL_FACE ); // orientation of front-facing polygons glFrontFace( GL_CCW );
Stages of Vertex Transformation To specify viewing, modeling, and projection transformations, you construct a 4 × 4 matrix M, which is then multiplied.
Representation. Objectives Introduce concepts such as dimension and basis Introduce coordinate systems for representing vectors spaces and frames for.
Modeling with OpenGL Practice with OpenGL transformations.
Jul 25, 2014IAT 3551 Scene Graphs.  A data structure that stores information about a graphics scene –Each node has information that structures the interpretation.
Intro to OpenGL Transformations CS 445/645 Introduction to Computer Graphics David Luebke, Spring 2003.
Computer Graphics Bing-Yu Chen National Taiwan University.
1 3D API OPENGL ES v1.0 Owned by Silicon Graphics (SGL) Control was then transferred to Khronos Group Introduction.
2 COEN Computer Graphics I Evening’s Goals n Discuss viewing and modeling transformations n Describe matrix stacks and their uses n Show basic geometric.
1 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 OpenGL Transformations.
Introduction to OpenGL & HW1 Announcement 劉軒銘, 網媒所 碩二 ICG 2012 Fall.
NoufNaief.net 1 TA: Nouf Al-Harbi.
CS552: Computer Graphics Lecture 6: Viewing in 2D.
Composing Transformations
OpenGL API 2D Graphic Primitives Angel Angel: Interactive Computer Graphics5E © Addison-Wesley
Learning Objectives Affine transformations Affine transformations Translation Translation Rotation Rotation Scaling Scaling Reflection Reflection Shear.
1 E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012 Programming with OpenGL Part 4: Color and Attributes Isaac Gang University.
C O M P U T E R G R A P H I C S Guoying Zhao 1 / 73 C O M P U T E R G R A P H I C S Guoying Zhao 1 / 73 Computer Graphics Three-Dimensional Graphics II.
Computer Graphics I, Fall 2010 Building Models.
CS559: Computer Graphics Lecture 12: OpenGL - Transformation Li Zhang Spring 2008.
1 Geometric Transformations-II Modelling Transforms By Dr.Ureerat Suksawatchon.
OpenGL Objects Finalised. Debugging Tip For Debugging your applications remember: glGetError(); gluErrorString(); Don’t use these in release code (the.
Introduction to Graphics Programming. Graphics API.
Geometric Transformations Ceng 477 Introduction to Computer Graphics Computer Engineering METU.
Computer Graphics I, Fall Programming with OpenGL Part 2: Complete Programs.
CS380 LAB II OpenGL Donghyuk Kim Reference1. [OpenGL course slides by Rasmus Stenholt] Reference2. [
4. Geometric Objects and Transformations
Computer Graphics Lecture 34. OpenGL Programming II Taqdees A. Siddiqi
Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009
Interactive Computer Graphics CS 418 – Fall 2017 Indexed Meshes Transformations Background Imagery:
IAT 355 Scene Graphs Feb 23, 2017 IAT 355.
Reference1. [OpenGL course slides by Rasmus Stenholt]
Programming with OpenGL Part 2: Complete Programs
Building Models Ed Angel
Geometric Transformations
Chapter 4/5 glMatrixMode Modeling Transformations glTranslate glScale
Isaac Gang University of Mary Hardin-Baylor
Geometric Transformations
Angel: Interactive Computer Graphics5E © Addison-Wesley 2009
Building Models Ed Angel Professor Emeritus of Computer Science
The Modelview Matrix Lecture 8 Mon, Sep 10, 2007.
Transformations in OpenGL
Isaac Gang University of Mary Hardin-Baylor
Geometric Transformations
Presentation transcript:

Interactive Computer Graphics CS 418 – Spring 2015 Mesh Rendering, Transformation, Camera Viewing and Projection in OpenGL TA: Zhicheng Yan Sushma S Kini Mary Pietrowicz

Agenda  Mesh format  Drawing with OpenGL  Matrix transformation

How to Load Your Mesh  Customized.obj 3D models with colors.  Won’t work with a obj reader code.  You should have skills to write a simple parser loading the files.

Our Mesh File Format  You will have a list of vertex attributes : Positions (v), Colors (vc), etc.  Vertices are indexed according to their orders in file.  Another indexed list for triangles ( f )  Ex : Triangle 1 is formed by vertex v1,v2 and v3 v v ….. vc vc ….. f f ….. Position v1 Position v2 Color v1 Color v2

Exercise v v v v vc vc vc vc f f Draw the object from the given vertex/face list :

Mesh Structure  Face-index List :  Recommend to use/implement basic matrix/vector structure and operations. (ex : libgfx )  Store vertex attributes in one array  Store face-vertex indices in another array.  When rendering, iterate through each face, and grab vertex attributes based on Indices.  More complicated structure is possible  Half-Edge, etc.

Display Your Mesh  Assuming you ’ ve set up the view/projection transformation.  Display one triangle glBegin(GL_TRIANGLES); glVertex3f(x1,y1,z1); glVertex3f(x2,y2,z2); glVertex3f(x3,y3,z3); glEnd();  glBegin  Decide which primitive you will display.  GL_POINTS, GL_LINES, GL_TRIANGLES, etc.  Display a mesh is similar, just go through each triangle in the mesh. ( Put loop between glBegin/glEnd)

Color Your Mesh  glColor3f  Set R,G,B color  Range from 0.0~1.0. (1.0,1.0,1.0) is white.  Use the provided colors, or generate your own.  Ex : Color one triangle with Red, Green, Blue at each vertex glBegin(GL_TRIANGLES); glColor3f(1.0,0.0,0.0); //red glVertex3f(x1,y1,z1); glColor3f(0.0,1.0,0.0); // green glVertex3f(x2,y2,z2); glColor3f(0.0,0.0,1.0); // blue glVertex3f(x3,y3,z3); glEnd();

Vertex Arrays  Vertex Arrays are retained in the sense that everything is sent at once. GLfloat vertices[] = {...}; // 8 of vertex cords GLfloat colors[] = {...}; // 8 of vertex colors GLubyte indices[] = {0,1,2, 2,3,0, // 36 of indices 0,3,4, 4,5,0, 0,5,6, 6,1,0, 1,6,7, 7,2,1, 7,4,3, 3,2,7, 4,7,6, 6,5,4};... glEnableClientState(GL_VERTEX_ARRAY); glVertexPointer(3, GL_FLOAT, 0, vertices); glColorPointer(3, GL_FLOAT, 0, colors); glDrawElements(GL_TRIANGLES, 36, GL_UNSIGNED_BYTE, indices); glDisableClientState(GL_VERTEX_ARRAY);

Vertex Buffer Object 1  VBO are closer to true retained mode rendering because the data is actually transferred over to GPU memory GLuint vboId; GLfloat* vertices = new GLfloat[vCount*4] glGenBuffersARB(1, &vboId); glBindBufferARB(GL_ARRAY_BUFFER_ARB, vboId); glBufferDataARB(GL_ARRAY_BUFFER_ARB, dataSize, vertices, GL_STATIC_DRAW_ARB); delete [] vertices;//notice we are not managing the memory glDeleteBuffersARB(1, &vboId);

Vertex Buffer Object 2  Draws use the same commands as Vertex Arrays with null pointers glBindBufferARB(GL_ARRAY_BUFFER_ARB, vboId1); glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, vboId2); glEnableClientState(GL_VERTEX_ARRAY); glVertexPointer(3, GL_FLOAT, 0, 0); glDrawElements(GL_QUADS, 24, GL_UNSIGNED_BYTE, 0); glDisableClientState(GL_VERTEX_ARRAY); glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0); glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 0);

OpenGL Matrix Transformation  Essential for interactive viewing/animation.  Things to Take Home  #1 : You are modifying a global “ current matrix ”  #2 : The “ last ” transformation gets applied “ first ”.  #3 : OpenGL store matrix in “ Column Major ”

 glScalef (2.5, 2.5, 1.0); Review of Matrix Ops.

Scaling

Translation  glTranslatef(2.5,2.0,0.0);

Translation

Rotation  glRotatef(90.0, 0.0, 0.0, 1.0)

Rotation You may also specify rotation about an arbitrary axis. You may also specify rotation about an arbitrary axis.

#1 Current Matrix  An OpenGL matrix operation affects a global 4x4 matrix.  It is the top matrix in the matrix stack you are currently working on.  glMatrixMode Projection Matrix Model View Matrix Current Matrix glMatrixMode(GL_MODEL_VIEW) glMatrixMode(GL_PROJECTION) glRotatef(1.0,0.0,0.0,1.0); gluPerspective(…); M1=M1*R M2=M2*P

#1 Current Matrix  When rendering, both of them are combined to transform the object. MVP = (Projection)*(Model View) Projection Matrix Model View Matrix V_Transform = MVP * V Object V Transform V_Transform MVP

#2 Last Transform Applied First  OpenGL Post-multiply new transformation with current matrix when we call glRotate, glTranslate, or glScale.  The last transformation is applied first to the object. glRotatef(1.0,0.0,0.0,1.0); M=I glLoadIdentity(); R glTranslatef(0.5,0.5,0.5); T glRotatef(1.0,0.0,0.0,1.0); glTranslatef(0.5,0.5,0.5); RTM=I glLoadIdentity();

Exercise Draw the result of the following OpenGL transformation code. glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glScalef(1.5, 1.0, 1.0); glRotatef(90.0, 0.0, 0.0, 1.0); glTranslatef(2.0, 2.0, 0.0); draw_teapot_image();

Exercise glMatrixMode(GL_MODELVIEW);glLoadIdentity(); glScalef(1.5, 1.0, 1.0); glRotatef(90.0, 0.0, 0.0, 1.0); glTranslatef(2.0, 2.0, 0.0); draw_teapot_image();

Exercise glMatrixMode(GL_MODELVIEW);glLoadIdentity(); glScalef(1.5, 1.0, 1.0); glRotatef(90.0, 0.0, 0.0, 1.0); glTranslatef(2.0, 2.0, 0.0); draw_teapot_image();

Exercise glMatrixMode(GL_MODELVIEW);glLoadIdentity(); glScalef(1.5, 1.0, 1.0); glRotatef(90.0, 0.0, 0.0, 1.0); glTranslatef(2.0, 2.0, 0.0); draw_teapot_image();

Exercise glMatrixMode(GL_MODELVIEW);glLoadIdentity(); glScalef(1.5, 1.0, 1.0); glRotatef(90.0, 0.0, 0.0, 1.0); glTranslatef(2.0, 2.0, 0.0); draw_teapot_image();

Useful OpenGL Matrix Ops.  glLoadIdentity : M = I  glScale : M = MS  glTranslate : M = MT  glRotate : Specify rotation axis, angle. M = MR

Column Major D array in C : Matrix in OpenGL : Given a 1D array of 16 floats :

Pre-multiply ?  What to do if you want to pre-multiply the matrix ? M=RM ? Make use of “glGetFloat” & “glMultMatrix”. glLoadIdentity(); glGetFloat(MODEL_VIEW,tempM); glTranslatef(0.3,0.3,0.2); glLoadIdentity(); glMultMatrix(tempM); glRotatef(1.0,0.0,0.0,1.0); M=IT tempM= M=I R tempM Useful for updating transformation with UI control.

Q&A