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

Similar documents
Programming with OpenGL Part 3: Three Dimensions

Meshing and Geometry

Programming with OpenGL Part 1: Background

Computer Graphics. Chapter 10 Three-Dimensional Viewing

Computer Viewing Computer Graphics I, Fall 2008

Describe the Orthographic and Perspective projections. How do we combine together transform matrices?

Fundamental Types of Viewing

Graphics Programming. 1. The Sierpinski Gasket. Chapter 2. Introduction:

CS354 Computer Graphics Viewing and Modeling

// double buffering and RGB glutinitdisplaymode(glut_double GLUT_RGBA); // your own initializations

Precept 2 Aleksey Boyko February 18, 2011

Transformations (Rotations with Quaternions) October 24, 2005

3D Viewing. With acknowledge to: Ed Angel. Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico

MORE OPENGL. Pramook Khungurn CS 4621, Fall 2011

CIS 636 Interactive Computer Graphics CIS 736 Computer Graphics Spring 2011

The Viewing Pipeline adaptation of Paul Bunn & Kerryn Hugo s notes

Introduction to OpenGL Transformations, Viewing and Lighting. Ali Bigdelou

Lecture 5: Viewing. CSE Computer Graphics (Fall 2010)

Computer Graphics. Basic 3D Programming. Contents

Computer Graphics (Basic OpenGL)

Computer Graphics. Transformations. CSC 470 Computer Graphics 1

Graphics and Visualization

Geometry: Outline. Projections. Orthographic Perspective

CITSTUDENTS.IN VIEWING. Computer Graphics and Visualization. Classical and computer viewing. Viewing with a computer. Positioning of the camera

Advanced Computer Graphics (CS & SE )

COMP3421. Introduction to 3D Graphics

UNIT 7 LIGHTING AND SHADING. 1. Explain phong lighting model. Indicate the advantages and disadvantages. (Jun2012) 10M

1 (Practice 1) Introduction to OpenGL

Computer graphics MN1

Overview. Viewing and perspectives. Planar Geometric Projections. Classical Viewing. Classical views Computer viewing Perspective normalization

CS559: Computer Graphics. Lecture 12: OpenGL Transformation Li Zhang Spring 2008

Transformation Pipeline

Introduction to OpenGL

Programming with OpenGL Part 2: Complete Programs Computer Graphics I, Fall

Viewing Transformation

COMP3421. Introduction to 3D Graphics

Three-Dimensional Graphics III. Guoying Zhao 1 / 67

CS 591B Lecture 9: The OpenGL Rendering Pipeline

CS 4204 Computer Graphics

OpenGL. Toolkits.

COMP3421. Introduction to 3D Graphics

3D computer graphics: geometric modeling of objects in the computer and rendering them

Getting Started. Overview (1): Getting Started (1): Getting Started (2): Getting Started (3): COSC 4431/5331 Computer Graphics.

Graphics Pipeline & APIs

2D and 3D Viewing Basics

GL_COLOR_BUFFER_BIT, GL_PROJECTION, GL_MODELVIEW

OpenGL: Open Graphics Library. Introduction to OpenGL Part II. How do I render a geometric primitive? What is OpenGL

Spring 2013, CS 112 Programming Assignment 2 Submission Due: April 26, 2013

Graphics Programming. August 31, Programming of the Sierpinski gasket. Programming with OpenGL and C/C++

OpenGL Transformations

1 Transformations. Chapter 1. Transformations. Department of Computer Science and Engineering 1-1

Lectures OpenGL Introduction

Lecture 4 of 41. Lab 1a: OpenGL Basics

CS380: Computer Graphics Viewing Transformation. Sung-Eui Yoon ( 윤성의 ) Course URL:

Graphics Pipeline & APIs

7. 3D Viewing. Projection: why is projection necessary? CS Dept, Univ of Kentucky

OpenGL. Jimmy Johansson Norrköping Visualization and Interaction Studio Linköping University

Graphics Programming

OpenGL. 1 OpenGL OpenGL 1.2 3D. (euske) 1. Client-Server Model OpenGL

Computer Graphics and Visualization. Graphics Systems and Models

2D Drawing Primitives

Visualizing Molecular Dynamics

API for creating a display window and using keyboard/mouse interations. See RayWindow.cpp to see how these are used for Assignment3

Chapter 3 - Basic Mathematics for 3D Computer Graphics

CSE 690: GPGPU. Lecture 2: Understanding the Fabric - Intro to Graphics. Klaus Mueller Stony Brook University Computer Science Department

Programming using OpenGL: A first Introduction

To Do. Computer Graphics (Fall 2008) Course Outline. Course Outline. Methodology for Lecture. Demo: Surreal (HW 3)

3D Graphics Pipeline II Clipping. Instructor Stephen J. Guy

Graphics Hardware and OpenGL

Scene Graphs. CS4620/5620: Lecture 7. Announcements. HW 1 out. PA 1 will be out on Wed

Matrix-Rechnung I ' z =... Universität Frankfurt

3D Graphics for Game Programming (J. Han) Chapter II Vertex Processing

CSC 470 Computer Graphics. Three Dimensional Viewing

Hierarchical Modeling: Tree of Transformations, Display Lists and Functions, Matrix and Attribute Stacks,

CSE528 Computer Graphics: Theory, Algorithms, and Applications

CSC 470 Computer Graphics

Basic Graphics Programming

Viewing and Modeling

Computer Viewing. Prof. George Wolberg Dept. of Computer Science City College of New York

Outline. Other Graphics Technology. OpenGL Background and History. Platform Specifics. The Drawing Process

Graphics and Computation Introduction to OpenGL

COMP Computer Graphics and Image Processing. 5: Viewing 1: The camera. In part 1 of our study of Viewing, we ll look at ˆʹ U ˆ ʹ F ˆʹ S

Surface Graphics. 200 polys 1,000 polys 15,000 polys. an empty foot. - a mesh of spline patches:

Lecture 3 Advanced Computer Graphics (CS & SE )

Computer Graphics and Visualization VTU QUESTION PAPER SOLUTION UNIT -1 INTRODUCTION

Computer Viewing. CITS3003 Graphics & Animation. E. Angel and D. Shreiner: Interactive Computer Graphics 6E Addison-Wesley

CMSC 425: Lecture 4 More about OpenGL and GLUT Tuesday, Feb 5, 2013

QUESTION 1 [10] 2 COS340-A October/November 2009

3D Graphics and OpenGl. First Steps

Computer Graphics. Chapter 7 2D Geometric Transformations

Computer Graphics. Bing-Yu Chen National Taiwan University

COS340A Assignment 1 I Pillemer Student# March 25 th 2007 p1/15

12. Selection. - The objects selected are specified by hit records in the selection buffer. E.R. Bachmann & P.L. McDowell MV 4202 Page 1 of 13

CS559: Computer Graphics. Lecture 12: OpenGL Li Zhang Spring 2008

OpenGL Tutorial. Ceng 477 Introduction to Computer Graphics

Introduction to OpenGL

Image Rendering. Rendering can be divided into three sub-problems. Image Formation The hidden surface problem visibility determination steps

3D Graphics and API with OpenGL

Transformation, Input and Interaction. Hanyang University

Modeling with Transformations

Transcription:

CSC 307 1.0 Graphics Programming Department of Statistics and Computer Science

Graphics Programming OpenGL 3D Drawing 2

3D Graphics Projections Getting 3D to 2D 3D scene 2D image 3

Projections Orthographic Projection Perspective Projection Orthographic Perspective 4

Orthographic Projections glortho ( double left, double right, double bottom, double top, double near, double far); Top Toward the viewport Left Right Bottom Viewing Volume Near Far 5

Perspective Projection gluperspective ( double angle, double aspect, double near, double far); aspect = w/h w Observer h map map zoom in zoom out 6

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

Object Composition Use Transformation glpushmatrix ( ); glpopmatrix ( ); Save the current transformation state and then restore it after some objects have been placed 8

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

Hidden Surface Removal Enable Depth Testing glenable (GL_DEPTH_TEST); Hidden Surface 10

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

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 12

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

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

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 15

Example After 4 interations 16

triangle code void triangle( point a, point b, point c) { // right-hand rule glbegin(gl_polygon); glvertex3fv(a); glvertex3fv(b); glvertex3fv(c); glend(); } 17

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)); } 18

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); } 19

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 20

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 21

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

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

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(); 24