OpenGL Introduction Computer Graphics and Visualization

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

Programming with OpenGL Part 1: Background

Drawing Primitives. OpenGL basics

Programming using OpenGL: A first Introduction

Lectures OpenGL Introduction

Graphics Programming

Computer Graphics. Bing-Yu Chen National Taiwan University

GL_COLOR_BUFFER_BIT, GL_PROJECTION, GL_MODELVIEW

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 2: Complete Programs Computer Graphics I, Fall

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

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

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

Programming with OpenGL Part 1: Background

Announcements OpenGL. Computer Graphics. Autumn 2009 CS4815

Lecture 3. Understanding of OPenGL programming

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

Basic Graphics Programming

Announcements OpenGL. Computer Graphics. Spring CS4815

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

Assignment 1. Simple Graphics program using OpenGL

Precept 2 Aleksey Boyko February 18, 2011

Introduction to Computer Graphics with OpenGL/GLUT

Computer Graphics (Basic OpenGL)

RECITATION - 1. Ceng477 Fall

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

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

Computer Graphics, Chapt 08

Computer Graphics. Making Pictures. Computer Graphics CSC470 1

Programming of Graphics

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

COMPUTER GRAPHICS LAB # 3

CS 4204 Computer Graphics

1.2 Basic Graphics Programming

Lecture 4 of 41. Lab 1a: OpenGL Basics

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

Computer Graphics Course 2005

Computer Graphics. OpenGL

Ulf Assarsson Department of Computer Engineering Chalmers University of Technology

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

This library uses only GL functions but contains code for creating common objects and simplifying viewing.

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

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

Basic Graphics Programming

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

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

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

Computer Graphics 1 Computer Graphics 1

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

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

Using OpenGL with CUDA

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

Introduction to OpenGL

Programming with OpenGL Part 3: Three Dimensions

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

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

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

CSE4030 Introduction to Computer Graphics

Drawing and Coordinate Systems

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

Exercise 1 Introduction to OpenGL

OpenGL Tutorial. Ceng 477 Introduction to Computer Graphics

OpenGL/GLUT Intro. Week 1, Fri Jan 12

Draw the basic Geometry Objects. Hanyang University

COMP 371/4 Computer Graphics Week 1

OpenGL. Toolkits.

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

GLUT. What is OpenGL? Introduction to OpenGL and GLUT

Bob s Concise Introduction to Doxygen

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

Drawing and Coordinate Systems

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

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

CS 4204 Computer Graphics

Introduction to OpenGL: Part 2

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

Computer Graphics Introduction to OpenGL

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

Input and Interaction. 1. Interaction. Chapter 3. Introduction: - We now turn to the development of interactive graphics programs.

Computer graphic -- Programming with OpenGL I

Computer graphics MN1

CS Computer Graphics: Intro to OpenGL

CS Computer Graphics: Intro to OpenGL

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

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

COS340A Assignment 1 I Pillemer Student# March 25 th 2007 p1/15

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

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

An Overview GLUT GLSL GLEW

LECTURE 02 OPENGL API

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

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

Interaction Computer Graphics I Lecture 3

CSC 8470 Computer Graphics. What is Computer Graphics?

Rendering. Part 1 An introduction to OpenGL

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

Graphics and Visualization

Computer Graphics and Visualization. Graphics Systems and Models

Transcription:

Fall 2009 2 OpenGL OpenGL System Interaction Portable Consistent visual display regardless of hardware, OS and windowing system Callable from Ada, C, C++, Fortran, Python, Perl and Java Runs on all major OS and windowing system. Well documented OpenGL is completely window system independent. But we need the window system for things like: Opening and closing windows Interaction Handling events We can work directly with the window system (X-windows, Win 32,...) or use a higher level toolkit (GLUT, Motif,...). 3 4 OpenGL Utility Toolkit OpenGL Libraries GLUT has been ported to all platforms that support OpenGL. Provides basic window system interaction Open/Close Window Mouse/Keyboard callbacks Idle callback for animation Pop-Up Menus Application GTK+ GLUI GLUT GLU WGL GLX AGL GL 5 6

OpenGL Functions OpenGL State Primitives Points Line Segments Triangles Quadrilions Polygons Attributes Transformations Viewing Modeling Control (GLUT) OpenGL functions are of two types Primitive generating Can cause output if primitive is visible How vertices are processed and appearance of primitive are controlled by the state State changing Transformation functions Attribute functions Input (GLUT) Query 7 8 No Overloading or Generics OpenGL function name dimensions There are multiple functions for a given logical function glvertex3f(x,y,z) glvertex3f glvertex2i glvertex3dv belongs to GL library glvertex3fv(p) x,y,z are floats p is a pointer to an array 9 10 A Simple Program Generate a square on a solid background OpenGL Examples 11 12

simple.c Event Loop 13 #include <GL/glut.h> void display(){ 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(); } int main(int argc, char** argv){ glutcreatewindow("simple"); glutdisplayfunc(display); glutmainloop(); } 14 Note that the program defines a display callback function named display Every glut program must have a display callback The display callback is executed whenever OpenGL decides the display must be refreshed, for example when the window is opened The main function ends with the program entering an event loop Primitives Primitives in OpenGL Complex objects are defined using simpler primitvies Points Line segments Polygons (filled) A non filled polygon is a set of lines. An object is defined by vertices. Vertices are grouped into primitives using glbegin(<type>)...glend(), where <type> defines the primitive type. OpenGl differs between filled and non-filled types 15 16 Line segment types Polygon types 17 GL_LINE Successive pairs of verteces are interpreted as endpoints in individual lines GL_LINE_STRIP and GL_LINE_LOOP Verteces are connected 18 To draw a filled polygon with displayed edges, the polygon needs to be rendered twice. glpolygonmode can be used to control if only the edges should be drawn or the polygon to be filled. Notice that a polygon with > 3 vertices may not be flat.

2D World and scrreen coordinates View port An object (or primitive) has its coordinate in world coordinates. A viewport and camera defines a viewing volume that defines which primitives should be draw or not, and which lines to clip. In 2D this volume is a rectangle in 2D coordinates. 19 20 Orthographics projection Screen Coordinates A 2D viewing volum can be seen as an orthographic projection in 3D onto a 2D viewplane. In an orthographic projection, all projectors are parallel (and often orthogonal to the viewplane). A defined viewing rectangle in 2D must then be converted into screen coordinates. Either each pixel is one unit in world coorinates or we scale the viewing rectangle. 21 22 Aspect ratio OpenGL and defining a 2D view port 23 If not the ration between the height and width of the viewing rectangle match the windows size we get mismatch in aspect ratio. 24 glitinitwindowsize(800, 600); glmatrixmode(gl_projection); glloadidentity(); gluortho2d(-400,400,-300,300); glmatrixmode(gl_modelview); glloadidentity(); glviewport(400, 300, 400, 300); glbegin(gl_line) glvertex2i(-100, -100);glVertex2i;(100,100) glend();

Classical Imperative Programming Event Driven Programming Previous programming paradigms have emphasized the process for solving a problem. Once the program was complete we would: provide input run the program display the answer(s) Things always happened in the same sequence. The program always terminated when the process was complete 25 26 Event Driven programming Event Driven programming Event-driven programs do not have a set sequence of instructions to execute. They also do not have a predetermined finish. The most common example of event-driven programming is found in graphical user interfaces (s): Windows, OSX, ios, X11 Other applications include embedded systems, control systems, sensor systems like home security, etc. In event driven architecture a programm idles awaiting events. Different events are stored in a queue. For each loop a new event is processed. If no new events in the queue, the program idles. Event driven programmes often threaded. 27 28 Imperative vs. Event Driven Event Driven APIs More or less integrated in languages but with a similar concept. High integration Java (AWT, Swing), Javascript Visual Basic Integrated with extensions C/C++ (GTK+, QT, etc.) Matlab An event producer produces an event, that when processed calls a callback function at an event handler. 29 30

GTK+ and Glade Glade is a RAD (Rapid Application Development) tool to develope user interfaces for the GTK+ toolkit. The user interfaces are saved as XML Using the libglade library these can be loaded dynamically. Can be used in many languages including C, C++, Java, Perl, Python, C#, Pike, Ruby, Haskell, Objective Caml and Scheme. GladeXML *xml = glade_xml_new( "project1gui.glade", NULL, NULL); 31 32 GLUT and the Given Given HOWTO is initialized by calling guiinit and initguiwindow Callback functions from the exists in project1gui.c GTK also uses a main loop, but GLUT main loop can call an idle callback function. GTK main loop content can be called separately. Call guimainiteration from the GLUT idle callback. Compile and link project1gui.c Use the callback functions to implement the features of your program. can also display simple text in its status bar (see project1gui.h). 33 34 Qt #include <QApplication> #include <QFont> #include <QPushButton> int main(int argc, char *argv[]) { QApplication app(argc, argv); QPushButton quit("quit"); quit.resize(75, 30); QObject::connect(&quit, SIGNAL(clicked()), &app, SLOT(quit())); 35 } quit.show(); return app.exec();