Basic OpenGL Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Wednesday, September 10, 2003.

Slides:



Advertisements
Similar presentations
OpenGL: Simple Use Open a window and attach OpenGL to it Set projection parameters (e.g., field of view) Setup lighting, if any Main rendering loop –Set.
Advertisements

Chapter 2: Graphics Programming
CS 450: COMPUTER GRAPHICS FILLING POLYGONS SPRING 2015 DR. MICHAEL J. REALE.
2IV60 Computer graphics Graphics primitives and attributes Jack van Wijk TU/e.
Informationsteknologi Monday, October 29, 2007Computer Graphics - Class 21 Today’s class Graphics programming Color.
OpenGL (Graphics Library) Software Interface to graphics software Allows to create interactive programs that produce color images of moving 3D objects.
Drawing Geometric Objects
1 Lecture 4 Graphical primitives Rasterization: algorithmic approach Rasterization: geometric approach 2D discrete lines, triangles Discrete planes 3D.
OpenGL and WebGL Drawing Functions CSCI 440 Day Five.
CSC 461: Lecture 6 1 CSC461 Lecture 6: 2D Programming in OpenGL Objectives:  Fundamental OpenGL primitives  Attributes  Viewport.
Computer Graphics CS 385 February 7, Fundamentals of OpenGl and Glut Today we will go through the basics of a minimal OpenGl Glut project, explaining.
Programming with OpenGL and GLUT
Reference1. [OpenGL course slides by Rasmus Stenholt]
CS380 LAB I OpenGL Donghyuk Kim Reference1. [OpenGL course slides by Rasmus Stenholt] Reference2. [
CAP 4703 Computer Graphic Methods Prof. Roy Levow Lecture 2.
Computer Graphics: Programming, Problem Solving, and Visual Communication Steve Cunningham California State University Stanislaus and Grinnell College.
Course Overview, Introduction to CG Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Friday, September 5, 2003.
Programming in OpenGL Ryan Holmes CSE 570 February 12 th, 2003.
COS 397 Computer Graphics Assoc. Prof. Svetla Boytcheva AUBG 2013 COS 397 Computer Graphics Practical Session №1 Introduction to OpenGL, GLFW and CG.
1 GLUT Callback functions Event-driven: Programs that use windows  Input/Output  Wait until an event happens and then execute some pre-defined functions.
Using OpenGL. 2 What is OpenGL? A software interface to graphics hardware It is a Graphics Rendering API (Application Programmer’s Interface) that is.
Polygon Lists & 3-D File Formats Glenn G. Chappell U. of Alaska Fairbanks CS 481/681 Lecture Notes Monday, February 18, 2002.
Drawing Basic Graphics Primitives Lecture 4 Wed, Sep 3, 2003.
Linear Interpolation, Brief Introduction to OpenGL Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Monday, September.
Triangulation Introduction to Computer Graphics and Animation (Principle of Computer Graphics) Rattapoom Waranusast.
OpenGl Graphics Programming. Introduction OpenGL is a low-level graphics library specification. It makes available to the programmer a small set of geomteric.
2 COEN Computer Graphics I Introductions n Brad Grantham lecturer lab dude n Dave Shreiner lecturer slave driver.
Computer Graphics CS 385 January 31, Fractals Some definitions Object which is self-similar at all scales. Regardless of scale the same level of.
Homogeneous Form, Introduction to 3-D Graphics Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Monday, October 20,
State Management and Drawing Geometry Objects
1. OpenGL/GLU/GLUT  OpenGL v4.0 (latest) is the “core” library that is platform independent  GLUT v3.7 is an auxiliary library that handles window creation,
1 Figures are extracted from Angel's book (ISBN x) The Human Visual System vs The Pinhole camera Human Visual System Visible Spectrum Pinhole.
P RACTICING O PEN GL- P RIMITIVES. O PEN GL O UTPUT P RIMITIVES  Each geometric object is described by a set of vertices and the type of primitive to.
More on Advanced Interfaces, Image Basics Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Friday, November 21, 2003.
Computer Graphics Bing-Yu Chen National Taiwan University.
Lecture 2: Some definitions of terms 1  Principles of Interactive Graphics  CMSCD2012  Dr David England, Room 711,  ex 2271 
Introduction to OpenGL. OpenGL is a low-level graphics library specification. It makes available to the programmer  a small set of geometric primitives.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
Chun-Yuan Lin Introduction to OpenGL 2015/12/19 1 CG.
Bézier Curves & Surfaces Glenn G. Chappell U. of Alaska Fairbanks CS 481/681 Lecture Notes Monday, March 1, 2004.
1 Graphics CSCI 343, Fall 2015 Lecture 3 Introduction to WebGL.
What are Computer Graphics Basically anything that is on you Monitor – This includes the text that you will see Text isn’t Advanced Graphics But…. Understanding.
CSCE 441: Computer Graphics
Lecture 2 Review OpenGL Libraries Graphics Overview Rendering Pipeline OpenGL command structure.
1 Programming with OpenGL Part 2: Complete Programs.
OpenGL API 2D Graphic Primitives Angel Angel: Interactive Computer Graphics5E © Addison-Wesley
1 E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012 Programming with OpenGL Part 4: Color and Attributes Isaac Gang University.
1 Perception, Illusion and VR HNRS 299, Spring 2008 Lecture 15 Creating 3D Models.
OpenGL: Introduction #include main() { OpenWindow() ; glClearColor(0.0, 0.0, 0.0, 0.0); glClear(GL_COLOR_BUFFER_BIT); glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0,
Introduction to Graphics Programming. Graphics API.
Introduction to OpenGL (INF 250) Veronika Solteszova et al., UiB Dept. of Informatics,
Introduction to Graphics Programming. Graphics: Conceptual Model Real Object Human Eye Display Device Graphics System Synthetic Model Synthetic Camera.
Computer Graphics I, Fall Programming with OpenGL Part 2: Complete Programs.
Computer Graphics (Fall 2003) COMS 4160, Lecture 5: OpenGL 1 Ravi Ramamoorthi Many slides courtesy Greg Humphreys.
Computer Graphics Lecture 34. OpenGL Programming II Taqdees A. Siddiqi
CSC Graphics Programming
The Human Visual System vs The Pinhole camera
Programming with OpenGL Part 2: Complete Programs
OpenGL API 2D Graphic Primitives
OpenGL (Open Graphics Library) Mr. B.A.Swamy Assistant Professor Dept of CSE.
Introduction to Computer Graphics with WebGL
Programming with OpenGL Part 4: Color and Attributes
Introduction to Computer Graphics
Display Lists & Text Glenn G. Chappell
Drawing in the plane 455.
Introduction to OpenGL
Primitive Objects Lecture 6 Wed, Sep 5, 2007.
CSCE 441 Computer Graphics: Clipping Polygons Jinxiang Chai
Programming with OpenGL Part 2: Complete Programs
Programming with OpenGL Part 4: Color and Attributes
Presentation transcript:

Basic OpenGL Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Wednesday, September 10, 2003

10 Sep 2003CS 3812 Review: Linear Interpolation [1/2] Approximating a quantity between places where the quantity is known, is called interpolation. The simplest interpolation method is linear interpolation (lirping). Linear interpolation makes the (usually false!) assumption that the graph of the quantity between the two known values is a straight line. When we lirp, we are given two values of a quantity; we determine its value somewhere between these. The simple case: When t = 0, the quantity is equal to a. When t = 1, the quantity is equal to b. Given a value of t between 0 and 1, the interpolated value of the quantity is

10 Sep 2003CS 3813 Review: Linear Interpolation [2/2] What if we are not given values of the quantity at 0 and 1? Say the value at s 1 is a and the value at s 2 is b, and we want to find the interpolated value at s. We set and proceed as before: Lastly, when we want to lirp quantities with several coordinates (like points or colors), lirp each coordinate separately.

10 Sep 2003CS 3814 Review: Introduction to OpenGL [1/2] Professional-quality 2-D & 3-D graphics API Developed by Silicon Graphics Inc. in Based on Iris GL, the SGI graphics library. Available in a number of languages. OS-independent and hardware-independent. Aimed at 2-D/3-D scenes made of polygons (and lines and points). Not as good for 2-D windows/text/GUI-style graphics.

10 Sep 2003CS 3815 Review: Introduction to OpenGL [2/2] OpenGL Itself The interface with the graphics hardware. Designed for efficient implementation in hardware. Particular OpenGL implementations may be partially or totally software. C/C++ header:. The OpenGL Utilities (GLU) Additional functions & types for various graphics operations. Designed to be implemented in software; calls GL. C/C++ header:. OpenGL Extensions Functionality that anyone can add to OpenGL. OpenGL specifies rules that extensions are to follow. May be system-dependent. We will not use any extensions.

10 Sep 2003CS 3816 Basic OpenGL: Overview We now discuss how to use OpenGL to produce 3-D graphics. We will cover: The design of OpenGL. Design philosophy and conventions. OpenGL primitives. The basic things that OpenGL can draw. Tomorrow we will look the workings of an actual OpenGL/GLUT program.

10 Sep 2003CS 3817 The Design of OpenGL: Introduction OpenGL is an API for rendering raster images of 2-D/3-D scenes. So OpenGL’s work ends when the completed image (or frame, in an animation context) is in the frame buffer. We deal with OpenGL via function calls (or commands). No global variables. Most OpenGL functions have few parameters. But you make lots of function calls. No complex data types. OpenGL is function-call intensive. Think: advantages/disadvantages.

10 Sep 2003CS 3818 The Design of OpenGL: Example Code To draw a red triangle with vertices (0,0), (1,0), (1,1): glColor3d(0.9, 0.1, 0.1); // red (setting an attribute) glBegin(GL_TRIANGLES); // starting a primitive glVertex2d(0., 0.); // vertex data glVertex2d(1., 0.); glVertex2d(1., 1.); glEnd(); // ending the primitive

10 Sep 2003CS 3819 The Design of OpenGL : Naming Conventions [1/2] OpenGL (C API) Functions Begin with “ gl ”, words capitalized & run together Example: glClearColor Can include type information. For example, the “ 2d ” in “ glVertex2d ” indicates two parameters of type GLdouble. Constants Begin with “ GL ”, all upper-case, “ _ ” between words Example: GL_TRIANGLE_STRIP Types Begin with “ GL ”, next word not capitalized, all words run together Example: GLdouble

10 Sep 2003CS The Design of OpenGL : Naming Conventions [2/2] Related packages use similar conventions. GLU Function: gluScaleImage Constant: GLU_TESS_ERROR Type: GLUtesselatorObj GLUT (to be discussed on Friday) Function: glutInitDisplayMode Constant: GLUT_MIDDLE_BUTTON

10 Sep 2003CS The Design of OpenGL: Types [1/2] OpenGL defines its own types, which have the same (minimum) precision on all systems. Some of these: GLint : at least 32-bit integer GLfloat : at least 32-bit floating-point GLdouble : at least 64-bit floating-point and others … So, for example, GLdouble is probably the same as double, but may not be. Converting (say) a GLdouble to a double is fine. But be careful when tossing around GLdouble * and double *. (Why?)

10 Sep 2003CS The Design of OpenGL: Types [2/2] Some OpenGL commands have several forms allowing for different types. For example, glVertex * can take 2, 3, or 4 parameters of many different types. Function glVertex2d takes 2 parameters of type GLdouble. Function glVertex3f takes 3 parameters of type GLfloat. Function glVertex3fv (“v” for “vector”) takes a single parameter of type GLfloat * (should be a pointer to an array of 3 GLfloat ’s). The command glTranslate * always takes three parameters, but they may vary in type. Function glTranslated takes 3 GLdouble ’s. Function glTranslatef takes 3 GLfloat ’s.

10 Sep 2003CS The Design of OpenGL: Attributes & Primitives OpenGL functions as a state machine. There are three kinds of functions: Those that set state. Those that return state. Those that draw. Drawing is done via primitives. States are used to set attributes of those primitives. So: all drawn objects are composed of primitives. The properties of these are attributes, which are determined by OpenGL states. (Recall the red triangle example.)

10 Sep 2003CS OpenGL Primitives: Overview [1/2] All rendering operations are composed of primitives. These need to be useful to the programmer and doable efficiently by the library & hardware. We will now look at those OpenGL primitives that are handled via the glBegin - glEnd mechanism. There are ten of these; they consist of ways to draw: Points. Polylines. Filled polygons. Other primitive rendering operations are handled differently in OpenGL. Specifically, those involving screen-aligned rectangles: pixmaps, bitmaps, and screen-aligned rectangular polygons. Recall: OpenGL has no circle/ellipse/curve primitives.

10 Sep 2003CS OpenGL Primitives: Overview [2/2] The ten glBegin -style OpenGL Primitives Points (1 primitive) GL_POINTS Polylines (3 primitives) GL_LINES GL_LINE_STRIP GL_LINE_LOOP Filled Polygons (6 primitives) Triangles GL_TRIANGLES GL_TRIANGLE_STRIP GL_TRIANGLE_FAN Quadrilaterals GL_QUADS GL_QUAD_STRIP General Polygons GL_POLYGON

10 Sep 2003CS A primitive is given a number of vertices (specified with glVertex… ). Now we look at what the primitives do with the vertices they are given. Numbers indicate vertex ordering. Blue objects mark what is actually rendered. Points GL_POINTS OpenGL Primitives: Points

10 Sep 2003CS Polylines GL_LINES GL_LINE_STRIP GL_LINE_LOOP OpenGL Primitives: Polylines

10 Sep 2003CS Polygons: Triangles GL_TRIANGLES Clockwise or counterclockwise does not matter (yet). GL_TRIANGLE_STRIP GL_TRIANGLE_FAN OpenGL Primitives: Polygons — Triangles

10 Sep 2003CS Polygons: Quadrilaterals GL_QUADS Clockwise or counterclockwise does not matter (yet). GL_QUAD_STRIP Note differences in vertex ordering! Polygons: General GL_POLYGON OpenGL Primitives: Polygons — Quad’s, General

10 Sep 2003CS OpenGL Primitives: Restrictions When drawing points, lines, and triangles, vertices can be in any positions you like. Individual quadrilaterals and general polygons must be: Planar (this is easy in 2-D). Simple (no crossings, holes). Convex (bulging outward; no concavities). Know the ten primitives! Know the associated vertex orderings!