Computer Graphics. Bing-Yu Chen National Taiwan University

Similar documents
Programming with OpenGL Part 1: Background

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

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

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

Exercise 1 Introduction to OpenGL

Lecture 4 of 41. Lab 1a: OpenGL Basics

OpenGL refresher. Advanced Computer Graphics 2012

Computer Graphics 1 Computer Graphics 1

Introduction to Computer Graphics with OpenGL/GLUT

CS 4204 Computer Graphics

Lecture 2 2D transformations Introduction to OpenGL

Introduction to OpenGL Week 1

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

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

Programming using OpenGL: A first Introduction

RECITATION - 1. Ceng477 Fall

Programming with OpenGL Part 1: Background

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

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

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

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

Drawing Primitives. OpenGL basics

GL_COLOR_BUFFER_BIT, GL_PROJECTION, GL_MODELVIEW

COMP 371/4 Computer Graphics Week 1

CS Computer Graphics: OpenGL, Continued

CS Computer Graphics: OpenGL, Continued

Computer Graphics. OpenGL

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

CS Computer Graphics: Intro to OpenGL

CS Computer Graphics: Intro to OpenGL

Introduction to OpenGL

LECTURE 02 OPENGL API

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

Graphics Programming

CIS 441/541: Introduction to Computer Graphics Lecture 14: OpenGL Basics

OpenGL/GLUT Intro. Week 1, Fri Jan 12

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

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

GLUT. What is OpenGL? Introduction to OpenGL and GLUT

Lectures OpenGL Introduction

An Interactive Introduction to OpenGL Programming

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

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

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

Introduction to OpenGL

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

OpenGL Introduction Computer Graphics and Visualization

An Overview GLUT GLSL GLEW

COMPUTER GRAPHICS LAB # 3

Computer graphics MN1

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

CSE4030 Introduction to Computer Graphics

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

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

OPEN GL BACKGROUND. Objectives. Early History of APIs. SGI and GL. PHIGS and X. Modified from Angel 6e book slides

Computer Graphics Course 2005

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

Computer Graphics, Chapt 08

Precept 2 Aleksey Boyko February 18, 2011

Rendering. Part 1 An introduction to OpenGL

OpenGL and GLUT. COMP413 Computer Graphics. School of Computer Sci. & Eng. Kyungpook National University, Korea. Spring Semester, 2016

Basic Graphics Programming

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

Basic Graphics Programming

Project Sketchpad. Ivan Sutherland (MIT 1963) established the basic interactive paradigm that characterizes interactive computer graphics:

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

Assignment 1. Simple Graphics program using OpenGL

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

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

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

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

Computer Graphics (Basic OpenGL)

Lecture 3. Understanding of OPenGL programming

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

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

(21) OpenGL GUI. OpenGL GUI 1 UNIX MAGAZINE UNIX. SGI (Silicon Graphics Inc.) Windows PC GUI. UNIX Windows GUI. Java. 1 prefposition() X X

Computer Graphics Introduction to OpenGL

Lecture 3 Advanced Computer Graphics (CS & SE )

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

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

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

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

CS 432 Interactive Computer Graphics

Announcements OpenGL. Computer Graphics. Autumn 2009 CS4815

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

GLUT Tutorial. John Tsiombikas (Nuclear / The Lab Demos) May 6, Introduction to GLUT (OpenGL Utility Toolkit)

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


Announcements OpenGL. Computer Graphics. Spring CS4815

Computer Graphics Primitive Attributes

SOURCES AND URLS BIBLIOGRAPHY AND REFERENCES

Graphics and Visualization

Introduction to OpenGL: Part 2

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

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

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

Using OpenGL with CUDA

Computer Graphics. Chapter 3 Computer Graphics Software

Lecture 10: Input, Interaction & callbacks. CITS 3003 Graphics & Animation

Display Lists in OpenGL

Transcription:

Computer Graphics Bing-Yu Chen National Taiwan University

Introduction to OpenGL General OpenGL Introduction An Example OpenGL Program Drawing with OpenGL Transformations Animation and Depth Buffering Lighting Evaluation and NURBS Texture Mapping Advanced OpenGL Topics Imaging modified from Dave Shreiner, Ed Angel, and Vicki Shreiner. An Interactive Introduction to OpenGL Programming. ACM SIGGRAPH 2001 Conference Course Notes #54. & ACM SIGGRAPH 2004 Conference Course Notes #29.

What is OpenGL? & What can it do for me? OpenGL is a computer graphics rendering API generate high-quality color images by rendering with geometric and image primitives create interactive applications with 3D graphics window system independent operating system independent

OpenGL as a Renderer Geometric primitives points, lines and polygons Image Primitives images and bitmaps separate pipeline for images & geometry linked through texture mapping Rendering depends on state colors, materials, light sources, etc.

OpenGL Libraries OpenGL core library OpenGL32 on Windows GL on most unix/linux systems OpenGL Utility Library (GLU) part of OpenGL Provides functionality in OpenGL core but avoids having to rewrite code NURBS, tessellators, quadric shapes, etc.

OpenGL Libraries Links with window system GLX for X window systems WGL for Widows AGL for Macintosh glue between OpenGL & windowing systems

GLUT OpenGL Utility Library (GLUT) Provides functionality common to all window systems Open a window Get input from mouse and keyboard Menus Event-driven Code is portable but GLUT lacks the functionality of a good toolkit for a specific platform Slide bars

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

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

OpenGL Functions Primitives Points Line Segments Polygons Attributes Transformations Viewing Modeling Control Input (GLUT)

What is Required for your Programs Headers Files #include <GL/gl.h> #include <GL/glext.h> #include <GL/glu.h> #include <GL/glut.h> Libraries Enumerated Types OpenGL defines numerous types for compatibility GLfloat, GLint, GLenum, etc.

Lack of Object Orientation OpenGL is not object oriented so that there are multiple functions for a given logical function, e.g. glvertex3f, glvertex2i, glvertex3dv,.. Underlying storage mode is the same Easy to create overloaded functions in C++ but issue is efficiency

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 )

OpenGL State OpenGL is a state machine OpenGL functions are of two types Primitive generating Can cause output if primitive is visible How vertices are processes and appearance of primitive are controlled by the state State changing Transformation functions Attribute functions

The OpenGL Pipeline Vertex Processing Fragment Processing Framebuffer Processing is controlled by setting OpenGL s state colors, lights and object materials, texture maps drawing styles, depth testing

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

Sequence of Most OpenGL Programs configure and open a window initialize OpenGL s state process user events update OpenGL s state (if necessary) Draw an image

A Simple Program Generate a square on a solid background

simple.c #include <GL/glut.h> void mydisplay(){ glclear(gl_color_buffer_bit); 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(); } int main(int argc, char** argv){ glutcreatewindow("simple"); glutdisplayfunc(mydisplay); glutmainloop(); }

Event Loop Note that the program defines a display callback function named mydisplay Every glut program must have a display callback The display callback is executed whenever OpenGL decides the display must be refreshed, for example when the window is opened The main function ends with the program entering an event loop

Notes on Compilation Unix/linux Include files usually in /include/gl Compile with lglut lglu lgl loader flags May have to add L flag for X libraries Mesa implementation included with most linux distributions Check web for latest versions of Mesa and glut

Compilation on Windows Visual C++ / Borland C Get glut.h, glut32.lib and glut32.dll Create a console application Add opengl32.lib, glu32.lib, glut32.lib to project settings (under link tab) Cygwin (linux under Windows) Can use gcc and similar makefile to linux Use lopengl32 lglu32 lglut32 flags

Another 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 Set up whatever state you re going to use 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 & continuous update glutidlefunc( idle ); void idle( void ) { } t += dt; glutpostredisplay();

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

On-Line Resources http://www.opengl.org/ start here; up to date specification and lots of sample code news:comp.graphics.api.opengl http://www.sgi.com/software/opengl/ http://www.mesa3d.org/ Brian Paul s Mesa 3D http://www.cs.utah.edu/~narobins/opengl.html very special thanks to Nate Robins for the OpenGL Tutors source code for tutors available here!

Books M. Woo, J. Neider, T. Davis, D. Shreiner. OpenGL Programming Guide: The Official Guide to Learning OpenGL, ver. 1.2, 3rd. ed., Addison-Wesley, 1999.

Books D. Shreiner. OpenGL Reference Manual: The Official Reference Document to OpenGL, ver. 1.2, 3rd. ed., Addison-Wesley, 1999.

Books E. Angel. Interactive Computer Graphics: A Top-Down Approach with OpenGL, 3rd. ed., Addison-Wesley, 2002.