ERKELEY DAVIS IRVINE LOS ANGELES RIVERSIDE SAN DIEGO SAN FRANCISCO EECS 104. Fundamentals of Computer Graphics. OpenGL

Similar documents
Lecture 4 of 41. Lab 1a: OpenGL Basics

Computer Graphics. Bing-Yu Chen National Taiwan University

Exercise 1 Introduction to OpenGL

Introduction to Computer Graphics with OpenGL/GLUT

Lecture 2 2D transformations Introduction to OpenGL

Computer Graphics 1 Computer Graphics 1

RECITATION - 1. Ceng477 Fall

VR-programming tools (procedural) More VRML later in this course! (declarative)

CS 4204 Computer Graphics

OpenGL refresher. Advanced Computer Graphics 2012

COMP 371/4 Computer Graphics Week 1

CS Computer Graphics: OpenGL, Continued

CS Computer Graphics: OpenGL, Continued

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

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

An Interactive Introduction to OpenGL Programming

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

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

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

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

Computer graphics MN1

Computer Graphics. OpenGL

Rendering. Part 1 An introduction to OpenGL

Introduction to OpenGL. CSCI 4229/5229 Computer Graphics Fall 2012

Image Processing. Geometry Processing. Reading: (Not really covered in our text. See Sects 18.1, 18.2.) Overview: Display

GLUT. What is OpenGL? Introduction to OpenGL and GLUT

Programming using OpenGL: A first Introduction

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

Lecture 3 Advanced Computer Graphics (CS & SE )

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

Lecture 2 CISC440/640 Spring Department of Computer and Information Science

Basic Graphics Programming

GL_COLOR_BUFFER_BIT, GL_PROJECTION, GL_MODELVIEW

Introduction to OpenGL Week 1

Objectives. Image Formation Revisited. Physical Approaches. The Programmer s Interface. Practical Approach. Introduction to OpenGL Week 1

CS 4731 Lecture 3: Introduction to OpenGL and GLUT: Part II. Emmanuel Agu

An Interactive Introduction to OpenGL and OpenGL ES Programming. Ed Angel Dave Shreiner

Lectures OpenGL Introduction

Precept 2 Aleksey Boyko February 18, 2011

Basic Graphics Programming

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

OpenGL. Toolkits.

Computer Graphics, Chapt 08

OpenGL/GLUT Intro. Week 1, Fri Jan 12

CS Computer Graphics: Intro to OpenGL

CS Computer Graphics: Intro to OpenGL

Computer Graphics Introduction to OpenGL

Computer Graphics Primitive Attributes

5HDOLVP7KURXJK6\QWKHVLV

11/1/13. Basic Graphics Programming. Teaching Assistant. What is OpenGL. Course Producer. Where is OpenGL used. Graphics library (API)

Programming with OpenGL Part 1: Background

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

Computer Graphics Course 2005

Teacher Assistant : Tamir Grossinger Reception hours: by - Building 37 / office -102 Assignments: 4 programing using

OpenGL and GLUT based library for Image Processing (GLIP)

Programming of Graphics

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

Assignment 1. Simple Graphics program using OpenGL

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

COMPUTER GRAPHICS LAB # 3

Programming with OpenGL Part 1: Background

Computer graphic -- Programming with OpenGL I

Lecture 2. Determinants. Ax = 0. a 11 x 1 + a 12 x a 1n x n = 0 a 21 x 1 + a 22 x a 2n x n = 0

Graphics Pipeline & APIs

Early History of APIs. PHIGS and X. SGI and GL. Programming with OpenGL Part 1: Background. Objectives

CSC 8470 Computer Graphics. What is Computer Graphics?

Introduction to OpenGL

Introduction to OpenGL

Drawing Primitives. OpenGL basics

C++ is Fun Part 13 at Turbine/Warner Bros.! Russell Hanson

An Overview GLUT GLSL GLEW

Computer Graphics (Basic OpenGL)

Overview of Graphics Systems Hearn & Baker Chapter 2. Some slides are taken from Robert Thomsons notes.

Graphics Pipeline & APIs

Graphics Programming

Class of Algorithms. Visible Surface Determination. Back Face Culling Test. Back Face Culling: Object Space v. Back Face Culling: Object Space.

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

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

Computer Graphics. Making Pictures. Computer Graphics CSC470 1

2. OpenGL -I. 2.1 What is OpenGL? Things OpenGL can do: -23-

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

Draw the basic Geometry Objects. Hanyang University

CS 543 Lecture 1 (Part II): Intro to OpenGL and GLUT (Part I) Emmanuel Agu

OpenGL: A Practical Introduction. (thanks, Mark Livingston!)

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

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

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

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

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

Display Lists in OpenGL

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

Computer graphics MN1

CS450/550. Pipeline Architecture. Adapted From: Angel and Shreiner: Interactive Computer Graphics6E Addison-Wesley 2012

CS130 : Computer Graphics. Tamar Shinar Computer Science & Engineering UC Riverside

1.2 Basic Graphics Programming

Introduction to OpenGL. Prof. Dr.-Ing. Lars Linsen

Computer Graphics Programming

Cameras (and eye) Ideal Pinhole. Real Pinhole. Real + lens. Depth of field

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

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

Transcription:

ERKELEY DAVIS IRVINE LOS ANGELES RIVERSIDE SAN DIEGO SAN FRANCISCO SANTA BARBARA SANTA CRUZ EECS 104 Fundamentals of Computer Graphics OpenGL Slides courtesy of Dave Shreine, Ed Angel and Vicki Shreiner (SIGGRAPH 2001).

Introduction to OpenGL Graphics API Window system independent Operating system independent Geometric and image primitives

OpenGL Architecture Polynomial Evaluator Per Vertex Operations & Primitive Assembly CPU Display List Rasterization Per Fragment Operations Frame Buffer Pixel Operations Texture Memory

OpenGL as a Renderer Geometric primitives points, lines, triangles, quadrilaterals, polygons Image Primitives images and bitmaps separate pipeline for images and geometry Rendering depends on state Colors Materials Lights

Related APIs AGL, GLX, WGL glue between OpenGL and windowing systems GLU (OpenGL Utility Library) part of OpenGL NURBS, tessellators, quadric shapes, etc. GLUT (OpenGL Utility Toolkit) portable windowing API not officially part of OpenGL

OpenGL and Related APIs application program OpenGL Motif widget or similar GLX, AGL or WGL X, Win32, Mac O/S GLUT GLU GL software and/or hardware

Preliminaries Libraries Headers Files #include <GL/gl.h> #include <GL/glu.h> #include <GL/glut.h>

GLUT Basics Application Structure 1. Configure and open window 2. Initialize OpenGL state 3. Register input callback functions render resize input: keyboard, mouse, etc. 4. Enter event processing loop

GLUT Display Modes GLUT_RGBA GLUT_RGB GLUT_INDEX GLUT_SINGLE GLUT_DOUBLE GLUT_ACCUM GLUT_ALPHA GLUT_DEPTH Select an RGBA mode window. This is the default if neither GLUT_RGBA nor GLUT_INDEX are specified. same as GLUT_RGBA. Select color index window mode. This overrides GLUT_RGBA. Select a single buffered window. This is the default. Select a double buffered window. This overrides GLUT_SINGLE. Select a window with an accumulation buffer. Select a window with an alpha component to the color buffer(s). Select a window with a depth buffer. GLUT_STENCIL Select a window with a stencil buffer. GLUT_MULTISAMPLE Select a window with multismapling support. GLUT_STEREO Select a stereo window. GLUT_LUMINANCE Select a stereo window with a "luminance" color model

Sample Program void main( int argc, char** argv ) { int mode = GLUT_RGB GLUT_DOUBLE; glutinitdisplaymode( mode ); glutcreatewindow( argv[0] ); init(); glutdisplayfunc( display ); glutreshapefunc( resize ); glutkeyboardfunc( key ); glutidlefunc( idle ); glutmainloop(); }

OpenGL Initialization Configure the state machine void init( void ) { glclearcolor( 0.0, 0.0, 0.0, 1.0 ); glcleardepth( 1.0 ); } glenable( GL_LIGHT0 ); glenable( GL_LIGHTING ); glenable( GL_DEPTH_TEST );

GLUT Callback Functions Routine to call when something happens window resize or redraw user input Animation Register callbacks with GLUT glutdisplayfunc( display ); glutidlefunc( idle ); glutkeyboardfunc( keyboard );

Rendering Callback Do all of your drawing here glutdisplayfunc( display ); void display( void ) { glclear( GL_COLOR_BUFFER_BIT ); glbegin( GL_TRIANGLE_STRIP ); glvertex3fv( v[0] ); glvertex3fv( v[1] ); glvertex3fv( v[2] ); glvertex3fv( v[3] ); glend(); glutswapbuffers(); }

Idle Callbacks Use for animation and continuous update glutidlefunc( idle ); void idle( void ) { t += dt; glutpostredisplay(); }

User Input Callbacks Process user input glutkeyboardfunc( keyboard ); void keyboard( char key, int x, int y ) { switch( key ) { case q : case Q : exit( EXIT_SUCCESS ); break; case r : case R : rotate = GL_TRUE; break; } }

Elementary Rendering Geometric Primitives OpenGL State Machine OpenGL Buffers

OpenGL Geometric Primitives All geometric primitives are specified by vertices GL_POINTS GL_LINES GL_LINE_STRIP GL_LINE_LOOP GL_POLYGON GL_TRIANGLES GL_TRIANGLE_STRIP GL_TRIANGLE_FAN GL_QUADS GL_QUAD_STRIP

OpenGL Command Formats glvertex3fv( v ) Number of components 2 - (x,y) 3 - (x,y,z) 4 - (x,y,z,w) Data Type b - byte ub - unsigned byte s - short us - unsigned short i - int ui - unsigned int f - float d - double Vector omit v for scalar form glvertex2f( x, y )

Simple Example void drawrhombus( GLfloat color[] ) { glbegin( GL_QUADS ); glcolor3fv( color ); glvertex2f( 0.0, 0.0 ); glvertex2f( 1.0, 0.0 ); glvertex2f( 1.5, 1.118 ); glvertex2f( 0.5, 1.118 ); glend(); }

Specifying Geometric Primitives Primitives are specified using glbegin( primtype ); glend(); primtype determines how vertices are combined GLfloat red, greed, blue; Glfloat coords[3]; glbegin( primtype ); for ( i = 0; i < nverts; ++i ) { glcolor3f( red, green, blue ); glvertex3fv( coords ); } glend();

OpenGL Color Models RGBA or Color Index CPU CPU Poly. Poly. DL DL Pixel Pixel Per Per Vertex Vertex Texture Texture Raster Raster Frag Frag FB FB 1 2 4 8 16 0 1 2 3 24 25 26 color index mode Red Green Blue 123 219 74 Display RGBA mode

Shapes Tutorial

Controlling Rendering Appearance From Wireframe to Texture Mapped

OpenGL s State Machine All rendering attributes are encapsulated rendering styles shading lighting texture mapping

Manipulating OpenGL State Appearance is controlled by current state for each ( primitive to render ) { update OpenGL state render primitive } Manipulating vertex attributes is most common way to manipulate state glcolor*() / glindex*() glnormal*() gltexcoord*()

Controlling current state Setting State glpointsize( size ); gllinestipple( repeat, pattern ); glshademodel( GL_SMOOTH ); Enabling Features glenable( GL_LIGHTING LIGHTING ); gldisable( GL_TEXTURE_2D );

Transformations in OpenGL Modeling Viewing Viewpoint (camera location and orientations) Projection Animation Map to screen

Camera Analogy Real-time photography viewing volume camera tripod model

Camera Analogy and Transformations Projection transformations adjust the lens of the camera Viewing transformations tripod define position and orientation of the viewing volume in the world Modeling transformations moving the model Viewport transformations enlarge or reduce the physical photograph

Coordinate Systems and Transforms Steps in Forming an Image specify geometry (world coordinates) specify camera (camera coordinates) project (window coordinates) map to viewport (screen coordinates) Each step uses transformations Every transformation is equivalent to a change in coordinate systems (frames)

Affine Transformations Want transformations which preserve geometry lines, polygons, quadrics Affine = line preserving Rotation, translation, scaling Projection Concatenation (composition)

Homogeneous Coordinates each vertex is a column vector w is usually 1.0 all operations are matrix multiplications directions (directed line segments) can be represented with w = 0.0 v r = x y z w