2002 by Jim X. Chen: Drawing Geometric Models.1. Objectives –OpenGL drawing primitives and attributes –OpenGL polygon face.

Slides:



Advertisements
Similar presentations
2IV60 Computer graphics Graphics primitives and attributes Jack van Wijk TU/e.
Advertisements

Informationsteknologi Monday, October 29, 2007Computer Graphics - Class 21 Today’s class Graphics programming Color.
OpenGL (Graphics Library) Software Interface to graphics software Allows to create interactive programs that produce color images of moving 3D objects.
CSCE 441: Computer Graphics Scan Conversion of Polygons
Drawing Geometric Objects
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Programming with OpenGL Part 2: Complete Programs Ed Angel Professor of Computer Science,
1 Lecture 4 Graphical primitives Rasterization: algorithmic approach Rasterization: geometric approach 2D discrete lines, triangles Discrete planes 3D.
1 Lecture 5 Rendering 3D graphical primitives. 2 3D Rendering Example:
CSC 461: Lecture 6 1 CSC461 Lecture 6: 2D Programming in OpenGL Objectives:  Fundamental OpenGL primitives  Attributes  Viewport.
OpenGL Programming Guide (Red Book) State Management and Drawing Geometric Objects 고려대학교 그래픽스 연구실 강 신 진.
Reference1. [OpenGL course slides by Rasmus Stenholt]
CS380 LAB I OpenGL Donghyuk Kim Reference1. [OpenGL course slides by Rasmus Stenholt] Reference2. [
CAP 4703 Computer Graphic Methods Prof. Roy Levow Lecture 2.
1 CSCE 441: Computer Graphics Scan Conversion of Polygons Jinxiang Chai.
Open GL Programming Speaker: 彭任右 Date: 2005/10/3.
Triangulation Introduction to Computer Graphics and Animation (Principle of Computer Graphics) Rattapoom Waranusast.
Graphics Systems and OpenGL. Business of Generating Images Images are made up of pixels.
State Management and Drawing Geometry Objects
1. OpenGL/GLU/GLUT  OpenGL v4.0 (latest) is the “core” library that is platform independent  GLUT v3.7 is an auxiliary library that handles window creation,
P RACTICING O PEN GL- P RIMITIVES. O PEN GL O UTPUT P RIMITIVES  Each geometric object is described by a set of vertices and the type of primitive to.
1Computer Graphics Programming with OpenGL Three Dimensions – 2 Lecture 7 John Shearer Culture Lab – space 2
Computer Graphics Bing-Yu Chen National Taiwan University.
Computer Graphics I, Fall 2010 Programming with OpenGL Part 3: Three Dimensions.
Implementation II.
Intro to OpenGL: Vertices and Drawing
UniS CS297 Graphics with Java and OpenGL State Management and Drawing Primative Geometric Objects.
Review on Graphics Basics. Outline Polygon rendering pipeline Affine transformations Projective transformations Lighting and shading From vertices to.
Computer Graphics I, Fall 2010 Implementation II.
Lecture 2 Review OpenGL Libraries Graphics Overview Rendering Pipeline OpenGL command structure.
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Programming with OpenGL Part 3: Three Dimensions Ed Angel Professor of Computer Science,
1 Programming with OpenGL Part 2: Complete Programs.
OpenGL API 2D Graphic Primitives Angel Angel: Interactive Computer Graphics5E © Addison-Wesley
1 E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012 Programming with OpenGL Part 4: Color and Attributes Isaac Gang University.
1 CSCE 441: Computer Graphics Scan Conversion of Polygons Jinxiang Chai.
1 Perception, Illusion and VR HNRS 299, Spring 2008 Lecture 15 Creating 3D Models.
31/1/2006Based on: Angel (4th Edition) & Akeine-Möller & Haines (2nd Edition)1 CSC345: Advanced Graphics & Virtual Environments Lecture 2: Introduction.
1 Computer Graphics Week11 : Hidden Surface Removal.
Learning Objectives Classification of Visible Surface Detection Algorithms Classification of Visible Surface Detection Algorithms Back-Face Detection Back-Face.
OpenGL: Introduction #include main() { OpenWindow() ; glClearColor(0.0, 0.0, 0.0, 0.0); glClear(GL_COLOR_BUFFER_BIT); glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0,
CIS 681 Review: OpenGL. CIS 681 Command Syntax OpenGL commands start with a gl. This is followed by the base command such as Color. Followed by the number.
Visible-Surface Detection Methods. To identify those parts of a scene that are visible from a chosen viewing position. Surfaces which are obscured by.
Computer Graphics I, Fall Programming with OpenGL Part 2: Complete Programs.
Computer Graphics (Fall 2003) COMS 4160, Lecture 5: OpenGL 1 Ravi Ramamoorthi Many slides courtesy Greg Humphreys.
OpenGL Programming Guide Chapter 2 Korea Univ. Graphics Labs. Ji Jun Yong Korea Univ. Graphics Labs. Ji Jun Yong.
Program Studi S-1 Teknik Informatika FMIPA Universitas Padjadjaran
Pattern filling in scan-conversion Antialiasing
CSC Graphics Programming
Draw a Simple Object.
State Management and Drawing Geometric Objects
State Management and Drawing Geometric Objects
Programming with OpenGL Part 2: Complete Programs
Materi Anatomi OpenGL Fungsi GLUT Posisi Kamera Proyeksi
OpenGL API 2D Graphic Primitives
Programming with OpenGL Part 2: Complete Programs
OpenGL (Open Graphics Library) Mr. B.A.Swamy Assistant Professor Dept of CSE.
Class 17 front and back lighting convex sets, convex hull
Lab 3 Geometric Drawing Lab 3 Geometric Drawing.
Objectives OpenGL drawing primitives and attributes
Starting to draw dealing with Windows which libraries? clipping
Programming with OpenGL Part 4: Color and Attributes
Drawing in the plane 455.
CSCE 441 Computer Graphics: Clipping Polygons Jinxiang Chai
Programming with OpenGL Part 2: Complete Programs
Programming with OpenGL Part 2: Complete Programs
Starting to draw dealing with Windows which libraries? clipping
Programming with OpenGL Part 4: Color and Attributes
Programming with OpenGL Part 2: Complete Programs
Class 18 front and back lighting convex sets, convex hull
Polygons.
Presentation transcript:

by Jim X. Chen: Drawing Geometric Models.1. Objectives –OpenGL drawing primitives and attributes –OpenGL polygon face and culling –OpenGL hidden-surface removal –Constructing 3D models in OpenGL –Collision detection

by Jim X. Chen: : Drawing Geometric Models.2. Review: OPENGL DRAWING PRIMITIVES glBegin(GL_POLYGON); glVertex2f(0.0, 0.0); glVertex2f(0.0, 3.0); glVertex2f(3.0, 3.0); glVertex2f(4.0, 1.5); glVertex2f(3.0, 0.0); glEnd(); OpenGL polygons must be convex

by Jim X. Chen: : Drawing Geometric Models.3. void glBegin(GLenum mode); mode: GL_POINTS individual points GL_LINES pairs of vertices interpreted as individual line segments GL_POLYGON boundary of a simple, convex polygon GL_TRIANGLES triples of vertices interpreted as triangles GL_QUADS quadruples of vertices interpreted as four-sided polygons GL_LINE_STRIP series of connected line segments GL_LINE_LOOP same as above, with a segment added between last and first vertices GL_TRIANGLE_STRIP linked strip of triangles GL_TRIANGLE_FAN linked fan of triangles GL_QUAD_STRIP linked strip of quadrilaterals

by Jim X. Chen: : Drawing Geometric Models.4. Review: Points and Line Attributes void glPointSize(GLfloat size); void glLineWidth(GLfloat width); glLineStipple(1, 0x3F07); glEnable(GL_LINE_STIPPLE); void glLineStipple(GLint factor, Glushort pattern); Stippled Lines Stippled Lines

by Jim X. Chen: Drawing Geometric Models.5. Review: SPECIFYING A COLOR glColor3f(0.0, 0.0, 0.0); draw_object(A); draw_object(B); glColor3f(1.0, 0.0, 0.0); draw_object(C); glColor3f(0.0, 0.0, 0.0); black glColor3f(1.0, 0.0, 0.0); red glColor3f(0.0, 1.0, 0.0); green glColor3f(1.0, 1.0, 0.0); yellow glColor3f(0.0, 0.0, 1.0); blue glColor3f(1.0, 0.0, 1.0); magenta glColor3f(0.0, 1.0, 1.0); cyan glColor3f(1.0, 1.0, 1.0); white

glFlush() and glFinish() glFlush() and glFinish() will push all buffered operations to the hardware so that the operations can be executed glFlush() returns immediately where as glFinish() blocks until all the operations are complete. glFlush() is pretty much obsolete, because the program flush the buffered operation anyway 2002 by Jim X. Chen:

: Drawing Geometric Models.7. DEPTH BUFFER (Z-BUFFER) glEnable(GL_DEPTH_TEST);... while (1) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); draw_3d_object_A(); draw_3d_object_B(); } Color buffer Depth buffer glClearColor(0.0, 0.0, 0.0, 0.0); // RGBA, A=>alpha

by Jim X. Chen: 8 Clearing the buffers int depthBuffer(XMAX, YMAX); Color frameBuffer(XMAX, YMAX); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) { for (y=0; y<YMAX; y++) for (x=0; x<XMAX; x++) { draw_frameBuffer(x,y); // glClearColor draw_depthBuffer (x,y, back); //Back_Clipping_Plane } z back

by Jim X. Chen: 9 THE Z-BUFFER ALGORITHM float pixelDepth; int depthBuffer(XMAX, YMAX); Color frameBuffer(XMAX, YMAX); for (each polygon) for (each pixel (x,y) in the polygon scan-conversion) { if (GL_DEPTH_TEST enabled) zBuffer(x,y); // glEnable(GL_DEPTH_TEST); else draw_frameBuffer(x,y); } zBuffer(int x, int y) { pixelDepth = polygon’s z-value at pixel (x,y); if (pixelDepth < read_depthBuffer(x,y)) { draw_depthBuffer(x, y, pixelDepth); draw_frameBuffer(x,y); // glColor } z

Depth Test: J2_5_Cone // clear both framebuffer and zbuffer gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); // for testing hidden-surface removal if (cnt % 600 < 500) { gl.glEnable(GL.GL_DEPTH_TEST); } else gl.glDisable(GL.GL_DEPTH_TEST); 2002 by Jim X. Chen:

: Drawing Geometric Models.11. void glPolygonMode(GLenum face, Glenum mode); face can be GL_FRONT_AND_BACK, GL_FRONT, or GL_BACK; mode can be GL_POINT, GL_LINE, or GL_FILL void glCullFace(GLenum mode); Indicates which polygons should be discarded. The mode is either GL_FRONT, GL_BACK, or GL_FRONT_AND_BACK. To take effect, use glEnable(GL_CULL_FACE). Faces of a Polygon and Back-face Culling Front face polygon has counterclockwise vertices, with normal facing viewer. In OpenGL, this can be defined.

PolygonMode and CullFace // for testing polygon mode if (cnt % 100 > 50) gl.glPolygonMode(GL.GL_FRONT_AND_BACK, GL.GL_LINE); else gl.glPolygonMode(GL.GL_FRONT_AND_BACK, GL.GL_FILL); // for testing cull face if (cnt % 500 > 495) { gl.glEnable(GL.GL_CULL_FACE); gl.glCullFace(GL.GL_FRONT); } else if (cnt % 500 > 490) { gl.glEnable(GL.GL_CULL_FACE); gl.glCullFace(GL.GL_BACK); } else { gl.glDisable(GL.GL_CULL_FACE); } 2002 by Jim X. Chen: J2_5_Cone

by Jim X. Chen: : Drawing Geometric Models.13. CIRCLE, CONE, CYLINDER, SPHERE, AND ANIMATION Circle Sphere Cylinder Cone

by Jim X. Chen: : Drawing Geometric Models.14. Circle depth=0, draw 4 triangles. depth=1, each triangle is subdivided into two and we draw 8 triangles. consider v1, v2, and v12 as vectors. Then, v12 is in the direction of (v1 + v2)=(v1 x +v2 x, v1 y +v2 y, v1 z +v2 z ) and |v1| = |v2| = |v12|. v12 = normalize(v1 + v2). Normalizing a vector is equivalent to scaling the vector to a unit vector. recursively subdivides depth times and draws 2 depth triangles.

by Jim X. Chen: : Drawing Geometric Models.15. raise the center of the circle along the z axis Example: J2_5_Cone // make sure the cone is within the viewing volume glOrtho(-Width/2, Width/2, -Height/2, Height/2, -Width/2, Width/2); Cone

J2_5_Cone private void subdivideCone(float v1[], float v2[], int depth) { float v0[] = {0, 0, 0}; float v12[] = new float[3]; if (depth==0) { gl.glColor3d(v1[0]*v1[0], v1[1]*v1[1], v1[2]*v1[2]); drawtriangle(v2, v1, v0); // bottom cover of the cone v0[2] = 1; // height of the cone, the tip on z axis drawtriangle(v1, v2, v0); // side cover of the cone return; } for (int i = 0; i<3; i++) v12[i] = v1[i]+v2[i]; normalize(v12); subdivideCone(v1, v12, depth-1); subdivideCone(v12, v2, depth-1); } 2002 by Jim X. Chen:

: Drawing Geometric Models.17. draw a circle at z=0, draw another circle at z=1. If we connect the rectangles of the same vertices on the edges of the two circles, we have a cylinder Example: J2_6_Cylinder // make sure the cone is within the viewing volume glOrtho(-Width/2, Width/2, -Height/2, Height/2, -Width/2, Width/2); Cylinder

by Jim X. Chen: : Drawing Geometric Models.18. assume equilateral triangle (v 1, v 2, v 3 ) on a sphere and |v 1 |=|v 2 |=|v 3 |=1. v 12 = normalize(v 1 +v 2 ) is also on the sphere. We can further subdivide the triangle into four equilateral triangles Sphere Example: J2_7_Sphere

J2_7_Sphere private void subdivideSphere( float v1[], float v2[], float v3[], long depth) { float v12[] = new float[3], v23[] = new float[3], v31[] = new float[3]; int i; if (depth==0) { gl.glColor3f(v1[0]*v1[0], v2[1]*v2[1], v3[2]*v3[2]); drawtriangle(v1, v2, v3); return; } for (i = 0; i<3; i++) { v12[i] = v1[i]+v2[i]; v23[i] = v2[i]+v3[i]; v31[i] = v3[i]+v1[i]; } normalize(v12); normalize(v23); normalize(v31); subdivideSphere(v1, v12, v31, depth-1); subdivideSphere(v2, v23, v12, depth-1); subdivideSphere(v3, v31, v23, depth-1); subdivideSphere(v12, v23, v31, depth-1); } 2002 by Jim X. Chen:

: Drawing Geometric Models.20. More Hidden-surface Removal  view point at the origin and the models are in the negative z axis  render the models in the order of their distances to the view point along z axis from the farthest to the closest  build up a box (bounding volume) with the faces perpendicular to the x, y, or z axis to bound a 3D model  compare the minimum and maximum bounds in the z direction between boxes to decide which model should be rendered first  Using bounding volumes to decide priority of rendering is also known as minmax testing. z

by Jim X. Chen: : Drawing Geometric Models.21. Collision Detection  collision detection avoid two models in an animation penetrating each other  we can use their bounding volumes to decide their physical distances and collision  bounding volume can be in a different shape other than a box, such as a sphere.  We may use multiple spheres with different radii to more accurately bound a model, but the collision detection would be more complex. z J2_11_ConeSolarCollision

Homework Implement hidden-surface removal to demonstrate the following that the box is fixed and the triangle is rotating 2002 by Jim X. Chen:

Homework Draw a cone, a cylinder, and a sphere that bounce back and forth in a circle. When the models meet, they change their directions of movement – Must be in double buffer mode –Must have hidden surface removal Clipping; Jim Chen

by Jim X. Chen: 24 HW4: 2012 Fall Class 1.Continue from previous homework; 2.Change the big circle into a rectangle, and you can get rid of the points that move on the circle; (40%) 3.Change the previous bouncing circles into spheres; (40%) 4.Some spheres are filled solid, some are wireframes; (20%) 5.Now you have spheres bouncing in a 2D rectangle.