1 / 20

OpenGL – Part One

OpenGL – Part One. Introduction. What is OpenGL. An application programming interface (API) A (low-level) Graphics rendering API Generate high-quality color images composed of geometric and image primitives Display device independent Window system independent

zurcher
Download Presentation

OpenGL – Part One

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. OpenGL – Part One Introduction

  2. What is OpenGL • An application programming interface (API) • A (low-level) Graphics rendering API • Generate high-quality color images composed of geometric and image primitives • Display device independent • Window system independent • Operating system independent • OpenGL: Open Graphics Library • GLU: OpenGL Toolkit • GLUT: OpenGL Utility Toolkit

  3. OpenGL Basics • OpenGL’s primary function – Rendering • Rendering – converting geometric/mathematical object descriptions into frame buffer values • OpenGL can render: • Geometric primitives • Bitmaps and Images (Raster primitives)

  4. Setting up OpenGL • Open this website: http://www.xmission.com/~nate/glut.html • Click over the link glut-3.7.6-bin.zip (117 KB) and download the file. • Unzip the file • Do following copies: • copy "glut.h" to C:\Program Files\Microsoft Visual Studio\VC98\Include\GL (Visual C++ include directory) • copy "glut32.lib" to c:\Program Files\Microsoft Visual Studio\VC98\lib (Visual C++ library directory) • copy "glut32.dll" to C:\WINNT\SYSTEM32, where your system files are located.

  5. Basic OpenGL syntax • Functions begin with gl • Constants and function arguments and data types begin with GL • Constant words are written in capital letters and separated using ( _ ) underscore • Like: GL_2D, GL_POLYGON • OpenGl use special built in data types to work with all environments: • GLbyte • Glint • GLfloat • GLdouble • GLboolean

  6. OpenGL Command Formats

  7. Header Files • Use the following header files in your program: • # include <windows.h> • # include <GL/gl.h> • # include <GL/glu.h> • # include <GL/glut.h> • You may need other header files for c++ command like: • # include <iostream> • # include <cmath>

  8. Basic Functions • 1. glutInit( &argc, argv ); • Is used to initialize the glut library. • 2. glutCreateWindow( “Type a name for window here” ); • Is used to creates a top-level window . • 3. glutMainLoop( ); • Must be the last one in our program. • Display the initial graphics • Put the program in an infinite loop that check for input from devices such as mouse or keyboard.

  9. Basic Functions (cont.) • 4/5. glutInitWindowPosition (…), glutInitWindowSize(…) • Is used to set the initial window position and size respectively • void glutInitWindowSize(int width, int height); • void glutInitWindowPosition(int x, int y); • width • Width in pixels. • height • Height in pixels. • x • Window X location in pixels. • y • Window Y location in pixels.

  10. Basic Functions (cont.) • 6. glutInitDisplayMode (…); • Is used to initialze the display mode • May have more than one mode. • Modes examples: • GLUT_SINGLE, used to select a single buffered window • GLUT_RGB, used to specify color mode • glutInitDisplayMode ( GLUT_SINGLE | GLUT_RGB );

  11. Basic Functions (cont.)

  12. Basic Functions (cont.) • Primitives are specified using 7. glBegin( primType ) ; // define your primitives here 8. glEnd( ); • primType:GL_POINTS, GL_LINES, GL_TRIANGLES, GL_QUADS, … • glVertix2i(x value, y value); // integer values • glVertix2f(x value, y value); // float values • Used to display point (x, y)

  13. Basic Functions (cont.)

  14. Basic Functions (cont.) • 9. glMatrixMode (GL_PROJECTION) • Specifies that the used matrix is the projection matrix • 10. gluOrtho2D (left , right , bottom , top ) • Used to display part from an image that specified by left/right/bottom/top values • See the figure in the next slide.

  15. Basic Functions (cont.) • The bordered part is to be displayed.

  16. Basic Functions (cont.) • 11. glFlush( ); • To ensures that the drawing commands are actually executed rather than stored in a buffer. • 12. glutDisplayFunction(... write your fn name here …); • To call the function in which you drawn shapes. • i.e glutDisplayFunction ( drawLine);, where drawLine is the function that you wrote to display a line

  17. Color Functions • 13. glColor3f( red value, green value, blue value) ; • Used to specify the wanted color • Has three float parameter; • 14. glClearColor( red value, green value, blue value, alpha value) ; • Used to specify the initial background color. • Has four float parameters • Alpha value is used to determine the color of two overlapped objects

  18. Color Functions (cont.) • 15. glClear ( GL_COLOR_BUFFER_BIT); • Used to set the bit value in the color buffer (refresh buffer) to the color indicated in the glClearColor function. • Colors that can be used after 0/1 combination for red, green and blue values appear in the next slide.

  19. Color Values

  20. Example The following page contains a complete C++/OpenGL program to draw simple triangle

More Related