Projections. Viewports Windows can have separate viewports void glViewport(GLint x, GLint y, GLsizei width, GLsizei height ) x, y - Specify the lower.

Slides:



Advertisements
Similar presentations
The View Frustum and the Camera Lecture 19 Fri, Oct 10, 2003.
Advertisements

© 2004, Tom Duff and George Ledin Jr1 Lectures OpenGL Introduction By Tom Duff Pixar Animation Studios Emeryville, California and George Ledin Jr Sonoma.
OpenGL Basics Donghui Han. Assignment Grading Visual Studio Glut Files of four types needed: – Source code:.cpp,.h – Executable file:.exe (build in release.
Viewing and Transformation
Viewing and Projections
CS 352: Computer Graphics Chapter 5: Viewing. Interactive Computer GraphicsChapter Overview Specifying the viewpoint Specifying the projection Types.
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.
Sierpinski Gasket Program
OpenGL (II). How to Draw a 3-D object on Screen?
CS 4731: Computer Graphics Lecture 11: 3D Viewing Emmanuel Agu.
Modeling and Viewing Modeling
Noggin (BYU Students, SIGGRAPH 2006). Introduction to OpenGL Programming Rick Skarbez, Instructor COMP 575 September 11, 2007.
Development of Interactive 3D Virtual World Applications
CS 470 Introduction to Computer Graphics Basic 3D in OpenGL.
Introduction to 3D viewing 3D is just like taking a photograph!
CAP 4703 Computer Graphic Methods Prof. Roy Levow Lecture 2.
3D coordinate systems X Y Z Right-Hand Coordinate System X Y Z Left-Hand Coordinate System OpenGL uses this! Direct3D uses this!
Computer Graphics, KKU. Lecture 131 Transformation and Viewing in OpenGL.
The Viewing Pipeline (Chapter 4) 5/26/ Overview OpenGL viewing pipeline: OpenGL viewing pipeline: – Modelview matrix – Projection matrix Parallel.
Geometric transformations The Pipeline
CS559: Computer Graphics Lecture 9: Projection Li Zhang Spring 2008.
CSE 470: Computer Graphics. 10/15/ Defining a Vertex A 2D vertex: glVertex2f(GLfloat x, GLfloat y); 2D vertexfloating pointopenGL parameter type.
Graphics Systems and OpenGL. Business of Generating Images Images are made up of pixels.
1 Figures are extracted from Angel's book (ISBN x) The Human Visual System vs The Pinhole camera Human Visual System Visible Spectrum Pinhole.
Introduction to GL Geb Thomas. Example Code int main(int argc, char **argv) { glutInit(&argc, argv); glutInitDisplayMode ( GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH);
Viewing With OpenGL Courtesy of Drs. Carol O’Sullivan / Yann Morvan Trinity College Dublin.
CAP 4703 Computer Graphic Methods Prof. Roy Levow Chapter 5.
Computer Graphics Bing-Yu Chen National Taiwan University.
CH8 Frame Buffer Object 1. Introduction Name OpenGL :Frame Buffer Object DirectX:Render Target Usage Render to Texture 2.
OpenGL The Viewing Pipeline: Definition: a series of operations that are applied to the OpenGL matrices, in order to create a 2D representation from 3D.
Draw a Simple Object. Pixel pipeline Vertex pipeline Course Map Transformation & Lighting Primitive assembly Viewport culling & clipping Texture blending.
OpenGL Viewing and Modeling Transformation Geb Thomas Adapted from the OpenGL Programming Guidethe OpenGL Programming Guide.
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.
The Camera Analogy ► Set up your tripod and point the camera at the scene (viewing transformation) ► Arrange the scene to be photographed into the desired.
Chapters 5 2 March Classical & Computer Viewing Same elements –objects –viewer –projectors –projection plane.
CGGM Lab. Tan-Chi Ho 2001 Viewing and Transformation.
Viewing Korea Univ. Computer Graphics Lab. Hong, Jin Kyung.
Color spaces. Draw Buffers Color models. Mathmatical Protocols for defining colors with numbers  RGB Red, Green, Blue  HSV Hue, Saturation, Value(Brightness)‏
Chap 3 Viewing and Transformation
1 Programming with OpenGL Part 2: Complete Programs.
OpenGL API 2D Graphic Primitives Angel Angel: Interactive Computer Graphics5E © Addison-Wesley
CS559: Computer Graphics Lecture 12: OpenGL - Transformation Li Zhang Spring 2008.
CS559: Computer Graphics Lecture 12: OpenGL: ModelView Li Zhang Spring 2010.
Introduction to Graphics Programming. Graphics API.
Graphics Graphics Korea University kucg.korea.ac.kr Graphics Programming 고려대학교 컴퓨터 그래픽스 연구실.
Implement of transformation,projection, viewing Hanyang University Jungsik Park.
Computer Graphics I, Fall Programming with OpenGL Part 2: Complete Programs.
OpenGL LAB III.
CS380 LAB II OpenGL Donghyuk Kim Reference1. [OpenGL course slides by Rasmus Stenholt] Reference2. [
Computer Graphics Lecture 41 Viewing Using OpenGL Taqdees A. Siddiqi
CS 490: Computer Graphics Chapter 5: Viewing. Interactive Computer GraphicsChapter Overview Specifying the viewpoint Specifying the projection Types.
CSC Graphics Programming
Viewing 고려대학교 컴퓨터 그래픽스 연구실 kucg.korea.ac.kr.
Courtesy of Drs. Carol O’Sullivan / Yann Morvan Trinity College Dublin
“Computer Science is no more about computers than astronomy is about telescopes.” Professor Edsger Dijkstra.
Projection v VP u VPN n.
Advanced Graphics Algorithms Ying Zhu Georgia State University
Lecture 08 and 09 View & Projection
CSC4820/6820 Computer Graphics Algorithms Ying Zhu Georgia State University View & Projection.
Computer Graphics, KKU. Lecture 13
Introduction to OpenGL
LAB 5 Drawing Objects Lab 5 Drawing Objects.
Type of View Perspective View COP(Center of Plane) Diminution of size
OpenGL program.
Computer Graphics 3Practical Lesson
Chapter 3 Viewing.
Projection v VP u VPN n.
Presentation transcript:

Projections

Viewports Windows can have separate viewports void glViewport(GLint x, GLint y, GLsizei width, GLsizei height ) x, y - Specify the lower left corner of the viewport rectangle, in pixels width, height - Specify the width and height of the viewport

Viewport Example Create two viewports in one window w=Window width h=Window height //Left Viewport glViewport(0.0,0.0,w/2.0,h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(-w/4.0,w/4.0,-h/2.0,h/2.0,-1.0,1.0); glMatrixMode(GL_MODELVIEW); //Draw the scene drawScene(); //Right Viewport glViewport(w/2.0,0.0,w/2.0,h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(-w/4.0,w/4.0,-h/2.0,h/2.0,-1.0,1.0); glMatrixMode(GL_MODELVIEW); //Draw the scene drawScene();

Projections Flattening a 3D virtual scene by projecting it onto a plane The projected geometry is next rasterized into fragments

View Frustum Frustum  A portion of a solid, normally a cone or pyramid, which lies between two parallel planes cutting the solid.  We are interested in Square frusta  Used to define the viewing volume

Near and Far Clipping Planes Near and Far clipping planes  “Clip out” geometry outside of them This Geometry is not rendered

Orthographic Projection Parallel projection where the view direction is orthogonal to the projection plane Projected Objects do not get bigger/smaller when moved away/toward the viewer

Orthographic Example //Left Viewport glViewport(0.0,0.0,w,h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(-w/4.0,w/4.0,-h/2.0,h/2.0,0.0,1.0); //Draw the scene glMatrixMode(GL_MODELVIEW); drawScene(); void glOrtho(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble nearVal, GLdouble farVal);

Perspective Projection Perspective projections have a viewpoint that is a finite distance from the projection plane Objects get smaller as distance from viewer gets larger

Perspective Example void glFrustum(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble nearVal, GLdouble farVal);

Perspective Example Defined in “GL/glu.h” void gluPerspective(GLdoublefovy, GLdoubleaspect, GLdoublezNear, GLdoublezFar )‏ //Left Viewport glViewport(0.0,0.0,w,h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(45.0,w/h,1.0,20.0); //Draw the scene glMatrixMode(GL_MODELVIEW); drawScene();

Model -> View -> Projection Modeling Transformation  Used to position geometry in the scene Viewing Transformation  Used to position and orient the view of a scene Projection Transformation  Used to project a scene onto a viewing plane glVertex Modeling Transformatio n View Transformatio n Projection Transformatio n

Setting up the view Used to position and orient the view of a scene Viewing transformation can be thought of as a camera viewing the scene  Order of transformations that setup a camera Position Orientation

gluLookAt Defined in void gluLookAt( GLdouble eyeX, GLdouble eyeY, GLdouble eyeZ, GLdouble centerX, GLdouble centerY, GLdouble centerZ, GLdouble upX, GLdouble upY, GLdouble upZ )‏ eyeX,eyeY, eyeZ  Specifies the position of the eye point. centerX, centerY, centerZ  Specifies the position of the reference point. upX, upY, upZ  Specifies the direction of the up vector.

gluLookAt continued eyeX,eyeY, eyeZ  Specifies the position of the eye point. centerX, centerY, centerZ  Specifies the position of the reference point. upX, upY, upZ  Specifies the direction of the up vector.

Depth Buffer Additional component of the frame buffer Holds the depth value of each fragment Needs to be cleared like color buffer

Setting up Depth Test OpenGL disables depth test by default  glEnable(GL_DEPTH_TEST); We have an additional part of the frame buffer that needs clearing  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); We need a drawing context that has a depth buffer  glutInitDisplayMode(GLUT_RGBA | GLUT_SINGLE | GLUT_DEPTH);

Depth Test Example void display(void)‏ { glEnable(GL_DEPTH_TEST); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //Setup state to start drawing glBegin(GL_TRIANGLES); glVertex3i(-100, 100, 1); glVertex3i(0, 100, 1); glVertex3i(-50, 50, 1); glVertex3i(50, 50, 3); glVertex3i(100, 100, 3); glVertex3i(75, 20, 3); glEnd(); } int main(int argc, char **argv)‏ { glutInit(&argc, argv); glutInitDisplayMode(GLUT_RGBA | GLUT_SINGLE | GLUT_DEPTH); glutCreateWindow("Depth Example"); glutDisplayFunc(display); glutReshapeFunc(reshape); glutMainLoop(); return 0; } Display code GLUT initialization