administration

Post on 23-Feb-2016

23 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

DESCRIPTION

Administration. Teacher Assistant : Abed Asi - email: abedas@cs.bgu.ac.il Reception hours: by email - Building 37 / office -102 Assignments: 4-5 (C/C++) - to be submitted in pairs - frontal session ?. OpenGL . is NOT: - A programming language - PowerPoint PPT Presentation

TRANSCRIPT

2

Administration

Teacher Assistant : Abed Asi - email: abedas@cs.bgu.ac.il

Reception hours: by email - Building 37 / office -102

Assignments: 4-5 (C/C++) - to be submitted in pairs - frontal session ?

3

OpenGL

is NOT: - A programming language - Windows API(access files, etc’)

is:- A 3D graphics and modeling library- Cross Platform - highly portable and very fast- Application programming Interface (API) - Defining more than 250 commands

4

OpenGL libraries

OpenGL Utility Library (GLU) - A set of utility functions that perform common (but

sometimes complex) tasks.

OpenGL Utility Toolkit (GLUT) - Provides functionality common to all window

systems • Open a window• Get input from mouse and keyboard • Menus• Event-driven

- Very basic GUI

5

Where does OpenGL reside?

6

The pipeline

Where texture and vertex data

is stored

Mathematically intensive stage

Creates the color image from the

geometric, color and texture data

The image is displayed on your

screen

7

OpenGL State Machine An abstract model of a collection of state

variables A state variable represents:

- Is a light shining on the object?- What are the properties of the light?- What are the properties of the material?- Which, if any, texture should be applied?- And more …

OpenGL keeps track of all the OpenGL state variables

glEnable(GLenum capability)glDisable(GLenum capability)

8

OpenGL Naming Convention

OpenGL commands use gl prefix GLU commands use glu prefix

GLUT commands use glut prefix

9

Coordinates and Color

Coordinates – glVertex(…)- Usually float - No restriction on the values range- Vectors – glNormal(..)

Color – glColor(…)- Usually float- Values of Red, Green and Blue- Range – 0.0 to 1.0

R G B

0.0f

0.0f

0.0f

0.0f

3.0f

0.0f 3.0

f0.0f

0.0f

10

Data types

11

Geometric Primitives – Draw something!

glBegin() – represents the beginning of vertices definition

glEnd() – represents the end of the definition glVertex() is used within the definition block

- has no influence out of this block Basic types of shapes:

- GL_POINTS – draw isolated points - GL_LINES – draw lines

- GL_TRIANGLES – triangles - GL_QUADS – squares.

- And many more.…

12

Geometric Primitives glBegin(Glenum mode) sets the type of

primitive OpenGL will interpret the next vertices list:

13

Geometric Primitives – GL_Points

glBegin(GL_Points) V0 V1 V2 V3 V4 V5 V6 V7glEnd()

Point size?

14

Geometric Primitives – GL_Lines

glBegin(GL_LINES) V0 V1 V2 V3 V4 V5 V6 V7glEnd()

Line size?

15

Geometric Primitives – GL_LINE_LOOP

glBegin(GL_LINE_LOOP) V0 V1 V2 V3 V4 V5 V6 V7glEnd()

Polygon?

16

Geometric Primitives – GL_TRIANGLES

glBegin(GL_TRIANGLES) V0 V1 V2 V3 V4 V5 V6 V7glEnd()

17

Geometric Primitives – GL_Polygon

glBegin(GL_POLYGON) V0 V1 V2 V3 V4 V5 V6 V7glEnd()

18

Geometric Primitives – GL_QUADS

glBegin(GL_QUADS) V0 V1 V2 V3 V4 V5 V6 V7glEnd()

19

Winding The combination of order and direction of the

vertices matters Counter-Clockwise winding Front facing polygon Clockwise winding Back facing polygon

Why this is important?

20

Back Face Culling Back face polygons are NOT

rendered

glEnable(GL_CULL_FACE)

glCullFace(GL_BACK) glFrontFace(…)

changes the default behavior

See code example 1

21

Coordinate Clipping The clipping area is the region of Cartesian space

that occupies the window

glOrtho(Gldouble left, Gldouble right, Gldouble bottom, Gldouble top, Gldouble near, Gldouble far)

22

Viewports Rarely would the clipping area dimensions match

the window’s dimensions The coordinate system must be mapped glViewport maps between logical Cartesian

coordinates and physical screen pixel coordinates

glViewport (GLint x, GLint y, GLsizei width, GLsizei height );

23

Program structure Most OpenGL programs have a similar structure that consists of the

following functions

- Main():• defines the callback functions• opens one or more windows with the required properties • enters event loop (last executable statement)

- Init ( ): sets the state variables• Viewing• Attributes

- Callbacks• Display function mydisplay( )• Input and window functions

24

GLUT functions glutInit allows application to get command line

arguments and initializes system glutInitDisplayMode requests properties for

the window - RGB color- Single buffering

glutWindowSize in pixels glutCreateWindow create window with title

“simple” glutDisplayFunc display callback glutMainLoop enter infinite event loop

25

main#include “glut.h”

int main(int argc, char** argv) { glutInit (& argc, argv) ; glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB) ; glutInitWindowSize ( 500,500) ; glutCreateWindow(“Simple”) ; glutDisplayFunc(mydisplay) ;

init () ; glutMainLoop () ;

}

26

init

Void init ( ){ glClearColor(0.0, 0.0, 0.0, 1.0) ;

glMatrixMode(GL_PROJECTION) ; glLoadIdentity( ) ; glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0) ;}

27

mydisplayvoid mydisplay(void){

glClear(GL_COLOR_BUFFER_BIT);glColor3f(1.0f, 0.0f , 0.0f); glBegin(GL_TRIANGLES);

glVertex2f(0.0 f, 0.0f);glVertex2f(1.0 f, 0.0f);glVertex2f(0.0 f, 1.0f);

glEnd();glColor3f(0.0f, 1.0f, 0.0f);glBegin(GL_LINES);

glVertex2f(0.0 f, 0.5f);glVertex2f(1.0 f, 0.5f);

glEnd();glFlush();

}

28

Your ‘Hello World’ in OpenGL

Expand code example 2 to draw a sixth shape

Draw a new INTERESTING shape in a new color

This is a warm up mission; should not take you more than an hour

top related