1 / 27

Administration

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

jeneil
Download Presentation

Administration

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 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 ?

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

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

  4. Where does OpenGL reside?

  5. The pipeline Mathematically intensive stage The image is displayed on your screen Creates the color image from the geometric, color and texture data Where texture and vertex data is stored

  6. 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)

  7. OpenGL Naming Convention OpenGL commands use gl prefix GLU commands use glu prefix GLUT commands use glut prefix

  8. Coordinates and Color 0.0f3.0f0.0f • 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 0.0f0.0f0.0f 3.0f0.0f0.0f RGB

  9. Data types

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

  11. Geometric Primitives • glBegin(Glenum mode) sets the type of primitive OpenGL will interpret the next vertices list:

  12. Geometric Primitives – GL_Points glBegin(GL_Points) V0 V1 V2 V3 V4 V5 V6 V7 glEnd() Point size?

  13. Geometric Primitives – GL_Lines glBegin(GL_LINES) V0 V1 V2 V3 V4 V5 V6 V7 glEnd() Line size?

  14. Geometric Primitives – GL_LINE_LOOP glBegin(GL_LINE_LOOP) V0 V1 V2 V3 V4 V5 V6 V7 glEnd() Polygon?

  15. Geometric Primitives – GL_TRIANGLES glBegin(GL_TRIANGLES) V0 V1 V2 V3 V4 V5 V6 V7 glEnd()

  16. Geometric Primitives – GL_Polygon glBegin(GL_POLYGON) V0 V1 V2 V3 V4 V5 V6 V7 glEnd()

  17. Geometric Primitives – GL_QUADS glBegin(GL_QUADS) V0 V1 V2 V3 V4 V5 V6 V7 glEnd()

  18. 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?

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

  20. Coordinate Clipping • The clipping area is the region of Cartesian space that occupies the window glOrtho(Gldoubleleft, Gldoubleright, Gldoublebottom, Gldoubletop, Gldoublenear, Gldoublefar)

  21. 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 coordinatesglViewport (GLint x, GLint y, GLsizei width, GLsizei height );

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

  23. GLUT functions • glutInit allows application to get command line arguments and initializes system • glutInitDisplayMode requests properties for the window - RGB color - Single buffering • glutWindowSizein pixels • glutCreateWindowcreate window with title “simple” • glutDisplayFunc display callback • glutMainLoop enter infinite event loop

  24. 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 () ; }

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

  26. mydisplay void 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(); }

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

More Related