1 Lecture 5 Rendering 3D graphical primitives. 2 3D Rendering Example:

Slides:



Advertisements
Similar presentations
OpenGL Computer Graphics
Advertisements

O a polygon is a plane figure specified by a set of three or more coordinate positions, called vertices, that are connected in sequence by straight-Line.
OPENGL.
3D Game Programming Geometric Transformations
Using GLU/GLUT Objects GLU/GLUT provides very simple object primitives glutWireCube glutWireCone gluCylinder glutWireTeapot.
CS 4363/6353 BASIC RENDERING. THE GRAPHICS PIPELINE OVERVIEW Vertex Processing Coordinate transformations Compute color for each vertex Clipping and Primitive.
Hidden Surface Removal CSE 581. Visibility Assumption: All polygons are opaque What polygons are visible with respect to your view frustum?  Outside:
1 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 Programming with OpenGL Part 3: Three Dimensions.
© 2004, Tom Duff and George Ledin Jr1 Lectures OpenGL Introduction By Tom Duff Pixar Animation Studios Emeryville, California and George Ledin Jr Sonoma.
OpenGL (Graphics Library) Software Interface to graphics software Allows to create interactive programs that produce color images of moving 3D objects.
Drawing Geometric Objects
#4: OpenGL Implementation & Project 2 CSE167: Computer Graphics TAs: Alex Kozlowski & Cameron Chrisman UCSD, Winter 2006.
1 CSC461 Lecture 7: 3D Programming in OpenGL Objectives: Develop 2D and 3D examples -- Sierpinski gasket: a fractal Develop 2D and 3D examples -- Sierpinski.
Vertices and Fragments III Mohan Sridharan Based on slides created by Edward Angel 1 CS4395: Computer Graphics.
CS 470 Introduction to Computer Graphics Basic 3D in OpenGL.
Geometric Objects and Transformations Chapter 4. Points, Scalars and Vectors  Points - position in space  Scalars - real numbers, complex numbers obey.
COS 397 Computer Graphics Assoc. Prof. Svetla Boytcheva AUBG 2013 COS 397 Computer Graphics Practical Session №1 Introduction to OpenGL, GLFW and CG.
Chapter 4 10 February Agenda Program 2 – Due 2/17 Chapter 4 – transformations GLUT solids.
Homogeneous Form, Introduction to 3-D Graphics Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Monday, October 20,
1Computer Graphics Programming with OpenGL Three Dimensions – 2 Lecture 7 John Shearer Culture Lab – space 2
1 Programming with OpenGL Part 3: Three Dimensions Yuanfeng Zhou Shandong University.
Introduction to OpenGL  OpenGL is a graphics API  Software library  Layer between programmer and graphics hardware (and software)  OpenGL can fit in.
Computer Graphics I, Fall 2010 Programming with OpenGL Part 3: Three Dimensions.
CS 480/680 Computer Graphics Programming with Open GL Part 6: Three Dimensions Dr. Frederick C Harris, Jr. Fall 2011.
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.
NoufNaief.net 1 TA: Nouf Al-Harbi.
Visible Surface Detection
OpenGL Basic Drawing 2003 Spring Keng Shih-Ling
Lecture 7 Midterm Review. OpenGL Libraries gl: Basic OpenGL library, e.g. primitives. glu: OpenGL Utility library, a set of functions to create texture.
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Programming with OpenGL Part 3: Three Dimensions Ed Angel Professor of Computer Science,
1 E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012 Programming with OpenGL Part 6: Three Dimensions Ed Angel Professor.
31/1/2006Based on: Angel (4th Edition) & Akeine-Möller & Haines (2nd Edition)1 CSC345: Advanced Graphics & Virtual Environments Lecture 2: Introduction.
Chapter 10 Measurement Section 10.5 Surface Area.
1 Computer Graphics Week11 : Hidden Surface Removal.
OpenGL Basic Drawing Jian-Liang Lin A Smidgen of OpenGL Code #include main() { InitializeAWindowPlease(); glClearColor (0.0, 0.0, 0.0, 0.0); glClear.
2002 by Jim X. Chen: Drawing Geometric Models.1. Objectives –OpenGL drawing primitives and attributes –OpenGL polygon face.
Introduction to Graphics Programming. Graphics API.
CSC Graphics Programming Budditha Hettige Department of Statistics and Computer Science.
Chapter 8 Three-dimensional Object Representations PART I
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.
CS 4722 Made by Dr. Jeffrey Chastine Modified by Dr. Chao Mei
Introduction of OpenGL - 3D Graphic and Animation
CSC Graphics Programming
School of Computer Science
Inside-Outside & Culling
Hidden Surface Removal
LAB 5 Drawing Objects Lab 5 Drawing Objects.
Programming with OpenGL Part 3: Three Dimensions
OpenGL (Open Graphics Library) Mr. B.A.Swamy Assistant Professor Dept of CSE.
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 3: Three Dimensions
Lecture 13 Clipping & Scan Conversion
Primitive Objects Lecture 6 Wed, Sep 5, 2007.
Chapter VII Rasterizer
LAB 5 Drawing Objects Lab 5 Drawing Objects.
OPENGL.
LAB 5 Drawing Objects Lab 5 Drawing Objects.
Starting to draw dealing with Windows which libraries? clipping
Programming with OpenGL Part 6: Three Dimensions
Programming with OpenGL Part 3: Three Dimensions
Chapter 4 15 March 2006 EventPro Strategies is looking for a part-time programmer (any language) who knows SQL. For more info, contact Ryan Taylor,
Polygons.
Angel: Interactive Computer Graphics5E © Addison-Wesley 2009
Programming with OpenGL Part 3: Three Dimensions
Angel: Interactive Computer Graphics5E © Addison-Wesley 2009
Presentation transcript:

1 Lecture 5 Rendering 3D graphical primitives

2 3D Rendering Example:

3 3D Rendering Pipeline

4

5 Rendering  How to render in different modes to get either a solid or an outlined object?  OpenGL allows both sides of an object to be rendered in a different mode.  Example: render a square solid on the front, and outlined on the back.  A question appears: “How does OpenGL know which side of an object is the front?”  Rule: OpenGL assumes that anything drawn in counter-clock-wise direction is the front side by default.

6 Example: program fragment drawing a red square with front solid and back outlined glPolygonMode( GL_FRONT, GL_FILL );// Front filled glPolygonMode( GL_BACK, GL_LINE );// Back Outlined glColor3f( 1.0, 0.0, 0.0 ); glBegin( GL_QUAD ); // Square drawn counter clockwise glVertex2d( -1.0, -1.0 ); glVertex2d( 1.0, -1.0 ); glVertex2d( 1.0, 1.0 ); glVertex2d( -1.0, 1.0 ); glEnd(); glPolygonMode( GL_FRONT_AND_BACK, GL_FILL ); // return the drawing mode

7 Example: program fragment drawing a red square with front solid and back outlined Notice that the points are ordered from the bottom left to the top left in a counter-clock-wise direction. This means that we will never see the outline back unless we rotate the camera.

8 GLFrontFace(): changes the default rule A call to glFrontFace( enum Mode ) can change the default counter-clock-wise front facing polygons to back facing. The accepted Modes are GL_CCW for counter-clock-wise, and GL_CW for clock-wise front facing polygons.  This function is rarely used, but may be useful for porting applications from different graphic environments.  For example, Microsoft’s DirectX uses clock-wise as front facing. In this case, making a call to this function may be easier than reordering the position of the vertices.

9 void glCullFace (enum Mode); Culling is a term in three-dimensional graphics that means not drawing.  When an object is drawn to the screen, all vertices are mapped to where they would be on the screen even if they are not going to be seen. If it is not necessary to draw a face of an object, calling the glCullFace function will save rendering if you know that a face will not be seen. The possible Modes correlate to the faces of the object. They are GL_FRONT, GL_BACK, and GL_FRONT_AND_BACK. In order to use this function, you must enable the culling with a call to glEnable( GL_CULL_FACE ).

10 Hidden Surface Removal How does OpenGL know what objects are in front of other objects? Assume, two objects are rendered. Object 1 is behind object 2 and object 2 is partially obscuring object 1. The display function would draw the object 1 first and then object 2. What if the camera rotated 180 degrees behind object 1? Now the tables are turned, and object 1 is in front with the respects to the camera. If the objects are drawn in the same order, object 2 will always look like it is in front of object 1 no matter what the camera location is.

11 Hidden Surface Removal OpenGL uses Z-buffering to solve this problem of hidden surface removal. Z-Buffering is a method in which every pixel’s z- coordinate is compared to every other pixel’s z- coordinate on a line from the camera. Only the pixel that is not covered by any other pixel is actually drawn to the screen.

12 Hidden Surface Removal To enable this powerful feature: First, in your setup function call to glClear should also contain GL_DEPTH_BUFFER_BIT along with any other buffer bit you wish to clear. glClear( GL_COLOR_BUFFER_BIT |GL_DEPTH_BUFFER_BIT); Second, your application should include GLUT_DEPTH in the main function’s glutInitDisplayMode. This would look something like this: glutInitDisplayMode(GLUT_DEPTH | … ); Third, a call to glEnable( GL_DEPTH_TEST ) to tell the API to use depth testing.

13 3D GLUT predefined shapes void glutSolidSphere( double radius, int slices, int stacks ); void glutWireSphere ( double radius, int slices, int stacks );  Radius is the radius of the sphere.  Slices are the number of subdivisions around the z- axis.  Stacks are the number of subdivisions along the z- axis.

14 3D GLUT predefined shapes

15 3D GLUT predefined shapes

16 3D GLUT predefined shapes void glutSolidCube( double size ); void glutWireCube ( double size ); Size is the length of each side

17 3D GLUT predefined shapes void glutSolidCone(double base,double height,int slices, int stacks ); void glutWireCone ( double base,double height,int slices,int stacks );  Radius is the radius of the cone.  Slices are the number of subdivisions around the z- axis.  Stacks are the number of subdivisions along the z- axis.

18 3D GLUT predefined shapes void glutSolidTorus( double InnerRadius, double OuterRadius, int sides, int rings ); void glutWireTorus( double InnerRadius, double OuterRadius, int sides, int rings );  InnerRadius is the inner radius of the torus.  OuterRadius is the outer radius of the torus.  Sides is the number of sides for each radial section.  Rings are the number of radial divisions for the torus.

19 3D GLUT predefined shapes void glutSolidTeapot( double size ); void glutWireTeapot ( double size );  Size is the relative size of the teapot.

20 3D GLUT predefined shapes The prototype for four more shapes are shown below. void glutSolidIcosahedron(); void glutWireIcosahedron (); void glutSolidOctahedron(); void glutWireOctahedron (); void glutSolidTetrahedron(); void glutWireTetrahedron (); void glutSolidDodecahedron(); void glutWireDodecahedron ();

21 3D GLUT predefined shapes By changing the Display function of the triangle program, we can get some good three-dimensional graphics. Example: a program fragment that draws a yellow teapot to the screen:

22 3D GLUT predefined shapes void Display() { // Clear pixels in buffer glClear( GL_COLOR_BUFFER_BIT ); glColor3f( 1.0, 1.0, 0.0 ); glutSolidTeapot( 0.5 ); glFlush();// Draw to the screen }