CS Computer Graphics: OpenGL, Continued

Similar documents
CS Computer Graphics: OpenGL, Continued

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

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

CS Computer Graphics: Intro to OpenGL

CS Computer Graphics: Intro to OpenGL

Introduction to Computer Graphics with OpenGL/GLUT

Computer Graphics. Making Pictures. Computer Graphics CSC470 1

Computer Graphics 1 Computer Graphics 1

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

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

Computer Graphics. OpenGL

RECITATION - 1. Ceng477 Fall

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

COMPUTER GRAPHICS LAB # 3

Lecture 2 2D transformations Introduction to OpenGL

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

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

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

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

CS 4204 Computer Graphics

CS621 Lab 1 Name: Ihab Zbib

Drawing Primitives. OpenGL basics

Programming using OpenGL: A first Introduction

GL_COLOR_BUFFER_BIT, GL_PROJECTION, GL_MODELVIEW

Lecture 4 of 41. Lab 1a: OpenGL Basics

Lecture 3 Advanced Computer Graphics (CS & SE )

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

Graphics and Visualization

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

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

Computer Graphics. Bing-Yu Chen National Taiwan University

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

GLUT. What is OpenGL? Introduction to OpenGL and GLUT

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

Computer Graphics Course 2005

Exercise 1 Introduction to OpenGL

Assignment 1. Simple Graphics program using OpenGL

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

Computer graphics MN1

Rendering. Part 1 An introduction to OpenGL

Basic Graphics Programming

COMP 371/4 Computer Graphics Week 1

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

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

Computer Graphics Introduction to OpenGL

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

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

OpenGL refresher. Advanced Computer Graphics 2012

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

Computer Graphics (Basic OpenGL)

Computer Graphics Primitive Attributes

Computer Graphics, Chapt 08

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

Precept 2 Aleksey Boyko February 18, 2011

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

Lectures OpenGL Introduction

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

Draw the basic Geometry Objects. Hanyang University

Programming with OpenGL Part 1: Background

Introduction to OpenGL

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

CS 432 Interactive Computer Graphics

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

Computer Graphics. Downloaded from: LectureNotes 1 CSC-254

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

Computer Graphics (CS 543) Lecture 3b: Shader Setup & GLSL Introduction

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

Display Lists in OpenGL

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

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

CSC 8470 Computer Graphics. What is Computer Graphics?

Basic Graphics Programming

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

Introduction to OpenGL Week 1

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

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

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

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

Announcements OpenGL. Computer Graphics. Autumn 2009 CS4815

Announcements OpenGL. Computer Graphics. Spring CS4815

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

Programming of Graphics

Input and Interaction

Computer Graphics CS 543 Lecture 4 (Part 2) Building 3D Models (Part 2)

Introduction to OpenGL: Part 2

Computer Graphics Anatomy of GUI. Computer Graphics CSC470 1

An Overview GLUT GLSL GLEW

Computer Graphics. Chapter 3 Computer Graphics Software

Chapter 13 Selection and Feedback

OpenGL/GLUT Intro. Week 1, Fri Jan 12

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

Computer graphic -- Programming with OpenGL I

An Interactive Introduction to OpenGL Programming

Bob s Concise Introduction to Doxygen

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

Computer Graphics Introduction to OpenGL

Lecture 3. Understanding of OPenGL programming

Computer graphics MN1

Computer graphic -- Programming with OpenGL 2


Transcription:

CS 543 - Computer Graphics: OpenGL, Continued by Robert W. Lindeman gogo@wpi.edu (with help from Emmanuel Agu ;-) Last time. OpenGL set up Basic structure OpenGL skeleton Callback functions, etc. R.W. Lindeman - WPI Dept. of Computer Science 2 1

Last Time: 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 3 This Time: Do Some Real Stuff How to actually draw something OpenGL commands & data types Interaction with OpenGL program Interaction examples using keyboard and mouse Notes: State-based system Set the state(s) Send vertices R.W. Lindeman - WPI Dept. of Computer Science 4 2

Example: Rendering Callback Do all your drawing in the display function Called initially & when picture changes (e.g., resize) Recall, 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 5 Basic Drawing Primitives Draw points, lines, polylines, polygons Primitives are specified using format: glbegin( primtype ); // define your primitives here glend( ); primtype One of: GL_POINTS, GL_LINES, GL_POLYGON, etc. R.W. Lindeman - WPI Dept. of Computer Science 6 3

Basic Drawing Primitives: Example Example: Draw four dots Basic idea send sequence of vertices Connect them in manner determined by primtype glbegin( GL_POINTS ); glvertex2i( 100, 50 ); glvertex2i( 100, 130 ); glvertex2i( 150, 130 ); glvertex2i( 150, 50 ); glend( ); R.W. Lindeman - WPI Dept. of Computer Science 7 Parameters for glbegin( ) Draw dots glbegin( GL_POINTS ); Draw lines glbegin( GL_LINES ); R.W. Lindeman - WPI Dept. of Computer Science 8 4

Parameters for glbegin( ) Draw polylines glbegin( GL_LINE_STRIP ); Draw convex polygons glbegin( GL_POLYGON ); R.W. Lindeman - WPI Dept. of Computer Science 9 Parameters for glbegin( ) GL_POINTS // dots GL_LINES // lines, in pairs GL_LINE_STRIP // polylines GL_LINE_LOOP // closed loop GL_TRIANGLES // triangles, in threes GL_QUADS // quad, in fours vertices GL_POLYGON // convex filled polygon R.W. Lindeman - WPI Dept. of Computer Science 10 5

OpenGL Command Format glvertex2i( ) library gl glu glut basic command Vertex Color Clear Flush number of arguments 2 - (x,y) 3 - (x,y,z) 4 - (x,y,z,w) or (r,g,b,a) type of argument b - byte ub - unsigned byte s - short us - unsigned short i - int ui - unsigned int f - float d - double * - wildcard R.W. Lindeman - WPI Dept. of Computer Science 11 Some OpenGL Commands glvertex2i( ); // x,y vertex position glcolor3f( ); // RGB color glrecti( ); // aligned rectangled glclearcolor( ); // clear color in RGB glclear( ); // clears screen glflush( ); // forces image drawing R.W. Lindeman - WPI Dept. of Computer Science 12 6

OpenGL Data Types C++ signed char short int float double unsigned char unsigned short unsigned int OpenGL GLByte GLShort GLInt GLFloat GLDouble GLubyte GLushort GLuint R.W. Lindeman - WPI Dept. of Computer Science 13 Keyboard Interaction Declare prototype mykeyboard( unsigned int key, int x, int y ); Register callback glutkeyboardfunc( mykeyboard ); Key values ASCII value of key pressed X, Y values Coordinates of mouse location The function mykeyboard( ) contains a large switch statement to act depending on which key was pressed R.W. Lindeman - WPI Dept. of Computer Science 14 7

Example: Keyboard Callback How to use keyboard to control program 1. Register callback in main( ) function glutkeyboardfunc( mykeyboard ); 2. Implement keyboard function void mykeyboard( unsigned int key, int x, int y ) { // put keyboard stuff here... switch( key ) { // check which key case f : // do stuff break;... R.W. Lindeman - WPI Dept. of Computer Science 15 Mouse Interaction Declare prototype mymouse( int button, int state, int x, int y ) mymovedmouse(... ); Register callbacks glutmousefunc( mymouse ) // when mouse button pressed glutmotionfunc( mymovedmouse ) // when mouse moves button parameter value will be one of GLUT_LEFT_BUTTON, GLUT_MIDDLE_BUTTON, GLUT_RIGHT_BUTTON state parameter value will be one of GLUT_UP, GLUT_DOWN x, y parameters will have the mouse coordinates R.W. Lindeman - WPI Dept. of Computer Science 16 8

Mouse Interaction Example Each mouse click generates separate events So, need to do your own checking, etc. in your mouse function Example: draw (or select ) rectangle on screen R.W. Lindeman - WPI Dept. of Computer Science 17 Mouse Interaction Example (cont.) void mymouse( int button, int state, int x, int y ) { static GLintPoint corner[2]; static int numcorners = 0; // initial value is 0 if( button == GLUT_LEFT_BUTTON && state == GLUT_DOWN ) { corner[numcorners].x = x; corner[numcorners].y = screenheight y; //flip y coord numcorners++; if( numcorners == 2 ) { // draw rectangle or do whatever you planned to do glrecti( corner[0].x, corner[0].y, corner[1].x, corner[1].y ); numcorners = 0; else { if( button == GLUT_RIGHT_BUTTON && state == GLUT_DOWN ) { glclear( GL_COLOR_BUFFER_BIT ); // clear the window glflush( ); R.W. Lindeman - WPI Dept. of Computer Science 18 9

OpenGL State OpenGL tracks states Drawing color Point size Rendered object's appearance based on current state State variable remains active until changed R.W. Lindeman - WPI Dept. of Computer Science 19 References Hill, chapter 2 R.W. Lindeman - WPI Dept. of Computer Science 20 10