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

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

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

Programming with OpenGL Part 1: Background

Computer Graphics. Bing-Yu Chen National Taiwan University

Introduction to OpenGL Week 1

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

GL_COLOR_BUFFER_BIT, GL_PROJECTION, GL_MODELVIEW

Drawing Primitives. OpenGL basics

Programming with OpenGL Part 1: Background

Programming using OpenGL: A first Introduction

Lecture 3. Understanding of OPenGL programming

Introduction to OpenGL

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

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

Graphics Programming

Lectures OpenGL Introduction

Lecture 4 of 41. Lab 1a: OpenGL Basics

Announcements OpenGL. Computer Graphics. Autumn 2009 CS4815

Announcements OpenGL. Computer Graphics. Spring CS4815

Lecture 2 2D transformations Introduction to OpenGL

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

Introduction to Computer Graphics with OpenGL/GLUT

COMPUTER GRAPHICS LAB # 3

Lecture 3 Advanced Computer Graphics (CS & SE )

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

Computer Graphics. Making Pictures. Computer Graphics CSC470 1

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

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

CS 4204 Computer Graphics

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

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

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

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

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

Computer Graphics. OpenGL

Basic Graphics Programming

RECITATION - 1. Ceng477 Fall

OpenGL/GLUT Intro. Week 1, Fri Jan 12

CS Computer Graphics: OpenGL, Continued

CS Computer Graphics: OpenGL, Continued

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

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

CS 432 Interactive Computer Graphics

Computer Graphics 1 Computer Graphics 1

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

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

Precept 2 Aleksey Boyko February 18, 2011

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

LECTURE 02 OPENGL API

Basic Graphics Programming

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

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

Exercise 1 Introduction to OpenGL

OpenGL Introduction Computer Graphics and Visualization

Computer graphics MN1

Computer Graphics Course 2005

COMP 371/4 Computer Graphics Week 1

C OMPUTER G RAPHICS Thursday

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

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

Computer Graphics, Chapt 08

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

Using OpenGL with CUDA

Introduction to OpenGL

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

Computer Graphics (Basic OpenGL)

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

Lecture 4. Interaction / Graphical Devices. CS 354 Computer Graphics Sunday, January 20, 13

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

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)

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

SOURCES AND URLS BIBLIOGRAPHY AND REFERENCES

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

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

CS Computer Graphics: Intro to OpenGL

CS Computer Graphics: Intro to OpenGL

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

CSE4030 Introduction to Computer Graphics

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

OpenGL Tutorial. Ceng 477 Introduction to Computer Graphics

Assignment 1. Simple Graphics program using OpenGL

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

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

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

An Overview GLUT GLSL GLEW

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

2 Transformations and Homogeneous Coordinates

Introduction to OpenGL: Part 2

Hierarchical Modeling: Tree of Transformations, Display Lists and Functions, Matrix and Attribute Stacks,

Comp 410/510 Computer Graphics Spring Input & Interaction

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

Bob s Concise Introduction to Doxygen

OpenGL refresher. Advanced Computer Graphics 2012

1.2 Basic Graphics Programming


Lecture 2 5 Aug 2004

Ulf Assarsson Department of Computer Engineering Chalmers University of Technology

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

GLUT. What is OpenGL? Introduction to OpenGL and GLUT

Transcription:

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

Today s Topic The secrets of Glut-tony 2

So let s do some graphics! For the next week or so this is your world: -1 1-1 1 A box ranging from [-1,1] in x, and [-1,1] in y We can easily draw in the box with a just few lines of code 3

So let s do some graphics! For the next week or so this is your world: void display11() { glclearcolor(0, 0, 0, 1); glclear(gl_color_buffer_bit); glcolor3d(0, 0.8, 1.0); glbegin(gl_polygon); glvertex2d(-0.5, -0.5); glvertex2d( 0.5, -0.5); glvertex2d( 0.5, 0.5); glvertex2d(-0.5, 0.5); glend(); glflush(); } Persistent State 4

So let s do some graphics! Make a small change void display2() { glviewport(0, 0, panelsize.width, panelsize.height); glclearcolor(0, 0, 0, 1); glclear(gl_color_buffer_bit); glcolor3d(0, 0.8, 1.0); glbegin(gl_polygon); glvertex2d(-0.5, -0.5); glvertex2d( 0.5, -0.5); glvertex2d( 0.5, 0.5); } glend(); glflush(); 5

So let s do some graphics! Another little tweak void Display3() { glclearcolor(0, 0, 0, 1); glclear(gl_color_buffer_bit); glcolor3d(0, 0.8, 1.0); double angle = 0; glbegin(gl_line_loop); for (int i = 0; i < 90; i++) { glvertex2d(math.cos(angle*math.pi/180.0), Math.Sin(angle*Math.PI/180.0)); angle += delta; } glend(); glflush(); } 6

OpenGL What is It? GL (Graphics Library): Library of 2-D, 3-D drawing primitives and operations API for 3-D hardware acceleration GLU (GL Utilities): Miscellaneous functions dealing with camera set-up and higher-level shape descriptions GLUT (GL Utility Toolkit): Window-system independent toolkit with numerous utility functions, mostly dealing with user interface Course web page has links to online function references (functions from each library start with library prefix i.e., gl*, glu*, glut*) Lecture 2

History of OpenGL Silicon Graphics (SGI) revolutionized the graphics workstation by implementing the pipeline in hardware (1982) To access the system, application programmers used a library called GL With GL, it was relatively simple to program three dimensional interactive applications 8

OpenGL: What is It? The success of GL lead to OpenGL (1992), a platform-independent API that was Easy to use Close enough to the hardware to get excellent performance Focus on rendering Omitted windowing and input to avoid window system dependencies 9

OpenGL Evolution Controlled by an Architectural Review Board (ARB) Members include SGI, Microsoft, Nvidia, HP, 3DLabs, IBM,. Relatively stable (present version 2.0) Evolution reflects new hardware capabilities 3D texture mapping and texture objects Vertex programs Allows for platform specific features through extensions 10

OpenGL Libraries GL (Graphics Library): Library of 2-D, 3-D drawing primitives and operations API for 3-D hardware acceleration GLU (GL Utilities): Miscellaneous functions dealing with camera set-up and higher-level shape descriptions GLUT (GL Utility Toolkit): Window-system independent toolkit with numerous utility functions, mostly dealing with user interface 11

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

OpenGL function format function name dimensions glvertex3f(x,y,z) belongs to GL library x,y,z are floats glvertex3fv(p) p is a pointer to an array 13

What is GLUT, Tony? A O/S agnostic OpenGL environment Advantages: Portable: Windows, Cygwin, Linux, Mac-OS minimal-overhead (Hides away details of opening windows, etc.) Appeals to C-hackers (console for printf() s, etc) Disadvantages Ugly (lacks look-and-feel of real app, outdated callback-based event-handling model) Limited Interaction Global variables galore 14

Event-driven GLUT program structure 1. Configure and open window 2. Initialize OpenGL state, program variables 3. Register callback functions Display (where rendering occurs) Resize User input: keyboard, mouse clicks, motion, etc. (next Tuesday) 4. Enter event processing loop Portions of some slides adapted from An Interactive Introduction to OpenGL Programming, D. Shreiner, E. Angel, V. Shreiner, SIGGRAPH 2001 course Lecture 2

Web site: Getting GLUT Windows: www.xmission.com/~nate/glut.html Others: www.opengl.org/developers/documentation/glut. html Overview: Appendix D of OpenGL Programming Guide Back to the Code 16

Program Structure Most OpenGL programs have the following structure main(): defines the callback functions opens one or more windows with the required properties enters event loop (last executable statement) init(): sets the state variables Viewing Attributes callbacks Display function Input and window functions 17

simple.c revisited #include <GL/glut.h> includes gl.h int main(int argc, char** argv) { glutinit(&argc,argv); glutinitdisplaymode(glut_single GLUT_RGB); glutinitwindowsize(500,500); glutinitwindowposition(0,0); glutcreatewindow("simple"); glutdisplayfunc(mydisplay); } init(); glutmainloop(); set OpenGL state define window properties enter event loop display callback 18

GLUT functions glutinit allows application to get command line arguments and initializes system gluinitdisplaymode requests properties for the window (the rendering context) RGB color Single buffering Properties logically ORed together glutwindowsize in pixels glutwindowposition from top-left corner of display glutcreatewindow create window with title simple glutdisplayfunc display callback glutmainloop enter infinite event loop 19

Window Initialization void init() { glclearcolor (0.0, 0.0, 0.0, 1.0); black clear color opaque window glcolor3f(1.0, 1.0, 1.0); glmatrixmode (GL_PROJECTION); fill/draw with white glloadidentity (); } //glortho2d(-1.0, 1.0, 1.0, -1.0); viewing volume i.e., world size 20

Display callback function 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(); 21

Input and Interaction Multiple input devices, each of which can send a trigger to the operating system at an arbitrary time by a user Button on mouse Pressing or releasing a key Each trigger generates an event whose measure is put in an event queue which can be examined by the user program 22

Callbacks Programming interface for event-driven input Define a callback function for each type of event the graphics system recognizes This user-supplied function is executed when the event occurs GLUT example: glutmousefunc(mymouse) mouse callback function 23

GLUT event loop Last line in main.c for a program using GLUT is the infinite event loop glutmainloop(); In each pass through the event loop, GLUT looks at the events in the queue for each event in the queue, GLUT executes the appropriate callback function if one is defined if no callback is defined for the event, the event is ignored In main.c glutdisplayfunc(mydisplay) identifies the function to be executed Every GLUT program must have a display callback 24

Posting redisplays Many events may invoke the display callback function Can lead to multiple executions of the display callback on a single pass through the event loop We can avoid this problem by instead using glutpostredisplay(); which sets a flag. GLUT checks to see if the flag is set at the end of the event loop If set then the display callback function is executed 25

Double Buffering Instead of one color buffer, we use two Front Buffer: one that is displayed but not written to Back Buffer: one that is written to but not displayed Program then requests a double buffer in main.c glutinitdisplaymode(gl_rgb GL_DOUBLE) At the end of the display callback buffers are swapped void mydisplay() { glclear(gl_color_buffer_bit.). /* draw graphics here */. glutswapbuffers() } 26

Using the idle callback The idle callback is executed whenever there are no events in the event queue glutidlefunc(myidle) Useful for animations void myidle() { /* change something */ t += dt glutpostredisplay(); } Void mydisplay() { glclear(); /* draw something that depends on t */ glutswapbuffers(); } 27

Using globals The form of all GLUT callbacks is fixed void mydisplay() void mymouse(glint button, GLint state, GLint x, GLint y) Must use globals to pass information to callbacks float t; /*global */ void mydisplay() { /* draw something that depends on t } 28

Other important functions glpushmatrix() / glpopmatrix() Pushes/pops the transformation matrix onto the matrix stack glloadidentity(), glloadmatrix(), glmultmatrix() Pushes the matrix onto the matrix stack Chapter 3 of the Red Book gives a detailed explanation of transformations Jackie Neider, Tom Davis, and Mason Woo, The OpenGL Programming Guide (The Red Book) 29

Rendering Steps (no animation) In function registered with glutdisplayfunc(): 1. Clear window: glclear(gl_color_buffer_bit) 2. Draw shapes Set colors, patterns, point/line sizes Specify type of geometric primitive(s) and list vertices 3. Make offscreen draw buffer the display buffer with glutswapbuffers() Lecture 2

Specifying Geometric Primitives Primitives are specified using glbegin(primtype);... glend(); primtype determines how vertices are combined GLfloat red, green, blue; GLfloat x, y; glbegin(primtype); for (i = 0; i < nverts; i++) { glcolor3f(red, green, blue); glvertex2f(x, y);... // change coord. values } glend(); Lecture 2

Drawing: Miscellaneous glcolor(): Range is [0, 1] for each color channel for glcolor3f(); [0, 255] for glcolor3ub() Can set persistent pen size outside of glbegin()/ glend() glpointsize(glfloat size) gllinewidth(glfloat width) glrect(x1, y1, x2, y2) specifying opposite corners of rectangle is equivalent to GL_POLYGON with four vertices listed (i.e., filled) Lecture 2

Next Time How to display an image World and Screen Space 33