CSE328:Computer Graphics OpenGL Tutorial

Post on 05-Feb-2016

127 views 1 download

Tags:

description

CSE328:Computer Graphics OpenGL Tutorial. Dongli Zhang Department of Computer Science, SBU dozhang@cs.stonybrook.edu. Department of Computer Science, Stony Brook University (SUNYSB). TA Information. Department of Computer Science, Stony Brook University (SUNYSB). TA Schedule: - PowerPoint PPT Presentation

Transcript of CSE328:Computer Graphics OpenGL Tutorial

CSE328:Computer Graphics

OpenGL Tutorial

Dongli Zhang

Department of Computer Science, SBU

dozhang@cs.stonybrook.edu

Department of Computer Science, Stony Brook University (SUNYSB)

TA Information

Department of Computer Science, Stony Brook University (SUNYSB)

TA Schedule:•Time: Tuesday: 4:30~6:00pm;•Location: Computer Science Building, 2110;•Email: dozhang@cs.stonybrook.edu

Introduction to OpenGL

CSE328

What is OpenGL?• Industrial standard library for doing computer graphics.• Developed by Silicon Graphics Inc.(SGI) in 1992.• Latest version: 4.3 (released at Aug 6, 2012).

Features:•Keep developing. More functions,GLSL,64-bit support.•OpenGL is a Graphic rendering API (software interface to graphics hardware)

• consists of lots of commands. for example: GL_BEGIN(GLint TYPE)• Operating system independent.

References:•http://en.wikipedia.org/wiki/Opengl•http://www.opengl.org/

Introduction to OpenGL

CSE328

• If you want to be a Software Engineer in Computer graphics area,OpenGL is a MUST!

• Giant Companies: NVidia, ATI(AMD),Google, Adobe, Pixar, Blizzard,Siemens Medical…

Introduction to OpenGL

CSE328

Other 3D Graphics APIs:•Direct3D --- a competitor to OpenGL.•Mesa 3D --- an open source implementation of OpenGL.•Open Inventor --- C++ object oriented 3D graphics API in higher layer

of programming.•RISpec --- Pixar’s open API for photorealistic off-line rendering.

Other 2D graphics APIs:•GTK+.•Java 2D, QT

OpenGL programming guide

CSE328

Things you should know before coding:1.OpenGL was designed be graphic output-only.

• Provide rendering functions only.• Core API has no concept of windowing systems, audio, printing to

screening, keyboard/mouse or other input devices.2.OpenGL need add-on APIs to interact with the host system.• GLX --- X11• WGL --- Microsoft Windows• CGL --- Mac OS X3.For convenient, people developed libraries to provide

functionality for basic windowing using OpenGL, such as GLUT.

OpenGL need a GUI in window system.OpenGL need a GUI in window system.

OpenGL programming guide

• Tools for programming:– C/C++ compiler and debugger: MS, gcc.– IDE: MS Visual studio, Dev-C++, Eclipse+cdt, Xcode, …– GUI: GLUT + GLUI, QT, MFC…

• Recommendation:• VS2010 + GLUT + GLUI(QT)• Reasons: free, easy for debug.

OpenGL language

• A state machine1. You put OpenGL into various states that then remain in effect until you change them

2. State is encapsulated in contexts. Each OpenGL window has its own, separate, state.

3. Think of each context as a C/C++ struct with fields for each OpenGL state variable.

• Generally, there are two operations that you do with OpenGL:1. Draw something

2. Change the state of how OpenGL draws

• OpenGL has two types of things that it can render:1. Geometric primitives: points, lines and polygons

2. Image Primitives: bitmaps and graphics image

• Additionally, OpenGL links images and geometric primitives together using Texture Mapping.

OpenGL language

OpenGL language

OpenGL language

OpenGL language

OpenGL language

OpenGL language

OpenGL geometric primitives

OpenGL geometric primitives

OpenGL geometric primitives

OpenGL geometric primitives

OpenGL geometric primitives

OpenGL geometric primitives

OpenGL geometric primitives

OpenGL geometric primitives

OpenGL geometric primitives

Rendering

Rendering

Controlling current state

GLUT

GLUT

What can GLUT do?What can GLUT do?

GLUT programming

Initialization

Initialization

Open a window

Open a window

Handle Events

Handle Event

Handle events

GLUT

GLUT

GLUT

GLUT

GLUT

Enter event processing loop

GLUT summary

GLUT Menu

GLUT Menu

Put together

GLUI

GLUI

Examples

Helpful sources