ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/libgender/test.C
(Generate patch)

Comparing libgender/test.C (file contents):
Revision 1.2 by root, Sat Oct 2 15:54:43 2004 UTC vs.
Revision 1.3 by root, Sun Oct 3 01:14:40 2004 UTC

252 SDL_FreeSurface (image); /* No longer needed */ 252 SDL_FreeSurface (image); /* No longer needed */
253 253
254 return texture; 254 return texture;
255} 255}
256 256
257
258void
259DrawLogoTexture (void)
260{
261 static GLfloat texMinX, texMinY;
262 static GLfloat texMaxX, texMaxY;
263 static int x = 0;
264 static int y = 0;
265 static int w, h;
266 static int delta_x = 1;
267 static int delta_y = 1;
268 static Uint32 last_moved = 0;
269
270 SDL_Surface *screen = SDL_GetVideoSurface ();
271
272 if (!global_texture)
273 {
274 SDL_Surface *image;
275 GLfloat texcoord[4];
276
277 /* Load the image (could use SDL_image library here) */
278 image = SDL_LoadBMP (LOGO_FILE);
279 if (image == NULL)
280 {
281 return;
282 }
283 w = image->w;
284 h = image->h;
285
286 /* Convert the image into an OpenGL texture */
287 global_texture = SDL_GL_LoadTexture (image, texcoord);
288
289 /* Make texture coordinates easy to understand */
290 texMinX = texcoord[0];
291 texMinY = texcoord[1];
292 texMaxX = texcoord[2];
293 texMaxY = texcoord[3];
294
295 /* We don't need the original image anymore */
296 SDL_FreeSurface (image);
297
298 /* Make sure that the texture conversion is okay */
299 if (!global_texture)
300 {
301 return;
302 }
303 }
304
305 /* Move the image around */
306 x += delta_x;
307 if (x < 0)
308 {
309 x = 0;
310 delta_x = -delta_x;
311 }
312 else if ((x + w) > screen->w)
313 {
314 x = screen->w - w;
315 delta_x = -delta_x;
316 }
317 y += delta_y;
318 if (y < 0)
319 {
320 y = 0;
321 delta_y = -delta_y;
322 }
323 else if ((y + h) > screen->h)
324 {
325 y = screen->h - h;
326 delta_y = -delta_y;
327 }
328
329 /* Show the image on the screen */
330 SDL_GL_Enter2DMode ();
331 glBindTexture (GL_TEXTURE_2D, global_texture);
332 glBegin (GL_TRIANGLE_STRIP);
333 glTexCoord2f (texMinX, texMinY);
334 glVertex2i (x, y);
335 glTexCoord2f (texMaxX, texMinY);
336 glVertex2i (x + w, y);
337 glTexCoord2f (texMinX, texMaxY);
338 glVertex2i (x, y + h);
339 glTexCoord2f (texMaxX, texMaxY);
340 glVertex2i (x + w, y + h);
341 glEnd ();
342 SDL_GL_Leave2DMode ();
343}
344
345int 257int
346RunGLTest (int argc, char *argv[], 258RunGLTest (int argc, char *argv[],
347 int logo, int slowly, int bpp, float gamma, int noframe, int fsaa) 259 int logo, int slowly, int bpp, float gamma, int noframe, int fsaa)
348{ 260{
349 int i; 261 int i;
364 276
365 /* See if we should detect the display depth */ 277 /* See if we should detect the display depth */
366 if (bpp == 0) 278 if (bpp == 0)
367 { 279 {
368 if (SDL_GetVideoInfo ()->vfmt->BitsPerPixel <= 8) 280 if (SDL_GetVideoInfo ()->vfmt->BitsPerPixel <= 8)
369 {
370 bpp = 8; 281 bpp = 8;
371 }
372 else 282 else
373 {
374 bpp = 16; /* More doesn't seem to work */ 283 bpp = 16; /* More doesn't seem to work */
375 }
376 } 284 }
377 285
378 video_flags = SDL_OPENGL; 286 video_flags = SDL_OPENGL;
379 287
380 for (i = 1; argv[i]; ++i) 288 for (i = 1; argv[i]; ++i)
381 {
382 if (strcmp (argv[1], "-fullscreen") == 0) 289 if (strcmp (argv[1], "-fullscreen") == 0)
383 {
384 video_flags |= SDL_FULLSCREEN; 290 video_flags |= SDL_FULLSCREEN;
385 }
386 }
387 291
388 if (noframe) 292 if (noframe)
389 {
390 video_flags |= SDL_NOFRAME; 293 video_flags |= SDL_NOFRAME;
391 }
392 294
393 /* Initialize the display */ 295 /* Initialize the display */
394 switch (bpp) 296 switch (bpp)
395 { 297 {
396 case 8: 298 case 8:
397 rgb_size[0] = 3; 299 rgb_size[0] = 3;
398 rgb_size[1] = 3; 300 rgb_size[1] = 3;
399 rgb_size[2] = 2; 301 rgb_size[2] = 2;
400 break; 302 break;
303
401 case 15: 304 case 15:
402 case 16: 305 case 16:
403 rgb_size[0] = 5; 306 rgb_size[0] = 5;
404 rgb_size[1] = 5; 307 rgb_size[1] = 5;
405 rgb_size[2] = 5; 308 rgb_size[2] = 5;
406 break; 309 break;
310
407 default: 311 default:
408 rgb_size[0] = 8; 312 rgb_size[0] = 8;
409 rgb_size[1] = 8; 313 rgb_size[1] = 8;
410 rgb_size[2] = 8; 314 rgb_size[2] = 8;
411 break; 315 break;
413 SDL_GL_SetAttribute (SDL_GL_RED_SIZE, rgb_size[0]); 317 SDL_GL_SetAttribute (SDL_GL_RED_SIZE, rgb_size[0]);
414 SDL_GL_SetAttribute (SDL_GL_GREEN_SIZE, rgb_size[1]); 318 SDL_GL_SetAttribute (SDL_GL_GREEN_SIZE, rgb_size[1]);
415 SDL_GL_SetAttribute (SDL_GL_BLUE_SIZE, rgb_size[2]); 319 SDL_GL_SetAttribute (SDL_GL_BLUE_SIZE, rgb_size[2]);
416 SDL_GL_SetAttribute (SDL_GL_DEPTH_SIZE, 16); 320 SDL_GL_SetAttribute (SDL_GL_DEPTH_SIZE, 16);
417 SDL_GL_SetAttribute (SDL_GL_DOUBLEBUFFER, 1); 321 SDL_GL_SetAttribute (SDL_GL_DOUBLEBUFFER, 1);
322
418 if (fsaa) 323 if (fsaa)
419 { 324 {
420 SDL_GL_SetAttribute (SDL_GL_MULTISAMPLEBUFFERS, 1); 325 SDL_GL_SetAttribute (SDL_GL_MULTISAMPLEBUFFERS, 1);
421 SDL_GL_SetAttribute (SDL_GL_MULTISAMPLESAMPLES, fsaa); 326 SDL_GL_SetAttribute (SDL_GL_MULTISAMPLESAMPLES, fsaa);
422 } 327 }
328
423 if (SDL_SetVideoMode (w, h, bpp, video_flags) == NULL) 329 if (SDL_SetVideoMode (w, h, bpp, video_flags) == NULL)
424 { 330 {
425 fprintf (stderr, "Couldn't set GL mode: %s\n", SDL_GetError ()); 331 fprintf (stderr, "Couldn't set GL mode: %s\n", SDL_GetError ());
426 SDL_Quit (); 332 SDL_Quit ();
427 exit (1); 333 exit (1);
443 printf ("SDL_GL_BLUE_SIZE: requested %d, got %d\n", rgb_size[2], value); 349 printf ("SDL_GL_BLUE_SIZE: requested %d, got %d\n", rgb_size[2], value);
444 SDL_GL_GetAttribute (SDL_GL_DEPTH_SIZE, &value); 350 SDL_GL_GetAttribute (SDL_GL_DEPTH_SIZE, &value);
445 printf ("SDL_GL_DEPTH_SIZE: requested %d, got %d\n", bpp, value); 351 printf ("SDL_GL_DEPTH_SIZE: requested %d, got %d\n", bpp, value);
446 SDL_GL_GetAttribute (SDL_GL_DOUBLEBUFFER, &value); 352 SDL_GL_GetAttribute (SDL_GL_DOUBLEBUFFER, &value);
447 printf ("SDL_GL_DOUBLEBUFFER: requested 1, got %d\n", value); 353 printf ("SDL_GL_DOUBLEBUFFER: requested 1, got %d\n", value);
354
448 if (fsaa) 355 if (fsaa)
449 { 356 {
450 SDL_GL_GetAttribute (SDL_GL_MULTISAMPLEBUFFERS, &value); 357 SDL_GL_GetAttribute (SDL_GL_MULTISAMPLEBUFFERS, &value);
451 printf ("SDL_GL_MULTISAMPLEBUFFERS: requested 1, got %d\n", value); 358 printf ("SDL_GL_MULTISAMPLEBUFFERS: requested 1, got %d\n", value);
452 SDL_GL_GetAttribute (SDL_GL_MULTISAMPLESAMPLES, &value); 359 SDL_GL_GetAttribute (SDL_GL_MULTISAMPLESAMPLES, &value);
457 /* Set the window manager title bar */ 364 /* Set the window manager title bar */
458 SDL_WM_SetCaption ("SDL GL test", "testgl"); 365 SDL_WM_SetCaption ("SDL GL test", "testgl");
459 366
460 /* Set the gamma for the window */ 367 /* Set the gamma for the window */
461 if (gamma != 0.0) 368 if (gamma != 0.0)
462 {
463 SDL_SetGamma (gamma, gamma, gamma); 369 SDL_SetGamma (gamma, gamma, gamma);
464 }
465 370
466 glViewport (0, 0, w, h); 371 view v;
467 glMatrixMode (GL_PROJECTION); 372 v.p = point (0, 0, 0);
468 glLoadIdentity (); 373 v.d = vec3 (0, 0, -1);
469 374 v.u = vec3 (0, 1, 0);
470 glOrtho (-2.0, 2.0, -2.0, 2.0, -20.0, 20.0); 375 v.w = w; v.h = h;
376 v.fov = 90;
471 377
472 glMatrixMode (GL_MODELVIEW); 378 glMatrixMode (GL_MODELVIEW);
473 glLoadIdentity (); 379 glLoadIdentity ();
474 380
475 glEnable (GL_DEPTH_TEST); 381 glEnable (GL_DEPTH_TEST);
476 382
477 glDepthFunc (GL_LESS); 383 glDepthFunc (GL_LESS);
478 384
479 glShadeModel (GL_SMOOTH); 385 glShadeModel (GL_SMOOTH);
386 GLfloat ambient[4] = { 1, 1, 1, 1 };
387 glEnable (GL_LIGHTING);
388 glEnable (GL_COLOR_MATERIAL);
389 glLightModelfv (GL_LIGHT_MODEL_AMBIENT, ambient);
480 390
481 /* Loop until done. */ 391 /* Loop until done. */
482 start_time = SDL_GetTicks (); 392 start_time = SDL_GetTicks ();
483 frames = 0; 393 frames = 0;
484 while (!done) 394 while (!done)
489 399
490 /* Do our drawing, too. */ 400 /* Do our drawing, too. */
491 glClearColor (0.0, 0.0, 0.0, 1.0); 401 glClearColor (0.0, 0.0, 0.0, 1.0);
492 glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 402 glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
493 403
494 glBegin (GL_QUADS); 404 static GLfloat ry;
405 ry += 0.1;
406 v.d.x = cos (ry);
407 v.d.z = sin (ry);
495 408
496 glEnd (); 409 draw_context c;
410 v.draw (c);
497 411
498 SDL_GL_SwapBuffers (); 412 SDL_GL_SwapBuffers ();
499 413
500 /* Check for error conditions. */ 414 /* Check for error conditions. */
501 gl_error = glGetError (); 415 gl_error = glGetError ();
502 416
503 if (gl_error != GL_NO_ERROR) 417 if (gl_error != GL_NO_ERROR)
504 {
505 fprintf (stderr, "testgl: OpenGL error: %d\n", gl_error); 418 fprintf (stderr, "testgl: OpenGL error: %d\n", gl_error);
506 }
507 419
508 sdl_error = SDL_GetError (); 420 sdl_error = SDL_GetError ();
509 421
510 if (sdl_error[0] != '\0') 422 if (sdl_error[0] != '\0')
511 { 423 {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines