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

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


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

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

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

Computer Graphics Introduction to OpenGL

OpenGL Programming Guide Chapter 1, Introduction to OpenGL 1

GL_COLOR_BUFFER_BIT, GL_PROJECTION, GL_MODELVIEW

Computer Graphics Primitive Attributes

Basic Graphics Programming

Computer Graphics. Making Pictures. Computer Graphics CSC470 1

Lectures OpenGL Introduction

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

Introduction to Computer Graphics with OpenGL/GLUT

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

Basic Graphics Programming

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

Lecture 2 2D transformations Introduction to OpenGL

Lecture 3 Advanced Computer Graphics (CS & SE )

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

Introduction to OpenGL

CS Computer Graphics: OpenGL, Continued

CS Computer Graphics: OpenGL, Continued

COMPUTER GRAPHICS LAB # 3

Lecture 3. Understanding of OPenGL programming

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

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

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

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

Lecture 4 of 41. Lab 1a: OpenGL Basics

Computer Graphics. OpenGL

Display Lists in OpenGL

Computer Graphics Course 2005

Introduction to OpenGL: Part 2

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

Interaction Computer Graphics I Lecture 3

Interaction. CSCI 480 Computer Graphics Lecture 3

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

Drawing Primitives. OpenGL basics

CS 4204 Computer Graphics

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

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

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

Computer Graphics. Bing-Yu Chen National Taiwan University

Computer Graphics (Basic OpenGL)

RECITATION - 1. Ceng477 Fall

Precept 2 Aleksey Boyko February 18, 2011

Computer Graphics 1 Computer Graphics 1

Using OpenGL with CUDA

OpenGL/GLUT Intro. Week 1, Fri Jan 12

Computer Graphics Introduction to OpenGL

UNIT 7 LIGHTING AND SHADING. 1. Explain phong lighting model. Indicate the advantages and disadvantages. (Jun2012) 10M

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

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

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

Programming with OpenGL Part 3: Three Dimensions

Chapter 13 Selection and Feedback

Graphics Programming

Programming using OpenGL: A first Introduction

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

COMP 371/4 Computer Graphics Week 1

OpenGL refresher. Advanced Computer Graphics 2012

C OMPUTER G RAPHICS Thursday

Announcements OpenGL. Computer Graphics. Autumn 2009 CS4815

Programming with OpenGL Part 1: Background

cs123 Lab 3 OpenGL Part One 1 Introduction 2 OpenGL Basics 2.2 The Rendering Pipeline 2.1 The CPU and the GPU 2.3 Basic Syntax of OpenGL commands

Exercise 1 Introduction to OpenGL

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

CSE4030 Introduction to Computer Graphics

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

Computer graphics MN1

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

6. Make use of glviewport() to display two sine curves on the same screen, one on the

Source code: #include <iostream>

Announcements OpenGL. Computer Graphics. Spring CS4815

Computer Graphics Introduction to OpenGL

Computer Graphics, Chapt 08

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

20 GLuint objects; 36 Scale += 0.1; 37 break; 38 case GLUT_KEY_DOWN:

Chapter 7 Display Lists

Computer Graphics Introduction to OpenGL

Interaction. CSCI 420 Computer Graphics Lecture 3

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

1.2 Basic Graphics Programming

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

Introduction to OpenGL

LAB MANUAL. Computer Graphics using OpenGL Department of CSE & IT, JUIT. Chief Course Coordinator: Dr Rajesh Siddavatam Associate Professor, CSE& IT

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

CS621 Lab 1 Name: Ihab Zbib

Introduction to OpenGL Week 1

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

Assignment 1. Simple Graphics program using OpenGL

Computer graphics MN1

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

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

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

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

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

Bob s Concise Introduction to Doxygen

Transcription:

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

Reading Redbook Ch 1 & 2

So far: 3D Geometry Pipeline Model Space (Object Space) Rotation Translation Resizing World Space M Rotation Translation world >view Eye Space (View Space) Mview >canonical Mcanonical > pixel Canonical View Space Screen Space (2D) Image Space (pixels) Raster Space

OpenGL We have been focused on math description We ll move on practical graphics programming for a week

Modern graphics systems Photoshop 3D Max Softimage Maya and? OpenGL Direct3D nvidia ATI Display Your homework

OpenGL A software interface to graphics hardware. 700 distinct commands 650 in the core OpenGL 50 in the utility library Specify objects, viewing, lighting, surface material Hardware independent interface No commands for windowing tasks No high level object models You need to specify geometric primitives Points, lines, polygons.

What can OpenGL do? wireframe

What can OpenGL do? Antialised lines

What can OpenGL do? Depth cue using fog

What can OpenGL do? Flat-shaded polygons

What can OpenGL do? Lighting and smooth-shaded polygons

What can OpenGL do? Texturemap and shadow

What can OpenGL do? Motion blur

What can OpenGL do? View point change

What can OpenGL do? Smoke

What can OpenGL do? Depth of field

Hello, world #include <whateveryouneed.h> main() { OpenAWindowPlease(); glclearcolor(0.0, 0.0, 0.0, 0.0); glclear(gl_color_buffer_bit); glcolor3f(1.0, 1.0, 1.0); glortho( 1.0, 1.0, 1.0, 1.0, 1.0, 1.0); glbegin(gl_polygon); glvertex2f( 0.5, 0.5); glvertex2f( 0.5, 0.5); glvertex2f(0.5, 0.5); glvertex2f(0.5, 0.5); glend(); glflush(); } KeepTheWindowOnTheScreenForAWhile();

OpenGL syntax gl prefix for all commands GL_ for constants glcolor3f(1.0, 1.0, 1.0); glcolor3d(1.0, 1.0, 1.0); glcolor3s(1, 1, 1); glcolor3i(1, 1, 1); Suffix Data Type Typical Corresponding C Language Type OpenGL Type Definition b 8 bit integer signed char GLbyte s 16 bit integer short GLshort i 32 bit integer long GLint, GLsizei f 32 bit floating point float GLfloat, GLclampf d 64 bit floating point double GLdouble, GLclampd ub 8 bit unsigned integer unsigned char GLubyte, GLboolean us 16 bit unsigned integer unsigned short GLushort ui 32 bit unsigned integer unsigned long GLuint, GLenum, GLbitfield

OpenGL syntax glvertex2i(1, 1); glvertex2f(1.0, 1.0); glcolor3f(1.0, 0.0, 0.0); glcolor3ub(255, 0, 0); glcolor3f(1.0, 0.0, 0.0); float color_array[] = {1.0, 0.0, 0.0}; glcolor3fv(color_array);

Windows management GLUT lib #include <GL/gl.h> #include <GL/glut.h> int main(int argc, char** argv){ glutinit(&argc, argv); glutinitdisplaymode (GLUT_SINGLE GLUT_RGB); glutinitwindowsize (250, 250); glutinitwindowposition (100, 100); glutcreatewindow ("hello"); init (); }

Windows management GLUT lib #include <GL/gl.h> #include <GL/glut.h> int main(int argc, char** argv){ glutinit(&argc, argv); glutinitdisplaymode (GLUT_SINGLE GLUT_RGB); glutinitwindowsize (250, 250); glutinitwindowposition (100, 100); glutcreatewindow ("hello"); init (); glutdisplayfunc(display); } void init (void) { glclearcolor (0.0, 0.0, 0.0, 0.0); glmatrixmode(gl_projection); glloadidentity(); glortho(0.0, 1.0, 0.0, 1.0, 1.0, 1.0); }

Windows management GLUT lib #include <GL/gl.h> #include <GL/glut.h> int main(int argc, char** argv){ glutinit(&argc, argv); glutinitdisplaymode (GLUT_SINGLE GLUT_RGB); glutinitwindowsize (250, 250); glutinitwindowposition (100, 100); glutcreatewindow ("hello"); init (); glutdisplayfunc(display); glutmainloop(); return 0; } void display(void){ glclear (GL_COLOR_BUFFER_BIT); glcolor3f (1.0, 1.0, 1.0); glbegin(gl_polygon); glvertex2f( 0.5, 0.5); glvertex2f( 0.5, 0.5); glvertex2f(0.5, 0.5); glvertex2f(0.5, 0.5); glend(); glflush (); }

Animation open_window(); for (i = 0; i < 1000000; i++) { clear_the_window(); draw_frame(i); wait_until_a_24th_of_a_second_is_over(); } Q: What happens when you write to the framebuffer while it is being displayed on the monitor?

Animation open_window(); for (i = 0; i < 1000000; i++) { clear_the_window(); draw_frame(i); wait_until_a_24th_of_a_second_is_over(); } Q: What happens when you write to the framebuffer while it is being displayed on the monitor?

Animation open_window(); for (i = 0; i < 1000000; i++) { clear_the_window(); draw_frame(i); wait_until_a_24th_of_a_second_is_over(); swap_the_buffers(); } Q: What happens when you write to the framebuffer while it is being displayed on the monitor?

Animation Example int main(int argc, char** argv){ glutinit(&argc, argv); glutinitdisplaymode (GLUT_DOUBLE GLUT_RGB); glutinitwindowsize (250, 250); glutinitwindowposition (100, 100); glutcreatewindow (argv[0]); init (); glutdisplayfunc(display); void init(void) { glclearcolor (0.0, 0.0, 0.0, 0.0); glshademodel (GL_FLAT); } }

Animation Example int main(int argc, char** argv){ glutinit(&argc, argv); static GLfloat spin = 0.0; glutinitdisplaymode (GLUT_DOUBLE GLUT_RGB); glutinitwindowsize (250, 250); void display(void){ glutinitwindowposition (100, 100); glclear(gl_color_buffer_bit); glutcreatewindow (argv[0]); glpushmatrix(); init (); glrotatef(spin, 0.0, 0.0, 1.0); glutdisplayfunc(display); glcolor3f(1.0, 1.0, 1.0); glutmousefunc(mouse); glrectf( 25.0, 25.0, 25.0, 25.0); glpopmatrix(); glutswapbuffers(); } }

Animation Example void mouse(int button, int state, int x, int y) { switch (button) { case GLUT_LEFT_BUTTON: if (state == GLUT_DOWN) glutidlefunc(spindisplay); break; } case GLUT_MIDDLE_BUTTON: if (state == GLUT_DOWN) glutidlefunc(null); break; default: break; } spindisplay(void){ spin = spin + 2.0; } if (spin > 360.0) spin = 360.0; glutpostredisplay(); int main(int argc, char** argv){ glutinit(&argc, argv); glutinitdisplaymode (GLUT_DOUBLE GLUT_RGB); glutinitwindowsize (250, 250); glutinitwindowposition (100, 100); glutcreatewindow (argv[0]); init (); glutdisplayfunc(display); glutmousefunc(mouse); glutreshapefunc(reshape); }

Animation Example void reshape(int w, int h){ glviewport (0, 0, (GLsizei) w, (GLsizei) h); glmatrixmode(gl_projection); int main(int argc, char** argv){ glloadidentity(); glutinit(&argc, argv); glortho( 50.0, 50.0, 50.0, 50.0, 1.0, glutinitdisplaymode 1.0); (GLUT_DOUBLE GLUT_RGB); glmatrixmode(gl_modelview); glutinitwindowsize (250, 250); glloadidentity(); glutinitwindowposition (100, 100); } glutcreatewindow (argv[0]); init (); glutdisplayfunc(display); glutmousefunc(mouse); glutreshapefunc(reshape); glutmainloop(); return 0; }

Event Driven Programming Window management library GLUT / FLTK Events: key strokes, mouse clicks Event handlers: mouse(), display(), reshape()

Viewport void reshape (int w, int h) { glviewport (0, 0, w, h); glmatrixmode (GL_PROJECTION); glloadidentity (); gluortho2d (0.0, w, 0.0, h); }

Points Lines Points, lines, and polygons Polygons Simple Polygonss: Convex & planar Nonplanar Polygon Transformed to Nonsimple Polygon

glbegin(gl_polygon); glvertex2f(0.0, 0.0); glvertex2f(0.0, 3.0); glvertex2f(4.0, 3.0); glvertex2f(6.0, 1.5); glvertex2f(4.0, 0.0); glend(); Drawing Primitives

glbegin(gl_points); glvertex2f(0.0, 0.0); glvertex2f(0.0, 3.0); glvertex2f(4.0, 3.0); glvertex2f(6.0, 1.5); glvertex2f(4.0, 0.0); glend(); Drawing Primitives

Drawing Primitives

Drawing Primitives

Drawing Primitives

Drawing Primitives

glpointsize(glfloat size) Primitive Details Approximate the point by squares for anti aliasing glenable(gl_point_smooth);

Primitive Details gllinewidth(glfloat width) Approximate the line by a rectangle for anti aliasing glenable (GL_LINE_SMOOTH); gllinewidth (1.5);

Primitive Details glpolygonmode(glenum face, GLenum mode); face: GL_FRONT, GL_BACK mode: GL_POINT, GL_LINE, GL_FILL glpolygonmode(gl_front, GL_FILL); glrectf(0, 0, 100, 100); glpolygonmode(gl_front, GL_LINE); glrectf(0, 0, 100, 100);