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

Similar documents
To Do. Demo: Surreal (HW 3) This Lecture. Introduction to OpenGL. Outline. Foundations of Computer Graphics (Spring 2012)

This Lecture. Why OpenGL? Introduction to OpenGL. Programmer s View

Basic Graphics Programming

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


Introduction to Computer Graphics with OpenGL/GLUT

RECITATION - 1. Ceng477 Fall

Lectures OpenGL Introduction

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

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

GL_COLOR_BUFFER_BIT, GL_PROJECTION, GL_MODELVIEW

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

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

Precept 2 Aleksey Boyko February 18, 2011

Basic Graphics Programming

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

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

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

OpenGL/GLUT Intro. Week 1, Fri Jan 12

Graphics Programming

Lecture 3. Understanding of OPenGL programming

Lecture 4 of 41. Lab 1a: OpenGL Basics

OpenGL refresher. Advanced Computer Graphics 2012

Introduction to OpenGL: Part 2

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

CS 4204 Computer Graphics

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

CS Computer Graphics: OpenGL, Continued

CS Computer Graphics: OpenGL, Continued

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

Drawing Primitives. OpenGL basics

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

Computer graphics MN1

Using OpenGL with CUDA

Exercise 1 Introduction to OpenGL

Computer Graphics (Basic OpenGL)

Introduction to OpenGL

Programming using OpenGL: A first Introduction

Computer Graphics. Bing-Yu Chen National Taiwan University

Computer Graphics Course 2005

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

CS418 OpenGL & GLUT Programming Tutorial (I) Presented by : Wei-Wen Feng 1/30/2008

Interaction Computer Graphics I Lecture 3

Computer Graphics. OpenGL

Announcements OpenGL. Computer Graphics. Autumn 2009 CS4815

Announcements OpenGL. Computer Graphics. Spring CS4815

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

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

Interaction. CSCI 480 Computer Graphics Lecture 3

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

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

COMPUTER GRAPHICS LAB # 3

Computer Graphics, Chapt 08

Display Lists in OpenGL

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

1.2 Basic Graphics Programming

Rendering Pipeline/ OpenGL

OpenGL JOGL. OpenGL & JOGL. Shaoting Zhang, or Tony. September 12, 2007

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

COMP 371/4 Computer Graphics Week 1

1/12/11. Basic Graphics Programming. What is OpenGL. OpenGL is cross-platform. How does OpenGL work. How does OpenGL work (continued) The result

Computer Graphics Introduction to OpenGL

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

Graphics Hardware and OpenGL

Programming with OpenGL Part 3: Three Dimensions

Interaction. CSCI 420 Computer Graphics Lecture 3

by modifying the glutinitwindowsize() function you can change the screen size to whatever you please.

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

Introduction to OpenGL

Computer Graphics Primitive Attributes

2 Transformations and Homogeneous Coordinates

Duc Nguyen CSE 420 Computer Graphics 10/10/2018 Homework 1

Programming with OpenGL Part 1: Background

CS 432 Interactive Computer Graphics

Lecture 3 Advanced Computer Graphics (CS & SE )

Computer Graphics. Making Pictures. Computer Graphics CSC470 1

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

Rendering. Part 1 An introduction to OpenGL

Ulf Assarsson Department of Computer Engineering Chalmers University of Technology

Lecture 2 2D transformations Introduction to OpenGL

C OMPUTER G RAPHICS Thursday

to OpenGL Introduction Pipeline Graphics pipeline OpenGL pipeline OpenGL syntax Modeling Arrays Conclusion 1 Introduction Introduction to OpenGL

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

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

CSE4030 Introduction to Computer Graphics

Introduction to OpenGL Week 1

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

Computer Graphics 1 Computer Graphics 1

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

An Overview GLUT GLSL GLEW

Bob s Concise Introduction to Doxygen

OpenGL. Toolkits.

OpenGL: Open Graphics Library. Introduction to OpenGL Part II. How do I render a geometric primitive? What is OpenGL

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

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

Assignment 1. Simple Graphics program using OpenGL

An Interactive Introduction to OpenGL Programming

Input and Interaction. 1. Interaction. Chapter 3. Introduction: - We now turn to the development of interactive graphics programs.

Programming of Graphics

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

Transcription:

Computer Graphics (Fall 2008) COMS 4160, Lecture 9: OpenGL 1 http://www.cs.columbia.edu/~cs4160 To Do Start thinking (now) about HW 3. Milestones are due soon. Course Course 3D Graphics Pipeline 3D Graphics Pipeline Modeling (Creating 3D Geometry) Rendering (Creating, shading images from geometry, lighting, materials) Modeling (Creating 3D Geometry) Rendering (Creating, shading images from geometry, lighting, materials) Unit 1: Transformations Weeks 1,2. Ass 1 due Sep 25 Unit 2: Spline Curves Weeks 3,4. Ass 2 due Oct 7 Unit 3: OpenGL Weeks 5-7. Ass 3 due Nov 11 Midterm on units 1-3: Oct 20 Demo: Surreal (HW 3) Methodology for Lecture This unit different from others in course Other units stress mathematical understanding This stresses implementation details and programming I am going to show (maybe write) actual code Same code (with comments) available online to help you understand how to implement basic concepts I hope the online code helps you understand HW 3 better ASK QUESTIONS if confused!! Simple demo 4160-opengl\opengl1\opengl1-orig.exe This lecture deals with very basic OpenGL setup. Next 2 lectures will likely be more interesting

Introduction to OpenGL OpenGL is a graphics API Software library Layer between programmer and graphics hardware (and software) OpenGL can fit in many places Between application and graphics system Between higher level API and graphics system Best source for OpenGL is the redbook. Of course, this is more a reference manual than a textbook, and you are better off implementing rather reading end to end. Though if you do have time, the book is actually quite readable Programmer s s View OpenGL Rendering Pipeline Application Application Graphics Package OpenGL Application Programming Interface Hardware and software Vertices Images Geometry Primitive Pixel Scan Conversion Texture Memory Fragment Framebuffer Output Device Input Device Input Device Many operations controlled by state (projection matrix, transformation matrix, color etc.) OpenGL is a large state machine OpenGL Rendering Pipeline GPUs and Programmability Vertices Images Programmable in Modern GPUs Geometry Primitive Pixel Scan Conversion Texture Memory Programmable in Modern GPUs Fragment Framebuffer Since 2003, can write vertex/pixel shaders Fixed function pipeline special type of shader Like writing C programs (see back of OpenGL book) Performance >> CPU (even used for non-graphics) Traditional Approach: Fixed function pipeline (state machine) New Development (2003-): Programmable pipeline

GPUs and Programmability Since 2003, can write vertex/pixel shaders Fixed function pipeline special type of shader Like writing C programs (see back of OpenGL book) Performance >> CPU (even used for non-graphics) But parallel paradigm All pixels/vertices operate in parallel Severe performance overheads for control flow, loops (limitations beginning to be relaxed in modern releases) Not directly covered in COMS 4160 But you can make use of in assignments for extra credit Why OpenGL? Fast Simple Window system independent Supports some high-end graphics features Geometric and pixel processing Standard, available on many platforms Buffers and Window Interactions Buffers: Color (front, back, left, right), depth (z), accumulation, stencil. When you draw, you write to some buffer (most simply, front and depth) No window system interactions (for portability) But can use GLUT (or Motif, GLX, Tcl/Tk) Callbacks to implement mouse, keyboard interaction Basic setup code (you will likely copy) int main(int argc, char** argv) glutinit(&argc, argv); // Requests the type of buffers (Single, RGB). // Think about what buffers you would need... glutinitdisplaymode (GLUT_SINGLE GLUT_RGB); glutinitwindowsize (500, 500); glutinitwindowposition (100, 100); glutcreatewindow ("Simple Demo"); init (); // Always initialize first // Now, we define callbacks and functions for various tasks. glutdisplayfunc(display); glutreshapefunc(reshape) ; glutkeyboardfunc(keyboard); glutmousefunc(mouse) ; glutmotionfunc(mousedrag) ; glutmainloop(); // Start the main code return 0; /* ANSI C requires main to return int. */

Viewing in OpenGL Viewing consists of two parts Object positioning: model view transformation matrix View projection: projection transformation matrix OpenGL supports both perspective and orthographic viewing transformations OpenGL s camera is always at the origin, pointing in the z direction Transformations move objects relative to the camera Matrices right-multiply top of stack. (Last transform in code is first actually applied) Basic initialization code #include <GL/glut.h> #include <stdlib.h> int mouseoldx, mouseoldy ; // For mouse motion GLdouble eyeloc = 2.0 ; // Where to look from; initially 0-2, 2 void init (void) /* select clearing color */ glclearcolor (0.0, 0.0, 0.0, 0.0); /* initialize viewing values */ glmatrixmode(gl_projection); glloadidentity(); // Think about this. Why is the up vector not normalized? glmatrixmode(gl_modelview) ; glloadidentity() ; glulookat(0,-eyeloc,eyeloc,0,0,0,0,1,1) ; Window System Interaction Not part of OpenGL Toolkits (GLUT) available Callback functions for events Keyboard, Mouse, etc. Open, initialize, resize window Similar to other systems (X, Java, etc.) Our main func included glutdisplayfunc(display); glutreshapefunc(reshape) ; glutkeyboardfunc(keyboard); glutmousefunc(mouse) ; glutmotionfunc(mousedrag) ; Basic window interaction code /* Defines what to do when various keys are pressed */ void keyboard (unsigned char key, int x, int y) switch (key) case 27: // Escape to quit exit(0) ; break ; default: break ; /* Reshapes the window appropriately */ void reshape(int w, int h) glviewport (0, 0, (GLsizei) w, (GLsizei) h); glmatrixmode(gl_projection); glloadidentity(); gluperspective(30.0, (GLdouble)w/(GLdouble)h, 1.0, 10.0) ; Mouse motion (demo (demo 4160 4160-opengl1\opengl1-orig.exe) /* Defines a Mouse callback to zoom in and out */ /* This is done by modifying glulookat */ /* The actual motion is in mousedrag */ /* mouse simply sets state for mousedrag */ void mouse(int button, int state, int x, int y) if (button == GLUT_LEFT_BUTTON) if (state == GLUT_UP) // Do Nothing ; else if (state == GLUT_DOWN) mouseoldx = x ; mouseoldy = y ; // so we can move wrt x, y else if (button == GLUT_RIGHT_BUTTON && state == GLUT_DOWN) // Reset glulookat eyeloc = 2.0 ; glmatrixmode(gl_modelview) ; glloadidentity() ; glulookat(0,-eyeloc,eyeloc,0,0,0,0,1,1) ; glutpostredisplay() ;

Mouse drag (demo (demo 4160 4160-opengl1\opengl1-orig.exe) void mousedrag(int x, int y) int yloc = y - mouseoldy ; // We will use the y coord to zoom in/out eyeloc += 0.005*yloc ; // Where do we look from if (eyeloc < 0) eyeloc = 0.0 ; mouseoldy = y ; /* Set the eye location */ glmatrixmode(gl_modelview) ; glloadidentity() ; glulookat(0,-eyeloc,eyeloc,0,0,0,0,1,1) ; glutpostredisplay() ; OpenGL Primitives GLUT 3D Primitives Points Lines Polygon Triangle Quad Quad Strip Cube Sphere And others Triangle Strip Triangle Fan Teapot Drawing idea Enclose vertices between glbegin() glend() pair Can include normal C code and attributes like the colors of points, but not other OpenGL commands Inside are commands like glvertex3f, glcolor3f Attributes must be set before the vertex Assembly line model (pass vertices, transform, clip, shade) Client-Server model (client generates vertices, server draws) even if on same machine glflush() forces client to send network packet glfinish() waits for ack, sparingly use synchronization Geometry Points (GL_POINTS) Stored in Homogeneous coordinates Line segments (GL_LINES) Polygons Simple, convex (take your chances with concave) Tessellate, GLU for complex shapes Rectangles: glrect Special cases (strips, loops, triangles, fans, quads) More complex primitives (GLUT): Sphere, teapot, cube,

Specifying Geometry glbegin(gl_polygon) ; // Chapter 2 but I do Counter Clock W glvertex2f (4.0, 0.0) ; glvertex2f (6.0, 1.5) ; glvertex2f (4.0, 3.0) ; glvertex2f (0.0, 3.0) ; glvertex2f (0.0, 0.0) ; // glcolor, glindex, glnormal, gltexcoord, (pp 47) // glmaterial, glarrayelement, glevalcoord, (pp 48) // Other GL commands invalid between begin and end // Can write normal C code (4,3) glend() ; (0,3) (0,0) (4,0) (6,1.5) Drawing in Display Routine void display(void) glclear (GL_COLOR_BUFFER_BIT); // draw polygon (square) of unit length centered at the origin // This code draws each vertex in a different color. // The hardware will blend between them. // This is a useful debugging trick. I make sure each vertex // appears exactly where I expect it to appear. glbegin(gl_polygon); glcolor3f (1.0, 0.0, 0.0); glvertex3f (0.5, 0.5, 0.0); glcolor3f (0.0, 1.0, 0.0); glvertex3f (-0.5, 0.5, 0.0); glcolor3f (0.0, 0.0, 1.0); glvertex3f (-0.5, -0.5, 0.0); glcolor3f (1.0, 1.0, 1.0); glvertex3f (0.5, -0.5, 0.0); glend(); glflush () ; (-.5,.5) GREEN (-.5, -.5) BLUE (.5,.5) RED (.5, -.5) WHITE Demo (change colors)