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

Similar documents
Computer Graphics. Chapter 10 Three-Dimensional Viewing

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

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

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

Geometry: Outline. Projections. Orthographic Perspective

Precept 2 Aleksey Boyko February 18, 2011

OpenGL Transformations

Viewing Transformation

Advanced Computer Graphics (CS & SE )

Lecture 4 of 41. Lab 1a: OpenGL Basics

1 (Practice 1) Introduction to OpenGL

Introduction to OpenGL Transformations, Viewing and Lighting. Ali Bigdelou

Notes on Assignment. Notes on Assignment. Notes on Assignment. Notes on Assignment

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

Fachhochschule Regensburg, Germany, February 15, 2017

The View Frustum. Lecture 9 Sections 2.6, 5.1, 5.2. Robb T. Koether. Hampden-Sydney College. Wed, Sep 14, 2011

Lecture 4. Viewing, Projection and Viewport Transformations

CIS 636 Interactive Computer Graphics CIS 736 Computer Graphics Spring 2011

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

GRAFIKA KOMPUTER. ~ M. Ali Fauzi

2D and 3D Viewing Basics

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

Fundamental Types of Viewing

Books, OpenGL, GLUT, GLUI, CUDA, OpenCL, OpenCV, PointClouds, and G3D

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

CS354 Computer Graphics Viewing and Modeling

CSE 167: Lecture #4: Vertex Transformation. Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2012

Transformation, Input and Interaction. Hanyang University

Lectures OpenGL Introduction

Transformation Pipeline

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

CS 4204 Computer Graphics

Computer Graphics. Bing-Yu Chen National Taiwan University

Books, OpenGL, GLUT, CUDA, OpenCL, OpenCV, PointClouds, G3D, and Qt

Prof. Feng Liu. Fall /19/2016

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

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

Using OpenGL with CUDA

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

Lecture 9 Sections 2.6, 5.1, 5.2. Wed, Sep 16, 2009

蔡侑庭 (Yu-Ting Tsai) National Chiao Tung University, Taiwan. Prof. Wen-Chieh Lin s CG Slides OpenGL 2.1 Specification

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

Computer Viewing Computer Graphics I, Fall 2008

Projection: Mapping 3-D to 2-D. Orthographic Projection. The Canonical Camera Configuration. Perspective Projection

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

Viewing and Projection

Evening s Goals. Mathematical Transformations. Discuss the mathematical transformations that are utilized for computer graphics

Computer Graphics. Basic 3D Programming. Contents

Introduction to OpenGL

3.1 Viewing and Projection

CSE 167: Introduction to Computer Graphics Lecture #4: Vertex Transformation

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

Today s class. Viewing transformation Menus Mandelbrot set and pixel drawing. Informationsteknologi

COMP3421. Introduction to 3D Graphics

COMS 4160: Problems on Transformations and OpenGL

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

Computer Graphics. OpenGL

Overview of Projections: From a 3D world to a 2D screen.

MORE OPENGL. Pramook Khungurn CS 4621, Fall 2011

Computer Graphics. Chapter 7 2D Geometric Transformations

Abel J. P. Gomes LAB. 1. INTRODUCTION TO OpenGL

Transformations (Rotations with Quaternions) October 24, 2005

Order of Transformations

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

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

Three-Dimensional Graphics III. Guoying Zhao 1 / 67

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

COMP3421. Introduction to 3D Graphics

Viewing and Projection

Introduction to MS Visual C/C++

CS 428: Fall Introduction to. Viewing and projective transformations. Andrew Nealen, Rutgers, /23/2009 1

An Interactive Introduction to OpenGL Programming

Programming using OpenGL: A first Introduction

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

Modeling Transform. Chapter 4 Geometric Transformations. Overview. Instancing. Specify transformation for objects 李同益

COMP3421. Introduction to 3D Graphics

CSE 167: Introduction to Computer Graphics Lecture #5: Projection. Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2017

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

Computer Graphics (Basic OpenGL)

CS 543: Computer Graphics. Projection

Graphics and Visualization

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

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

Viewing COMPSCI 464. Image Credits: Encarta and

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

Android and OpenGL. Android Smartphone Programming. Matthias Keil. University of Freiburg

Graphics Programming

CSCI 4620/8626. The 2D Viewing Pipeline

CS 4204 Computer Graphics

CSC 470 Computer Graphics. Three Dimensional Viewing

Lecture 3 Sections 2.2, 4.4. Mon, Aug 31, 2009

Using OpenGL & GLUT in Visual Studio.NET 2003

Computer graphics MN1

part 3 Martin Samuelčík Room I4

CSC 470 Computer Graphics

Wire-Frame 3D Graphics Accelerator IP Core. C Library Specification

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

3D Graphics and API with OpenGL

Today. Rendering pipeline. Rendering pipeline. Object vs. Image order. Rendering engine Rendering engine (jtrt) Computergrafik. Rendering pipeline

Announcements. Submitting Programs Upload source and executable(s) (Windows or Mac) to digital dropbox on Blackboard

Transcription:

Overview (1): Getting Started Setting up OpenGL/GLUT on Windows/Visual Studio COSC 4431/5331 Computer Graphics Thursday January 22, 2004 Overview Introduction Camera analogy Matrix operations and OpenGL Transformation Details transformation Projection transformation Viewport transformation 2 Getting Started (1): Installing GLUT Getting Started Download GLUT from Nate Robin s web site http://www.xmission.com/~nate/glut.html Download: glut-3.7.6-bin.zip (117 KB) Three files of interest: glut32.dll, glut32.lib & glut.h Place them in following directories: glut32.dll to Windows\System, glut32.lib to \VC98\lib, glut.h to \VC98\include\GL. 3 VC98 directory is in the Visual Studio directory: C:\Program Files\Microsoft Visual Studio\VC98 4 Getting Started (2): Microsoft Windows (XP) & Visual Studio (C++) OpenGL included in newer versions of Windows OS Compiling and linking After creating project From menu bar, go to Project -> Settings -> Link Append the following string to the existing Objects/Library Modules string opengl32.lib glu32.lib glut32.lib Build & execute program Getting Started (3): Include Libraries For all OpenGL applications, include gl.h in every file Almost all OpenGL applications use GLU, so include glu.h as well If using Glut, you also need glut.h OpenGL source file typically begins with #include <GL/gl.h> #include <GL/glu.h> #include <GL/glut.h> But glut.h includes the gl.h and glu.h so really only glut.h is needed! 5 6

Getting Started (4): Setting Up Project in Visual Studio/C++ 1. Load Visual Studio/C++ 2. File->New a dialog box will appear - choose "Win 32 Console Application", give the project a name and press "OK 3. Another dialog box will then appear: choose "A Simple Application" and click "Finish 4. Your new project workspace will now be available and on the screen - add the three libraries as previously described 5. All necessary files etc. will be generated in addition to the file containing main method this is entry point Overview 7 8 Introduction to (1): Summary of Transformations Position viewing volume in the world Modeling Position models in the real world Projection Determine shape of viewing volume Viewport Draw final image to display window Introduction to (2): Camera Analogy Set-up tripod Point camera at the scene Modeling Arrange the scene to be photographed Projection Choose desired camera lens and zoom Viewport Determine how large final photograph will be 9 10 Introduction to (3): Modeling Introduction to (4): Stages of Vertex Transformations 4 x 4 matrix M is used to specify viewing, modeling and projection transformations Transformation is accomplished by multiplying coordinates of each vertex v in scene by M? v = Mv Projection Viewport 11 12

Introduction to (5): Transformation Matrices Homogenous coordinates e.g. [x, y, z, w] w is typically equal to 1 Modelview Matrix Combined viewing and modeling transformations Convert object coordinates in world to (viewer) eye coordinates Introduction to (6): Transformation Matrices (cont ) Ordering of Transformations is important Rotation followed by translation is not necessarily equivalent to translation followed by rotation! Matrix multiplication: ML not always equal to LM 13 14 Introduction to (7): Current Matrix State Variable Single matrix used to perform transformations Modelview, projection & texture transformations Transformations are applied to current matrix Vertices multiplied by current matrix Warning? Transformations are accumulative Typically need to reset current matrix prior to performing transformation Introduction to (8): Current Matrix (cont ) Can specify which of the three matrices becomes the current matrix using glmatrixmode() matrix? glmatrixmode(matrix) GL_MODELVIEW, GL_PROJECTION,GL_TEXTURE glmatrixmode(gl_modelview) glmatrixmode(gl_projection) glmatrixmode(gl_texture) glloadidentity() 15 16 Introduction to (9): Notes Regarding Transformations Window Coordinates Obtained after applying the viewport transformation Coordinates relative to display window Details Transformations Assumptions Requires some knowledge of linear algebra (matrices) 17 18

Transformations (1): Transformation Changes direction and orientation of viewpoint or eye Default location Origin (0,0,0) Pointing (looking) down z axis Model Transformations (2): Transformation (cont ) Several ways to change viewing position/direction 1. Use modeling transformation commands: glrotate() and gltranslate() 2. GLU routine: glulookat() 3. Create your own utility routine which encapsulates rotations and translations Camera (eye) 19 20 Transformations (3): Transformations in OpenGL Translation: gltranslate(x, y, z) Multiplies current matrix that moves object by the given x,y,z values Rotation: glrotation(angle, x, y, z) Multiplies current matrix that rotates object in counter-clockwise direction about ray from origin through x,y,z Scale: glscale(x, y, z) Stretches, shrinks or reflects object along axis Transformations (4): Using Modeling Transformations Rather than moving camera (or viewer, eye), move the model while leaving camera at default position Same effect as it s the position of camera relative to model that s of interest e.g. rather than moving camera backwards, 5 units, from objects (model), move objects forward from camera by 5 units gltranslate(0.0, 0.0, -5.0) Remember? Forward is down z axis! 21 22 Transformations (5): Using Modeling Transformations -Illustration Original camera position Transformations (6): glulookat() Three sets of arguments (all of type GLdouble): Eye coordinates (x,y,z) Point to be viewed along line of sight (x,y,z) Orientation vector which direction is UP (x,y,z) Move object forward Along z-axis Move camera backward along z-axis New camera position 23 glulookat(eyex, eyey, eyez, centerx, centery, centerz, upx, upy, upz); Default Settings Eye (camera) at origin Looking down z axis, positive y-axis straight up 24

Transformations (7): glulookat() Examples volume volume Projection Transformations (1): Projection Transformations Purpose? define a viewing volume which: 1. Determines how object is projected onto screen? either perspective or orthographic projection 2. Defines which objects or portions of objects are clipped (removed) from final image Default glulookat(4,2,1, 2,4,-3, 2,2,-1); 25 26 Projection Transformations (2): Perspective Projection volume is a frustum: Truncated pyramid with top cut off Six planes: left, right, bottom, top, near, far Pyramid apex & viewpoint Frustum Projection Transformations (3): Perspective Projection (cont ) Objects falling within frustum are projected towards viewpoint (pyramid apex) Objects closer to view point occupy larger amount of viewing volume Foreshortening? the farther an object from camera, the small it appears in final image Similar to how our eyes work Two ways to set up in OpenGL 1. glufrustum() 2. glupersepctive() 27 28 Projection Transformations (4): glfrustum() glfrustum(left, right, bottom, top, near, far); volume defined by coordinates: (left, bottom, -near)? lower left (x,y,z) coordinates (right, top, -far)? upper right (x,y,z) coordinates Projection Transformations (5): gluperspective() glfrustum(fovy, aspect, near, far); fovy? Field of view angle in the yz plane [0 180 o ] aspect? Aspect ratio (width/height) near, far? distance to near and far planes from viewpoint down z-axis!! 29 30

Projection Transformations (6): gluperspective() Graphical Illustration Projection Transformations (7): Orthographic Projection volume is a rectangular parallelepid (a box) Size of viewing volume doesn t change from one end to other Distance from camera is irrelevant to size of projected object Used for blueprint drawings, CAD and applications where object dimensions are important Two ways to set up in OpenGL 1. glortho() 2. gluortho2d() 31 32 Projection Transformations (8): glortho() Projection Transformations (9): glortho() Graphical Illustration glortho(left, right, bottom, top, near, far); volume defined by coordinates: (left, bottom, -near) & (right, top, -near)? are on near clipping plane & mapped to lower left and upper right viewport window respectively (left, bottom, -far) & (right, top, -far)? are on far clipping plane & also mapped to lower left and upper right viewport window respectively 33 34 Projection Transformations (10): gluortho2d() glortho(left, right, bottom, top); Use with 2D scene onto a 2D screen only! Coordinates of rectangular clipping region Left, right, bottom, top Viewport Transformations (1): Chooses Size of Final Image on Screen Defines the rectangle in the window which final image is placed glviewport(x, y, width, height); Integer argument types (Glint) x, y? lower left corner of viewport width, height? size of the viewport rectangle Default: (0, 0, winwidth, winheight) e.g. entire window 35 36

Viewport Transformations (2): Some Notes Aspect ratio of viewport should be equal to aspect ratio of viewing volume otherwise final image will be distorted! Remember? window re-sizing may require resetting of viewport! Viewport Transformations (3): Distortion Example Normal (square window 400 x 400) gluperspective(fovy, 1.0, near, far); glviewport(0, 0, 400, 400); Distorted View: Resized window to a non-equilateral rectangular viewport, 400 x 200 Projection remains the same (un-changed) gluperspective(fovy, 1.0, near, far); glviewport(0, 0, 400, 200); 37 38 Viewport Transformations (4): Putting it All Together (1): Notes Regarding Transformations Modelview transformations typically specified when drawing/re-drawing the scene Display callback function! For example: Corrected View: Modify aspect ratio to match viewport gluperspective(fovy, 2.0, near, far); void display(void) { } glclear (GL_COLOR_BUFFER_BIT); glcolor3f (1.0, 1.0, 1.0); glloadidentity (); /* clear the matrix */ /* viewing transformation */ glulookat (0.0, 0.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0); glscalef (1.0, 2.0, 1.0); /* modeling transformation */ glutwirecube (1.0); glflush (); glviewport (0, 0, 400, 200); 39 40 Putting it All Together (2): Notes Regarding Transformations Projection and viewport typically specified when window is initially created/re-seized etc Window re-shape callback function! For example: void reshape (int w, int h) { glviewport (0, 0, (GLsizei) w, (GLsizei) h); glmatrixmode (GL_PROJECTION); glloadidentity (); glfrustum (-1.0, 1.0, -1.0, 1.0, 1.5, 20.0); glmatrixmode (GL_MODELVIEW); } Putting it All Together (3): Final Notes Many problems you encounter are probably due to incorrect viewing set-up Ensure objects (model) are within viewing volume remember, near/far planes are down z axis For example: if near and far are 1 and 3 respectively, make sure objects are within 1 and 3 as well Try temporarily setting near and far planes to 0.0001 and 100000 41 42