Administrivia Back on track: canceling OpenGL lecture 2 Assignment 1

Slides:



Advertisements
Similar presentations
Computer Graphics - Viewing -
Advertisements

SI23 Introduction to Computer Graphics
02/17/05CISC640/440 OpenGL Tutorial1 OpenGL Tutorial CISC 640/440 Computer Graphics TA: Qi Li/Mani Thomas
OpenGL: Simple Use Open a window and attach OpenGL to it Set projection parameters (e.g., field of view) Setup lighting, if any Main rendering loop –Set.
2 COEN Computer Graphics I Evening’s Goals n Discuss the fundamentals of lighting in computer graphics n Analyze OpenGL’s lighting model n Show.
David Luebke5/16/2015 Administrivia l Back on track: canceling OpenGL lecture 2 l Assignment 1 –Greg Yukl found an alternate XForms site:
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.
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Programming with OpenGL Part 2: Complete Programs Ed Angel Professor of Computer Science,
OpenGL and Projections
Further Programming for 3D applications CE Introduction to Further Programming for 3D application Bob Hobbs Faculty of Computing, Engineering and.
3.1si31_2001 SI31 Advanced Computer Graphics AGR Lecture 3 Viewing Transformation Getting Started with OpenGL Introduction to Projections.
Sep 30, I3I3DG&VR CE00539-m Interactive 3D Graphics and Virtual Reality Bob Hobbs Faculty of Computing, Engineering and Technology Staffordshire.
CS 4731: Computer Graphics Lecture 11: 3D Viewing Emmanuel Agu.
3D Rendering with JOGL Introduction to Java OpenGL Graphic Library By Ricardo Veguilla
Introduction to 3D viewing 3D is just like taking a photograph!
3D coordinate systems X Y Z Right-Hand Coordinate System X Y Z Left-Hand Coordinate System OpenGL uses this! Direct3D uses this!
COS 397 Computer Graphics Assoc. Prof. Svetla Boytcheva AUBG 2013 COS 397 Computer Graphics Practical Session №1 Introduction to OpenGL, GLFW and CG.
Introduction to Computer Graphics CS 445 / 645 Lecture 4 OpenGL OpenGL OpenGL Programming Guide.
Using OpenGL. 2 What is OpenGL? A software interface to graphics hardware It is a Graphics Rendering API (Application Programmer’s Interface) that is.
INTRO TO COMPUTER GRAPHICS TEXT EDWARD ANGEL: EDITION 5 CS770/870
Week 2 - Wednesday CS361.
Image Synthesis Rabie A. Ramadan, PhD 2. 2 Java OpenGL Using JOGL: Using JOGL: Wiki: You can download JOGL from.
Homogeneous Form, Introduction to 3-D Graphics Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Monday, October 20,
CS 445 / 645 Introduction to Computer Graphics Lecture 4 OpenGL Intro Assignment 1 Lecture 4 OpenGL Intro Assignment 1.
1. OpenGL/GLU/GLUT  OpenGL v4.0 (latest) is the “core” library that is platform independent  GLUT v3.7 is an auxiliary library that handles window creation,
The Rendering Pipeline CS 445/645 Introduction to Computer Graphics David Luebke, Spring 2003.
Computer Graphics I, Fall 2010 Computer Viewing.
Intro to OpenGL Transformations CS 445/645 Introduction to Computer Graphics David Luebke, Spring 2003.
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.
OpenGL: The Open Graphics Language Introduction By Ricardo Veguilla.
David Luebke1/5/2016 CS 551 / 645: Introductory Computer Graphics David Luebke
1 Programming with OpenGL Part 2: Complete Programs.
OpenGL API 2D Graphic Primitives Angel Angel: Interactive Computer Graphics5E © Addison-Wesley
1 Perception, Illusion and VR HNRS 299, Spring 2008 Lecture 15 Creating 3D Models.
CIS 681 Review: OpenGL. CIS 681 Command Syntax OpenGL commands start with a gl. This is followed by the base command such as Color. Followed by the number.
CS5500 Computer Graphics March 20, Computer Viewing Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts.
CSC Graphics Programming Budditha Hettige Department of Statistics and Computer Science.
Computer Graphics I, Fall Programming with OpenGL Part 2: Complete Programs.
OpenGL CS418 Computer Graphics John C. Hart. OpenGL Based on GL (graphics library) by Silicon Graphics Inc. (SGI) Advantages: Runs on everything, including.
OpenGL LAB III.
OpenGL: The Open Graphics Language Technology and Historical Overview By Ricardo Veguilla.
Computer Graphics (Fall 2003) COMS 4160, Lecture 5: OpenGL 1 Ravi Ramamoorthi Many slides courtesy Greg Humphreys.
The Human Visual System vs The Pinhole camera
Viewing.
Computer Viewing.
Isaac Gang University of Mary Hardin-Baylor
Jason Lawrence COS426 Precept Notes 2/16/04
Rendering Pipeline Aaron Bloomfield CS 445: Introduction to Graphics
Modeling 101 For the moment assume that all geometry consists of points, lines and faces Line: A segment between two endpoints Face: A planar area bounded.
“Computer Science is no more about computers than astronomy is about telescopes.” Professor Edsger Dijkstra.
Programming with OpenGL Part 2: Complete Programs
Materi Anatomi OpenGL Fungsi GLUT Posisi Kamera Proyeksi
The Graphics Rendering Pipeline
CS451Real-time Rendering Pipeline
OpenGL API 2D Graphic Primitives
Programming with OpenGL Part 2: Complete Programs
CSC4820/6820 Computer Graphics Algorithms Ying Zhu Georgia State University View & Projection.
Three-Dimensional viewing
Projection in 3-D Glenn G. Chappell
Lecture 13 Clipping & Scan Conversion
Primitive Objects Lecture 6 Wed, Sep 5, 2007.
University of New Mexico
Computer Graphics 4Practical Lesson
Programming with OpenGL Part 2: Complete Programs
Programming with OpenGL Part 2: Complete Programs
Last Time Liang-Barsky Details Weiler-Atherton clipping algorithm
CS297 Graphics with Java and OpenGL
Programming with OpenGL Part 2: Complete Programs
Presentation transcript:

Administrivia Back on track: canceling OpenGL lecture 2 Assignment 1 Greg Yukl found an alternate XForms site: http://world.std.com/~xforms/ Updating display Call canvas_expose() directly (can ignore most args) Figure out how to post a redisplay Questions? David Luebke 4/15/2018

Introducing OpenGL Recall the rendering pipeline: Transform geometry (object world, world eye) Apply perspective projection (eye screen) Clip to the view frustum Perform visible-surface processing (Z-buffer) Calculate surface lighting Implementing all this is a lot of work (as you’ll find) OpenGL provides a standard implementation So why study the basics? David Luebke 4/15/2018

OpenGL Design Goals SGI’s design goals for OpenGL: High-performance (hardware-accelerated) graphics APIsome hardware independence Natural, terse API with some built-in extensibility OpenGL has become a standard because: It doesn’t try to do too much Only renders the image, doesn’t manage windows, etc. No high-level animation, modeling, sound (!), etc. It does enough Useful rendering effects + high performance It is promoted by SGI (& Microsoft, half-heartedly) David Luebke 4/15/2018

OpenGL: Conventions Functions in OpenGL start with gl Most functions just gl (e.g., glColor()) Functions starting with glu are utility functions (e.g., gluLookAt()) Functions starting with glx are for interfacing with the X Windows system (e.g., in gfx.c) David Luebke 4/15/2018

OpenGL: Conventions Function names indicate argument type and number Functions ending with f take floats Functions ending with i take ints Functions ending with b take bytes Functions ending with ub take unsigned bytes Functions that end with v take an array. Examples glColor3f() takes 3 floats glColor4fv() takes an array of 4 floats David Luebke 4/15/2018

OpenGL: Simple Use Open a window and attach OpenGL to it Set projection parameters (e.g., field of view) Setup lighting, if any Main rendering loop Set camera pose with gluLookAt() Camera position specified in world coordinates Render polygons of model Simplest case: vertices of polygons in world coordinates David Luebke 4/15/2018

OpenGL: Simple Use Open a window and attach OpenGL to it XForms glcanvas widget + code in gfx.c Set projection parameters (e.g., field of view) Setup lighting, if any Main rendering loop Set camera pose with gluLookAt() Camera position specified in world coordinates Render polygons of model Simplest case: vertices of polygons in world coordinates David Luebke 4/15/2018

OpenGL: Simple Use Open a window and attach OpenGL to it Set projection parameters (e.g., field of view) Setup lighting, if any Main rendering loop Set camera pose with gluLookAt() Camera position specified in world coordinates Render polygons of model Simplest case: vertices of polygons in world coordinates David Luebke 4/15/2018

OpenGL: Perspective Projection Typically, we use a perspective projection Distant objects appear smaller than near objects Vanishing point at center of screen Defined by a view frustum (draw it) Other projections: orthographic, isometric David Luebke 4/15/2018

OpenGL: Perspective Projection In OpenGL: Projections implemented by projection matrix gluPerspective() creates a perspective projection matrix: glSetMatrix(GL_PROJECTION); glLoadIdentity(); //load an identity matrix gluPerspective(vfov, aspect, near, far); Parameters to gluPerspective(): vfov: vertical field of view aspect: window width/height near, far: distance to near & far clipping planes David Luebke 4/15/2018

OpenGL: Simple Use Open a window and attach OpenGL to it Set projection parameters (e.g., field of view) Setup lighting, if any Main rendering loop Set camera pose with gluLookAt() Camera position specified in world coordinates Render polygons of model Simplest case: vertices of polygons in world coordinates David Luebke 4/15/2018

OpenGL: Lighting Simplest option: change the current color between polygons or vertices glColor() sets the current color Or OpenGL provides a simple lighting model: Set parameters for light(s) Intensity, position, direction & falloff (if applicable) Set material parameters to describe how light reflects from the surface Won’t go into details now; check the red book if interested David Luebke 4/15/2018

OpenGL: Simple Use Open a window and attach OpenGL to it Set projection parameters (e.g., field of view) Setup lighting, if any Main rendering loop Set camera pose with gluLookAt() Camera position specified in world coordinates Render polygons of model Simplest case: vertices of polygons in world coordinates David Luebke 4/15/2018

OpenGL: Specifying Viewpoint glMatrixMode(GL_MODELVIEW); glLoadIdentity(); gluLookAt(eyeX, eyeY, eyeZ, lookX, lookY, lookZ, upX, upY, upZ); eye[XYZ]: camera position in world coordinates look[XYZ]: a point centered in camera’s view up[XYZ]: a vector defining the camera’s vertical Creates a matrix that transforms points in world coordinates to camera coordinates Camera at origin Looking down -Z axis (Why?) Up vector aligned with Y axis (actually Y-Z plane) David Luebke 4/15/2018

OpenGL: Specifying Geometry Geometry in OpenGL consists of a list of vertices in between calls to glBegin() and glEnd() A simple example: telling GL to render a triangle glBegin(GL_POLYGON); glVertex3f(x1, y1, z1); glVertex3f(x2, y2, z2); glVertex3f(x3, y3, z3); glEnd(); Usage: glBegin(geomtype) where geomtype is: Points, lines, polygons, triangles, quadrilaterals, etc... David Luebke 4/15/2018

OpenGL: More Examples Example: GL supports quadrilaterals: glBegin(GL_QUADS); glVertex3f(-1, 1, 0); glVertex3f(-1, -1, 0); glVertex3f(1, -1, 0); glVertex3f(1, 1, 0); glEnd(); This type of operation is called immediate-mode rendering; each command happens immediately Why do you suppose OpenGL uses a series of glVertex() calls instead of one polygon function that takes all its vertices as arguments? David Luebke 4/15/2018

OpenGL: Front/Back Rendering Each polygon has two sides, front and back OpenGL can render the two differently The ordering of vertices in the list determines which is the front side: When looking at the front side, the vertices go counterclockwise This is basically the right-hand rule Note that this still holds after perspective projection David Luebke 4/15/2018

OpenGL: Drawing Triangles You can draw multiple triangles between glBegin(GL_TRIANGLES) and glEnd(): float v1[3], v2[3], v3[3], v4[3]; ... glBegin(GL_TRIANGLES); glVertex3fv(v1); glVertex3fv(v2); glVertex3fv(v3); glVertex3fv(v1); glVertex3fv(v3); glVertex3fv(v4); glEnd(); Each set of 3 vertices forms a triangle What do the triangles drawn above look like? How much redundant computation is happening? David Luebke 4/15/2018

OpenGL: Triangle Strips An OpenGL triangle strip primitive reduces this redundancy by sharing vertices: glBegin(GL_TRIANGLE_STRIP); glVertex3fv(v0); glVertex3fv(v1); glVertex3fv(v2); glVertex3fv(v3); glVertex3fv(v4); glVertex3fv(v5); glEnd(); triangle 0 is v0, v1, v2 triangle 1 is v2, v1, v3 (why not v1, v2, v3?) triangle 2 is v2, v3, v4 triangle 3 is v4, v3, v5 (again, not v3, v4, v5) v2 v4 v0 v5 v1 v3 David Luebke 4/15/2018

OpenGL: Specifying Color Can specify other properties such as color To produce a single aqua-colored triangle: glColor3f(0.1, 0.5, 1.0); glVertex3fv(v0); glVertex3fv(v1); glVertex3fv(v2); To produce a Gouraud-shaded triangle: glColor3f(1, 0, 0); glVertex3fv(v0); glColor3f(0, 1, 0); glVertex3fv(v1); glColor3f(0, 0, 1); glVertex3fv(v2); In OpenGL, colors can also have a fourth component  (opacity) Generally want  = 1.0 (opaque); David Luebke 4/15/2018

OpenGL: Specifying Normals Calling glColor() sets the color for vertices following, until the next call to glColor() Calling glNormal() sets the normal vector for the following vertices, till next glNormal() So flat-shaded lighting requires: glNormal3f(Nx, Ny, Nz); glVertex3fv(v0);glVertex3fv(v1);glVertex3fv(v2); While smooth shading requires: glNormal3f(N0x, N0y, N0z); glVertex3fv(v0); glNormal3f(N1x, N1y, N1z); glVertex3fv(v1); glNormal3f(N2x, N2y, N2z); glVertex3fv(v2); (Of course, lighting requires additional setup…) David Luebke 4/15/2018