~ubuntu-branches/ubuntu/edgy/glui/edgy

« back to all changes in this revision

Viewing changes to example1.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Marcelo E. Magallon
  • Date: 2001-09-23 12:57:28 UTC
  • Revision ID: james.westby@ubuntu.com-20010923125728-qbts7xit2eg1ogo2
Tags: upstream-2.1.0.beta
ImportĀ upstreamĀ versionĀ 2.1.0.beta

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
 
 
3
  A simple GLUT program using the GLUI User Interface Library
 
4
 
 
5
  This program sets up a checkbox and a spinner, both with live variables.
 
6
  No callbacks are used.
 
7
 
 
8
  -----------------------------------------------------------------------
 
9
           
 
10
  9/9/98 Paul Rademacher (rademach@cs.unc.edu)
 
11
 
 
12
****************************************************************************/
 
13
 
 
14
#include <string.h>
 
15
#include <GL/glut.h>
 
16
#include "glui.h"
 
17
 
 
18
/** These are the live variables passed into GLUI ***/
 
19
int   wireframe = 0;
 
20
int   segments = 8;
 
21
int   main_window;
 
22
 
 
23
 
 
24
/***************************************** myGlutIdle() ***********/
 
25
 
 
26
void myGlutIdle( void )
 
27
{
 
28
  /* According to the GLUT specification, the current window is 
 
29
     undefined during an idle callback.  So we need to explicitly change
 
30
     it if necessary */
 
31
  if ( glutGetWindow() != main_window ) 
 
32
    glutSetWindow(main_window);  
 
33
 
 
34
  glutPostRedisplay();
 
35
}
 
36
 
 
37
 
 
38
/**************************************** myGlutReshape() *************/
 
39
 
 
40
void myGlutReshape( int x, int y )
 
41
{
 
42
  float xy_aspect;
 
43
 
 
44
  xy_aspect = (float)x / (float)y;
 
45
  glViewport( 0, 0, x, y );
 
46
 
 
47
  glMatrixMode( GL_PROJECTION );
 
48
  glLoadIdentity();
 
49
  glFrustum( -xy_aspect*.08, xy_aspect*.08, -.08, .08, .1, 15.0 );
 
50
 
 
51
  glutPostRedisplay();
 
52
}
 
53
 
 
54
/***************************************** myGlutDisplay() *****************/
 
55
 
 
56
void myGlutDisplay( void )
 
57
{
 
58
  static float rotationX = 0.0, rotationY = 0.0;
 
59
 
 
60
  glClearColor( .9f, .9f, .9f, 1.0f );
 
61
  glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
 
62
 
 
63
  /*** Rotate the object ***/
 
64
  rotationX += 3.3f;
 
65
  rotationY += 4.7f;
 
66
 
 
67
  glMatrixMode( GL_MODELVIEW );
 
68
  glLoadIdentity();
 
69
  glTranslatef( 0.0, 0.0, -1.0 );
 
70
  glRotatef( rotationY, 0.0, 1.0, 0.0 );
 
71
  glRotatef( rotationX, 1.0, 0.0, 0.0 );
 
72
 
 
73
  /*** Now we render object, using the variables 'segments' and
 
74
    'wireframe'.  These are _live_ variables, which are transparently 
 
75
    updated by GLUI ***/
 
76
  
 
77
  if ( wireframe )
 
78
    glutWireTorus( .2,.5,16,segments );
 
79
  else
 
80
    glutSolidTorus( .2,.5,16,segments );
 
81
 
 
82
  glutSwapBuffers(); 
 
83
}
 
84
 
 
85
 
 
86
/**************************************** main() ********************/
 
87
 
 
88
void main(int argc, char* argv[])
 
89
{
 
90
  /****************************************/
 
91
  /*   Initialize GLUT and create window  */
 
92
  /****************************************/
 
93
 
 
94
  glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH );
 
95
  glutInitWindowPosition( 50, 50 );
 
96
  glutInitWindowSize( 300, 300 );
 
97
 
 
98
  main_window = glutCreateWindow( "GLUI Example 1" );
 
99
  glutDisplayFunc( myGlutDisplay );
 
100
  glutReshapeFunc( myGlutReshape );  
 
101
 
 
102
  /****************************************/
 
103
  /*       Set up OpenGL lights           */
 
104
  /****************************************/
 
105
 
 
106
  GLfloat light0_ambient[] =  {0.1f, 0.1f, 0.3f, 1.0f};
 
107
  GLfloat light0_diffuse[] =  {.6f, .6f, 1.0f, 1.0f};
 
108
  GLfloat light0_position[] = {1.0f, 1.0f, 1.0f, 0.0f};
 
109
 
 
110
  glEnable(GL_LIGHTING);
 
111
  glEnable(GL_LIGHT0);
 
112
  glLightfv(GL_LIGHT0, GL_AMBIENT, light0_ambient);
 
113
  glLightfv(GL_LIGHT0, GL_DIFFUSE, light0_diffuse);
 
114
  glLightfv(GL_LIGHT0, GL_POSITION, light0_position);
 
115
 
 
116
  /****************************************/
 
117
  /*          Enable z-buferring          */
 
118
  /****************************************/
 
119
 
 
120
  glEnable(GL_DEPTH_TEST);
 
121
 
 
122
 
 
123
  /****************************************/
 
124
  /*         Here's the GLUI code         */
 
125
  /****************************************/
 
126
  
 
127
  GLUI *glui = GLUI_Master.create_glui( "GLUI" );
 
128
  glui->add_checkbox( "Wireframe", &wireframe );
 
129
  GLUI_Spinner *segment_spinner = 
 
130
    glui->add_spinner( "Segments:", GLUI_SPINNER_INT, &segments );
 
131
  segment_spinner->set_int_limits( 3, 60 ); 
 
132
   
 
133
  glui->set_main_gfx_window( main_window );
 
134
 
 
135
  /* We register the idle callback with GLUI, *not* with GLUT */
 
136
  GLUI_Master.set_glutIdleFunc( myGlutIdle ); 
 
137
 
 
138
  glutMainLoop();
 
139
}
 
140
 
 
141
 
 
142