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

Similar documents
Introduction to OpenGL Week 1

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

Programming with OpenGL Part 1: Background

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

Programming using OpenGL: A first Introduction

Graphics Programming

GL_COLOR_BUFFER_BIT, GL_PROJECTION, GL_MODELVIEW

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

Introduction to OpenGL

Computer Graphics. Making Pictures. Computer Graphics CSC470 1

Lecture 3 Advanced Computer Graphics (CS & SE )

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

COMPUTER GRAPHICS LAB # 3

Computer Graphics. OpenGL

Introduction to Computer Graphics with OpenGL/GLUT

Basic Graphics Programming

Assignment 1. Simple Graphics program using OpenGL

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

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

Lectures OpenGL Introduction

Computer graphics MN1

Programming with OpenGL Part 3: Three Dimensions

Precept 2 Aleksey Boyko February 18, 2011

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

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

Computer Graphics (Basic OpenGL)

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

RECITATION - 1. Ceng477 Fall

Drawing Primitives. OpenGL basics

Basic Graphics Programming

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

Computer Graphics Introduction to OpenGL

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

Computer Graphics Primitive Attributes

Lecture 4 of 41. Lab 1a: OpenGL Basics

Announcements OpenGL. Computer Graphics. Autumn 2009 CS4815

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

Computer Graphics, Chapt 08

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

COMP 371/4 Computer Graphics Week 1

CS Computer Graphics: OpenGL, Continued

CS Computer Graphics: OpenGL, Continued

Draw the basic Geometry Objects. Hanyang University

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

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

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

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

Announcements OpenGL. Computer Graphics. Spring CS4815

Lecture 3. Understanding of OPenGL programming

1.2 Basic Graphics Programming

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

CS 432 Interactive Computer Graphics

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

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

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

OpenGL Introduction Computer Graphics and Visualization

OpenGL/GLUT Intro. Week 1, Fri Jan 12


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

2 Transformations and Homogeneous Coordinates

Bob s Concise Introduction to Doxygen

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

CSC 8470 Computer Graphics. What is Computer Graphics?

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

Using OpenGL with CUDA

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

6. Make use of glviewport() to display two sine curves on the same screen, one on the

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

Rendering. Part 1 An introduction to OpenGL

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

Computer graphic -- Programming with OpenGL I

Introduction to OpenGL

OpenGL. Toolkits.

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

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

Computer graphics MN1

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

Graphics Hardware and OpenGL

Introduction to OpenGL: Part 2

Programming of Graphics

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

Computer Graphics. Bing-Yu Chen National Taiwan University

CS 4204 Computer Graphics

Computer Graphics 1 Computer Graphics 1

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

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

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

Lecture 3. Programming with OpenGL GLUT + GLEW. CS 354 Computer Graphics Sunday, January 20, 13

1/12/11. Basic Graphics Programming. What is OpenGL. OpenGL is cross-platform. How does OpenGL work. How does OpenGL work (continued) The result

Luiz Fernando Martha André Pereira

Programming with OpenGL Part 1: Background

An Interactive Introduction to OpenGL Programming

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

Models and Architectures. Angel and Shreiner: Interactive Computer Graphics 7E Addison-Wesley 2015

Computer Graphics Introduction to OpenGL

Ulf Assarsson Department of Computer Engineering Chalmers University of Technology

CSE4030 Introduction to Computer Graphics

C OMPUTER G RAPHICS Thursday

Display Lists in OpenGL

Lecture 2 2D transformations Introduction to OpenGL

Transcription:

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

Objectives Refine first program Alter default values Introduce standard program structure Simple viewing 2-D viewing as special case of 3-D viewing Fundamental OpenGL primitives Attributes 91.427 Computer Graphics I, Fall 2008 2 2

Program Structure Most OpenGL programs have similar structure Consists of following functions -main(): defines callback functions opens one or more windows with required properties enters event loop (last executable statement) -init(): sets state variables Viewing Attributes callbacks Display function Input and window functions 91.427 Computer Graphics I, Fall 2008 3 3

simple.c revisited In this version, see same output, but defined all relevant state values through function calls using default values In particular, we set Colors Viewing conditions Window properties 91.427 Computer Graphics I, Fall 2008 4 4

main.c #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(); } define window properties display callback set OpenGL state enter event loop 91.427 Computer Graphics I, Fall 2008 5 5

GLUT functions glutinit allows application to get command line arguments and initializes system gluinitdisplaymode requests properties for window (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 91.427 Computer Graphics I, Fall 2008 6 6

init.c void init() { glclearcolor (0.0, 0.0, 0.0, 1.0); black clear color opaque window glcolor3f(1.0, 1.0, 1.0); fill/draw with white glmatrixmode (GL_PROJECTION); glloadidentity (); glortho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0); } viewing volume 91.427 Computer Graphics I, Fall 2008 7 7

Coordinate Systems Units in glvertex determined by application object or problem coordinates Viewing specifications also in object coordinates size of viewing volume determines what will appear in image Internally, OpenGL convert to camera (eye) coordinates and later to screen coordinates OpenGL also uses some internal representations usually not visible to application 91.427 Computer Graphics I, Fall 2008 8 8

OpenGL Camera OpenGL places camera at origin in object space pointing in negative z direction default viewing volume = box centered at origin with side of length 2 91.427 Computer Graphics I, Fall 2008 9 9

Orthographic Viewing In default orthographic view, points are projected forward along z axis onto plane z = 0 z=0 z=0 91.427 Computer Graphics I, Fall 2008 10 10

Transformations and Viewing In OpenGL, projection carried out by projection matrix (transformation) only one set of transformation functions ==> must set matrix mode first glmatrixmode (GL_PROJECTION) Transformation functions incremental ==> start with identity matrix alter it with projection matrix that gives view volume glloadidentity(); glortho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0); 91.427 Computer Graphics I, Fall 2008 11 11

Two- and three-dim viewing In glortho(left, right, bottom, top, near, far) near and far distances measured from camera 2-D vertex commands place all vertices in plane z = 0 If application is in 2-D, can use function gluortho2d(left, right,bottom,top) In 2-D view or clipping volume becomes clipping window 91.427 Computer Graphics I, Fall 2008 12 12

mydisplay.c 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(); } 91.427 Computer Graphics I, Fall 2008 13 13

OpenGL Primitives GL_POINTS GL_LINES GL_LINE_STRIP GL_POLYGON GL_LINE_LOOP GL_TRIANGLES GL_QUAD_STRIP GL_TRIANGLE_STRIP GL_TRIANGLE_FAN 91.427 Computer Graphics I, Fall 2008 14 14

Polygon Issues OpenGL only display correctly polygons that are Simple: edges cannot cross Convex: All points on segment also in polygon Flat: all vertices in same plane (planar) User program can check if above true OpenGL produce output if conditions violated but may not be what desired Triangles satisfy all conditions nonsimple polygon nonconvex polygon 91.427 Computer Graphics I, Fall 2008 15 15

Attributes Attributes are part of OpenGL state determine appearance of objects Color (points, lines, polygons) Size and width (points, lines) Stipple pattern (lines, polygons) Polygon mode Display as filled: solid color or stipple pattern Display edges Display vertices 91.427 Computer Graphics I, Fall 2008 16 16

RGB color Each color component stored separately in frame buffer Usually 8 bits per component in buffer Note in glcolor3f color values range from 0.0 (none) to 1.0 (all), whereas in glcolor3ub values range from 0 to 255 91.427 Computer Graphics I, Fall 2008 17 17

Indexed Color Colors = indices into tables of RGB values Requires less memory indices usually 8 bits not as important now Memory inexpensive Need more colors for shading 91.427 Computer Graphics I, Fall 2008 18 18

Color and State color as set by glcolor becomes part of state will be used until changed Colors and other attributes not part of object but assigned when object rendered can create conceptual vertex colors by code such as glcolor glvertex glcolor glvertex 91.427 Computer Graphics I, Fall 2008 19 19

Smooth Color Default is smooth shading OpenGL interpolates vertex colors across visible polygons Alternative is flat shading Color of first vertex determines fill color glshademodel (GL_SMOOTH) or GL_FLAT 91.427 Computer Graphics I, Fall 2008 20 20

Viewports Don t have to use entire window for image: glviewport(x,y,w,h) Values in pixels (screen coordinates) 91.427 Computer Graphics I, Fall 2008 21 21