Intro to OpenGL, Tcl/Tk continued

First, as promised, some useful links:


OpenGL

The SGIs you're working on can do lots of graphics stuff in hardware. Fortunately SGI has also come up with a standard interface to this hardware: OpenGL. OpenGL looks a lot like GL, their previous "Graphics Language", except that it is an open standard , and totally hardware/windowing system/operating system/network independent. So that's why we use other software for the user I/O (Tcl/Tk...).

Now how do you create pictures?

  1. Build models from points (vertices), lines, polygons (must be convex)
  2. Specify the scene: type of projection, position of viewpoint
  3. Specify whether shading, lighting, etc. should be used
  4. Specify drawing attributes, e.g. line width, drawing colour...
  5. Send your data to OpenGL


OpenGL and Tcl/Tk

To enable you to use OpenGL commands with Tcl/Tk, an OpenGL widget is available, called GLxwin. You could add it in your Tcl script like this:
GLxwin .w -width 400 -height 300
pack .w
Click here for a list of all possible parameters.

In the polyfill example (in /u/cs426/Examples/Tcl+OpenGL/ex5), you'll see this:

set myGLWin [GLxwin .w -width 500 -height 500];
This allows you to refer to your window as $myGLWin. Examine the polyfill source for usage examples. Feel free to work from that example to create your assignment 1 program. If you do so, make a note somewhere (for example in a README file) that you used that code.


Mapping your picture to the screen

In the polyfill example, the OpenGL initialization code sets up a projection that makes sure that mouse coordinates correspond exactly to window coordinates (well almost, there's a tiny bug in the polyfill code, you could use /usr/demos/bin/snoop to help you with finding "off-by-one" errors...):
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(-0.5, winWidth-0.5, -0.5, winHeight-0.5);
glViewport(0, 0, winWidth, winHeight);


Patrick Min, CS Department, Princeton University
Last modified: Wed Oct 2 18:04:04 1996