00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 #include <unistd.h>
00037 #include <string.h>
00038
00039 #include <libplayercore/playercore.h>
00040
00041 #include <GLUT/glut.h>
00042 #include <stdio.h>
00043 #include <math.h>
00044
00045
00046 GLfloat light0_ambient[] =
00047 {0.2, 0.2, 0.2, 1.0};
00048 GLfloat light0_diffuse[] =
00049 {0.0, 0.0, 0.0, 1.0};
00050 GLfloat light1_diffuse[] =
00051 {1.0, 0.0, 0.0, 1.0};
00052 GLfloat light1_position[] =
00053 {1.0, 1.0, 1.0, 0.0};
00054 GLfloat light2_diffuse[] =
00055 {0.0, 1.0, 0.0, 1.0};
00056 GLfloat light2_position[] =
00057 {-1.0, -1.0, 1.0, 0.0};
00058 float s = 0.0;
00059 GLfloat angle1 = 0.0, angle2 = 0.0;
00060
00061 void
00062 output(GLfloat x, GLfloat y, char *text)
00063 {
00064 char *p;
00065
00066 glPushMatrix();
00067 glTranslatef(x, y, 0);
00068 for (p = text; *p; p++)
00069 glutStrokeCharacter(GLUT_STROKE_ROMAN, *p);
00070 glPopMatrix();
00071 }
00072
00073 void
00074 display(void)
00075 {
00076 static GLfloat amb[] =
00077 {0.4, 0.4, 0.4, 0.0};
00078 static GLfloat dif[] =
00079 {1.0, 1.0, 1.0, 0.0};
00080
00081 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
00082 glEnable(GL_LIGHT1);
00083 glDisable(GL_LIGHT2);
00084 amb[3] = dif[3] = cos(s) / 2.0 + 0.5;
00085 glMaterialfv(GL_FRONT, GL_AMBIENT, amb);
00086 glMaterialfv(GL_FRONT, GL_DIFFUSE, dif);
00087
00088 glPushMatrix();
00089 glTranslatef(-0.3, -0.3, 0.0);
00090 glRotatef(angle1, 1.0, 5.0, 0.0);
00091 glCallList(1);
00092 glPopMatrix();
00093
00094 glClear(GL_DEPTH_BUFFER_BIT);
00095 glEnable(GL_LIGHT2);
00096 glDisable(GL_LIGHT1);
00097 amb[3] = dif[3] = 0.5 - cos(s * .95) / 2.0;
00098 glMaterialfv(GL_FRONT, GL_AMBIENT, amb);
00099 glMaterialfv(GL_FRONT, GL_DIFFUSE, dif);
00100
00101 glPushMatrix();
00102 glTranslatef(0.3, 0.3, 0.0);
00103 glRotatef(angle2, 1.0, 0.0, 5.0);
00104 glCallList(1);
00105 glPopMatrix();
00106
00107 glPushAttrib(GL_ENABLE_BIT);
00108 glDisable(GL_DEPTH_TEST);
00109 glDisable(GL_LIGHTING);
00110 glMatrixMode(GL_PROJECTION);
00111 glPushMatrix();
00112 glLoadIdentity();
00113 gluOrtho2D(0, 1500, 0, 1500);
00114 glMatrixMode(GL_MODELVIEW);
00115 glPushMatrix();
00116 glLoadIdentity();
00117
00118 glRotatef(4, 0.0, 0.0, 1.0);
00119 output(200, 225, "This is antialiased.");
00120 glDisable(GL_LINE_SMOOTH);
00121 glDisable(GL_BLEND);
00122 output(160, 100, "This text is not.");
00123 glPopMatrix();
00124 glMatrixMode(GL_PROJECTION);
00125 glPopMatrix();
00126 glPopAttrib();
00127 glMatrixMode(GL_MODELVIEW);
00128
00129 glutSwapBuffers();
00130 }
00131
00132 void
00133 idle(void)
00134 {
00135 angle1 = (GLfloat) fmod(angle1 + 0.8, 360.0);
00136 angle2 = (GLfloat) fmod(angle2 + 1.1, 360.0);
00137 s += 0.05;
00138
00139
00140
00141 static int g=1;
00142 printf( "cycle %d\n", g++ );
00143
00144 glutPostRedisplay();
00145 }
00146
00147 void
00148 redraw( int val )
00149 {
00150 angle1 = (GLfloat) fmod(angle1 + 0.8, 360.0);
00151 angle2 = (GLfloat) fmod(angle2 + 1.1, 360.0);
00152 s += 0.05;
00153
00154
00155
00156 static int g=1;
00157 printf( "cycle %d\n", g++ );
00158
00159 glutPostRedisplay();
00160
00161 glutTimerFunc( 100, redraw, 0 );
00162 }
00163
00164 void
00165 visible(int vis)
00166 {
00167 if (vis == GLUT_VISIBLE)
00168
00169 glutIdleFunc( idle );
00170 else
00171 glutIdleFunc(NULL);
00172 }
00173
00174
00176
00177 class ExampleDriver : public Driver
00178 {
00179 public:
00180
00181
00182 ExampleDriver(ConfigFile* cf, int section);
00183
00184
00185 virtual int Setup();
00186 virtual int Shutdown();
00187
00188
00189 virtual int ProcessMessage(MessageQueue* resp_queue,
00190 player_msghdr * hdr,
00191 void * data);
00192
00193 private:
00194
00195
00196 virtual void Main();
00197
00198 virtual void Update();
00199
00200 int foop;
00201 };
00202
00203
00204
00205
00206
00207 Driver*
00208 ExampleDriver_Init(ConfigFile* cf, int section)
00209 {
00210 puts( "my init" );
00211
00212 return((Driver*)(new ExampleDriver(cf, section)));
00213 }
00214
00215
00216
00217
00218
00219 void ExampleDriver_Register(DriverTable* table)
00220 {
00221 table->AddDriver("glutgraphics", ExampleDriver_Init);
00222 }
00223
00225
00226
00227 ExampleDriver::ExampleDriver(ConfigFile* cf, int section)
00228 : Driver(cf, section, false, PLAYER_MSGQUEUE_DEFAULT_MAXLEN,
00229 PLAYER_GRAPHICS3D_CODE)
00230 {
00231
00232
00233
00234 return;
00235 }
00236
00237
00238 static int argc = 1;
00239 static char *argv = "fake";
00240
00242
00243 int ExampleDriver::Setup()
00244 {
00245 puts("Example driver initialising");
00246
00247
00248
00249
00250
00251
00252 glutInit( &argc, &argv );
00253 glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
00254 glutCreateWindow("blender");
00255 glutDisplayFunc(display);
00256 glutVisibilityFunc(visible);
00257
00258 glNewList(1, GL_COMPILE);
00259 glutSolidIcosahedron();
00260 glEndList();
00261
00262 glEnable(GL_LIGHTING);
00263 glEnable(GL_LIGHT0);
00264 glLightfv(GL_LIGHT0, GL_AMBIENT, light0_ambient);
00265 glLightfv(GL_LIGHT0, GL_DIFFUSE, light0_diffuse);
00266 glLightfv(GL_LIGHT1, GL_DIFFUSE, light1_diffuse);
00267 glLightfv(GL_LIGHT1, GL_POSITION, light1_position);
00268 glLightfv(GL_LIGHT2, GL_DIFFUSE, light2_diffuse);
00269 glLightfv(GL_LIGHT2, GL_POSITION, light2_position);
00270 glEnable(GL_DEPTH_TEST);
00271 glEnable(GL_CULL_FACE);
00272 glEnable(GL_BLEND);
00273 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
00274 glEnable(GL_LINE_SMOOTH);
00275 glLineWidth(2.0);
00276
00277 glMatrixMode(GL_PROJECTION);
00278 gluPerspective( 40.0,
00279 1.0,
00280 1.0, 10.0);
00281 glMatrixMode(GL_MODELVIEW);
00282 gluLookAt(0.0, 0.0, 5.0,
00283 0.0, 0.0, 0.0,
00284 0.0, 1.0, 0.);
00285 glTranslatef(0.0, 0.6, -1.0);
00286
00287
00288 puts("Example driver ready");
00289
00290
00291
00292
00293
00294 return(0);
00295 }
00296
00297
00299
00300 int ExampleDriver::Shutdown()
00301 {
00302 puts("Shutting example driver down");
00303
00304
00305 StopThread();
00306
00307
00308
00309
00310 puts("Example driver has been shutdown");
00311
00312 return(0);
00313 }
00314
00315 int ExampleDriver::ProcessMessage(MessageQueue* resp_queue,
00316 player_msghdr * hdr,
00317 void * data)
00318 {
00319
00320
00321
00322
00323
00324
00325
00326 return(0);
00327 }
00328
00329
00330 void ExampleDriver::Update()
00331 {
00332 ProcessMessages();
00333 glutCheckLoop();
00334 return;
00335 }
00336
00338
00339 void ExampleDriver::Main()
00340 {
00341 printf( "entering main loop" );
00342
00343
00344
00345
00346
00347 for(;;)
00348 {}
00349
00350
00351
00352
00353
00354
00355
00356
00357
00358
00359
00360
00361
00362 }
00363
00365
00366
00367
00368 extern "C" {
00369 int player_driver_init(DriverTable* table)
00370 {
00371 puts("Example driver initializing");
00372 ExampleDriver_Register(table);
00373 puts("Example driver done");
00374 return(0);
00375 }
00376 }
00377