27
Administration Teacher Assistant : Abed Asi - email: [email protected] Reception hours: by email - Building 37 / office -102 Assignments: 4-5 (C/C++) - to be submitted in pairs - frontal session ? 2

Administration

  • Upload
    jeneil

  • View
    23

  • Download
    0

Embed Size (px)

DESCRIPTION

Administration. Teacher Assistant : Abed Asi - email: [email protected] 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

Citation preview

Page 1: Administration

2

Administration

Teacher Assistant : Abed Asi - email: [email protected]

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

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

Page 2: Administration

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

Page 3: Administration

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

Page 4: Administration

5

Where does OpenGL reside?

Page 5: Administration

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

Page 6: Administration

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)

Page 7: Administration

8

OpenGL Naming Convention

OpenGL commands use gl prefix GLU commands use glu prefix

GLUT commands use glut prefix

Page 8: Administration

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

Page 9: Administration

10

Data types

Page 10: Administration

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.…

Page 11: Administration

12

Geometric Primitives glBegin(Glenum mode) sets the type of

primitive OpenGL will interpret the next vertices list:

Page 12: Administration

13

Geometric Primitives – GL_Points

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

Point size?

Page 13: Administration

14

Geometric Primitives – GL_Lines

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

Line size?

Page 14: Administration

15

Geometric Primitives – GL_LINE_LOOP

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

Polygon?

Page 15: Administration

16

Geometric Primitives – GL_TRIANGLES

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

Page 16: Administration

17

Geometric Primitives – GL_Polygon

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

Page 17: Administration

18

Geometric Primitives – GL_QUADS

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

Page 18: Administration

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?

Page 19: Administration

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

Page 20: Administration

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)

Page 21: Administration

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 );

Page 22: Administration

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

Page 23: Administration

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

Page 24: Administration

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 () ;

}

Page 25: Administration

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) ;}

Page 26: Administration

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();

}

Page 27: Administration

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