CSC 307 1.0 Graphics Programming Budditha Hettige Department of Statistics and Computer Science.

Slides:



Advertisements
Similar presentations
Computer Graphics - Viewing -
Advertisements

David Luebke5/16/2015 Administrivia l Back on track: canceling OpenGL lecture 2 l Assignment 1 –Greg Yukl found an alternate XForms site:
1 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 Programming with OpenGL Part 3: Three Dimensions.
Based on slides created by Edward Angel
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Computer Viewing Ed Angel Professor of Computer Science, Electrical and Computer Engineering,
CSC 461: Lecture 51 CSC461 Lecture 5: Simple OpenGL Program Objectives: Discuss a simple program Discuss a simple program Introduce the OpenGL program.
OpenGL and Projections
1 CSC461 Lecture 7: 3D Programming in OpenGL Objectives: Develop 2D and 3D examples -- Sierpinski gasket: a fractal Develop 2D and 3D examples -- Sierpinski.
OpenGL (II). How to Draw a 3-D object on Screen?
CS 4731: Computer Graphics Lecture 11: 3D Viewing Emmanuel Agu.
1 Lecture 5 Rendering 3D graphical primitives. 2 3D Rendering Example:
Development of Interactive 3D Virtual World Applications
CS 470 Introduction to Computer Graphics Basic 3D in OpenGL.
3D coordinate systems X Y Z Right-Hand Coordinate System X Y Z Left-Hand Coordinate System OpenGL uses this! Direct3D uses this!
Geometric transformations The Pipeline
Demetriou/Loizidou – ACSC330 – Chapter 2 Graphics Programming Dr. Giorgos A. Demetriou Dr. Stephania Loizidou Himona Computer Science Frederick Institute.
Viewing Angel Angel: Interactive Computer Graphics5E © Addison-Wesley
Chapter 5 Viewing.
C O M P U T E R G R A P H I C S Guoying Zhao 1 / 67 C O M P U T E R G R A P H I C S Guoying Zhao 1 / 67 Computer Graphics Three-Dimensional Graphics III.
Introduction to OpenGL 1. 2 OpenGL A Graphics rendering API introduced in 1992 by Silicon Graphics Inc Provide the low-level functions to access graphics.
CAP 4703 Computer Graphic Methods Prof. Roy Levow Chapter 5.
Computer Graphics Bing-Yu Chen National Taiwan University.
Computer Graphics I, Fall 2010 Computer Viewing.
Modeling with OpenGL Practice with OpenGL transformations.
1Computer Graphics Programming with OpenGL Three Dimensions – 2 Lecture 7 John Shearer Culture Lab – space 2
Intro to OpenGL Transformations CS 445/645 Introduction to Computer Graphics David Luebke, Spring 2003.
1 Programming with OpenGL Part 3: Three Dimensions Yuanfeng Zhou Shandong University.
1Computer Graphics Programming with OpenGL Three Dimensions Lecture 06 John Shearer Culture Lab – space 2
Computer Graphics I, Fall 2010 Programming with OpenGL Part 3: Three Dimensions.
1 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 Programming with OpenGL Review.
1 Chapter 2: Graphics Programming Bryson Payne CSCI 3600 NGCSU.
CS 480/680 Computer Graphics Programming with Open GL Part 6: Three Dimensions Dr. Frederick C Harris, Jr. Fall 2011.
Viewing Chapter 5. CS 480/680 2Chapter 5 -- Viewing Introduction: Introduction: We have completed our discussion of the first half of the synthetic camera.
1 Chapter 2 Graphics Programming. 2 Using OpenGL in Visual C++ – 1/3 Opengl32.dll and glu32.dll should be in the system folder Opengl32.lib and glu32.lib.
Graphics Graphics Korea University kucg.korea.ac.kr Viewing 고려대학교 컴퓨터 그래픽스 연구실.
Viewing and Transformation. Pixel pipeline Vertex pipeline Course Map Transformation & Lighting Primitive assembly Viewport culling & clipping Texture.
Chapters 5 2 March Classical & Computer Viewing Same elements –objects –viewer –projectors –projection plane.
CGGM Lab. Tan-Chi Ho 2001 Viewing and Transformation.
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Classical Viewing Ed Angel Professor of Computer Science, Electrical and Computer Engineering,
Classical Viewing Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico.
Chap 3 Viewing and Transformation
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.
1 E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012 Programming with OpenGL Part 6: Three Dimensions Ed Angel Professor.
CS559: Computer Graphics Lecture 12: OpenGL - Transformation Li Zhang Spring 2008.
31/1/2006Based on: Angel (4th Edition) & Akeine-Möller & Haines (2nd Edition)1 CSC345: Advanced Graphics & Virtual Environments Lecture 2: Introduction.
Viewing Angel Angel: Interactive Computer Graphics5E © Addison-Wesley
CS5500 Computer Graphics March 20, Computer Viewing Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts.
OpenGL LAB III.
CSC Graphics Programming
Viewing 고려대학교 컴퓨터 그래픽스 연구실 kucg.korea.ac.kr.
Administrivia Back on track: canceling OpenGL lecture 2 Assignment 1
Introduction of OpenGL - 3D Graphic and Animation
Viewing.
Computer Graphics - Chapter 5 Viewing
Computer Viewing.
Isaac Gang University of Mary Hardin-Baylor
Programming with OpenGL Part 1: Background
Programming with OpenGL Part 3: Three Dimensions
Introduction to Computer Graphics with WebGL
CSC461: Lecture 24 Lighting and Shading in OpenGL
Programming with OpenGL Part 3: Three Dimensions
Introduction to Computer Graphics with WebGL
University of New Mexico
Computer Graphics 3Practical Lesson
Programming with OpenGL Part 6: Three Dimensions
Programming with OpenGL Part 3: Three Dimensions
Angel: Interactive Computer Graphics5E © Addison-Wesley 2009
Programming with OpenGL Part 3: Three Dimensions
Angel: Interactive Computer Graphics5E © Addison-Wesley 2009
Presentation transcript:

CSC Graphics Programming Budditha Hettige Department of Statistics and Computer Science

Graphics Programming OpenGL 3D Drawing 2

3D Graphics Projections – Getting 3D to 2D 3

Projections Orthographic Projection Perspective Projection 4 Orthographic Perspective

Orthographic Projections glOrtho ( double left, double right, double bottom, double top, double near, double far); 5

Perspective Projection gluPerspective ( double angle, double aspect, double near, double far); 6

Draw a 3D Model Object Composition 7 3D Model Polygon

Object Composition Use Transformation – glPushMatrix ( ); – glPopMatrix ( ); –Save the current transformation state and then restore it after some objects have been placed

The Matrix Stack Draw a car use transformation – The car body and four wheeles The Car Body Wheele 1 Wheele 2 Wheele 3 Wheele 4 Transformation state

Hidden Surface Removal Enable Depth Testing – glEnable (GL_DEPTH_TEST); 10 Hidden Surface

Drawing 3D Objects Cube –void glutWireCube(GLdouble size); –void glutSolidCube(GLdouble size); Sphere –void glutWireSphere(GLdouble radius, GLint slices, GLint stacks); –void glutSolidSphere(GLdouble radius, GLint slices, GLint stacks); Cone 11

12 Three-dimensional Applications In OpenGL, two-dimensional applications are a special case of three-dimensional graphics –Not much changes –Use glVertex3*( ) –Have to worry about the order in which polygons are drawn or use hidden-surface removal –Polygons should be simple, convex, flat

13 Sierpinski Gasket (2D) Start with a triangle Connect bisectors of sides and remove central triangle Repeat Example : Gasket.cpp

14 Moving to 3D We can easily make the program three- dimensional by using typedef Glfloat point3[3] glVertex3f glOrtho But that would not be very interesting Instead, we can start with a tetrahedron

15 3D Gasket We can subdivide each of the four faces We can easily make the program three-dimensional by using typedef Glfloat point3[3] glVertex3f glOrtho

16 Example After 4 interations

17 triangle code void triangle( point a, point b, point c) {// right-hand rule glBegin(GL_POLYGON); glVertex3fv(a); glVertex3fv(b); glVertex3fv(c); glEnd(); }

18 subdivision code void divide_triangle(point a, point b, point c, int m) { point v1, v2, v3; int j; if(m>0) { for(j=0; j<3; j++) v1[j]=(a[j]+b[j])/2; for(j=0; j<3; j++) v2[j]=(a[j]+c[j])/2; for(j=0; j<3; j++) v3[j]=(b[j]+c[j])/2; divide_triangle(a, v1, v2, m-1); divide_triangle(c, v2, v3, m-1); divide_triangle(b, v3, v1, m-1); } else(triangle(a,b,c)); }

19 tetrahedron code void tetrahedron( int m) { glColor3f(1.0,0.0,0.0); divide_triangle(v[0], v[1], v[2], m); glColor3f(0.0,1.0,0.0); divide_triangle(v[3], v[2], v[1], m); glColor3f(0.0,0.0,1.0); divide_triangle(v[0], v[3], v[1], m); glColor3f(0.0,0.0,0.0); divide_triangle(v[0], v[2], v[3], m); }

20 Problem Because the triangles are drawn in the order they are defined in the program, the front triangles are not always rendered in front of triangles behind them get this want this

21 Solution: Hidden-Surface Removal We want to see only those surfaces in front of other surfaces OpenGL uses a hidden-surface method called the z-buffer algorithm that saves depth information as objects are rendered so that only the front objects appear in the image

Locating the camera 22 Position and orient the camera – three inputs Eye, at, and direction – up Camera is on Model-View mode

Default Camera Settings With default, camera is located at the origin and oriented at the negative z-axes If place a cube at the origin, only one side of the cube is visible Look at objects from different angles –Move the objects –Move the camera Example – a cube Glu function void gluLookAt(eyex, eyey, eyez, atx, aty, atz, upx, upy, upz) gluLookAt(1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0); 23

24 Code: Display a cube void display() { glClear(GL_COLOR_BUFFER_BIT); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); gluLookAt(1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0); glutWireCube(1.0f); glFlush(); }