Jump to content

GLUT.LIB

From EDM2

GLUT.LIB is the import library for the OS/2 port of the OpenGL Utility Toolkit (GLUT), distributed with the IBM OS/2 Developer's Toolkit. GLUT is a portable windowing and event toolkit designed for writing OpenGL programs that run across multiple platforms with minimal platform-specific code. It was originally written by Mark Kilgard at Silicon Graphics. The OS/2 port implements the GLUT 3.6 API binding to the Presentation Manager windowing system.

File size in the OS/2 Warp 4.52 Toolkit 4.5: 6,144 bytes (2000-10-16). Source DLL: GLUT.DLL.

GLUT supersedes the earlier TK library for new OpenGL programs. Compared to TK, GLUT adds multiple windows, pop-up menus, additional callback types, timer callbacks, font rendering, and a richer set of 3D primitives.

API Summary

GLUT.LIB exports 86 symbols across seven functional groups:

Group Count Description
Initialization 4 Program init, window size/position defaults, display mode selection
Window management 16 Create, destroy, resize, show, hide, iconify, title, front/back
Event loop 1 Main event loop entry point
Callbacks 11 Display, reshape, keyboard, mouse, motion, idle, timer, visibility
Menus 11 Create hierarchical pop-up menus, attach to mouse buttons
3D primitives 16 Solid and wire-frame built-in geometry objects
Fonts 2 Bitmap and stroke character rendering
State queries 3 Window/device state, extension test
Color map 3 Color-index mode palette management

Initialization

glutInit(pArgc, argv)
Initializes the GLUT library. Must be called before any other GLUT function. Processes and removes GLUT-specific arguments from the command line. On OS/2, initializes the PM message queue for the calling thread.
glutInitWindowPosition(x, y)
Sets the default upper-left corner for the next window created with glutCreateWindow, in screen pixels. Has no effect after window creation.
glutInitWindowSize(width, height)
Sets the default size (in pixels) for the next created window.
glutInitDisplayMode(mode)
Sets the required rendering context attributes as a bitmask of GLUT_* flags. Common flags:
  • GLUT_RGBA — RGBA color mode (default; mutually exclusive with GLUT_INDEX)
  • GLUT_INDEX — color-index mode
  • GLUT_DOUBLE — double-buffered rendering (default: single-buffered)
  • GLUT_SINGLE — single-buffered rendering
  • GLUT_DEPTH — depth (Z) buffer
  • GLUT_STENCIL — stencil buffer
  • GLUT_ACCUM — accumulation buffer
  • GLUT_ALPHA — alpha channel in the color buffer
  • GLUT_MULTISAMPLE — multisampling (if supported)
  • GLUT_STEREO — stereoscopic rendering (if supported)

Window Management

Lifecycle

glutCreateWindow(title)
Creates a top-level OS/2 PM window with an OpenGL rendering context using the display mode and position/size set by the init functions. Returns an integer window ID. The window becomes the current window. title is the title bar string.
glutCreateSubWindow(win, x, y, width, height)
Creates a sub-window as a child of window win at position (x, y) within the parent, sized width × height. Returns a new window ID. Sub-windows have their own rendering contexts and callbacks.
glutDestroyWindow(win)
Destroys window win (and all its sub-windows) and releases their OpenGL contexts.

Current window

glutSetWindow(win)
Makes window win the current window. All subsequent window management calls and OpenGL rendering apply to this window.
glutGetWindow()
Returns the ID of the current window.

Geometry and visibility

glutReshapeWindow(width, height)
Resizes the current window to width × height pixels.
glutPositionWindow(x, y)
Moves the current window's upper-left corner to screen position (x, y).
glutShowWindow()
Makes the current window visible.
glutHideWindow()
Hides the current window without destroying it.
glutIconifyWindow()
Minimizes the current window to an icon.
glutPushWindow()
Pushes the current window below all other windows (sends it to the back of the Z order).
glutPopWindow()
Brings the current window to the front of the Z order.

Title

glutSetWindowTitle(title)
Changes the title bar text of the current window.
glutSetIconTitle(title)
Changes the icon label of the current window.

Redisplay and buffer swap

glutPostRedisplay()
Marks the current window as needing a redraw. GLUT calls the display callback on the next iteration of the event loop. Multiple calls to glutPostRedisplay before the next loop iteration coalesce into a single display callback.
glutSwapBuffers()
Swaps the front and back buffers of the current double-buffered window. Called at the end of the display callback to present the completed frame.

Event Loop

glutMainLoop()
Enters the GLUT event loop. Does not return. Processes OS/2 PM window messages and dispatches them to registered callbacks. Calls the idle callback when the message queue is empty. Applications must register at least a display callback before calling glutMainLoop.

Callbacks

All callbacks are registered as function pointers. Passing NULL unregisters the callback. Callbacks are per-window; register them after setting the current window with glutSetWindow.

glutDisplayFunc(func)
Registers the display callback. Signature: void func(void). Called when the window needs to be redrawn — after exposure, reshape, or a glutPostRedisplay request. This is the application's main rendering function. Must be set before glutMainLoop.
glutReshapeFunc(func)
Registers the reshape callback. Signature: void func(int width, int height). Called when the window is resized. The callback should update the viewport and projection matrix. Default behavior (no callback): calls glViewport(0, 0, width, height).
glutKeyboardFunc(func)
Registers the keyboard callback for ASCII key presses. Signature: void func(unsigned char key, int x, int y). x and y are the mouse position when the key was pressed.
glutSpecialFunc(func)
Registers the callback for non-ASCII (special) keys. Signature: void func(int key, int x, int y). key is a GLUT_KEY_* constant: GLUT_KEY_F1–GLUT_KEY_F12, GLUT_KEY_LEFT, GLUT_KEY_RIGHT, GLUT_KEY_UP, GLUT_KEY_DOWN, GLUT_KEY_PAGE_UP, GLUT_KEY_PAGE_DOWN, GLUT_KEY_HOME, GLUT_KEY_END, GLUT_KEY_INSERT.
glutMouseFunc(func)
Registers the mouse button callback. Signature: void func(int button, int state, int x, int y). button is GLUT_LEFT_BUTTON, GLUT_MIDDLE_BUTTON, or GLUT_RIGHT_BUTTON. state is GLUT_DOWN or GLUT_UP.
glutMotionFunc(func)
Registers the mouse-motion callback for motion with a button held down. Signature: void func(int x, int y).
glutPassiveMotionFunc(func)
Registers the mouse-motion callback for motion without any button held down (hover). Same signature as glutMotionFunc.
glutIdleFunc(func)
Registers the idle callback. Signature: void func(void). Called by glutMainLoop whenever the event queue is empty. Used for continuous animation; the idle function typically updates state and calls glutPostRedisplay.
glutTimerFunc(msecs, func, value)
Registers a one-shot timer callback. Signature: void func(int value). Called once after at least msecs milliseconds. value is a user-supplied integer passed back to the callback. Re-register inside the callback for a repeating timer.
glutVisibilityFunc(func)
Registers the visibility callback. Signature: void func(int state). state is GLUT_VISIBLE or GLUT_NOT_VISIBLE. Used to pause animation when the window is hidden.
glutMenuStateFunc(func)
Registers the menu state callback. Signature: void func(int state). state is GLUT_MENU_IN_USE or GLUT_MENU_NOT_IN_USE. Called when a pop-up menu is opened or closed.

Pop-up Menus

GLUT menus are hierarchical pop-up menus attached to mouse buttons. They are system-independent and managed entirely by GLUT.

Lifecycle

glutCreateMenu(func)
Creates a new menu and returns its integer menu ID. func is the selection callback: void func(int value), called when a menu entry is selected with the value associated with that entry. The new menu becomes the current menu.
glutDestroyMenu(menu)
Destroys menu menu.
glutSetMenu(menu)
Makes menu the current menu.
glutGetMenu()
Returns the ID of the current menu.

Entries

glutAddMenuEntry(label, value)
Appends an entry with the display string label and integer value to the current menu.
glutAddSubMenu(label, submenu)
Appends a sub-menu trigger entry with display string label that opens menu ID submenu on hover.
glutChangeToMenuEntry(entry, label, value)
Replaces item at position entry (1-based) in the current menu with a new entry.
glutChangeToSubMenu(entry, label, submenu)
Replaces item at position entry with a sub-menu trigger.
glutRemoveMenuItem(entry)
Removes the menu item at position entry.

Attachment

glutAttachMenu(button)
Attaches the current menu to mouse button button (GLUT_LEFT_BUTTON, GLUT_MIDDLE_BUTTON, or GLUT_RIGHT_BUTTON) for the current window. The menu pops up when that button is pressed.
glutDetachMenu(button)
Detaches the menu from mouse button button in the current window.

3D Primitives

GLUT provides 16 built-in 3D geometry objects, each in solid (with normals, suitable for lighting) and wire-frame form.

Solid function Wire function Object Parameter(s)
glutSolidSphere(radius, slices, stacks) glutWireSphere(radius, slices, stacks) UV sphere Radius; longitudinal/latitudinal subdivisions
glutSolidCone(base, height, slices, stacks) glutWireCone(base, height, slices, stacks) Cone Base radius, height; subdivisions
glutSolidCube(size) glutWireCube(size) Cube Edge length
glutSolidTorus(inner, outer, sides, rings) glutWireTorus(inner, outer, sides, rings) Torus Inner/outer radii; ring/side counts
glutSolidTeapot(size) glutWireTeapot(size) Utah Teapot Approximate size
glutSolidTetrahedron() glutWireTetrahedron() Regular tetrahedron (none; unit size)
glutSolidIcosahedron() glutWireIcosahedron() Icosahedron (20 faces) (none; unit size)
glutSolidDodecahedron() glutWireDodecahedron() Dodecahedron (12 faces) (none; unit size)

All primitives are centered at the world-space origin. Solid variants include per-vertex normals for correct Phong shading under GL lighting. The Utah Teapot is a historic test model; it appears slightly non-round due to the Bézier surface tessellation used in the original.

Font Rendering

glutBitmapCharacter(font, character)
Renders a single character using a bitmap (raster) font at the current raster position (glRasterPos). Advances the raster position by the character width. font is a GLUT_BITMAP_* constant:
  • GLUT_BITMAP_8_BY_13 — fixed 8×13 pixel font
  • GLUT_BITMAP_9_BY_15 — fixed 9×15 pixel font
  • GLUT_BITMAP_TIMES_ROMAN_10 — Times Roman 10 pt
  • GLUT_BITMAP_TIMES_ROMAN_24 — Times Roman 24 pt
  • GLUT_BITMAP_HELVETICA_10 — Helvetica 10 pt
  • GLUT_BITMAP_HELVETICA_12 — Helvetica 12 pt
  • GLUT_BITMAP_HELVETICA_18 — Helvetica 18 pt
glutStrokeCharacter(font, character)
Renders a single character using a stroke (vector) font as line segments in world space. The font can be scaled and rotated with the modelview matrix. font is a GLUT_STROKE_* constant:
  • GLUT_STROKE_ROMAN — proportional Roman strokes
  • GLUT_STROKE_MONO_ROMAN — monospaced Roman strokes

To render a string, call glutBitmapCharacter or glutStrokeCharacter in a loop over each character of the string.

State Queries

glutGet(type)
Returns an integer state value for the given GLUT_* type. Common values:
  • GLUT_WINDOW_WIDTH / GLUT_WINDOW_HEIGHT — current window dimensions
  • GLUT_WINDOW_X / GLUT_WINDOW_Y — current window position
  • GLUT_WINDOW_DOUBLEBUFFER — 1 if double-buffered
  • GLUT_WINDOW_DEPTH_SIZE — depth buffer bits
  • GLUT_SCREEN_WIDTH / GLUT_SCREEN_HEIGHT — screen dimensions in pixels
  • GLUT_SCREEN_WIDTH_MM / GLUT_SCREEN_HEIGHT_MM — screen dimensions in millimeters
  • GLUT_ELAPSED_TIME — milliseconds since glutInit
  • GLUT_DISPLAY_MODE_POSSIBLE — 1 if the requested display mode is achievable
glutDeviceGet(type)
Returns device capability information. Common values:
  • GLUT_HAS_KEYBOARD — 1 if a keyboard is attached
  • GLUT_HAS_MOUSE — 1 if a mouse is attached
  • GLUT_NUM_MOUSE_BUTTONS — number of mouse buttons
  • GLUT_HAS_JOYSTICK — 1 if a joystick is available
  • GLUT_HAS_SPACEBALL — 1 if a Spaceball is connected
  • GLUT_HAS_TABLET — 1 if a digitizer tablet is connected
glutExtensionSupported(extension)
Returns 1 if the named OpenGL extension string is listed in glGetString(GL_EXTENSIONS). A convenience wrapper that handles string scanning.

Color Map (Color-Index Mode)

These functions manage the hardware color map when rendering in color-index mode (GLUT_INDEX).

glutSetColor(index, red, green, blue)
Sets the color map entry at index to the given normalized RGB values (0.0–1.0).
glutGetColor(index, component)
Returns the red, green, or blue component (as a float 0.0–1.0) of the color map entry at index. component is GLUT_RED, GLUT_GREEN, or GLUT_BLUE.
glutCopyColormap(win)
Copies the color map from window win into the current window's color map.

Usage

IBM VisualAge C++ / ILINK

icc -O2 -Gm -c myapp.c
ilink /PM:PM myapp.obj os2386.lib opengl.lib glut.lib

OpenWatcom (wlink)

wcl386 -bt=os2 -mf -c myapp.c
wlink system os2_pm file myapp.obj library os2386.lib library opengl.lib library glut.lib

EMX/GCC

gcc -Zomf -c myapp.c
gcc -Zomf -o myapp.exe myapp.o os2386.lib opengl.lib glut.lib

Include files

Header Contents
gl\glut.h All GLUT prototypes; GLUT_* display mode, key, button, callback type, and query constants; includes gl\gl.h and gl\glu.h automatically.

Minimal GLUT program

#include <gl\glut.h>

static void display(void)
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glLoadIdentity();
    glTranslatef(0.0f, 0.0f, -3.0f);
    glColor3f(0.8f, 0.2f, 0.2f);
    glutSolidTeapot(1.0);
    glutSwapBuffers();
}

static void reshape(int w, int h)
{
    glViewport(0, 0, w, h);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(45.0, (double)w / h, 0.1, 100.0);
    glMatrixMode(GL_MODELVIEW);
}

static void keyboard(unsigned char key, int x, int y)
{
    if (key == 27) exit(0);  /* Escape */
}

int main(int argc, char *argv[])
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
    glutInitWindowSize(640, 480);
    glutCreateWindow("GLUT Teapot");
    glEnable(GL_DEPTH_TEST);
    glEnable(GL_LIGHTING);
    glEnable(GL_LIGHT0);
    glutDisplayFunc(display);
    glutReshapeFunc(reshape);
    glutKeyboardFunc(keyboard);
    glutMainLoop();
    return 0;
}

Continuous animation with idle callback

static float angle = 0.0f;

static void idle(void)
{
    angle += 0.5f;
    if (angle > 360.0f) angle -= 360.0f;
    glutPostRedisplay();
}

/* In main, after glutDisplayFunc: */
glutIdleFunc(idle);

Comparison with TK (LIBTK)

Feature GLUT TK (LIBTK)
Multiple windows Yes (glutCreateSubWindow) No (single window only)
Pop-up menus Yes (full hierarchical) No
Timer callbacks Yes (glutTimerFunc) No
Special key callback Yes (glutSpecialFunc) No
Visibility callback Yes (glutVisibilityFunc) No
Passive mouse motion Yes (glutPassiveMotionFunc) No
Additional primitives Teapot, dodecahedron, icosahedron, tetrahedron No
Stroke fonts Yes (glutStrokeCharacter) Yes (tkCreateStrokeFont)
Image loading No Yes (tkRGBImageLoad)
Front buffer capture No Yes (tkClipBoard, tkGrabFrontBitmap)
Platform detection No (glutGet provides sizes) Yes (tkGetSystem)

Version History

GLUT version OS/2 release Date Notes
GLUT 3.5 OS/2 Warp 4 1996 Initial OS/2 port. Core window, callbacks, menus, primitives, bitmap fonts.
GLUT 3.6 OS/2 Warp 4.x 1997–1998 Added glutTimerFunc, glutPassiveMotionFunc, glutMenuStateFunc, stroke character fonts, glutExtensionSupported, glutDeviceGet.
GLUT 3.6 OS/2 Warp 4.52 Developer's Toolkit 4.5 2000 Final IBM release. File size: 6,144 bytes (2000-10-16). Source DLL: GLUT.DLL.

Note: GLUT 3.7 features not present in this release include glutFullScreen, glutSetCursor, glutWarpPointer, game mode (glutGameModeEnter), video resize support, and overlay window support.

See Also