21
3D Computer Graphics OpenGL David Kabala

OpenGL Introduction

Embed Size (px)

Citation preview

Page 1: OpenGL Introduction

3D Computer GraphicsOpenGL

David Kabala

Page 2: OpenGL Introduction

Why Cool?

Page 3: OpenGL Introduction

Computer Graphics

Raster Graphics Images are created

from pixel data Vector Graphics

Images are created from primitives of points, lines, curves, and other shapes

Final image is computed by processing this representation

Page 4: OpenGL Introduction

OpenGL

OpenGL is a mixture of Vector and Raster graphics Vector graphics

polygons, surface normals, colors, etc. Raster graphics

textures(images) that are mapped onto surfaces Rasterizing vector graphics into frame buffer

Most platforms have an implementation of OpenGL Windows, Linux, Mac, iPhone, Android, PS3,

and many more

Page 5: OpenGL Introduction

OpenGL Rendering Pipeline

VectorOperations

Rasterization

FragmentOperations

FrameBuffer

Data

Page 6: OpenGL Introduction

OpenGL Rendering Pipeline

Page 7: OpenGL Introduction

OpenGL Rendering Pipeline

ATI R600 Pipeline

Page 8: OpenGL Introduction

OpenGL Changing with 3.0

Many parts of the OpenGL API have been deprecated in version 3.0, and removed in version 3.1

This includes much of the fixed functionality of the pipeline Lighting

Programing these portions in the pipeline is the path forward

Page 9: OpenGL Introduction

OpenGL as a state machine

OpenGL is organized for functional programming not object-oriented

Stays in a persistent state until it receives a message that tells it to change

Objects are bound Changes are made to the state

Color, lighting, line width, etc

Immediate draw mode

Page 10: OpenGL Introduction

OpenGL API

All methods are prefixed with gl e.g. glEnable(GLbool), glVertex2i(GLint,GLint)

All Types are prefixed with GL e.g. GLbool, GLint, GLflaot, GLenum

All constants are prefixed with GL_ e.g. GL_POINTS, GL_CULL_FACE, GL_QUADS

Page 11: OpenGL Introduction

OpenGL defined types

C/C++ leave the number of bytes of each type up to the compiler writer

OpenGL has defined types that are the same size in all implementations

Important Types GLshort

16 bit integer GLint

32 bit integer GLfloat

32 bit floating point GLdouble

64 bit floating point GLboolean

8 bit unsigned integer GLenum

32 bit unsigned integer

Page 12: OpenGL Introduction

Drawing

Primitives are drawn by sending vertex positions inside of a glBegin and glEnd block

Example:void display(void){ //Setup state to start drawing //points glBegin(GL_POINTS); //Draw a point at 10,10 glVertex2i(10,10); glEnd();}

Page 13: OpenGL Introduction

glBegin/glEnd block

OpenGL receives primitive geometry data “inside” a glBegin and glEnd block

glBegin(GLenum primitiveType) primitiveType argument takes a GLenum value

of the type of primitives to drawvoid display(void){ glBegin(GL_POINTS); glVertex2i(10,10);

glVertex2i(20,10);

glVertex2i(0,0); glEnd();

glVertex2i(10,0); //Will not draw}

Page 14: OpenGL Introduction

GlVertex variations

Some sets of OpenGL methods take multiple numbers and types of arguments

glVertex2i

Type of argumentNumber of arguments

glColor4f

Type SuffixGLbyte bGLshort s

i

f

d

ubGLushort us

ui

GLint, GLsizeiGLfloat, GLclampfGLdouble, GLclampdGLubyte, GLboolean

GLuint, GLenum, GLbitfield

Page 15: OpenGL Introduction

Primitives

Points

Lines

Triangles

Quadrilaterals

Polygons

Page 16: OpenGL Introduction

Points

send GL_POINTS as parameter to glBegin Every glVertex produces a single point

Changing point drawing parameters glPointSize(GLint size);

void display(void){ //Setup state to start drawing //points glPointSize(5.0); glBegin(GL_POINTS); //Draw a point at 10,10 glVertex2i(10,10); glEnd();}

Page 17: OpenGL Introduction

Lines

Line Draw Modes GL_LINES

GL_LINE_STRIP

Changing line width glLineWidth(GLint size);

GL_LINE_LOOP

v1 v2

v2

v1

v3

v4

v1

v2

v3

v4

v5

Page 18: OpenGL Introduction

Triangles

GL_TRIANGLES

GL_TRIANGLE_STRIP

GL_TRIANGLE_FAN

Page 19: OpenGL Introduction

Quads

GL_QUADS

GL_QUAD_STRIP

Page 20: OpenGL Introduction

Polygons

GL_POLYGONS

Must be convex Must be non-intersecting Separate polygons

must be in separateglBegin/glEnd blocks

v1

v2

v3

v4

v5

v1

v2 v3

v4

v5

v6v6

v8

Page 21: OpenGL Introduction

Next Time

Using GLUT (OpenGL Utility) to manage window and context creation

Transformations using matrix and vector algebra