Como hacer funcionar un glut

Páginas: 57 (14145 palabras) Publicado: 8 de marzo de 2012
GLUT --- REVIEW
Why are we using GLUT?
OpenGL does not include anything about creating windows, detecting keyboard presses, or processing mouse motion. This allows OpenGL to be used on most any platform, and leaves the details of the GUI to the programmer. There are, of course, many GUI libraries which allow or facilitate the creation of OpenGL windows. For example, you can write OpenGLprograms using Tcl/Tk, Motif or Visual C++ (using the UI builder). GLUT is another alternative -- it is very simple, and runs on most any platform. It doesn't provide any functionality like buttons or scrollbars -- only popup menus. While this is rather unfortunate, the available alternatives on Unix (Motif or Tcl/Tk) tend to have a steep learning curve (but are much more general), and would mainly be adistraction from the rest of the course material.
Using GLUT
When using GLUT, you will need to include:
#include
This actually includes gl.h and glu.h, so it is the only OpenGL related include file you need.
Here is part of a simple GLUT program, which simply opens a window and draws something in it:
void display(void)
{
/* Draw stuff ... */

glutSwapBuffers();
}

intmain(int argc, char *argv[])
{
glutInit(&argc, argv);

glutInitWindowSize(250, 250);
glutInitWindowPosition(100, 100);

glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);

glutCreateWindow("hello");

glutDisplayFunc(display);

glutMainLoop();
return 0;
}
Going through this program step-by-step; the function glutInit must always be called before any OpenGLoperations are performed. The next two functions set the preferred size and location of the window. glutInitDisplayMode is used to specify the mode of OpenGL window created. It is here where you specify the details of the frame buffer used (whether it has a z-buffer, whether it is single or double buffered, etc...). After this, glutCreateWindow creates the window.
Callback functions are the means usedfor GLUT to tell your program what the user is doing. In this case, the function passed to glutDisplayFunc is called whenever the window needs to be redrawn. Similar functions are available for keyboard and mouse input (glutKeyboardFunc, glutMouseFunc, glutMotionFunc, ...). Two special callbacks are used to specify what to do when the interface is inactive (glutIdleFunc) or if something needs to bedone at regular intervals (glutTimerFunc).
Finally, control of the program is given to GLUT by calling glutMainLoop, which maintains the GUI by monitoring for actions by the user, and calling the appropriate callback functions when they occur.
In the function display, glutSwapBuffers is called when double-buffering is used to switch between the two framebuffers. Note that this function alsoflushes the OpenGL buffer (see glFlush).

1.1 Background

One of the major accomplishments in the specification of OpenGL [14,10] was the isolation of window system dependencies from OpenGL's rendering model. The result is that OpenGL is window system independent.
Window system operations such as the creation of a rendering window and the handling of window system events are left to the nativewindow system to define. Necessary interactions between OpenGL and the window system such as creating and binding an OpenGL context to a window are described separately from the OpenGL specification in a window system dependent specification. For example, the GLX specification [3] describes the standard by which OpenGL interacts with the X Window System.
The predecessor to OpenGL is IRIS GL[15,16]. Unlike OpenGL, IRIS GL does specify how rendering windows are created and manipulated. IRIS GL's windowing interface is reasonably popular largely because it is simple to use. IRIS GL programmers can worry about graphics programming without needing to be an expert in programming the native window system. Experience also demonstrated that IRIS GL's windowing interface was high-level enough...
Leer documento completo

Regístrate para leer el documento completo.

Estos documentos también te pueden resultar útiles

  • Como hacer un organigrama de funciones
  • Como Hacer Que Funcione La Globalización
  • Como Hacer Que Funcione La Globalizacion
  • Como hacer que funcione la globalizacion
  • Como Hacer Que Funcione La Globalizacion
  • Como hacer funcionar Ebay
  • como hacer que funcione la globalización
  • como hacer un manual de procedimientos y funciones

Conviértase en miembro formal de Buenas Tareas

INSCRÍBETE - ES GRATIS