Computer Graphics, Chapt 08

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

Computer Graphics. Chapter 3 Computer Graphics Software

Assignment 1. Simple Graphics program using OpenGL

Computer Graphics. OpenGL

Lecture 4 of 41. Lab 1a: OpenGL Basics

Drawing Primitives. OpenGL basics

Programming using OpenGL: A first Introduction

Computer Graphics. Making Pictures. Computer Graphics CSC470 1

GL_COLOR_BUFFER_BIT, GL_PROJECTION, GL_MODELVIEW

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

Announcements OpenGL. Computer Graphics. Autumn 2009 CS4815

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

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

Announcements OpenGL. Computer Graphics. Spring CS4815

Lectures OpenGL Introduction

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

Basic Graphics Programming

COMPUTER GRAPHICS LAB # 3

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

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

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

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

Computer Graphics. Bing-Yu Chen National Taiwan University

Introduction to Computer Graphics with OpenGL/GLUT

Precept 2 Aleksey Boyko February 18, 2011

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

Programming with OpenGL Part 1: Background

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

Graphics Programming

Computer graphics MN1

CS Computer Graphics: OpenGL, Continued

CS Computer Graphics: OpenGL, Continued

RECITATION - 1. Ceng477 Fall

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

Exercise 1 Introduction to OpenGL

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

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

Computer Graphics Course 2005

Computer Graphics 1 Computer Graphics 1

Lecture 3. Understanding of OPenGL programming

Lecture 2 2D transformations Introduction to OpenGL

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

CS 4204 Computer Graphics

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

Basic Graphics Programming

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

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

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

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

LECTURE 02 OPENGL API

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

OpenGL JOGL. OpenGL & JOGL. Shaoting Zhang, or Tony. September 12, 2007

Introduction to OpenGL

COMP 371/4 Computer Graphics Week 1

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

OpenGL Introduction Computer Graphics and Visualization

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

CSE4030 Introduction to Computer Graphics

CS Computer Graphics: Intro to OpenGL

CS Computer Graphics: Intro to OpenGL

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

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

OpenGL/GLUT Intro. Week 1, Fri Jan 12

Computer Graphics (Basic OpenGL)

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

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

CSC 8470 Computer Graphics. What is Computer Graphics?

OpenGL refresher. Advanced Computer Graphics 2012

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

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

Graphics Pipeline & APIs

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

Computer Graphics Introduction to OpenGL

Graphics and Visualization

OpenGL. Toolkits.

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

Graphics Pipeline & APIs

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

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

2 Transformations and Homogeneous Coordinates

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

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

An Interactive Introduction to OpenGL Programming

Computer Graphics Primitive Attributes

CS621 Lab 1 Name: Ihab Zbib

Rendering. Part 1 An introduction to OpenGL

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

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

Draw the basic Geometry Objects. Hanyang University

SOURCES AND URLS BIBLIOGRAPHY AND REFERENCES

Chapter 13 Selection and Feedback

Programming with OpenGL Part 3: Three Dimensions

OpenGL Tutorial. Ceng 477 Introduction to Computer Graphics

Introduction to OpenGL

AC60/AT60 COMPUTER GRAPHICS JUN 2015

An Overview GLUT GLSL GLEW

Programming of Graphics

Graphics Hardware and OpenGL

Transcription:

Computer Graphics, Chapt 08

Creating an Image Components, parts of a scene to be displayed Trees, terrain Furniture, walls Store fronts and street scenes Atoms and molecules Stars and galaxies Describe Internal structure of the individual objects Location (coordinates) within the scene Functions in a graphics package to describe the various image components: graphics output primitives or (geometric) primitives Computer Graphics, WS 07/08 2

Software Standards in Computer Graphics Goal of graphics standards Portability, independent of hardware platform Simple transfer between systems GKS (Graphical Kernel System) 1984 Adopted as first graphics software standard by International Standards Organization (ISO) American National Standards Institute (ANSI) Various national standards organizations Designed as 2D package, extended to 3D PHIGS (Programmer s Hierarchical Interactive Graphics Standard) Extension of GKS Capabilities for hierarchical modeling, color specification Surface rendering, picture manipulations Computer Graphics, WS 07/08 3

ERLGRAPH (Erlanger Graphik System) ~1985 Vom Regionalen Rechenzentrums Erlangen Weiterentwicklung des Erlanger Graphik Systems (EGS) Programmbibliothek für FORTRAN Funktionen für das Visualisieren wissenschaftlicher Daten Mathematischer Funktionen als 2-D- und 3-D-Plots Ausgabe auf verschiedenen Ausgabegeräten Computer Graphics, WS 07/08 4

GL (Graphics Library) Came with workstations ti from Silicon Graphics, Inc. (SGI) Widely used in graphics community and a de facto standard Set of routines designed for fast, real-time rendering Soon extended to other hardware systems OpenGL Hardware independent version of GL (early 1990s) OpenGL Architecture Review Board responsible for maintenance and updates Consortium of many graphics companies and organizations Specifically designed for efficient processing in 3D Also handles 2D scene descriptions as a special case Available language binding C, C++, Fortran, Ada Computer Graphics, WS 07/08 5

OpenGL in computer graphics Provides hardware abstraction layer through its Application Programmer Interface (API) Thereby provides low level, platform independent graphics allows non-standard extensions It does not have high level modeling constructs, such as scene graphs windowing facilities requires interface to window system: GLUT, GLX, AGL, WGL Computer Graphics, WS 07/08 6

Literature: OpenGL Reference Manual The Blue Book html-version: http://www.opengl.org/documentation/blue_book_1.0 org/documentation/blue book D. Hearn, M.B. Baker: Computer Graphics with OpenGL, (3rd edition) OpenGL(R) Programming Guide: The Official Guide to Learning OpenGL(R), Version 2 (5th Edition) (OpenGL) Computer Graphics, WS 07/08 7

Basic OpenGL Syntax Function names Prefixed with gl Each component word has its first letter capitalized: e.g.: glclear, glcopypixel, glpolygonmode Assignment of symbolic constants Certain functions require one or more e.g: GL_2D, GL_RGB, GL_POLYGON All begin with GL_ and component words in capital letters Data types Problem: specifications can be different on different machines (e.g. integer) Special built in data-types e.g.: GLbyte, GLshort, GLfloat, GLdouble Computer Graphics, WS 07/08 8

Related Libraries OpenGL Utility (GLU) Included by every OpenGL implementation Common prefix: glu Supplies advanced routines, e.g. Setting gup viewing gand dpojecto projection matrices Complex objects with line and polygon approximations Display of quadrics and B-splines using linear approximations Processing of surface rendering operations Open Inventor Object oriented toolkit based on OpenGL, written in C++ Routines and predefined object shapes for interactive 3D applications Scene description by scene graphs Computer Graphics, WS 07/08 9

Graphics display with OpenGL Set up a display window on the screen computer dependent d Not directly with OpenGL (device independent functions only!) Window system libraries supporting OpenGL GLX (OpenGL extension to the X Window System) set of routines prefixed with: glx AGL (Apple GL) on Apple systems set of routines prefixed with: agl WGL (Windows to OpenGL) on Microsoft Windows systems set of routines prefixed with: wgl PGL (Presentation Manager to OpenGL) for IBM OS/2 set of routines prefixed with: pgl OpenGL Utility Toolkit (GLUT) set of routines prefixed with: glut Interaction with any screen-windowing system Computer Graphics, WS 07/08 10

Header Files OpenGL core library GLU library for most applications Windowing systems Example for Microsoft Windows If GLUT is used #include <windows.h> #inlcude <GL/gl.h> #include <GL/glu.h> #include <windows.h> #inlcude <GL/glut.h> Computer Graphics, WS 07/08 11

Display-window management using GLUT Initialization glutinit(&argc, argv); Creation of a display window with caption glutcreatewindow( OpenGL example ); Specification what the display window should contain Supposing a code for line description called linesegment glutdisplayfunc(linesegment); Passes line-segment description to display window Activation of all display window including graphic content glutmainloop (); Must be the last function Displays the graphics and puts program to infinite loop Checks for input from devices (e.g.: mouse, keyboard) Computer Graphics, WS 07/08 12

Initial location of display window glutinitwindowposition(50, iti 100); Top left corner of the display Initial pixel width and height of display window glutinitwindowssize(400, 300); Other options (e.g.: buffering, color mode) glutinitdisplaymode(glut_single GLUT_RGB); Values of constants passed with logical or operations other values: GLUT_DOUBLE, GLUT_DEPTH 50 100 400 300 Computer Graphics, WS 07/08 13

To complete a program Set background color glclearcolor(1.0, 1.0, 1.0, 0.0); The 4 th value specifies the alpha value used in blending to mimic transparency Displaying the assigned window color glclear(gl_color_buffer_bit); GL_COLOR_BUFFER_BIT specifies the bit values in the color buffer (refresh buffer) to be set to the values indicated in glclearcolor Assignment of color to objects glcolor3f(1.0, 0.0, 0.0); RGB components using floating-point (f) values Note that each vertex can have a different color Computer Graphics, WS 07/08 14

Definition of output primitives Point position, straight lines, circles, other conic sections Quadric surfaces, spline curves and surfaces Polygon color areas, character strings After geometry definition Projection of output primitives Onto a 2D plane display area of output device Scan conversion: integer pixel positions in frame buffer glflush(); Process all OpenGL routines as quickly as possible Computer Graphics, WS 07/08 15

2D Cartesian reference frame in OpenGL (also see chapter 3 of Hearn & Baker for further details) Defining coordinate frame for screen display window gluortho2d orthogonal projection glmatrixmode (GL_PROJECTION); glloadidentity (); gluortho2d(xmin, xmax, ymin, ymax); Assign identity matrix in OpenGL projection matrix Prevents accumulation with previous values Place coordinate values in OpenGL projection matrix y max y min x min x max y min Computer Graphics, WS 07/08 16

Example program Main routine #include <GL/glut.h> void main (int argc, char** argv){ glutinit(&argc, argv); // initialize GLUT glutinitdisplaymode(glut_single GLUT_RGB); l glutinitwindowposition(50, 100); // top-left pos. glutinitwindowssize(400, 300); // width, height glutcreatewindow( OpenGL example); // create display window init(); // initialization procedure glutdisplayfunc(linesegment); // send graphics to display glutmainloop (); // display and wait } Computer Graphics, WS 07/08 17

Additional routines void init (void) { // Initialization p glclearcolor(1.0, 1.0, 1.0, 0.0); glmatrixmode (GL_PROJECTION); // projection parameters glloadidentity (); gluortho2d(0.0, 200.0, 0.0, 150.0); } void linesegment(void){ glclear(gl_color_buffer_bit); // clear display window glcolor3f(1.0, 0.0, 0.0); // set line color glbegin (GL_LINES); // line geometry glvertex2i (180, 15); glvertex2i (10, 145); glend (); glflush(); } Computer Graphics, WS 07/08 18

Graphics Output Primitives OpenGL point functions Specify geometry of a point glvertex * ( coordinate position in reference frame ) *: suffix codes are used Identify spatial dimension: values 2, 3, 4 State data type: i (integer), s (short), f (float), d (double) Identification of output primitive (here points) glbegin g (gl_ POINTS); glvertex* (); glend (); Coordinate values List explicitly Array referencing coordinate position append suffix code v (for vector) Computer Graphics, WS 07/08 19

Graphics Output Primitives Geometric primitives are passed through the lighting /shading algorithms, the 3D viewing (projection) algorithms, and finally rasterization (scan conversion) Default display Color (white) Size (one screen pixel) Coordinate extents of a primitive Within range of display window All of the primitive is displayed Beyond range of display window Only those parts within the coordinate range of the display window are shown (clipped object) Computer Graphics, WS 07/08 20

Graphics Output Primitives Example glbegin (GL_POINTS); glvertex2i (50, 100); glvertex2i (75, 150); glvertex2i (100, 200); glend (); Coordinate definition in arrays int point1 [] = {50, 100}; int point2 [] = {75, 150}; int point3 [] = {100, 200}; glbegin (GL_POINTS); glvertex2iv (point1); glvertex2iv (point2); glvertex2iv (point3); glend (); Computer Graphics, WS 07/08 21 200 100 100 200

Graphics Output Primitives OpenGL line functions Define the two endpoint coordinate positions Specify one or more straight-line segments Use glvertex funtions Enclose between glbegin / glend Use symbolic constant t for glbegin G_LINES GL_LINE_STRIPLINE GL_LINE_LOOP Default display Solid, white lines Computer Graphics, WS 07/08 22

Graphics Output Primitives Example glbegin (GL_LINES); p3 glvertex2iv (p1); glvertex2iv (p2); glvertex2iv (p3); glvertex2iv (p4); glvertex2iv (p5); glend (); p2 p4 glbegin (GL_LINE_STRIP); glvertex2iv (p1); glvertex2iv (p2); glvertex2iv (p3); glvertex2iv (p4); glvertex2iv (p5); glend (); p2 p4 p5 p3 p1 p1 Computer Graphics, WS 07/08 23

Graphics Output Primitives continued glbegin (GL_LINE_LOOP); glvertex2iv (p1); glvertex2iv (p2); glvertex2iv (p3); glvertex2iv (p4); glvertex2iv (p5); glend (); p5 p2 p3 p4 p1 Computer Graphics, WS 07/08 24

Tutorial (some kind of) : Tuto -- an OpenGL-Demo-Generator G available on CIP Computer Graphics, WS 07/08 25