Computação Gráfica. Computer Graphics Engenharia Informática (11569) 3º ano, 2º semestre. Chap. 4 Windows and Viewports

Similar documents
CS475/CS675 - Computer Graphics. OpenGL Drawing

CSE 167: Introduction to Computer Graphics Lecture #7: GLSL. Jürgen P. Schulze, Ph.D. University of California, San Diego Spring Quarter 2016

COMP371 COMPUTER GRAPHICS

CS 548: COMPUTER GRAPHICS INTRODUCTION TO OPENGL AND GLUT SPRING 2015 DR. MICHAEL J. REALE

CS 450: COMPUTER GRAPHICS REVIEW: STATE, ATTRIBUTES, AND OBJECTS SPRING 2015 DR. MICHAEL J. REALE

Tutorial 04. Harshavardhan Kode. September 14, 2015

Modern OpenGL Guide. Alexander Overvoorde. May Introduction 3 Credits... 3 Prerequisites... 4

CSE 167. Discussion 03 ft. Glynn 10/16/2017

OpenGL pipeline Evolution and OpenGL Shading Language (GLSL) Part 2/3 Vertex and Fragment Shaders

Rendering Objects. Need to transform all geometry then

CS 432 Interactive Computer Graphics

COSC342: Computer Graphics

CSE 167: Introduction to Computer Graphics Lecture #5: Visibility, OpenGL

Geometry Shaders. And how to use them

Discussion 3. PPM loading Texture rendering in OpenGL

Building Models. CS 537 Interactive Computer Graphics Prof. David E. Breen Department of Computer Science

CS 432 Interactive Computer Graphics

Comp 410/510 Computer Graphics Spring Programming with OpenGL Part 2: First Program

CS452/552; EE465/505. Image Processing Frame Buffer Objects

Graphics Programming. Computer Graphics, VT 2016 Lecture 2, Chapter 2. Fredrik Nysjö Centre for Image analysis Uppsala University

Computer Graphics (CS 543) Lecture 1 (Part 2): Introduction to OpenGL/GLUT (Part 1)

gvirtualxray Tutorial 01: Creating a Window and an OpenGL Context Using GLUT

INTRODUCTION TO OPENGL PIPELINE

Best practices for effective OpenGL programming. Dan Omachi OpenGL Development Engineer

OpenGL refresher. Advanced Computer Graphics 2012

Information Coding / Computer Graphics, ISY, LiTH. OpenGL! ! where it fits!! what it contains!! how you work with it 11(40)

Introduction to Computer Graphics with WebGL

From system point of view, a graphics application handles the user input, changes the internal state, called the virtual world by modeling or

Shaders. Slide credit to Prof. Zwicker

Table of Contents

The Projection Matrix

Announcement. Homework 1 has been posted in dropbox and course website. Due: 1:15 pm, Monday, September 12

Introductory Seminar

CPSC 436D Video Game Programming

Comp 410/510 Computer Graphics Spring Programming with OpenGL Part 4: Three Dimensions

2/3/16. Interaction. Triangles (Clarification) Choice of Programming Language. Buffer Objects. The CPU-GPU bus. CSCI 420 Computer Graphics Lecture 3

Tutorial 1: Your First Triangle!

Shader Programs. Lecture 30 Subsections 2.8.2, Robb T. Koether. Hampden-Sydney College. Wed, Nov 16, 2011

Computer Graphics Seminar

The OpenGL Mathematics (GLM) Library

Interaction. CSCI 420 Computer Graphics Lecture 3

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

Learn OpenGL. An offline transcript of learnopengl.com. Joey de Vries

compatibility mode core mode

Overview. By end of the week:

CS 548: COMPUTER GRAPHICS PORTRAIT OF AN OPENGL PROGRAM SPRING 2015 DR. MICHAEL J. REALE

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

Comp 410/510 Computer Graphics Spring Programming with OpenGL Part 3: Shaders

Computer graphics Labs: OpenGL (2/2) Vertex Shaders and Fragment Shader

CGT520 Lighting. Lighting. T-vertices. Normal vector. Color of an object can be specified 1) Explicitly as a color buffer

The OpenGL Mathematics (GLM) Library. What is GLM?

Shaders. Introduction. OpenGL Grows via Extensions. OpenGL Extensions. OpenGL 2.0 Added Shaders. Shaders Enable Many New Effects

CS452/552; EE465/505. Image Formation

Starting out with OpenGL ES 3.0. Jon Kirkham, Senior Software Engineer, ARM

3d Programming I. Dr Anton Gerdelan

CSE 167: Introduction to Computer Graphics Lecture #5: Illumination Model

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

CS380: Computer Graphics Screen Space & World Space. Sung-Eui Yoon ( 윤성의 ) Course URL:

OUTLINE. Learn the basic design of a graphics system Introduce pipeline architecture Examine software components for a graphics system

Computer Graphics CS 543 Lecture 4 (Part 2) Building 3D Models (Part 2)

Copyright Khronos Group 2012 Page 1. Teaching GL. Dave Shreiner Director, Graphics and GPU Computing, ARM 1 December 2012

Lab 2-3D Transformations and Vertex Shaders

[175 points] The purpose of this assignment is to give you practice with shaders in OpenGL.

This Lecture. Introduction to OpenGL. Outline. Why OpenGL? Programmer s View. Foundations of Computer Graphics

Computer Graphics (4731) Lecture 4: 2D Graphics Systems (Drawing Polylines, tiling, & Aspect Ratio)

CSE 4431/ M Advanced Topics in 3D Computer Graphics. TA: Margarita Vinnikov

Computer Graphics (CS 4731) & 2D Graphics Systems

GLSL Overview: Creating a Program

CS770/870 Spring 2017 Open GL Shader Language GLSL

CS770/870 Spring 2017 Open GL Shader Language GLSL

Today s Agenda. Basic design of a graphics system. Introduction to OpenGL

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

The Projection Matrix

Computer Graphics (CS 4731) OpenGL/GLUT(Part 1)

Computer Graphics (CS 543) Lecture 3b: Shader Setup & GLSL Introduction

CENG 477 Introduction to Computer Graphics. Graphics Hardware and OpenGL

CS452/552; EE465/505. Review & Examples

To Do. Demo: Surreal (now 15+ years ago) This Lecture. Outline. Computer Graphics. CSE 167 [Win 19], Lecture 6: OpenGL 1 Ravi Ramamoorthi

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

the gamedesigninitiative at cornell university Lecture 6 Scene Graphs

An Overview GLUT GLSL GLEW

EECS 487: Interactive Computer Graphics

Programming with OpenGL Part 5: More GLSL. Ed Angel Professor Emeritus of Computer Science University of New Mexico

Programming with OpenGL Complete Programs Objectives Build a complete first program

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

OUTLINE. Implementing Texturing What Can Go Wrong and How to Fix It Mipmapping Filtering Perspective Correction

GLM. Mike Bailey. What is GLM?

Rasterization Overview

CS 543 Lecture 1 (Part 3) Prof Emmanuel Agu. Computer Science Dept. Worcester Polytechnic Institute (WPI)

The Graphics Pipeline

OpenGL Performances and Flexibility. Visual Computing Laboratory ISTI CNR, Italy

WebGL A quick introduction. J. Madeira V. 0.2 September 2017

CS 591B Lecture 9: The OpenGL Rendering Pipeline

CGT520 Transformations

Advanced Graphics. OpenGL and Shaders I. Alex Benton, University of Cambridge Supported in part by Google UK, Ltd

Computer Graphics (CS 4731) OpenGL/GLUT (Part 2)

Computergraphics Exercise 15/ Shading & Texturing

the gamedesigninitiative at cornell university Lecture 12 Scene Graphs

8 Three-Dimensional Object Representations. Chapter 8. Three-Dimensional Object Representations. Department of Computer Science and Engineering 8-1

Draw the basic Geometry Objects. Hanyang University

Transcription:

Computação Gráfica Computer Graphics Engenharia Informática (11569) 3º ano, 2º semestre Chap. 4 Windows and Viewports

Outline : Basic definitions in 2D: Global coordinates (scene domain): continuous domain Screen coordinates (image domain): discrete domain Window-viewport transformation Window-viewport transformation in OpenGL Geometric transformations in OpenGL/GLM Graphics pipeline (or rendering pipeline) Mapping a scene into various viewports Avoiding image distortion OpenGL examples

Definitions image domain (screen) screen window scene window viewport Image coordinate system (or image domain) - is associated with a screen window -screen space where the raster image is displayed (e.g., 500x500 pixels) - a screen window may comprise various viewports, which may overlap - the image domain is discrete (pixels) Viewport (image sub-domain) - part of the screen window where the image is rendered

Window-viewport transformation We need an automated process: To map a scene window (world coordinates) into a viewport (screen coordinates), the so-called window-viewport transformation. Thus, in principle, the same scene can be mapped into different viewports, no matter they belong to the same screen window or not. screen window scene window viewport 4

Window-viewport transformation - This operation is performed in na automated manner by the graphics system. - It involves 3 geometric transformations: translation in global coordinates, scalling, and translation in screen coordinates. v y (x max,y max ) y v (u max,v max ) (u min,v min ) (x min,y min ) x x u u window in global or world coordinates (scene domain) window translated to the origin viewport in image coordinates viewport translated to its pre-defined position 5

Window-viewport transformation: matrix representation v y (x max,y max ) y v (u max,v max ) (u min,v min ) (x min,y min ) x x u u

Window-viewport transformation: in more detail v y (x max,y max ) Keeping the ratio in mapping (x,y) to (u,v) (u max,v max ) (u min,v min ) (x min,y min ) x translation scaling translation u x min x x max u min u u max y max v max y y min 7 v v min

Window-viewport transformation: example y (x max,y max ) v (u max,v max ) (x min,y min ) x (u min,v min ) u window(10.0,5.0,40.0,30.0) viewport(100,50,250,300)

Window-viewport transformation: GLM and OpenGL glm::ortho(left, right, bottom, top) It sets up the 2D scene domain. It is defined by two vertical lines (left and right) and two horizontal lines (bottom and top) Default scene domain is (-1,1,-1,1). It defines the orthogonal projection matrix in 2D. Also, it defines the window-viewport transformation in an automated manner. glviewport(x, y, width, height) It defines the viewport in the screen window, where (x,y) represent its bottom-left corner, while (width,height) its size. By default, the viewport spans the entire domain of screen window. There may exist various viewports inside the screen window, which may eventually overlap.

OpenGL graphics pipeline eye coordinates clipping coordinates viewport coordinates Vertex Modelview Matrix Projection Matrix Viewport GL_MODELVIEW mode glm::translate() glm::rotate() glm::scale() gluniformmatrix*() glm::lookat() GL_PROJECTION mode glm::ortho() glm::frustum() glm::perspective() glviewport()

Example in OpenGL (using a scene domain and a default viewport) n n In this example, we do not use the default scene domain (-1,1,-1,1); that is, the scene domain is given by glm::ortho(xmin,xmax,ymin,ymax) The function glviewport(x, y, width, height) is not used explicitly, so the default viewport spans the entire extent of the screen window.

P01, Exercise 3: Graphics application to draw a house (3 triangles) // Include standard headers #include <stdio.h> #include <stdlib.h> // Include GLEW #include <GL/glew.h> // Include GLFW #include <GLFW/glfw3.h> GLFWwindow* window; // GLM header file #include <glm/glm.hpp> using namespace glm; // shaders header file #include <common/shader.hpp> // Vertex array object (VAO) GLuint VertexArrayID; // Vertex buffer object (VBO) GLuint vertexbuffer; // color buffer object (CBO) GLuint colorbuffer; // GLSL program from the shaders GLuint programid; // function prototypes void transferdatatogpumemory(void); void cleanupdatafromgpu(); void draw();

P01, Exercise 3: Graphics application to draw a house (3 triangles) int main( void ) { // Initialise GLFW glfwinit(); // Setting up OpenGL version and the like glfwwindowhint(glfw_samples, 4); glfwwindowhint(glfw_context_version_major, 3); glfwwindowhint(glfw_context_version_minor, 3); glfwwindowhint(glfw_opengl_forward_compat, GL_TRUE); // To make MacOS happy; should not be needed glfwwindowhint(glfw_opengl_profile, GLFW_OPENGL_CORE_PROFILE); // Open a window window = glfwcreatewindow( 1024, 768, House in Red and Green", NULL, NULL); // Create window context glfwmakecontextcurrent(window); // Initialize GLEW glewexperimental = true; // Needed for core profile glewinit(); // Ensure we can capture the escape key being pressed below glfwsetinputmode(window, GLFW_STICKY_KEYS, GL_TRUE); // Dark blue background glclearcolor(0.0f, 0.0f, 0.4f, 0.0f); // transfer my data (vertices, colors, and shaders) to GPU side transferdatatogpumemory(); // render scene for each frame } do{ // drawing callback draw(); // Swap buffers glfwswapbuffers(window); // looking for input events glfwpollevents(); } while (glfwgetkey(window, GLFW_KEY_ESCAPE )!= GLFW_PRESS && glfwwindowshouldclose(window) == 0 ); // Cleanup VAO, VBOs, and shaders from GPU cleanupdatafromgpu(); // Close OpenGL window and terminate GLFW glfwterminate(); return 0;

P01, Exercise 3: Graphics application to draw a house (3 triangles) void transferdatatogpumemory(void) { // VAO glgenvertexarrays(1, &VertexArrayID); glbindvertexarray(vertexarrayid); // Create and compile our GLSL program from the shaders programid = LoadShaders( "SimpleVertexShader.vertexshader", "SimpleFragmentShader.fragmentshader" ); // vertices for 2 triangles static const GLfloat g_vertex_buffer_data[] = { 0.0f, 0.0f, 0.0f, 20.0f, 0.0f, 0.0f, 20.0f, 20.0f, 0.0f, // first triangle 0.0f, 0.0f, 0.0f, 20.0f, 20.0f, 0.0f, 0.0f, 20.0f, 0.0f, // second triangle 0.0f, 20.0f, 0.0f, 20.0f, 20.0f, 0.0f, 10.0f, 30.0f, 0.0f, // third triangle }; // One color for each vertex static const GLfloat g_color_buffer_data[] = { 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, }; // color for 3 vertices of the first triangle // color for 3 vertices of the second triangle // color for 3 vertices of the third triangle // Move vertex data to video memory; specifically to VBO called vertexbuffer glgenbuffers(1, &vertexbuffer); glbindbuffer(gl_array_buffer, vertexbuffer); glbufferdata(gl_array_buffer, sizeof(g_vertex_buffer_data), g_vertex_buffer_data, GL_STATIC_DRAW); // Move color data to video memory; specifically to CBO called colorbuffer glgenbuffers(1, &colorbuffer); glbindbuffer(gl_array_buffer, colorbuffer); glbufferdata(gl_array_buffer, sizeof(g_color_buffer_data), g_color_buffer_data, GL_STATIC_DRAW); }

P01, Exercise 3: Graphics application to draw a house (3 triangles) void cleanupdatafromgpu() { gldeletebuffers(1, &vertexbuffer); gldeletebuffers(1, &colorbuffer); gldeletevertexarrays(1, &VertexArrayID); gldeleteprogram(programid); }

P01, Exercise 3: Graphics application to draw a house (3 triangles) void draw (void) { // Clear the screen glclear( GL_COLOR_BUFFER_BIT ); // Use our shader gluseprogram(programid); // window-viewport transformation glm::mat4 mvp = glm::ortho(-40.0f, 40.0f, -40.0f, 40.0f); // retrieve the matrix uniform locations unsigned int matrix = glgetuniformlocation(programid, "mvp"); gluniformmatrix4fv(matrix, 1, GL_FALSE, &mvp[0][0]); // 1rst attribute buffer : vertices glenablevertexattribarray(0); glbindbuffer(gl_array_buffer, vertexbuffer); glvertexattribpointer(0, 3, GL_FLOAT, GL_FALSE, 0, (void*)0); // 2nd attribute buffer : colors glenablevertexattribarray(1); glbindbuffer(gl_array_buffer, colorbuffer); glvertexattribpointer(1, 3, GL_FLOAT, GL_FALSE, 0, (void*)0); // Draw the 3 triangles! gldrawarrays(gl_triangles, 0, 9); // 9 indices starting at 0 } // Disable arrays of attributes for vertices gldisablevertexattribarray(0); gldisablevertexattribarray(1);

P01, Exercise 3: Graphics application to draw a house (3 triangles) #version 330 core // Input vertex data and color data layout(location = 0) in vec3 vertexposition; layout(location = 1) in vec3 vertexcolor; // window-viewport transformation matrix uniform mat4 mvp; // Output fragment data out vec3 fragmentcolor; void main() { // project each vertex in homogeneous coordinates gl_position = mvp * vec4(vertexposition, 1.0); vertexshader.vs } // the vertex shader just passes the color to fragment shader fragmentcolor = vertexcolor;

P01, Exercise 3: Graphics application to draw a house (3 triangles) #version 330 core // Interpolated values from the vertex shaders in vec3 fragmentcolor; // Ouput data out vec3 color; void main() { color = fragmentcolor; } fragmentshader.fs

P01, Exercise 3: Graphics application to draw a house (3 triangles)

Example in OpenGL (using a scene domain and 4 viewports) n n n In this example, we use a specific scene domain given by glm::ortho(xmin,xmax,ymin,ymax) The function glviewport(x, y, width, height) is used explicitly to define each viewport inside the screen window. This program takes advantage of the same shaders as the previous program.

Graphics application to draw the same house in 4 viewports // Include standard headers #include <stdio.h> #include <stdlib.h> // Include GLEW #include <GL/glew.h> // Include GLFW #include <GLFW/glfw3.h> GLFWwindow* window; // GLM header file #include <glm/glm.hpp> using namespace glm; // shaders header file #include <common/shader.hpp> // Vertex array object (VAO) GLuint VertexArrayID; // Vertex buffer object (VBO) GLuint vertexbuffer; // color buffer object (CBO) GLuint colorbuffer; // GLSL program from the shaders GLuint programid; // screen window GLint WindowWidth = 600; GLint WindowHeight = 600; // function prototypes void transferdatatogpumemory(void); void cleanupdatafromgpu(); void draw();

Graphics application to draw the same house in 4 viewports int main( void ) { // Initialise GLFW glfwinit(); // Setting up OpenGL version and the like glfwwindowhint(glfw_samples, 4); glfwwindowhint(glfw_context_version_major, 3); glfwwindowhint(glfw_context_version_minor, 3); glfwwindowhint(glfw_opengl_forward_compat, GL_TRUE); // To make MacOS happy; should not be needed glfwwindowhint(glfw_opengl_profile, GLFW_OPENGL_CORE_PROFILE); // Open a window window = glfwcreatewindow( 1024, 768, House in 4 Viewports", NULL, NULL); // Create window context glfwmakecontextcurrent(window); // Initialize GLEW glewexperimental = true; // Needed for core profile glewinit(); // Ensure we can capture the escape key being pressed below glfwsetinputmode(window, GLFW_STICKY_KEYS, GL_TRUE); // White background glclearcolor(1.0f, 1.0f, 1.0f, 0.0f); // Clear the screen glclear( GL_COLOR_BUFFER_BIT ); // transfer my data (vertices, colors, and shaders) to GPU side transferdatatogpumemory(); // see next page for more

Graphics application to draw the same house in 4 viewports // Create a framebuffer for viewports GLuint FramebufferName = 0; glgenframebuffers(1, &FramebufferName); // render scene for each frame do{ //left bottom glbindframebuffer(gl_framebuffer, 0); glviewport(0, 0, WindowWidth*0.5, WindowHeight*0.5); draw(); //right bottom glviewport(windowwidth*0.5, 0, WindowWidth*0.5, WindowHeight*0.5); draw(); //left top glviewport(0, WindowHeight*0.5, WindowWidth*0.5, WindowHeight*0.5); draw(); //right top glviewport(windowwidth*0.5, WindowHeight*0.5, WindowWidth*0.5, WindowHeight*0.5); draw(); // Swap buffers glfwswapbuffers(window); // looking for input events glfwpollevents(); } while (glfwgetkey(window, GLFW_KEY_ESCAPE )!= GLFW_PRESS && glfwwindowshouldclose(window) == 0 ); // delete framebuffer gldeleteframebuffers(1,&framebuffername); // Cleanup VAO, VBOs, and shaders from GPU cleanupdatafromgpu(); } // Close OpenGL window and terminate GLFW glfwterminate(); return 0;

Graphics application to draw the same house in 4 viewports void transferdatatogpumemory(void) { // VAO glgenvertexarrays(1, &VertexArrayID); glbindvertexarray(vertexarrayid); // Create and compile our GLSL program from the shaders programid = LoadShaders( "SimpleVertexShader.vertexshader", "SimpleFragmentShader.fragmentshader" ); // vertices for 2 triangles static const GLfloat g_vertex_buffer_data[] = { 0.0f, 0.0f, 0.0f, 20.0f, 0.0f, 0.0f, 20.0f, 20.0f, 0.0f, // first triangle 0.0f, 0.0f, 0.0f, 20.0f, 20.0f, 0.0f, 0.0f, 20.0f, 0.0f, // second triangle 0.0f, 20.0f, 0.0f, 20.0f, 20.0f, 0.0f, 10.0f, 30.0f, 0.0f, // third triangle }; // One color for each vertex static const GLfloat g_color_buffer_data[] = { 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, }; // color for 3 vertices of the first triangle // color for 3 vertices of the second triangle // color for 3 vertices of the third triangle // Move vertex data to video memory; specifically to VBO called vertexbuffer glgenbuffers(1, &vertexbuffer); glbindbuffer(gl_array_buffer, vertexbuffer); glbufferdata(gl_array_buffer, sizeof(g_vertex_buffer_data), g_vertex_buffer_data, GL_STATIC_DRAW); // Move color data to video memory; specifically to CBO called colorbuffer glgenbuffers(1, &colorbuffer); glbindbuffer(gl_array_buffer, colorbuffer); glbufferdata(gl_array_buffer, sizeof(g_color_buffer_data), g_color_buffer_data, GL_STATIC_DRAW); }

Graphics application to draw the same house in 4 viewports void cleanupdatafromgpu() { gldeletebuffers(1, &vertexbuffer); gldeletebuffers(1, &colorbuffer); gldeletevertexarrays(1, &VertexArrayID); gldeleteprogram(programid); }

Graphics application to draw the same house in 4 viewports void draw (void) { // Clear the screen : this has been moved to main(); otherwise only one house is displayed // glclear( GL_COLOR_BUFFER_BIT ); // Use our shader gluseprogram(programid); // window-viewport transformation glm::mat4 mvp = glm::ortho(-40.0f, 40.0f, -40.0f, 40.0f); // retrieve the matrix uniform locations unsigned int matrix = glgetuniformlocation(programid, "mvp"); gluniformmatrix4fv(matrix, 1, GL_FALSE, &mvp[0][0]); // 1rst attribute buffer : vertices glenablevertexattribarray(0); glbindbuffer(gl_array_buffer, vertexbuffer); glvertexattribpointer(0, 3, GL_FLOAT, GL_FALSE, 0, (void*)0); // 2nd attribute buffer : colors glenablevertexattribarray(1); glbindbuffer(gl_array_buffer, colorbuffer); glvertexattribpointer(1, 3, GL_FLOAT, GL_FALSE, 0, (void*)0); // Draw the 3 triangles! gldrawarrays(gl_triangles, 0, 9); // 9 indices starting at 0 } // Disable arrays of attributes for vertices gldisablevertexattribarray(0); gldisablevertexattribarray(1);

Graphics application to draw the same house in 4 viewports

Automated setup of the viewport without image distortion n n R = aspect ratio of the scene domain or window = width / height We consider two cases: y scene window R>W/H screen window y scene window R<W/H screen window width height viewport W/R H width height viewport H.R H x W x W n n To avoid image distortion, a rectangular region on the top of screen window will be discarded. Thus, the mapped image will own the resolution W W/R. n n To avoid image distortion, a rectangular region on the right-hand side of screen window will be discarded. Thus, the mapped image will own the resolution H R H. glviewport(0,0,w,w/r); glviewport(0,0,h*r,h); 28

Summary: : Basic definitions in 2D: Global coordinates (scene domain): continuous domain Screen coordinates (image domain): discrete domain Window-viewport transformation Window-viewport transformation in OpenGL Geometric transformations in OpenGL/GLM Graphics pipeline (or rendering pipeline) Mapping a scene into various viewports Avoiding image distortion OpenGL examples