Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ExampleSimpleGLApp1.cpp
1 /*
2 This file is part of the BIAS library (Basic ImageAlgorithmS).
3 
4 Copyright (C) 2003, 2004 (see file CONTACTS for details)
5  Multimediale Systeme der Informationsverarbeitung
6  Institut fuer Informatik
7  Christian-Albrechts-Universitaet Kiel
8 
9 
10 BIAS is free software; you can redistribute it and/or modify
11 it under the terms of the GNU Lesser General Public License as published by
12 the Free Software Foundation; either version 2.1 of the License, or
13 (at your option) any later version.
14 
15 BIAS is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU Lesser General Public License for more details.
19 
20 You should have received a copy of the GNU Lesser General Public License
21 along with BIAS; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 */
24 
25 /**
26  * @example ExampleSimpleGLApp1.cpp
27  * @ingroup g_examples
28  * @brief Very simple GL application with a single scene
29  * @author Jan Woetzel
30  */
31 
32 #include <Gui/SimpleGLApp.hh>
33 #include <Gui/SceneGL.hh>
34 
35 
36 // global helpers
37 GLfloat light_position0[] = {1.0f, 1.0, 3.0f, 1.0f}; // w=0: direction
38 void SetMaterial();
39 
40 
41 // your simple wrapper for a (possibly global) display function
42 /** \cond HIDDEN_SYMBOLS */
43 class MyScene : public BIAS::SceneGL {
44 public:
45  void Display(){
46  BIASASSERT(this->pc!=NULL); // should be set in ctor
47 
48  // clear scene, either with canvas' function
49  // this->pc->DisplayClear();
50  // or optionally by hand- may be more efficient by tighter buffer mask:
51  glClearColor(0.2,0,0,0);
52  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
53 
54  // set MODELVIEW_PROJECTION
55  // internal+external virtual camera parameters
56  // with mouse interaction
57  this->pc->DisplayCameraView();
58 
59  //
60  // more of your fancy GL calls, here:
61  //
62  this->pc->DisplayCoordCross();
63 
64  // a lit geometry that depnds on mode:
65  glPushMatrix();
66  glTranslatef(0, 0. ,-1.);
67  SetMaterial();
68  glColor4f( 0.9f, 0.2f, 0.5f, 1.0f ); // paintcolor
69  // select geometry based on mode
70  const int geoMode = BIAS::SimpleGLFrame::mode %4;
71  switch(geoMode){
72  case 0:
73  glFrontFace(GL_CW);
74  glutSolidTeapot(1);
75  glFrontFace(GL_CCW);
76  break;
77  case 1: glutSolidSphere(1,20,20);break;
78  case 2: glutSolidCube(1); break;
79  case 3: glutSolidCone(1, 1, 20, 20); break;
80  }
81 
82  glPopMatrix();
83 
84  // the light position:
85  glPushMatrix();
86  glTranslatef(light_position0[0], light_position0[1], light_position0[2] );
87  glColor3f(1, 1, 0);
88  glDisable(GL_LIGHTING);
89  glutSolidSphere(0.2,32,32);
90  glPopMatrix();
91 
92  // ...
93 
94  }
95 };
96 
97 // your simple application
98 class MyApp : public BIAS::SimpleGLApp {
99 public:
100  MyApp() : SimpleGLApp(){
101  this->scene = new MyScene();
102  }
103 };
104 
105 IMPLEMENT_APP(MyApp)
106 
107 
108 // helper
109 void SetMaterial(){
110  // light source proeprties for enabled lighting:
111  // specified pos by w=1, direction by w=0:
112  GLfloat light_maincolor0[] = {1.0f, 1.0, 1.0f, 1.0f};
113  GLfloat light_ambientcolor0[] = {0.4f, 0.2f, 0.2f, 1.0f};
114 
115  // GL create light 0
116  glLightfv(GL_LIGHT0, GL_POSITION, light_position0);
117  glLightfv(GL_LIGHT0, GL_DIFFUSE, light_maincolor0);
118  glLightfv(GL_LIGHT0, GL_SPECULAR, light_maincolor0);
119  glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambientcolor0);
120 
121  glEnable(GL_LIGHT0);
122  glEnable(GL_LIGHTING); // may be switched on/off for every object
123  glEnable(GL_DEPTH_TEST); // depth buffer occlusions of objects
124 
125  // material properties for enabled lighting:
126  GLfloat paintcolor0[] = { 0.9f, 0.2f, 0.5f, 1.0f};
127  GLfloat specularcolor0[] = { 1.0f, 1.0f, 1.0f, 1.0f};
128  GLfloat shininess0[] = { 70.0f }; // 1..128, large values make smaller specular highlights
129 
130  // activate material properties:
131  glMaterialfv( GL_FRONT_AND_BACK, GL_SPECULAR, specularcolor0);
132  glMaterialfv( GL_FRONT_AND_BACK, GL_SHININESS, shininess0);
133  glMaterialfv( GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, paintcolor0);
134 
135  glColor4fv(&paintcolor0[0]);
136 }
137 /** \endcond */
Simple interface for GL calls.
Definition: SceneGL.hh:14
Simple GL application.
Definition: SimpleGLApp.hh:17
virtual void Display()=0
main interface
static int mode
(global) params for simple user interaction with client Display routine