Programming in OpenGL Ryan Holmes CSE 570 February 12 th, 2003.

Slides:



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

OpenGL CMSC340 3D Character Design & Animation. What is OpenGL? A low-level graphics library specification designed for use with the C and C++ provides…
Chapter 2: Graphics Programming
Computer Graphics CSCE 441
Pemrograman OpenGL Dasar
Introduction to OpenGL
CS 4731 Lecture 2: Intro to 2D, 3D, OpenGL and GLUT (Part I) Emmanuel Agu.
OpenGL (Graphics Library) Software Interface to graphics software Allows to create interactive programs that produce color images of moving 3D objects.
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Programming with OpenGL Part 2: Complete Programs Ed Angel Professor of Computer Science,
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Programming with OpenGL Part 1: Background Ed Angel Professor of Computer Science, Electrical.
Painterly Rendering CMPS Assignment 2. OpenGL OpenGL is a cross-language, cross- platform specification defining and API for 2D and 3D graphics.
Programming with OpenGL Part 0: 3D API March 1, 2007.
CMPE 466 COMPUTER GRAPHICS
Programming with OpenGL Part 1: Background Mohan Sridharan Based on slides created by Edward Angel CS4395: Computer Graphics 1.
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Models and Architectures Ed Angel Professor of Computer Science, Electrical and Computer.
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.
Reference1. [OpenGL course slides by Rasmus Stenholt]
CSE328:Computer Graphics OpenGL Tutorial Dongli Zhang Department of Computer Science, SBU Department of Computer Science, Stony.
Computer Graphics Bing-Yu Chen National Taiwan University.
CAP4730: Computational Structures in Computer Graphics Introduction to OpenGL.
Basic OpenGL Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Wednesday, September 10, 2003.
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.
INTRO TO COMPUTER GRAPHICS TEXT EDWARD ANGEL: EDITION 5 CS770/870
Andy Wilson - GLUT and GLVU - 9/99 - Slide 1 GLUT and GLVU Andy Wilson September 22, 1999.
Drawing Basic Graphics Primitives Lecture 4 Wed, Sep 3, 2003.
C O M P U T E R G R A P H I C S Jie chen Computer graphic -- OpenGL Howto.
CSC 461: Lecture 41 CSC461: Lecture 4 Introduction to OpenGL Objectives: Development of the OpenGL API OpenGL Architecture -- OpenGL as a state machine.
Graphics Architectures & OpenGL API Introduction Angel Angel: Interactive Computer Graphics5E © Addison-Wesley
Graphics Programming using OpenGL. OpenGL is a software interface that allows the programmer to create 2D and 3D graphics images. This interface consists.
Programming with OpenGL Part 1: Background
CSE 470: Computer Graphics. 10/15/ Defining a Vertex A 2D vertex: glVertex2f(GLfloat x, GLfloat y); 2D vertexfloating pointopenGL parameter type.
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Programming with OpenGL Part 1: Background Ed Angel Professor of Computer Science, Electrical.
CSC 461: Lecture 3 1 CSC461 Lecture 3: Models and Architectures  Objectives –Learn the basic design of a graphics system –Introduce pipeline architecture.
 “OpenGL (Open Graphics Library) is a standard specification defining a cross- language cross-platform API for writing applications that produce 2D and.
Ch 2 Graphics Programming page 1 CSC 367 Coordinate Systems (2.1.2) Device coordinates, or screen coordinates (pixels) put limitations on programmers and.
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,
CD2012 Principles of Interactive Graphics Lecture 01 Introduction Abir Hussain (Rome: 6.33,Tel , Web:
Image Synthesis Rabie A. Ramadan, PhD 1. 2 About my self Rabie A. Ramadan My website and publications
Introduction to OpenGL Programming Jian-Liang Lin 2002.
Introduction to OpenGL and GLUT. What’s OpenGL? An Application Programming Interface (API) A low-level graphics programming API – Contains over 250 functions.
C O M P U T E R G R A P H I C S Guoying Zhao 1 / 43 C O M P U T E R G R A P H I C S Guoying Zhao 1 / 43 Computer Graphics Programming with OpenGL I.
Image Synthesis Rabie A. Ramadan, PhD 4. 2 Review Questions Q1: What are the two principal tasks required to create an image of a three-dimensional scene?
Color and Color Models Angel 2.5 Angel: Interactive Computer Graphics5E © Addison-Wesley
Programming With OpenGL
Chun-Yuan Lin Introduction to OpenGL 2015/12/19 1 CG.
NoufNaief.net TA: Nouf Al-harbi.
CGGM Lab. Tan-Chi Ho Introduction to OpenGL.
OpenGL Basic Drawing 2003 Spring Keng Shih-Ling
Lecture 2 Review OpenGL Libraries Graphics Overview Rendering Pipeline OpenGL command structure.
Lecture 7 Midterm Review. OpenGL Libraries gl: Basic OpenGL library, e.g. primitives. glu: OpenGL Utility library, a set of functions to create texture.
1 Programming with OpenGL Part 2: Complete Programs.
OpenGL API 2D Graphic Primitives Angel Angel: Interactive Computer Graphics5E © Addison-Wesley
Chapter 1 Graphics Systems and Models Models and Architectures.
Introduction to OpenGL (INF 250) Veronika Solteszova et al., UiB Dept. of Informatics,
Computer Graphics I, Fall Programming with OpenGL Part 2: Complete Programs.
OpenGL CS418 Computer Graphics John C. Hart. OpenGL: Event-driven How in OpenGL? Programmer registers callback functions Callback function called when.
INTRODUCTION TO OPENGL
Computer Graphics (Fall 2003) COMS 4160, Lecture 5: OpenGL 1 Ravi Ramamoorthi Many slides courtesy Greg Humphreys.
Computer Graphics (fall,2010) School of Computer Science University of Seoul Minho Kim.
Administrivia Back on track: canceling OpenGL lecture 2 Assignment 1
Programming with OpenGL Part 2: Complete Programs
Models and Architectures
Programming with OpenGL Part 2: Complete Programs
Drawing in the plane 455.
Introduction to OpenGL
Models and Architectures
Programming with OpenGL Part 2: Complete Programs
Programming with OpenGL Part 2: Complete Programs
Programming with OpenGL Part 2: Complete Programs
Presentation transcript:

Programming in OpenGL Ryan Holmes CSE 570 February 12 th, 2003

Overview What does OpenGL include? What doesn’t OpenGL include? How do you get started with OpenGL? Tips and Tricks Resources Questions and Answers

OpenGL Is A low-level 3D graphics API A separate piece of code you access through an API An interface to hardware Primitive-based A state machine

A low-level 3D graphics API Separate code Opengl32.dll on Windows Vendors package their own version of this library with the graphics card Windows 2000 supports a software-only version of OpenGL 1.1 out of the box

A low-level 3D graphics API An interface to hardware The library knows how to interface with the card drivers to get the hardware to handle the graphics. Anything not done in hardware is done in software

A low-level 3D graphics API Primitive-based Objects consist of points, line-segments, and polygons OpenGL is not aware of any connections between primitives Exception  The GLU libraries include quadric and NURBS “objects” that encapsulate primitives for you

A state machine Functions are global and change the state of the OpenGL environment State can be pushed onto stacks and popped back off OpenGL properties remain as you set them until you set them again

OpenGL Is Not A modeling language Compiled directly into your code 3D object-oriented

Getting Started - Syntax OpenGL core functions are prefixed with gl OpenGL utility functions are prefixed with glu OpenGL typedef defined types are prefixed with GL OpenGL constants are all caps and prefixed with GL_

Getting Started - Example ::glBegin(GL_LINE_LOOP); ::glVertex3d(0, 0, 0); ::glVertex3d(x, 0, 0); ::glVertex3d(x, y, 0); ::glVertex3d(0, y, 0); ::glEnd(); ::glBegin(GL_LINE_LOOP); ::glVertex3d(0, 0, z); ::glVertex3d(x, 0, z); ::glVertex3d(x, y, z); ::glVertex3d(0, y, z); ::glEnd(); ::glBegin(GL_LINES); ::glVertex3d(0, 0, 0); ::glVertex3d(0, 0, z); ::glVertex3d(x, 0, 0); ::glVertex3d(x, 0, z); ::glVertex3d(x, y, 0); ::glVertex3d(x, y, z); ::glVertex3d(0, y, 0); ::glVertex3d(0, y, z); ::glEnd();

Getting Started - Interface OpenGL has no direct interface functionality Mouse, keyboard and window management handled by separate interface Windows wgl (“wiggle”) functions

Environment Choice MFC Strong interface support (Dialogs, menus, mouse handling) Steep learning curve GLUT Portable Easier learning curve

MFC Program Organization Document/View architecture Document – Encapsulate Data View – Display Data from Document OnDraw() Called every time the window needs to be displayed. Indirectly called by you with the Invalidate() call.

GLUT Program Organization Callback architecture – Register functions to be called when events happen. glutCreateWindow() – Setup glutDisplayFunc() – Registers your “OnDraw” equivalent glutMainLoop() – Handles redraw decisions

Creating Primitives glBegin(type) and glEnd() All primitives begin as vertices GL_POINTSGL_POLYGON GL_LINESGL_LINE_STRIP GL_LINE_LOOPGL_QUADS GL_QUAD_STRIPGL_TRIANGLES GL_TRIANGLE_FAN GL_TRIANGLE_STRIP

Vertex Data x,y,z coordinates Color (If lighting is disabled) Materials (If lighting is enabled) Normal (If lighting is enabled) Other data (e.g. texture coordinates) Vertex data is part of the current state!

Shading OpenGL supports flat shading (GL_FLAT) and smooth (GL_SMOOTH) (Gouraud) shading only – glShadeModel(type) Shading is vertex-centric, not face-centric Lighting disabled – glColor Lighting enabled – glMaterial and normals must be specified properly

Flat Shading Sequence // Set material with glMaterial glNormal3d(0, 0, 1.0); glBegin(GL_TRIANGLES); glVertex3d(0,0,0); glVertex3d(2, 0, 0); glVertex3d(1, 1, 0); glEnd();

Smooth Shading Sequence // Set material with glMaterial glBegin(GL_TRIANGLES); glNormal3d(0, 0, 1.0); glVertex3d(0,0,0); glNormal3d(0, 0, 1.0); glVertex3d(2, 0, 0); glNormal3d(0, 0, 1.0); glVertex3d(1, 1, 0); glEnd();

Typical Rendering Sequence Clear the frame buffer and depth buffer – glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) Specify all primitives in the scene glBegin(type) glVertex()… glEnd() Swap the buffers – windowing system specific

Tips and Tricks I Plan first Break things into pieces Put only what is necessary into OnDraw Choose your “default” state and initialize it during program start-up. Make sure that every function returns the state to that default before it exits

Tips and Tricks II Read the Red Book Appendices contain a wealth of speed-up and optimization information Learn the debugging tools. When a graphics program doesn’t display anything, it can be difficult to figure out what’s wrong

Fundamental Principle of Graphics Programming Graphics programming is 30% understanding what data you need and 70% keeping track of where that data is and updating it. Design your data structures accordingly.

Resources I Project Zero walk-through and skeleton code. Links page The “Red Book” _bookshelves/SGIindex/SGI_Developer_ OpenGL_PG.html _bookshelves/SGIindex/SGI_Developer_ OpenGL_PG.html

Resources II GLUT GLUT Documentation - ation/glut/ ation/glut/.NET Framework -

Questions and Answers