Introduction to OpenGL (INF 250) Veronika Solteszova et al., UiB Dept. of Informatics, 2016-03-17.

Slides:



Advertisements
Similar presentations
Programming with OpenGL - Getting started - Hanyang University Han Jae-Hyek.
Advertisements

COMPUTER GRAPHICS SOFTWARE.
©Zachary Wartell, UNCC9/28/ :30 AM 1 Overview of OpenGL Revision: 1.2 Copyright Professor Zachary Wartell, University of North Carolina All Rights.
Chapter 2: Graphics Programming
Graphics Pipeline.
Status – Week 257 Victor Moya. Summary GPU interface. GPU interface. GPU state. GPU state. API/Driver State. API/Driver State. Driver/CPU Proxy. Driver/CPU.
Computer Graphic Creator: Mohsen Asghari Session 2 Fall 2014.
 The success of GL lead to OpenGL (1992), a platform-independent API that was  Easy to use  Close enough to the hardware to get excellent performance.
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.
What is OpenGL The OpenGL graphics system is a software interface to graphics hardware. (The GL stands for Graphics Library.) It allows you to create interactive.
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Programming with OpenGL Part 2: Complete Programs Ed Angel Professor of Computer Science,
Computer Graphics (Fall 2003) COMS 4160, Lecture 6: OpenGL 2 Ravi Ramamoorthi Many slides courtesy Greg Humphreys.
Interactive 3D Graphics and Virtual Reality Introduction to OpenGL concepts Session 2.
CSC 461: Lecture 6 1 CSC461 Lecture 6: 2D Programming in OpenGL Objectives:  Fundamental OpenGL primitives  Attributes  Viewport.
3D Rendering with JOGL Introduction to Java OpenGL Graphic Library By Ricardo Veguilla
Introduction to OpenGL M. Ramanathan STTP CAD 2011Introduction to OpenGL.
Computer Graphics: Programming, Problem Solving, and Visual Communication Steve Cunningham California State University Stanislaus and Grinnell College.
Introduction to OpenGL Jian Huang This set of slides are extracted from the Interactive OpenGL Programming course given by Dave Shreine, Ed Angel and Vicki.
Programming in OpenGL Ryan Holmes CSE 570 February 12 th, 2003.
Lecture 5 - Programming with OpenGL
Basic Graphics Concepts Day One CSCI 440. Terminology object - the thing being modeled image - view of object(s) on the screen frame buffer - memory that.
What is ? Open Graphics Library A cross-language, multi-platform API for rendering 2D and 3D computer graphics. The API is used to interact with a Graphics.
Programmable Pipelines. Objectives Introduce programmable pipelines ­Vertex shaders ­Fragment shaders Introduce shading languages ­Needed to describe.
1 OpenGL Basics A Graphics Standard ©Mel Slater, Anthony Steed
Basic OpenGL Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Wednesday, September 10, 2003.
Using OpenGL. 2 What is OpenGL? A software interface to graphics hardware It is a Graphics Rendering API (Application Programmer’s Interface) that is.
INTRO TO COMPUTER GRAPHICS TEXT EDWARD ANGEL: EDITION 5 CS770/870
Drawing Basic Graphics Primitives Lecture 4 Wed, Sep 3, 2003.
OpenGL Shading Language (Advanced Computer Graphics) Ernest Tatum.
Image Synthesis Rabie A. Ramadan, PhD 2. 2 Java OpenGL Using JOGL: Using JOGL: Wiki: You can download JOGL from.
2 COEN Computer Graphics I Introductions n Brad Grantham lecturer lab dude n Dave Shreiner lecturer slave driver.
CSE 470: Computer Graphics. 10/15/ Defining a Vertex A 2D vertex: glVertex2f(GLfloat x, GLfloat y); 2D vertexfloating pointopenGL parameter type.
OpenGL Conclusions OpenGL Programming and Reference Guides, other sources CSCI 6360/4360.
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,
CS 4363/6353 OPENGL BACKGROUND. WHY IS THIS CLASS SO HARD TO TEACH? (I’LL STOP WHINING SOON) Hardware (GPUs) double in processing power ever 6 months!
Computing & Information Sciences Kansas State University CIS 536/636 Introduction to Computer Graphics Lecture 4 of 41 William H. Hsu Department of Computing.
OpenGL: Introduction Yanci Zhang Game Programming Practice.
Review of OpenGL Basics
Introduction to OpenGL  OpenGL is a graphics API  Software library  Layer between programmer and graphics hardware (and software)  OpenGL can fit in.
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 3D API OPENGL ES v1.0 Owned by Silicon Graphics (SGL) Control was then transferred to Khronos Group Introduction.
Advanced Computer Graphics Spring 2014 K. H. Ko School of Mechatronics Gwangju Institute of Science and Technology.
OpenGL: The Open Graphics Language Introduction By Ricardo Veguilla.
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.
What are shaders? In the field of computer graphics, a shader is a computer program that runs on the graphics processing unit(GPU) and is used to do shading.
1 Programming with OpenGL Part 2: Complete Programs.
OpenGL API 2D Graphic Primitives Angel Angel: Interactive Computer Graphics5E © Addison-Wesley
CIS 681 Review: OpenGL. CIS 681 Command Syntax OpenGL commands start with a gl. This is followed by the base command such as Color. Followed by the number.
Introduction to Graphics Programming. Graphics API.
Computer Graphics I, Fall Programming with OpenGL Part 2: Complete Programs.
OpenGL: The Open Graphics Language Technology and Historical Overview By Ricardo Veguilla.
INTRODUCTION TO OPENGL
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
The Human Visual System vs The Pinhole camera
Draw a Simple Object.
Introduction to OpenGL
“Computer Science is no more about computers than astronomy is about telescopes.” Professor Edsger Dijkstra.
Programming with OpenGL Part 2: Complete Programs
OpenGL API 2D Graphic Primitives
Programming with OpenGL Part 2: Complete Programs
OpenGL (Open Graphics Library) Mr. B.A.Swamy Assistant Professor Dept of CSE.
Programming with OpenGL Part 2: Complete Programs
Programming with OpenGL Part 2: Complete Programs
Programming with OpenGL Part 2: Complete Programs
OpenGL Background CS 4722.
OpenGL-Rendering Pipeline
Presentation transcript:

Introduction to OpenGL (INF 250) Veronika Solteszova et al., UiB Dept. of Informatics,

Topics What is OpenGL? Basic principles Rendering Pipeline OpenGL as a state machine, OpenGL context Drawing polygons Vertex colors Textures Creating an OpenGL window Useful literature

What is OpenGL Software application interface (API) to graphics hardware (GPU) to achieve hardware-accelerated rendering Free of charge Developed by Silicon Graphics Inc., now managed by consortium Khronos Exists for several programming languages (C++, python, java, Delphi, …) For different platforms (therefore window management is not part of OpenGL, but there are helping libraries)

OpenGL commands Naming convention starts with gl and GL - commands start with gl* (no spaces between words, words start with a capital letter) Ex.: glMatrixMode(.), glDepthFunc(.) - constants/bitmasks start with GL_* (all capital letters, words separated by underscores, used as parameters of OpenGL commands) Ex.: GL_POLYGON, GL_FLAT, GL_MODELVIEW In OpenGL documentation, a command can be specified as glCommand, but there is a suffix specifying dimension and data type and an optional v (input is a pointer) Ex.: glVertex in documentation, but actual commands are glVertex2f, glVertex3f, glVertex3d, glVertex3fv …

Rendering Pipeline Blue boxes are programmable (programs are called shaders) 1 Vertex specification: Upload vertex coordinates to GPU 2 – 4: Vertex processing (blue boxes, optional) 3: Vertex post-processing: coordinate transformation (model, viewing space, perspective space, clipping, perspective division, viewport transformation) 4: Primitive assembly: GPU will determine (specified by programmer) which vertices will create primitives 5: Rasterization: Conversion of primitives into fragments 6: Fragment processing: optional, programmable 7: Pre-sample operations: scissor test, stencil test, depth test, blending…

The State Machine Concept OpenGL rendering pipeline operates in various modes States/modes are set and they stay as long as they are changed again by the programmer The design avoid the necessity to set many parameters in each function call (higher speed) Each state has a default value You can query the system for its current value glGet*(.) glEnable(…), glDisable(.) can be GL_DEPTH_TEST, GL_TEXTURE_3D

Structure of an OpenGL Program Depends on the library, but usually has the following callback methods: init (commands that can for ex. set modes) reshape or resize (what happens if the window is resized) display or draw (drawing functions) idle (what happens if no user input comes) close (what happens when the application closes, clearing memory etc.)

Errors GLenum glGetError(void) return the value of the error flag GL_NO_ERROR means no error since GL was initialized or since glGetError was last called Possible error check: If(myError == GL_INVALID_ENUM){..} If(myError == GL_INVALID_OPERATION){..} If(myError == GL_INVALID_VALUE){..} If(myError == GL_INVALID_FRAMEBUFFER_OPERATION){..} If(myError == GL_OUT_OF_MEMORY){..}

The Stack Concept The states are stored in an attribute stack Store and restore attributes via glPushAttrib(.), glPopAttrib() Matrix stacks glMatrixMode(.) for activating model-view, projection, texture, color NB! Stack has finite depth and can overflow (each push must have a corresponding pop)

Matrix stacks Transformation of vertices happens via matrix multiplication (revise linear algebra) Matrices in OpenGL are 4x4, column-major order OpenGL has a command for matrix right multiplication Ex.: glMultMatrixf(const GLfloat *m), m points to an array of 16 floats that store matrix elements in column-major order If the current matrix on the stack is C, the transformed vector will be C x v. After glMultMatrixf( &(M[0]), the transformation will be C x M x v and not M x C x v

Matrix Stacks - Example

Drawing glBegin(..); //vertices and their properties glEnd(); glBegin parameters define what primitives is going to be drawn (GL_POINTS, GL_LINES, GL_LINE_STRIP, GL_LINE_LOOP, GL_TRIANGLES, GL_TRIANGLE_STRIP, GL_TRIANGLE_FAN, GL_QUAD, GL_QUAD_STRIP, GL_POLYGON) Do not change OpenGL modes between glBegin and glEnd, only set vertex properties Vertex properties can be color, texture coordinates, normal vector

Specify Vertices – Immediate Mode

Specify Vertices – Other Options Vertices can be specified in a more efficient way: uploaded once to the GPU and re-used allows the same vertex to be part of several primitives How it works: initiate a buffer upload vertex data to the GPU upload vertex properties to the GPU upload a data structure that will allow GPU to generate primitives from vertex data More advanced, not part of this lecture

The Depth Buffer Every fragment has a depth value (Z-coordinate in screen- space) By default: depth 0.0 = depth of the viewing plane, 1.0 depth of the far plane Fragment color (color buffer) and depth (depth buffer) Depth test steers what happens if two polygons overlap (last stage of the rendering pipeline) glDepthFunc( glEnum param); Param can be: GL_NEVER, GL_ALWAYS, GL_LESS, GL_LEQUAL, GL_GREATER, GL_GEQUAL, …

Color in OpenGL In the beginning of the drawing routine, clear the color buffer (often called at the same time as the clear-of-depth – buffer command) For each vertex, color can be specified via glColor??(..) (glColor3f, glColor4f, …) If it is not, then the vertex will have the same color that was set the last time (NB! State machine)

Vertex Color

Vertex Color cont.

Textures Color of fragments can also be defined by bitmaps (images) that are called textures Textures can be 1D, 2D and 3D - A texture object must be first generated (a unique non- zero ID is generated) - Image data is then uploaded to the texture memory (GPU) with the respective ID - Mapping textures to vertices (texture coordinates)

Generate and Delete Textures Generate texture ID and upload data Delete texture

m

Creating an OpenGL Window NeHe OpenGL tutorial 1 w_(win32)/13001/ w_(win32)/13001/ GLUT library (quite simple) Qt OpenGL canvas (QGL Widget as a part of the user interface)

Useful Resources “The Red Book” OpenGL Programming Guide _guide_8th_edition.pdf Older editions are good enough for this course NeHe tutorials Contain lots of useful tutorials from window creating and OpenGL basics up to more advanced lessons.