(modified 01/26/2007) OpenGL notes OpenGL is an interactive computer graphics system - it allows you to access graphics hardware OpenGL is an industry standard see: http://www.opengl.org/about/overview.html It is a vendor independent graphics library that started from SGI's GL. OpenGL was developed for use in C (and C++) but has (some unofficial) bindings to other languages including Java, Python, Fortran, Perl, and others. These language bindings map the calls in C to the appropriate language. JOGL is Java's supported bindings to OpenGL. there are other projects that have OpenGL-like capabilities for Java that we are not using. They include: Java 3d, OpenGL for Java (gl4java), and others. ===================================================================== Coordinate systems differences between windowing system and openGL Windowing systems typically have the origin 0,0 in upper left corner with x increasing to the right and y increasing downwards (known as: window coordinates or screen coordinates) openGL's object coordinate system has the origin 0,0 in the bottom left corner with x increasing to the right and y increasing upwards (known as: object coordinates or world coordinates) ===================================================================== OpenGL's primary concern is with rendering. Rendering is creating an image based on some geometric model and their properties and based on a virtual camera and lights. Programmer interacts with OpenGL by 1) specifying the objects to render 2) specifying the attributes (to be associated with those objects) of the state 3) define how they should be viewed OpenGL function groupings 1) primitive functions - for defining polygons in different dimensions and image primitives (points, lines ...) 2) attribute functions - for appearance of the primitives - color, material properties, textures, etc. 3) viewing functions - for defining properties of the virtual camera 4) control functions - for abling/disabling openGL features and to find out implementation capabilities 5) OpenGl does not contain Windowing & User Input / event handling functions. These are taken care of typically by glut (the OpenGL Utility Toolkit). In Java we can use either the Swing or AWT. C, C++ can use glut. glut in turn uses, depending on the platform - glx for XWindows (linux/unix) - wgl for Windows - agl for Mac OpenGL is not object oriented noticeable when you see how many functions could have been overloaded instead of having the types of the parameters as part of their name e.g. glVertex3f takes floats as parameters and glVertex3i takes ints -- however, JOGL gives you access to the methods via a gl object and glu object reference OpenGl contains gl and glu functions. Those beginning with gl are the core functions glu are the utility functions (written using the gl functions) Ignoring glut or any windowing for the time being, let's discuss some functions in openGL: To specify geometric objects we use vertices. Vertices are specified between calls to glBegin and glEnd. glBegin(mode) - takes one argument mode mode can be (among other things): GL_POINTS, GL_POLYGON, GL_LINES, GL_LINE_STRIP, GL_LINE_LOOP before calling glEnd() we then specify vertices by calling: glVertex*( ... ) where * is digit among: 2,3,or 4 followed by letter among: s,i,f, or d, optionally followed by v (for "vector") The 2, 3, 4, specifies the dimensions of space The s = short, i = int, f = float, d = double The v is used when the coordinates are specified in an array and this array is the only argument. If the v is not specified, then the number of arguments is the number of dimensions 2,3 or 4. example: glVertex2d(3.4, 4.5); is a vertex in 2 dimensions coordinates are in World Coordinates openGL automatically makes the transformation from world to screen coordinates. =================================================================== glClearColor( ... ) - takes four floats between 0-1 in the order R, G, B, A (for opacity) Opacity of 0 = transparent Opacity of 1 = opaque --- used when blending. Use 0 for now. - sets the color that the display area is cleared to. glClear(GL_COLOR_BUFFER_BIT) - clears the color display to the clear color glColor*( ... ) - sets the drawing color where * is digit among: 3 (for RGB) or 4 (for RGBA) followed by letter(s) specifying type of args among: b, i, f, d, ub, us, ui optionally followed by v (for "vector") b = byte i = int (or long) - 32 bits f = float d = double ub = unsigned byte us = unsigned short ui = unsigned int (or long) - 32 bits There is also another way to specify color called color mapping where you specify an index to a table of colors and that is the color shown. Ignore this for now. note: color, as well as other attributes, are not attached to objects instead they are part of the state of openGL --- they are not attached to particular primitives. ===================================================================== Data types in openGL: GLbyte (8), GLshort (16), GLint (32), GLfloat (32), GLdouble (64), GLubyte (8), GLushort (16), GLuint (32) ===================================================================== glFlush() - forces previously buffered openGL commands to execute - openGL buffers commands for efficiency, but sometimes you want to make sure the functions you called have executed so call glFlush() ===================================================================== openGL uses three dimensions when specifying two dimensions (a plane) openGL treats this as a special case of 3d with z=0. // the following three lines set the "projection matrix" // the identity matrix is loaded first as a start // otherwise the gluOrtho2D line alters the existing matrix (last // value of it) glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluOrtho2D(0, 100, 0, 100); // in world coordinates gluOrtho2D(left, right, bottom, top) or if you prefer these names: gluOrtho2D(startX, endX, startY, endY) - used to specify how much of the object space you wish to display orthographically - maps the world coordinates specified as parameters here to the screen coordinates - useful because of window resizing etc. glMatrixMode(matrixmode) - for Model-view Matrix: use GL_MODELVIEW as argument - for Projection Matrix: use GL_PROJECTION glLoadIdentity() - loads the identity matrix into the current matrix (eg. for instance the current model view matrix or the current projection matrix) glViewport(startx, starty, width, height) - if don't want to use the entire window for displaying graphics you can use this to draw to a subset of the window startx, starty are the coordinates of the bottom left pixel width and height are in pixels ===================================================================== some attribute functions glPointSize(size) - size in pixels glLineWidth(width) - width in pixels ===================================================================== More topics to come ... 3d & Homogeneous coordinates translation, rotation, scaling Perspective projection 3d objects and viewing surface normals I will provide suggestions on getting openGL and a windowing system to work for your own computers. But the Linux lab will be our safety place, where it will be guaranteed to work. I will provide sample programs in both Java and C that will work in the Linux lab you can use as a guide. Also, I will provide some documentation and/or code on both a Java windowing system and event handling (Swing or AWT) and for C, glut. ===================================================================== LINKS The Official OpenGL website http://www.opengl.org/ OpenGL Reference Manual (Blue Book) http://www.rush3d.com/reference/opengl-bluebook-1.0/ OpenGL Programming Guide (Red Book) http://www.rush3d.com/reference/opengl-redbook-1.1/ Java bindings for OpenGL (the JOGL API Project) https://jogl.dev.java.net/ Mesa is an open-source implementation of the OpenGL specification. http://www.mesa3d.org/ - also for MesaGLUT ===================================================================== Linux Lab - Harder 207 JOGL is installed Installed on the Linux machines in the Linux Lab are the libraries for the September 14, 2006 build of JOGL. This consists of jogl.jar (necessary for compilation) placed in /usr/local/jogl-1_0_0-linux-i586/lib/ and the native libraries (necessary for running) are in the same directory: /usr/local/jogl-1_0_0-linux-i586/lib/ When using Eclipse, you'll see jogl.jar as part of the JRE System Library [jdk1.5.0_03] in your project.