home *** CD-ROM | disk | FTP | other *** search
/ Chip 2000 March / Chip_2000-03_cd.bin / zkuste / linux / opengl / Terry / OpenGL / Examples / Hello_World.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-01-24  |  1.8 KB  |  77 lines

  1. // OpenGL Tutorial
  2. // Hello_World.c
  3.  
  4. /*************************************************************************
  5. This program essentially opens a window, clears it, sets the drawing
  6. color, draws the object, and flushes the drawing buffer.  It then goes
  7. into an infinite loop accepting events and calling the appropriate
  8. functions.
  9. *************************************************************************/
  10.  
  11. // gcc -o Hello_World  Hello_World.c -lX11 -lMesaGL -lMesaGLU -lMesatk -lm
  12.  
  13. #include <stdlib.h>
  14. #include <stdio.h>
  15. #include <math.h>
  16. #include <gltk.h>
  17.  
  18. void expose(int width, int height) {
  19.  
  20.     // Clear the window
  21.     glClear(GL_COLOR_BUFFER_BIT);
  22. }
  23.  
  24. void reshape(int width, int height) {
  25.  
  26.     // Set the new viewport size
  27.     glViewport(0, 0, (GLint)width, (GLint)height);
  28.  
  29.     // Clear the window
  30.     glClear(GL_COLOR_BUFFER_BIT);
  31. }
  32.  
  33. void draw(void) {
  34.  
  35.     // Set the drawing color
  36.     glColor3f(1.0, 1.0, 1.0);
  37.  
  38.     // Specify which primitive type is to be drawn
  39.     glBegin(GL_POLYGON);
  40.         // Specify verticies in quad
  41.         glVertex2f(-0.5, -0.5);
  42.         glVertex2f(-0.5, 0.5);
  43.         glVertex2f(0.5, 0.5);
  44.         glVertex2f(0.5, -0.5);
  45.     glEnd();
  46.  
  47.     // Flush the buffer to force drawing of all objects thus far
  48.     glFlush();
  49. }
  50.  
  51. void main(int argc, char **argv) {
  52.  
  53.     // Open a window, name it "Hello World"
  54.     if (tkInitWindow("Hello World") == GL_FALSE) {
  55.         tkQuit();
  56.     }
  57.  
  58.     // Set the clear color to black
  59.     glClearColor(0.0, 0.0, 0.0, 0.0);
  60.  
  61.     // Assign expose() to be the function called whenever
  62.     // an expose event occurs
  63.     tkExposeFunc(expose);
  64.  
  65.     // Assign reshape() to be the function called whenever 
  66.     // a reshape event occurs
  67.     tkReshapeFunc(reshape);
  68.  
  69.     // Assign draw() to be the function called whenever a display
  70.     // event occurs, generally after a resize or expose event
  71.     tkDisplayFunc(draw);
  72.  
  73.     // Pass program control to tk's event handling code
  74.     // In other words, loop forever
  75.     tkExec();
  76. }
  77.