CP SC 4040/6040 Computer Graphics Images. Joshua Levine

Similar documents
CP SC 4040/6040 Computer Graphics Images. Joshua Levine

CPSC 4040/6040 Computer Graphics Images. Joshua Levine

GL_COLOR_BUFFER_BIT, GL_PROJECTION, GL_MODELVIEW

CS Computer Graphics: Intro to OpenGL

CS Computer Graphics: Intro to OpenGL

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

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

Lectures OpenGL Introduction

CS 432 Interactive Computer Graphics

Multimedia Retrieval Exercise Course 2 Basic of Image Processing by OpenCV

Introduction to OpenGL

Chapter 3. Texture mapping. Learning Goals: Assignment Lab 3: Implement a single program, which fulfills the requirements:

CpSc 101, Fall 2015 Lab7: Image File Creation

Lesson 7. Reading and Writing a.k.a. Input and Output

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

CS193E Lecture 17. Multiple Document Windows OpenGL & Cocoa

Computer Graphics. Bing-Yu Chen National Taiwan University

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

OpenImageIO 0.7. Programmer Documentation. (in progress) Editor: Larry Gritz Date: 20 July, 2009 (with corrections, 26 July, 2009)

CSC 8470 Computer Graphics. What is Computer Graphics?

Announcements OpenGL. Computer Graphics. Spring CS4815

CS103L PA4. March 25, 2018

Bridging Graphics. Lori Scarlatos, January 2007

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

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

Representation of image data

Introduction to Computer Graphics with OpenGL/GLUT

OpenGL refresher. Advanced Computer Graphics 2012

Lecture 2 Sections 3.6, 3.7. Fri, Aug 28, 2009

Computer Graphics Course 2005

Announcements OpenGL. Computer Graphics. Autumn 2009 CS4815

Introduction to Computer Science (I1100) Data Storage

Assignment 1. Simple Graphics program using OpenGL

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

Problem 1. Multiple Choice (choose only one answer)

BLM2031 Structured Programming. Zeyneb KURT

Character Strings. String-copy Example

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

Lecture 4 of 41. Lab 1a: OpenGL Basics

Midterm Exam #2 Spring (1:00-3:00pm, Friday, March 15)

RECITATION - 1. Ceng477 Fall

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

Programming using OpenGL: A first Introduction

Reading on the Accumulation Buffer: Motion Blur, Anti-Aliasing, and Depth of Field

GLUT. What is OpenGL? Introduction to OpenGL and GLUT

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

Drawing Primitives. OpenGL basics

Week 5: Files and Streams

last time put back pipeline figure today will be very codey OpenGL API library of routines to control graphics calls to compile and load shaders

Computer Graphics. OpenGL

Exercise 1 Introduction to OpenGL

CS Computer Graphics: OpenGL, Continued

CS Computer Graphics: OpenGL, Continued

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

Graphical User Interface (GUI)

CS Computer Graphics: Raster Graphics, Part 3

Topic 6: A Quick Intro To C. Reading. "goto Considered Harmful" History

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

OptimiData. JPEG2000 Software Development Kit for C/C++ Reference Manual. Version 1.6. from

Variables Data types Variable I/O. C introduction. Variables. Variables 1 / 14

MCS 2514 Fall 2012 Programming Assignment 3 Image Processing Pointers, Class & Dynamic Data Due: Nov 25, 11:59 pm.

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

Example 1: Color-to-Grayscale Image Processing

Computer Labs: Lab 5 & Sprites

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

CPE 101, reusing/mod slides from a UW course (used by permission) Lecture 5: Input and Output (I/O)

Data Representation and Storage. Some definitions (in C)

Binghamton University. CS-211 Fall Syntax. What the Compiler needs to understand your program

2 Transformations and Homogeneous Coordinates

CS/ENGRD 2110 FALL Lecture 2: Objects and classes in Java

Graphical User Interface (GUI)

Arrays. Comp Sci 1570 Introduction to C++ Array basics. arrays. Arrays as parameters to functions. Sorting arrays. Random stuff

We will start our journey into Processing with creating static images using commands available in Processing:

XPM 2D Transformations Week 2, Lecture 3

CS 4204 Computer Graphics

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

Bob s Concise Introduction to Doxygen

TODO. parse float input update outfile s header info resize horizontally remember padding! resize vertically

CS 112 Introduction to Computing II. Wayne Snyder Computer Science Department Boston University

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

Lec 7. for loops and methods

OpenGL/GLUT Intro. Week 1, Fri Jan 12

QUIZ: loops. Write a program that prints the integers from -7 to 15 (inclusive) using: for loop while loop do...while loop

Computer graphic -- Programming with OpenGL I

COMPUTER GRAPHICS LAB # 3

+ Inheritance. Sometimes we need to create new more specialized types that are similar to types we have already created.

MIDIPoet -- User's Manual Eugenio Tisselli

HW2d Project Addenda

ECE 3331, Dr. Hebert, Summer-3, 2016 HW 11 Hardcopy HW due Tues 07/19 Program due Sunday 07/17. Problem 1. Section 10.6, Exercise 3.

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

XPM 2D Transformations Week 2, Lecture 3

Digital Image Fundamentals. Prof. George Wolberg Dept. of Computer Science City College of New York

BMP file format - Wikipedia

Computer Labs: Lab5 Video Card in Graphics Mode

Computer Graphics (Basic OpenGL)

Computer Graphics Fundamentals. Jon Macey

Computer Programming

Notes from the Boards Set # 5 Page

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

Machine Programming 4: Structured Data

Transcription:

CP SC 4040/6040 Computer Graphics Images Joshua Levine levinej@clemson.edu

Lecture 02 OpenImageIO and OpenGL Aug. 25, 2015

Agenda Reminder, course webpage: http://people.cs.clemson.edu/~levinej/courses/6040 Is everyone on Piazza? Clarification on Final Project Presentations (only on last day of lecture) vs. Final Exams (Fri., Dec. 11) Open Discussion: Quizzes Topics for today: Encoding Digital Images, OIIO, OpenGL

Encoding Digital Images

Bitmaps Bitmap: digital image that is a 2d array of pixels which store one bit. Simplest digital image, a representation of a black and white image. Pixel: picture element, individual sample of an image. Bit: ones/zeros, convention is 0 = black & 1 = white. Scanline: a row in the 2d array (terminology from acquisition).

Digital Images Linearized While we think of images as 2-dimensional, in memory they are 1-dimensional. U in 8 bytes, binary + hexadecimal

Greyscale Images - Pixmaps We use 0 for black and 1 for white -- what value should we use for grey? Could use floating point numbers Instead, one convention is to use 8bits for pixel -- how many different shades of grey? Can convert to [0.0,1.0] by dividing by 256

const int ROWS = 8; const int COLS = 8; unsigned char pixmap[rows][cols]; unsigned char pixmap2[rows*cols]; Code! Pixmap Declaration //top left pixel (x,y) = (0,0) pixmap[0][0]; pixmap2[0]; //top right pixel (x,y) = (0,7) pixmap[0][7]; pixmap2[7]; //bottom left pixel, in general [index] = [y*cols+x] pixmap[7][0]; pixmap2[56]; //bottom right pixel pixmap[7][7] pixmap2[?? ]; //fill me in

void print_greymap(unsigned char *greymap, int width, int height) { // scanline number int y; // pixel number on scanline int x; // value of pixel (0 to 255) int value; More Code! Pixmap Display for(y = 0; y < height; y++){ // loop for each scanline for(x = 0; x < width; x++){ // loop for each pixel on line value = greymap[y * width + x]; // fetch pixel value printf("%5.3f ", value / 255.0); printf("\n");

const int ROWS = 8; const int COLS = 8; //like pixmap[][] unsigned char ** pixmap3; pixmap3 = new unsigned char*[rows]; for (int y=0; y<rows; y++) { pixmap3[y] = new unsigned char[cols]; Ever More Code! Pixmap Declaration #2 //like pixmap2[] unsigned char * pixmap4; pixmap4 = new unsigned char[rows*cols]; //contiguous allocation unsigned char ** pixmap5; pixmap5 = new unsigned char*[rows]; unsigned char * data = new unsigned char[rows*cols]; pixmap5[0] = data; //note y starts with 1!!! for (int y=1; y<rows; y++) { pixmap5[y] = pixmap[y-1] + COLS;

Image Allocation pixmap3 const int ROWS = 8; const int COLS = 8; unsigned char ** pixmap3; //like pixmap[][] pixmap3 = new unsigned char*[rows]; for (int y=0; y<rows; y++) { pixmap3[y] = new unsigned char[cols]; unsigned char * pixmap4; //like pixmap2[] pixmap4 = new unsigned char[rows*cols]; unsigned char ** pixmap5; pixmap5 = new unsigned char*[rows]; //contiguous allocation unsigned char * data = new unsigned char[rows*cols]; pixmap5[0] = data; for (int y=1; y<rows; y++) { //note index starts with 1!!! pixmap5[y] = pixmap[i-1] + COLS; pixmap5[y] = pixmap[y-1] + COLS; Rows separated in memory!

Image Allocation pixmap3 const int ROWS = 8; const int COLS = 8; unsigned char ** pixmap3; //like pixmap[][] pixmap3 = new unsigned char*[rows]; for (int y=0; y<rows; y++) { pixmap3[y] = new unsigned char[cols]; unsigned char * pixmap4; //like pixmap2[] pixmap4 = new unsigned char[rows*cols]; unsigned char ** pixmap5; pixmap5 = new unsigned char*[rows]; //contiguous pixmap3[2] allocation unsigned char * data = new unsigned char[rows*cols]; pixmap5[0] = data; for (int y=1; y<rows; y++) { //note index starts with 1!!! pixmap5[y] = pixmap[i-1] + COLS; pixmap5[y] = pixmap[y-1] + COLS; Rows separated in memory!

Image Allocation pixmap3 const int ROWS = 8; const int COLS = 8; unsigned char ** pixmap3; //like pixmap[][] pixmap3 = new unsigned char*[rows]; for (int y=0; y<rows; y++) { pixmap3[y] = new unsigned char[cols]; unsigned char * pixmap4; //like pixmap2[] pixmap4 = new unsigned char[rows*cols]; unsigned char ** pixmap5; pixmap5 = new unsigned char*[rows]; //contiguous pixmap3[2] allocation unsigned char * data = new unsigned char[rows*cols]; pixmap3[3] pixmap5[0] = data; for (int y=1; y<rows; y++) { //note index starts with 1!!! pixmap5[y] = pixmap[i-1] + COLS; pixmap5[y] = pixmap[y-1] + COLS; Rows separated in memory!

Image Allocation pixmap3 const int ROWS = 8; const int COLS = 8; unsigned char ** pixmap3; //like pixmap[][] pixmap3 = new unsigned char*[rows]; for (int y=0; y<rows; y++) { pixmap3[y] = new unsigned char[cols]; unsigned char * pixmap4; //like pixmap2[] pixmap4 = new unsigned char[rows*cols]; unsigned char ** pixmap5; pixmap5 = new unsigned char*[rows]; //contiguous pixmap3[2] allocation unsigned char * data = new unsigned char[rows*cols]; pixmap3[3] pixmap5[0] = data; for pixmap3[4] (int y=1; y<rows; y++) { //note index starts with 1!!! pixmap5[y] = pixmap[i-1] + COLS; pixmap5[y] = pixmap[y-1] + COLS;...... Rows separated in memory!

Image Allocation pixmap3 const int ROWS = 8; const int COLS = 8; unsigned char ** pixmap3; //like pixmap[][] pixmap3 = new unsigned char*[rows]; for (int y=0; y<rows; y++) { pixmap3[y] = new unsigned char[cols]; unsigned char * pixmap4; //like pixmap3[2][3] pixmap2[] pixmap4 = new unsigned char[rows*cols]; unsigned char ** pixmap5; pixmap5 = new unsigned char*[rows]; //contiguous pixmap3[2] allocation unsigned char * data = new unsigned char[rows*cols]; pixmap3[3] pixmap5[0] = data; for pixmap3[4] (int y=1; y<rows; y++) { //note index starts with 1!!! pixmap5[y] = pixmap[i-1] + COLS; pixmap5[y] = pixmap[y-1] + COLS;...... Rows separated in memory!

Image Allocation pixmap4 const int ROWS = 8; const int COLS = 8; unsigned char * pixmap4; //like pixmap2[] pixmap4 = new unsigned char[rows*cols]; unsigned char ** pixmap3; //like pixmap[][] pixmap3 = new unsigned char*[rows]; for (int y=0; y<rows; y++) { pixmap3[y] = new unsigned char[cols]; unsigned char ** pixmap5; pixmap5 = new unsigned char*[rows]; //contiguous pixmap4[2] allocation unsigned char * data = new unsigned char[rows*cols]; pixmap4[3] Memory contiguous, pixmap5[0] = data; for pixmap4[4] (int y=1; y<rows; y++) { //note index starts with 1!!! pixmap5[y] = pixmap[i-1] + COLS; pixmap5[y] = pixmap[y-1] + COLS; but cannot index by row / column

Image Allocation pixmap4 const int ROWS = 8; const int COLS = 8; unsigned char * pixmap4; //like pixmap2[] pixmap4 = new unsigned char[rows*cols]; unsigned char ** pixmap3; //like pixmap[][] pixmap3 = new unsigned char*[rows]; for (int y=0; y<rows; y++) { pixmap3[y] = new unsigned char[cols]; unsigned char ** pixmap5; pixmap5 = new unsigned char*[rows]; //contiguous pixmap4[2] allocation unsigned char * data = new unsigned char[rows*cols]; pixmap4[3] Memory contiguous, pixmap5[0] = data; for pixmap4[4] (int y=1; y<rows; y++) { //note index starts with 1!!! pixmap5[y] = pixmap[i-1] + COLS; pixmap5[y] = pixmap[y-1] + COLS; We don t have this but cannot index by row / column XXXX[2][3]

Image Allocation pixmap5 const int ROWS = 8; const int COLS = 8; unsigned char ** pixmap5; pixmap5 = new unsigned char*[rows]; //contiguous allocation unsigned char * data = new unsigned char[rows*cols]; pixmap5[0] = data; for (int y=1; y<rows; y++) { //note index starts with 1!!! pixmap5[y] = pixmap5[y-1] + COLS; unsigned char ** pixmap3; //like pixmap[][] pixmap3 = new unsigned char*[rows]; for (int y=0; y<rows; y++) { pixmap3[y] = new unsigned char[cols]; unsigned char * pixmap4; //like pixmap2[] pixmap4 = new unsigned char[rows*cols]; (y,x) access AND contiguous memory...

Image Allocation pixmap5 const int ROWS = 8; const int COLS = 8; unsigned char ** pixmap5; pixmap5 = new unsigned char*[rows]; //contiguous allocation unsigned char * data = new unsigned char[rows*cols]; pixmap5[0] = data; for (int y=1; y<rows; y++) { //note index starts with 1!!! pixmap5[y] = pixmap5[y-1] + COLS; unsigned char ** pixmap3; //like pixmap[][] pixmap3 = new unsigned char*[rows]; for (int y=0; y<rows; y++) { pixmap3[y] = new unsigned char[cols]; unsigned char * pixmap4; //like pixmap2[] pixmap4 = new unsigned char[rows*cols]; (y,x) access AND contiguous memory... data

Image Allocation pixmap5 const int ROWS = 8; const int COLS = 8; unsigned char ** pixmap5; pixmap5 = new unsigned char*[rows]; //contiguous allocation unsigned char * data = new unsigned char[rows*cols]; pixmap5[0] = data; for (int y=1; y<rows; y++) { //note index starts with 1!!! pixmap5[y] = pixmap5[y-1] + COLS; unsigned char ** pixmap3; //like pixmap[][] pixmap3 = new unsigned char*[rows]; for (int y=0; y<rows; y++) { pixmap3[y] = new unsigned char[cols]; unsigned char * pixmap4; //like pixmap2[] pixmap4 = new unsigned char[rows*cols]; (y,x) access AND contiguous memory... data

Image Allocation pixmap5 const int ROWS = 8; const int COLS = 8; unsigned char ** pixmap5; pixmap5 = new unsigned char*[rows]; //contiguous allocation unsigned char * data = new unsigned char[rows*cols]; pixmap5[0] = data; for (int y=1; y<rows; y++) { //note index starts with 1!!! pixmap5[y] = pixmap5[y-1] + COLS; unsigned char ** pixmap3; //like pixmap[][] pixmap3 = new unsigned char*[rows]; for (int y=0; y<rows; y++) { pixmap5[1] pixmap3[y] = new unsigned char[cols]; unsigned char * pixmap4; //like pixmap2[] pixmap4 = new unsigned char[rows*cols]; (y,x) access AND contiguous memory... data

Image Allocation pixmap5 const int ROWS = 8; const int COLS = 8; unsigned char ** pixmap5; pixmap5 = new unsigned char*[rows]; //contiguous allocation unsigned char * data = new unsigned char[rows*cols]; pixmap5[0] = data; for (int y=1; y<rows; y++) { //note index starts with 1!!! pixmap5[y] = pixmap5[y-1] + COLS; unsigned char ** pixmap3; //like pixmap[][] pixmap3 = new unsigned char*[rows]; for (int y=0; y<rows; y++) { pixmap5[1] pixmap3[y] = new unsigned char[cols]; pixmap5[2] unsigned char * pixmap4; //like pixmap2[] pixmap4 = new unsigned char[rows*cols]; (y,x) access AND contiguous memory... data

Image Allocation pixmap5 const int ROWS = 8; const int COLS = 8; unsigned char ** pixmap5; pixmap5 = new unsigned char*[rows]; //contiguous allocation unsigned char * data = new unsigned char[rows*cols]; pixmap5[0] = data; for (int y=1; y<rows; y++) { //note index starts with 1!!! pixmap5[y] = pixmap5[y-1] + COLS; unsigned char ** pixmap3; //like pixmap[][] pixmap3 = new unsigned char*[rows]; for (int y=0; y<rows; y++) { pixmap5[1] pixmap3[y] = new unsigned char[cols]; pixmap5[2] unsigned char * pixmap4; //like pixmap2[] pixmap4 pixmap5[3] = new unsigned char[rows*cols]; (y,x) access AND contiguous memory... data

Image Allocation pixmap5 const int ROWS = 8; const int COLS = 8; unsigned char ** pixmap5; pixmap5 = new unsigned char*[rows]; //contiguous allocation unsigned char * data = new unsigned char[rows*cols]; pixmap5[0] = data; for (int y=1; y<rows; y++) { //note index starts with 1!!! pixmap5[y] = pixmap5[y-1] + COLS; unsigned char ** pixmap3; //like pixmap[][] pixmap3 = new unsigned char*[rows]; for (int y=0; y<rows; y++) { pixmap5[1] pixmap3[y] = new unsigned char[cols]; pixmap5[2] unsigned char * pixmap4; //like pixmap2[] pixmap4 pixmap5[3] = new unsigned char[rows*cols]; (y,x) access AND contiguous memory... data pixmap5[1][3]

Encoding Color Images Could encode 256 colors with an unsigned char. But what convention to use? One of the most common is to use 3 channels or bands Red-Green-Blue or RGB color is the most common -- based on how color is represented by lights. Coincidentally, this just happens to be related to how our eyes work too. NOTE : There are many schemes to represent color, most use 3 channels. We ll come back to them in a future lecture

RGB Colors Additive Mixing of 3 Lights

RGB Cube Code Demo

Encoding Color Channels Could use 8-bits, spread across all 3 channels (a bit ugly ) Could also use just 8 bits (why?):

//separate channel encoding unsigned char red_pixmap[rows][cols]; unsigned char green_pixmap[rows][cols]; unsigned char blue_pixmap[rows][cols]; RGB Pixmap Encoding //all together, could use an 32-bit uint, //might be useful if we have 4 channels //see House for how to access individual channels. unsigned int rgb_pixmap[rows][cols]; //or pack the bits with a struct struct pixel { unsigned char red; unsigned char green; unsigned char blue; ; pixel * pixmap = new pixel[rows*cols]; //can we do better???

OIIO Nuts and Bolts http://retro-gamer.deviantart.com/gallery/

OIIO Includes At the top of every file which uses OIIO: #include <OpenImageIO/imageio.h> Includes the declarations of main OIIO classes OIIO_NAMESPACE_USING Sets up the namespace appropriately

OIIO Classes ImageSpec Describes the type of data in an image ImageOutput Provides functionality to write images ImageInput Provides functionality to read images

ImageSpec Members width, height, depth - resolution of the image x, y, z - origin of image nchannels - number of channels TypeDesc format and std::vector<typedesc> channelformats format used if all channels the same format, otherwise channelformats describes each channel TypeDesc is a class which stores different data depths, e.g. TypeDesc::UINT8, TypeDesc::FLOAT std::vector<std::string> channelnames

ImageOutput Methods ImageOutput::create(string fn) Static creation of an image output. Checks that provided filename fn is a valid type open(string fn, ImageSpec s) Opens a file at filename fn and write data to with a particular spec s write_image(typedesc t, void* d) Writes data d to file, given a type t to interpret it with close() Closes the file and finishes writing

#include <OpenImageIO/imageio.h> OIIO_NAMESPACE_USING Example Write... const char *filename = "foo.jpg"; const int xres = 640, yres = 480; const int channels = 3; // RGB //assume this vector is populated with what we want to write unsigned char pixels[xres*yres*channels]; ImageOutput *out = ImageOutput::create(filename); if (!out) { std::cerr << Could not create: << geterror(); exit(-1); //create the ImageSpec that describes how you will write the output data ImageSpec spec (xres, yres, channels, TypeDesc::UINT8); out->open(filename, spec); //it is possible that this TypeDesc does not match the ImageSpec, //in which case it will convert the raw data into the spec. //But it MUST match the datatype of raw data out->write_image(typedesc::uint8, pixels); out->close(); delete out;

ImageInput Methods ImageInput::open(string fn) Static creation of an image input. Checks that provided filename fn is a valid type read_image(typedesc t, void* d) Writes data d to file, given a type t to interpret it with close() Closes the file and finishes writing

#include <OpenImageIO/imageio.h> OIIO_NAMESPACE_USING Example Read... ImageInput *in = ImageInput::open(filename); if (!in) { std::cerr << Could not create: << geterror(); exit(-1); //after opening the image we can access //information about it const ImageSpec &spec = in->spec(); int xres = spec.width; int yres = spec.height; int channels = spec.nchannels; //declare memory, open and read it unsigned char* pixels = new unsigned char[xres*yres*channels]; //TypeDesc::UINT8 maps the data into a desired type (unsigned char), //even if it wasn t originally of that type in->read_image(typedesc::uint8, &pixels[0]); in->close(); delete in;

Error Checking OpenImageIO::geterror() returns strings with informative error messages Also, so does geterror() for the ImageInput and ImageOutput classes. You should check this if an open(), write(), read(), or close() fails

Error Checking Examples ImageInput *in = ImageInput::open (filename); if (!in) { std::cerr << "Could not open " << filename << ", error = " << OpenImageIO::geterror() << "\n"; exit(-1); if (!in->read_image (TypeDesc::UINT8, pixels)) { std::cerr << "Could not read pixels from " << filename << ", error = " << in->geterror() << "\n"; delete in; exit(-1); if (!in->close ()) { std::cerr << "Error closing " << filename << ", error = " << in->geterror() << "\n"; delete in; exit(-1);

OpenGL Intro

OpenGL Includes At the top of your code that uses OpenGL: #include <GL/gl.h> Includes the declarations of main OIIO classes For GLUT (which by default includes gl.h as well, so you could be lazy and skip the above): #include <GL/glut.h> On an Mac: #include <OpenGL/gl.h> #include <GLUT/glut.h> All library function calls with begin gl*, glu*, glut*, depending on where they come from.

OpenGL / GLUT Structure glutinit(); GLUT Initialization function, must be called before glutmainloop(); glutdisplayfunc(display_func); Sets the callback function (pointer) to be called in the draw loop. glutkeyboardfunc(keyboard_func); Sets the keyboard callback will be triggered if there is a keyboard event. This is also function pointer. Also callbacks for mouse, motion, window resizing, etc.. glutmainloop(); Goes into (infinite) draw loop

Program Structure with glutmainloop() Read command line arguments Check if there is an event Call glutinit(), then create and open window (s) Hook up callbacks Process appropriate callback call glutmainloop() Call display to draw the next frame Note: This is greatly simplified. For example, display only redraws if there s a signal too

glsquare Demo

Lec03 Required Reading

Hunt, 3.1, 3.3, 4.2, 10.2 House, 5.1, 5.2