CS Computer Graphics: Intro to OpenGL

Similar documents
CS Computer Graphics: Intro to OpenGL

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

CS Computer Graphics: OpenGL, Continued

CS Computer Graphics: OpenGL, Continued

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

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

RECITATION - 1. Ceng477 Fall

COMPUTER GRAPHICS LAB # 3

Introduction to Computer Graphics with OpenGL/GLUT

CS 432 Interactive Computer Graphics

Computer Graphics. Bing-Yu Chen National Taiwan University

GLUT. What is OpenGL? Introduction to OpenGL and GLUT

OpenGL refresher. Advanced Computer Graphics 2012

Programming using OpenGL: A first Introduction

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

GL_COLOR_BUFFER_BIT, GL_PROJECTION, GL_MODELVIEW

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

Drawing Primitives. OpenGL basics

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

Announcements OpenGL. Computer Graphics. Autumn 2009 CS4815

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

Announcements OpenGL. Computer Graphics. Spring CS4815

Computer Graphics 1 Computer Graphics 1

CS 4204 Computer Graphics

An Overview GLUT GLSL GLEW

Lecture 4 of 41. Lab 1a: OpenGL Basics

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

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

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

Computer graphics MN1

COMP 371/4 Computer Graphics Week 1

Graphics and Visualization

Computer Graphics. OpenGL

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

Lectures OpenGL Introduction

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

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

Computer Graphics (CS 543) Lecture 1 (Part 1): Introduction to Computer Graphics

Computer Graphics, Chapt 08

LECTURE 02 OPENGL API

Lecture 3 Advanced Computer Graphics (CS & SE )

Introduction to OpenGL Week 1

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

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

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

Basic Graphics Programming

CSE4030 Introduction to Computer Graphics

Using OpenGL with CUDA

Lecture 2 2D transformations Introduction to OpenGL

Computer Graphics (Basic OpenGL)

Programming with OpenGL Part 1: Background

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

Programming with OpenGL Part 1: Background

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

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

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

OpenGL/GLUT Intro. Week 1, Fri Jan 12

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

Introduction to OpenGL: Part 2

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

Exercise 1 Introduction to OpenGL

Computer Graphics (4731) Lecture 4: 2D Graphics Systems (Drawing Polylines, tiling, & Aspect Ratio)

Assignment 1. Simple Graphics program using OpenGL

Bob s Concise Introduction to Doxygen

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

Computer Graphics Introduction to OpenGL

CS380: Computer Graphics Basic OpenGL Structure. Sung-Eui Yoon ( 윤성의 ) Course URL:

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

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

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

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

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

Computer Graphics. Making Pictures. Computer Graphics CSC470 1

Basic Graphics Programming

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

Display Lists in OpenGL

Introduction to MS Visual C/C++

Computer Graphics (CS 543) Lecture 2b: 2D Graphics Systems (Drawing Polylines, tiling, & Aspect Ratio)

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

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

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

Lecture 3. Understanding of OPenGL programming

Introduction to OpenGL

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

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

Programming with OpenGL Part 3: Three Dimensions

OpenGL Introduction Computer Graphics and Visualization

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

Introduction to OpenGL

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

Precept 2 Aleksey Boyko February 18, 2011

CS Computer Graphics: Raster Graphics, Part 3

An Interactive Introduction to OpenGL Programming

Computer Graphics Course 2005

Draw the basic Geometry Objects. Hanyang University

Input and Interaction

2 Transformations and Homogeneous Coordinates

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

Graphics Programming

Transcription:

CS 543 - Computer Graphics: Intro to OpenGL by Robert W. Lindeman gogo@wpi.edu (with help from Emmanuel Agu ;-)

OpenGL Basics Last time: What is Computer Graphics? What is a graphics library What to expect from class Intro stuff. Today: Start learning OpenGL basics OpenGL program structure "Hello, world!" skeleton Note: Only basics here! Learn a bunch on your own (more fun anyway!) R.W. Lindeman - WPI Dept. of Computer Science 2

OpenGL Basics Primary goal: rendering Rendering? Convert geometric/mathematical object and environment descriptions into images OpenGL can render: Geometric primitives (lines, dots, etc.) Bitmap images (.bmp,.jpg, etc.) OpenGL does not do window, mouse, keyboard, or device management R.W. Lindeman - WPI Dept. of Computer Science 3

OpenGL Basics Low-level graphics rendering Application Programming Interface (API) Widely used all over the graphics field Will be used in this class Highly portable Display device independent Window system independent (X Windows, Aqua, Windows, etc.) OS independent (Unix, OS X, Linux, Windows, etc.) OpenGL programs behave same on different output devices and OSs Event-driven approach R.W. Lindeman - WPI Dept. of Computer Science 4

OpenGL: Event-Driven Programming Very important programming model! Program only responds to events Do nothing until event occurs Sample Events: mouse click, key stroke, window resize Programmer defines Events of interest Actions to take upon event occurrence System Maintains an event queue Dispatches events to programmer-defined code Left-mouse click Keyboard h key R.W. Lindeman - WPI Dept. of Computer Science 5

OpenGL: Event-Driven vs. Sequential Programming Sequential program Read some data Do some processing Print some results Event-driven program Initialize some things Enter an infinite loop Wait until defined event occurs Take defined action What is the world s most widely used event-driven program? R.W. Lindeman - WPI Dept. of Computer Science 6

OpenGL: Event-Driven Programming in OpenGL How in OpenGL? Programmer registers callback functions Callback function called when associated event occurs Example: Declare a function mymouse to respond to mouse click Register it: Tell OpenGL to call it when mouse clicked Code? glutmousefunc( mymouse ); Notice this is not an OpenGL function! R.W. Lindeman - WPI Dept. of Computer Science 7

OpenGL Utility Toolkit (GLUT) OpenGL Window system independent Concerned only with drawing No window-management functions (create, resize, etc.) Very portable GLUT: Minimal window management: fast prototyping Interfaces with different windowing systems Allows easy porting between windowing systems By far the most-widely used library for OpenGL GLUI: More-advanced GUI widgets R.W. Lindeman - WPI Dept. of Computer Science 8

OpenGL Utility Toolkit (GLUT) No bells nor whistles No sliders No dialog boxes No menu bar, etc. To add bells and whistles, need other API: GLUI Qt X window system Microsoft: WGL, etc. R.W. Lindeman - WPI Dept. of Computer Science 9

Getting Started with First OpenGL Program At top of program, include required headers #include <gl/gl.h> #include <gl/glu.h> gl directory is sub-directory of your include file location Then include GLUT for window management #include <gl/glut.h> R.W. Lindeman - WPI Dept. of Computer Science 10

Getting Started If you want full-blown, pull-down windows (WGL, AGL, etc.) #include <windows.h> // do this before gl.h, glu.h Most OpenGL applications use standard C library so #include <stdlib.h> #include <stdio.h> R.W. Lindeman - WPI Dept. of Computer Science 11

Program Structure Configure and open window (GLUT) Initialize OpenGL state Register input callback functions (GLUT) Render Resize Input: keyboard, mouse, etc. My initialization Set background color, clear color, drawing color, point size, establish coordinate system, etc. glutmainloop( ); Draws image and waits infinitely until action occurs R.W. Lindeman - WPI Dept. of Computer Science 12

GLUT: Opening a window glutinit( &argc, argv ); // initializes glutinitdisplaymode( GLUT_SINGLE GLUT_RGB ); // sets display mode (e.g., single buffer with RGB colorspace) glutinitwindowsize( 640, 480 ); // sets window size (WxH) glutinitposition( 100, 150 ); // sets upper left corner of window glutcreatewindow( my first attempt ); // open window with title my first attempt R.W. Lindeman - WPI Dept. of Computer Science 13

OpenGL Skeleton int main( int argc, char *argv[] ) { // First initialize toolkit, set display mode and create window glutinit( &argc, argv ); glutinitdisplaymode( GLUT_SINGLE GLUT_RGB ); glutinitwindowsize( 640, 480 ); glutinitwindowposition( 100, 150 ); glutcreatewindow( my first attempt ); } //...then register callback functions //...do my initialization //...wait in glutmainloop for events 100 150 my first attempt 480 640 R.W. Lindeman - WPI Dept. of Computer Science 14

GLUT Callback Functions Register all events your program will react to Event occurs => system generates callback Callback: routine system calls when event occurs No registered callback = no reaction! Example: if you do not define a keyboard callback function, you can bang on keyboard all you want, NO RESPONSE!! Except from your neighbor. R.W. Lindeman - WPI Dept. of Computer Science 15

GLUT Callback Functions in Skeleton glutdisplayfunc( mydisplay ); // called when window contents need to be redrawn glutreshapefunc( myreshape ); // called when window is reshaped glutmousefunc( mymouse ); // called when mouse button is pressed glutkeyboardfunc( mykeyboard ); // called when keyboard is pressed or released glutmainloop( ); // Now draw the initial picture and enter infinite loop until a registered event occurs R.W. Lindeman - WPI Dept. of Computer Science 16

Example: Rendering Callback Do all your drawing in the display function Called initially & when picture changes (e.g., resize) First, register callback in main( ) function glutdisplayfunc( mydisplay ); Then, implement display function void mydisplay( void ) { // put drawing stuff here... glbegin( GL_LINES ); glvertex3fv( v[0] ); glvertex3fv( v[1] );... glend( ); } R.W. Lindeman - WPI Dept. of Computer Science 17

OpenGL Skeleton int main( int argc, char *argv[] ) { // First initialize toolkit, set display mode and create window glutinit( &argc, argv ); glutinitdisplaymode( GLUT_SINGLE GLUT_RGB ); glutinitwindowsize( 640, 480 ); glutinitwindowposition( 100, 150 ); glutcreatewindow( my first attempt ); // Now register callback functions glutdisplayfunc( mydisplay ); glutreshapefunc( myreshape ); glutmousefunc( mymouse ); glutkeyboardfunc( mykeyboard ); } myinit( ); glutmainloop( ); R.W. Lindeman - WPI Dept. of Computer Science 18

Final Thoughts Need for global variables Callback API is predefined No way to add parameters R.W. Lindeman - WPI Dept. of Computer Science 19

References Hill, chapter 2 R.W. Lindeman - WPI Dept. of Computer Science 20