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

Comparing libgender/test.C (file contents):
Revision 1.1 by root, Sat Oct 2 12:10:40 2004 UTC vs.
Revision 1.43 by root, Wed Oct 6 16:51:20 2004 UTC

2#include <stdio.h> 2#include <stdio.h>
3#include <string.h> 3#include <string.h>
4#include <math.h> 4#include <math.h>
5 5
6#include "SDL.h" 6#include "SDL.h"
7
8#include "SDL_opengl.h" 7#include "SDL_opengl.h"
9
10/* Undefine this if you want a flat cube instead of a rainbow cube */
11#define SHADED_CUBE
12
13/* Define this to be the name of the logo image to use with -logo */
14#define LOGO_FILE "icon.bmp"
15
16/* The SDL_OPENGLBLIT interface is deprecated.
17 The code is still available for benchmark purposes though.
18*/
19
20static SDL_bool USE_DEPRECATED_OPENGLBLIT = SDL_FALSE;
21 8
22static SDL_Surface *global_image = NULL; 9static SDL_Surface *global_image = NULL;
23static GLuint global_texture = 0; 10static GLuint global_texture = 0;
24 11
12#include "util.h"
13#include "entity.h"
14#include "txtprt_import.h"
15
16CGcontext cgc;
17CGprogram vsh, fsh;
18CGparameter mv, mvp, lightpos;
19CGprofile vsh_profile, fsh_profile;
20
21static void CheckCgError(void)
22{
23 CGerror err = cgGetError();
24
25 if (err != CG_NO_ERROR)
26 {
27 printf("CG error: %s\n", cgGetErrorString(err));
28 exit(1);
29 }
30}
31
25/**********************************************************************/ 32/**********************************************************************/
33
34view camera;
35vec3 camera_velocity;
36float camera_angle = 0, camera_velocity_angle;
37float camera_velocity_factor = 20;
26 38
27void 39void
28HotKey_ToggleFullScreen (void) 40HotKey_ToggleFullScreen (void)
29{ 41{
30 SDL_Surface *screen; 42 SDL_Surface *screen;
31 43
32 screen = SDL_GetVideoSurface (); 44 screen = SDL_GetVideoSurface ();
33 if (SDL_WM_ToggleFullScreen (screen)) 45 if (SDL_WM_ToggleFullScreen (screen))
34 {
35 printf ("Toggled fullscreen mode - now %s\n", 46 printf ("Toggled fullscreen mode - now %s\n",
36 (screen->flags & SDL_FULLSCREEN) ? "fullscreen" : "windowed"); 47 (screen->flags & SDL_FULLSCREEN) ? "fullscreen" : "windowed");
37 }
38 else 48 else
39 {
40 printf ("Unable to toggle fullscreen mode\n"); 49 printf ("Unable to toggle fullscreen mode\n");
41 }
42} 50}
43 51
44void 52void
45HotKey_ToggleGrab (void) 53HotKey_ToggleGrab (void)
46{ 54{
47 SDL_GrabMode mode; 55 SDL_GrabMode mode;
48 56
49 printf ("Ctrl-G: toggling input grab!\n"); 57 printf ("Ctrl-G: toggling input grab!\n");
50 mode = SDL_WM_GrabInput (SDL_GRAB_QUERY); 58 mode = SDL_WM_GrabInput (SDL_GRAB_QUERY);
51 if (mode == SDL_GRAB_ON) 59 if (mode == SDL_GRAB_ON)
52 {
53 printf ("Grab was on\n"); 60 printf ("Grab was on\n");
54 }
55 else 61 else
56 {
57 printf ("Grab was off\n"); 62 printf ("Grab was off\n");
58 }
59 63
60 mode = SDL_WM_GrabInput (mode ? SDL_GRAB_OFF : SDL_GRAB_ON); 64 mode = SDL_WM_GrabInput (mode ? SDL_GRAB_OFF : SDL_GRAB_ON);
61 if (mode == SDL_GRAB_ON) 65 if (mode == SDL_GRAB_ON)
62 {
63 printf ("Grab is now on\n"); 66 printf ("Grab is now on\n");
64 }
65 else 67 else
66 {
67 printf ("Grab is now off\n"); 68 printf ("Grab is now off\n");
68 }
69} 69}
70 70
71void 71void
72HotKey_Iconify (void) 72HotKey_Iconify (void)
73{ 73{
101 101
102 printf ("focus\n"); 102 printf ("focus\n");
103 break; 103 break;
104 104
105 case SDL_KEYDOWN: 105 case SDL_KEYDOWN:
106 if (event->key.keysym.sym == SDLK_UP) camera_velocity.z--;
107 if (event->key.keysym.sym == SDLK_DOWN) camera_velocity.z++;
108 if (event->key.keysym.sym == SDLK_LEFT) camera_velocity.x--;
109 if (event->key.keysym.sym == SDLK_RIGHT) camera_velocity.x++;
110 if (event->key.keysym.sym == SDLK_a) camera_velocity.y--;
111 if (event->key.keysym.sym == SDLK_s) camera_velocity.y++;
112 if (event->key.keysym.sym == SDLK_v) camera_velocity_factor *= 1.5;
113 if (event->key.keysym.sym == SDLK_b) camera_velocity_factor /= 1.5;
114 if (event->key.keysym.sym == SDLK_e) camera_velocity_angle++;
115 if (event->key.keysym.sym == SDLK_q) camera_velocity_angle--;
116
106 if (event->key.keysym.sym == SDLK_ESCAPE) 117 if (event->key.keysym.sym == SDLK_ESCAPE)
107 {
108 done = 1; 118 done = 1;
109 }
110 119
111 if ((event->key.keysym.sym == SDLK_g) && 120 if ((event->key.keysym.sym == SDLK_g) &&
112 (event->key.keysym.mod & KMOD_CTRL)) 121 (event->key.keysym.mod & KMOD_CTRL))
113 {
114 HotKey_ToggleGrab (); 122 HotKey_ToggleGrab ();
115 }
116 123
117 if ((event->key.keysym.sym == SDLK_z) && 124 if ((event->key.keysym.sym == SDLK_z) &&
118 (event->key.keysym.mod & KMOD_CTRL)) 125 (event->key.keysym.mod & KMOD_CTRL))
119 {
120 HotKey_Iconify (); 126 HotKey_Iconify ();
121 }
122 127
123 if ((event->key.keysym.sym == SDLK_RETURN) && 128 if ((event->key.keysym.sym == SDLK_RETURN) &&
124 (event->key.keysym.mod & KMOD_ALT)) 129 (event->key.keysym.mod & KMOD_ALT))
125 {
126 HotKey_ToggleFullScreen (); 130 HotKey_ToggleFullScreen ();
127 }
128 131
129 printf ("key '%s' pressed\n", SDL_GetKeyName (event->key.keysym.sym)); 132 break;
133
134 case SDL_KEYUP:
135 if (event->key.keysym.sym == SDLK_UP) camera_velocity.z++;
136 if (event->key.keysym.sym == SDLK_DOWN) camera_velocity.z--;
137 if (event->key.keysym.sym == SDLK_LEFT) camera_velocity.x++;
138 if (event->key.keysym.sym == SDLK_RIGHT) camera_velocity.x--;
139 if (event->key.keysym.sym == SDLK_a) camera_velocity.y++;
140 if (event->key.keysym.sym == SDLK_s) camera_velocity.y--;
141 if (event->key.keysym.sym == SDLK_e) camera_velocity_angle--;
142 if (event->key.keysym.sym == SDLK_q) camera_velocity_angle++;
130 break; 143 break;
131 144
132 case SDL_QUIT: 145 case SDL_QUIT:
133 done = 1; 146 done = 1;
134 break; 147 break;
135 } 148 }
136 149
137 return (done); 150 return (done);
138}
139
140void
141SDL_GL_Enter2DMode ()
142{
143 SDL_Surface *screen = SDL_GetVideoSurface ();
144
145 /* Note, there may be other things you need to change,
146 depending on how you have your OpenGL state set up.
147 */
148 glPushAttrib (GL_ENABLE_BIT);
149 glDisable (GL_DEPTH_TEST);
150 glDisable (GL_CULL_FACE);
151 glEnable (GL_TEXTURE_2D);
152
153 /* This allows alpha blending of 2D textures with the scene */
154 glEnable (GL_BLEND);
155 glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
156
157 glViewport (0, 0, screen->w, screen->h);
158
159 glMatrixMode (GL_PROJECTION);
160 glPushMatrix ();
161 glLoadIdentity ();
162
163 glOrtho (0.0, (GLdouble) screen->w, (GLdouble) screen->h, 0.0, 0.0, 1.0);
164
165 glMatrixMode (GL_MODELVIEW);
166 glPushMatrix ();
167 glLoadIdentity ();
168
169 glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
170}
171
172void
173SDL_GL_Leave2DMode ()
174{
175 glMatrixMode (GL_MODELVIEW);
176 glPopMatrix ();
177
178 glMatrixMode (GL_PROJECTION);
179 glPopMatrix ();
180
181 glPopAttrib ();
182}
183
184/* Quick utility function for texture creation */
185static int
186power_of_two (int input)
187{
188 int value = 1;
189
190 while (value < input)
191 {
192 value <<= 1;
193 }
194 return value;
195}
196
197GLuint
198SDL_GL_LoadTexture (SDL_Surface * surface, GLfloat * texcoord)
199{
200 GLuint texture;
201 int w, h;
202 SDL_Surface *image;
203 SDL_Rect area;
204 Uint32 saved_flags;
205 Uint8 saved_alpha;
206
207 /* Use the surface width and height expanded to powers of 2 */
208 w = power_of_two (surface->w);
209 h = power_of_two (surface->h);
210 texcoord[0] = 0.0f; /* Min X */
211 texcoord[1] = 0.0f; /* Min Y */
212 texcoord[2] = (GLfloat) surface->w / w; /* Max X */
213 texcoord[3] = (GLfloat) surface->h / h; /* Max Y */
214
215 image = SDL_CreateRGBSurface (SDL_SWSURFACE, w, h, 32,
216#if SDL_BYTEORDER == SDL_LIL_ENDIAN /* OpenGL RGBA masks */
217 0x000000FF, 0x0000FF00, 0x00FF0000, 0xFF000000
218#else
219 0xFF000000, 0x00FF0000, 0x0000FF00, 0x000000FF
220#endif
221 );
222 if (image == NULL)
223 {
224 return 0;
225 }
226
227 /* Save the alpha blending attributes */
228 saved_flags = surface->flags & (SDL_SRCALPHA | SDL_RLEACCELOK);
229 saved_alpha = surface->format->alpha;
230 if ((saved_flags & SDL_SRCALPHA) == SDL_SRCALPHA)
231 {
232 SDL_SetAlpha (surface, 0, 0);
233 }
234
235 /* Copy the surface into the GL texture image */
236 area.x = 0;
237 area.y = 0;
238 area.w = surface->w;
239 area.h = surface->h;
240 SDL_BlitSurface (surface, &area, image, &area);
241
242 /* Restore the alpha blending attributes */
243 if ((saved_flags & SDL_SRCALPHA) == SDL_SRCALPHA)
244 {
245 SDL_SetAlpha (surface, saved_flags, saved_alpha);
246 }
247
248 /* Create an OpenGL texture for the image */
249 glGenTextures (1, &texture);
250 glBindTexture (GL_TEXTURE_2D, texture);
251 glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
252 glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
253 glTexImage2D (GL_TEXTURE_2D,
254 0,
255 GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, image->pixels);
256 SDL_FreeSurface (image); /* No longer needed */
257
258 return texture;
259}
260
261
262void
263DrawLogoTexture (void)
264{
265 static GLfloat texMinX, texMinY;
266 static GLfloat texMaxX, texMaxY;
267 static int x = 0;
268 static int y = 0;
269 static int w, h;
270 static int delta_x = 1;
271 static int delta_y = 1;
272 static Uint32 last_moved = 0;
273
274 SDL_Surface *screen = SDL_GetVideoSurface ();
275
276 if (!global_texture)
277 {
278 SDL_Surface *image;
279 GLfloat texcoord[4];
280
281 /* Load the image (could use SDL_image library here) */
282 image = SDL_LoadBMP (LOGO_FILE);
283 if (image == NULL)
284 {
285 return;
286 }
287 w = image->w;
288 h = image->h;
289
290 /* Convert the image into an OpenGL texture */
291 global_texture = SDL_GL_LoadTexture (image, texcoord);
292
293 /* Make texture coordinates easy to understand */
294 texMinX = texcoord[0];
295 texMinY = texcoord[1];
296 texMaxX = texcoord[2];
297 texMaxY = texcoord[3];
298
299 /* We don't need the original image anymore */
300 SDL_FreeSurface (image);
301
302 /* Make sure that the texture conversion is okay */
303 if (!global_texture)
304 {
305 return;
306 }
307 }
308
309 /* Move the image around */
310 x += delta_x;
311 if (x < 0)
312 {
313 x = 0;
314 delta_x = -delta_x;
315 }
316 else if ((x + w) > screen->w)
317 {
318 x = screen->w - w;
319 delta_x = -delta_x;
320 }
321 y += delta_y;
322 if (y < 0)
323 {
324 y = 0;
325 delta_y = -delta_y;
326 }
327 else if ((y + h) > screen->h)
328 {
329 y = screen->h - h;
330 delta_y = -delta_y;
331 }
332
333 /* Show the image on the screen */
334 SDL_GL_Enter2DMode ();
335 glBindTexture (GL_TEXTURE_2D, global_texture);
336 glBegin (GL_TRIANGLE_STRIP);
337 glTexCoord2f (texMinX, texMinY);
338 glVertex2i (x, y);
339 glTexCoord2f (texMaxX, texMinY);
340 glVertex2i (x + w, y);
341 glTexCoord2f (texMinX, texMaxY);
342 glVertex2i (x, y + h);
343 glTexCoord2f (texMaxX, texMaxY);
344 glVertex2i (x + w, y + h);
345 glEnd ();
346 SDL_GL_Leave2DMode ();
347} 151}
348 152
349int 153int
350RunGLTest (int argc, char *argv[], 154RunGLTest (int argc, char *argv[],
351 int logo, int slowly, int bpp, float gamma, int noframe, int fsaa) 155 int logo, int slowly, int bpp, float gamma, int noframe, int fsaa)
355 int w = 640; 159 int w = 640;
356 int h = 480; 160 int h = 480;
357 int done = 0; 161 int done = 0;
358 int frames; 162 int frames;
359 Uint32 start_time, this_time; 163 Uint32 start_time, this_time;
164 Uint32 video_flags;
360 int value; 165 int value;
361 166
362 if (SDL_Init (SDL_INIT_VIDEO) < 0) 167 if (SDL_Init (SDL_INIT_VIDEO) < 0)
363 { 168 {
364 fprintf (stderr, "Couldn't initialize SDL: %s\n", SDL_GetError ()); 169 fprintf (stderr, "Couldn't initialize SDL: %s\n", SDL_GetError ());
367 172
368 /* See if we should detect the display depth */ 173 /* See if we should detect the display depth */
369 if (bpp == 0) 174 if (bpp == 0)
370 { 175 {
371 if (SDL_GetVideoInfo ()->vfmt->BitsPerPixel <= 8) 176 if (SDL_GetVideoInfo ()->vfmt->BitsPerPixel <= 8)
372 {
373 bpp = 8; 177 bpp = 8;
374 }
375 else 178 else
376 {
377 bpp = 16; /* More doesn't seem to work */ 179 bpp = 16; /* More doesn't seem to work */
378 }
379 }
380
381 /* Set the flags we want to use for setting the video mode */
382 if (logo && USE_DEPRECATED_OPENGLBLIT)
383 { 180 }
384 video_flags = SDL_OPENGLBLIT; 181
385 }
386 else
387 {
388 video_flags = SDL_OPENGL; 182 video_flags = SDL_OPENGL;
389 } 183
390 for (i = 1; argv[i]; ++i) 184 for (i = 1; argv[i]; ++i)
391 {
392 if (strcmp (argv[1], "-fullscreen") == 0) 185 if (strcmp (argv[1], "-fullscreen") == 0)
393 {
394 video_flags |= SDL_FULLSCREEN; 186 video_flags |= SDL_FULLSCREEN;
395 }
396 }
397 187
398 if (noframe) 188 if (noframe)
399 {
400 video_flags |= SDL_NOFRAME; 189 video_flags |= SDL_NOFRAME;
401 }
402 190
403 /* Initialize the display */ 191 /* Initialize the display */
404 switch (bpp) 192 switch (bpp)
405 { 193 {
406 case 8: 194 case 8:
407 rgb_size[0] = 3; 195 rgb_size[0] = 3;
408 rgb_size[1] = 3; 196 rgb_size[1] = 3;
409 rgb_size[2] = 2; 197 rgb_size[2] = 2;
410 break; 198 break;
199
411 case 15: 200 case 15:
412 case 16: 201 case 16:
413 rgb_size[0] = 5; 202 rgb_size[0] = 5;
414 rgb_size[1] = 5; 203 rgb_size[1] = 5;
415 rgb_size[2] = 5; 204 rgb_size[2] = 5;
416 break; 205 break;
206
417 default: 207 default:
418 rgb_size[0] = 8; 208 rgb_size[0] = 8;
419 rgb_size[1] = 8; 209 rgb_size[1] = 8;
420 rgb_size[2] = 8; 210 rgb_size[2] = 8;
421 break; 211 break;
422 } 212 }
213
423 SDL_GL_SetAttribute (SDL_GL_RED_SIZE, rgb_size[0]); 214 SDL_GL_SetAttribute (SDL_GL_RED_SIZE, rgb_size[0]);
424 SDL_GL_SetAttribute (SDL_GL_GREEN_SIZE, rgb_size[1]); 215 SDL_GL_SetAttribute (SDL_GL_GREEN_SIZE, rgb_size[1]);
425 SDL_GL_SetAttribute (SDL_GL_BLUE_SIZE, rgb_size[2]); 216 SDL_GL_SetAttribute (SDL_GL_BLUE_SIZE, rgb_size[2]);
426 SDL_GL_SetAttribute (SDL_GL_DEPTH_SIZE, 16); 217 SDL_GL_SetAttribute (SDL_GL_DEPTH_SIZE, 16);
427 SDL_GL_SetAttribute (SDL_GL_DOUBLEBUFFER, 1); 218 SDL_GL_SetAttribute (SDL_GL_DOUBLEBUFFER, 1);
219
428 if (fsaa) 220 if (fsaa)
429 { 221 {
430 SDL_GL_SetAttribute (SDL_GL_MULTISAMPLEBUFFERS, 1); 222 SDL_GL_SetAttribute (SDL_GL_MULTISAMPLEBUFFERS, 1);
431 SDL_GL_SetAttribute (SDL_GL_MULTISAMPLESAMPLES, fsaa); 223 SDL_GL_SetAttribute (SDL_GL_MULTISAMPLESAMPLES, fsaa);
432 } 224 }
225
433 if (SDL_SetVideoMode (w, h, bpp, video_flags) == NULL) 226 if (SDL_SetVideoMode (w, h, bpp, video_flags) == NULL)
434 { 227 {
435 fprintf (stderr, "Couldn't set GL mode: %s\n", SDL_GetError ()); 228 fprintf (stderr, "Couldn't set GL mode: %s\n", SDL_GetError ());
436 SDL_Quit (); 229 SDL_Quit ();
437 exit (1); 230 exit (1);
453 printf ("SDL_GL_BLUE_SIZE: requested %d, got %d\n", rgb_size[2], value); 246 printf ("SDL_GL_BLUE_SIZE: requested %d, got %d\n", rgb_size[2], value);
454 SDL_GL_GetAttribute (SDL_GL_DEPTH_SIZE, &value); 247 SDL_GL_GetAttribute (SDL_GL_DEPTH_SIZE, &value);
455 printf ("SDL_GL_DEPTH_SIZE: requested %d, got %d\n", bpp, value); 248 printf ("SDL_GL_DEPTH_SIZE: requested %d, got %d\n", bpp, value);
456 SDL_GL_GetAttribute (SDL_GL_DOUBLEBUFFER, &value); 249 SDL_GL_GetAttribute (SDL_GL_DOUBLEBUFFER, &value);
457 printf ("SDL_GL_DOUBLEBUFFER: requested 1, got %d\n", value); 250 printf ("SDL_GL_DOUBLEBUFFER: requested 1, got %d\n", value);
251
458 if (fsaa) 252 if (fsaa)
459 { 253 {
460 SDL_GL_GetAttribute (SDL_GL_MULTISAMPLEBUFFERS, &value); 254 SDL_GL_GetAttribute (SDL_GL_MULTISAMPLEBUFFERS, &value);
461 printf ("SDL_GL_MULTISAMPLEBUFFERS: requested 1, got %d\n", value); 255 printf ("SDL_GL_MULTISAMPLEBUFFERS: requested 1, got %d\n", value);
462 SDL_GL_GetAttribute (SDL_GL_MULTISAMPLESAMPLES, &value); 256 SDL_GL_GetAttribute (SDL_GL_MULTISAMPLESAMPLES, &value);
463 printf ("SDL_GL_MULTISAMPLESAMPLES: requested %d, got %d\n", fsaa, 257 printf ("SDL_GL_MULTISAMPLESAMPLES: requested %d, got %d\n", fsaa,
464 value); 258 value);
465 } 259 }
466 260
467 /* Set the window manager title bar */ 261 /* Set the window manager title bar */
468 SDL_WM_SetCaption ("SDL GL test", "testgl"); 262 SDL_WM_SetCaption ("libgender rendering test", "gendertest");
469 263
470 /* Set the gamma for the window */ 264 /* Set the gamma for the window */
471 if (gamma != 0.0) 265 if (gamma != 0.0)
472 {
473 SDL_SetGamma (gamma, gamma, gamma); 266 SDL_SetGamma (gamma, gamma, gamma);
267
268 for (int i = 0; i < 70; i++)
474 } 269 {
270 // load a entity
271 txtprt_parser p;
272 entity *e;
273 try
274 {
275 e = p.read ("test.blasc");
276 }
277 catch (txtprt_i_exception & e)
278 {
279 cout << "ERR: " << e.msg << endl;
280 }
475 281
476 glViewport (0, 0, w, h); 282 entity_transform *f = new entity_transform;
477 glMatrixMode (GL_PROJECTION); 283 f->set (e);
478 glLoadIdentity (); 284 f->update (matrix::translation (vec3 (i*5, -3, -i*10)));
479 285 f->show ();
480 glOrtho (-2.0, 2.0, -2.0, 2.0, -20.0, 20.0); 286 }
287 draw_some_random_funky_floor_dance_music (10, -500, -10, -1000);
288 camera.orig.x = camera.orig.y = camera.orig.z = 0;
289 camera.p = point (0, 0, 10);
290 camera.d = vec3 (0, 0, -1);
291 camera.u = vec3 (0, 1, 0);
292 camera.w = w; camera.h = h;
293 camera.fov = 80;
481 294
482 glMatrixMode (GL_MODELVIEW); 295 glMatrixMode (GL_MODELVIEW);
483 glLoadIdentity (); 296 glLoadIdentity ();
484 297
298 glEnable (GL_CULL_FACE);
485 glEnable (GL_DEPTH_TEST); 299 glEnable (GL_DEPTH_TEST);
486 300
487 glDepthFunc (GL_LESS);
488
489 glShadeModel (GL_SMOOTH); 301 glShadeModel (GL_SMOOTH);
302
303 glEnable (GL_LIGHTING);
304 //GLfloat lightc[4] = { 1, 0.1, 0.1, 1 };
305 //glLightf (GL_LIGHT0, GL_QUADRATIC_ATTENUATION);
306 //glLightfv (GL_LIGHT0, GL_DIFFUSE, lightc);
307 glEnable (GL_LIGHT0);
308
309 cgc = cgCreateContext ();
310
311 vsh_profile = CG_PROFILE_ARBVP1;
312 //if (cgGLIsProfileSupported (CG_PROFILE_VP30)) vsh_profile = CG_PROFILE_VP30;
313 //if (cgGLIsProfileSupported (CG_PROFILE_VP40)) vsh_profile = CG_PROFILE_VP40;
314 fsh_profile = CG_PROFILE_ARBFP1;
315 //if (cgGLIsProfileSupported (CG_PROFILE_FP30)) fsh_profile = CG_PROFILE_FP30;
316 //if (cgGLIsProfileSupported (CG_PROFILE_FP40)) fsh_profile = CG_PROFILE_FP40;
317
318 vsh = cgCreateProgramFromFile (cgc, CG_SOURCE, "vsh.cg", vsh_profile, 0, 0);
319 CheckCgError ();
320 cgGLLoadProgram (vsh);
321 CheckCgError ();
322 mv = cgGetNamedParameter (vsh, "WorldProj");
323 mvp = cgGetNamedParameter (vsh, "WorldViewProj");
324 lightpos = cgGetNamedParameter (vsh, "LightPos");
325 CheckCgError ();
326
327 CGparameter g_Texture; // the texture parameter
328
329
330 fsh = cgCreateProgramFromFile (cgc, CG_SOURCE, "fsh.cg", fsh_profile, 0, 0);
331 Texture t("o.jpg");
332 g_Texture = cgGetNamedParameter(fsh, "Texture"); // the texture cg-warper ;)
333 cgGLSetTextureParameter(g_Texture, t.texture); // Bind the texture number 999 to g_Texture
334 CheckCgError ();
335 cgGLLoadProgram (fsh);
336 CheckCgError ();
337
338 cgGLBindProgram (vsh);
339 CheckCgError ();
340 cgGLBindProgram (fsh);
341 CheckCgError ();
490 342
491 /* Loop until done. */ 343 /* Loop until done. */
492 start_time = SDL_GetTicks (); 344 start_time = SDL_GetTicks ();
493 frames = 0; 345 frames = 0;
346
494 while (!done) 347 while (!done)
495 { 348 {
496 GLenum gl_error; 349 GLenum gl_error;
497 char *sdl_error; 350 char *sdl_error;
498 SDL_Event event; 351 SDL_Event event;
499 352
500 /* Do our drawing, too. */ 353 camera.p.x += camera_velocity_factor * camera_velocity.x * timer.diff;
501 glClearColor (0.0, 0.0, 0.0, 1.0); 354 camera.p.y += camera_velocity_factor * camera_velocity.y * timer.diff;
502 glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 355 camera.p.z += camera_velocity_factor * camera_velocity.z * timer.diff;
503 356
504 glBegin (GL_QUADS); 357 camera_angle += camera_velocity_factor * camera_velocity_angle * timer.diff;
358 camera.d.z = -cos (camera_angle * 12 / 180.);
359 camera.d.x = sin (camera_angle * 12 / 180.);
505 360
506#ifdef SHADED_CUBE 361 cgGLSetParameter4f (lightpos, camera.p.x, camera.p.y, camera.p.z, 1);
507 glColor3fv (color[0]);
508 glVertex3fv (cube[0]);
509 glColor3fv (color[1]);
510 glVertex3fv (cube[1]);
511 glColor3fv (color[2]);
512 glVertex3fv (cube[2]);
513 glColor3fv (color[3]);
514 glVertex3fv (cube[3]);
515 362
516 glColor3fv (color[3]); 363 glBindTexture (GL_TEXTURE_2D, t.texture);
517 glVertex3fv (cube[3]); 364 cgGLEnableTextureParameter (g_Texture); // Enable the texture parameter
518 glColor3fv (color[4]);
519 glVertex3fv (cube[4]);
520 glColor3fv (color[7]);
521 glVertex3fv (cube[7]);
522 glColor3fv (color[2]);
523 glVertex3fv (cube[2]);
524 365
525 glColor3fv (color[0]); 366#if 0
526 glVertex3fv (cube[0]); 367 static GLfloat ry;
527 glColor3fv (color[5]); 368 ry += 0.001;
528 glVertex3fv (cube[5]); 369 camera.d.x = cos (ry);
529 glColor3fv (color[6]); 370 camera.d.z = sin (ry);
530 glVertex3fv (cube[6]); 371 //camera.d.y = sin (ry * 0.1);
531 glColor3fv (color[1]); 372#endif
532 glVertex3fv (cube[1]);
533 373
534 glColor3fv (color[5]); 374 camera.begin ();
535 glVertex3fv (cube[5]); 375 camera.pass (view::DEPTH);
536 glColor3fv (color[4]); 376 camera.pass (view::LIGHTED);
537 glVertex3fv (cube[4]); 377 camera.end ();
538 glColor3fv (color[7]);
539 glVertex3fv (cube[7]);
540 glColor3fv (color[6]);
541 glVertex3fv (cube[6]);
542
543 glColor3fv (color[5]);
544 glVertex3fv (cube[5]);
545 glColor3fv (color[0]);
546 glVertex3fv (cube[0]);
547 glColor3fv (color[3]);
548 glVertex3fv (cube[3]);
549 glColor3fv (color[4]);
550 glVertex3fv (cube[4]);
551
552 glColor3fv (color[6]);
553 glVertex3fv (cube[6]);
554 glColor3fv (color[1]);
555 glVertex3fv (cube[1]);
556 glColor3fv (color[2]);
557 glVertex3fv (cube[2]);
558 glColor3fv (color[7]);
559 glVertex3fv (cube[7]);
560#else // flat cube
561 glColor3f (1.0, 0.0, 0.0);
562 glVertex3fv (cube[0]);
563 glVertex3fv (cube[1]);
564 glVertex3fv (cube[2]);
565 glVertex3fv (cube[3]);
566
567 glColor3f (0.0, 1.0, 0.0);
568 glVertex3fv (cube[3]);
569 glVertex3fv (cube[4]);
570 glVertex3fv (cube[7]);
571 glVertex3fv (cube[2]);
572
573 glColor3f (0.0, 0.0, 1.0);
574 glVertex3fv (cube[0]);
575 glVertex3fv (cube[5]);
576 glVertex3fv (cube[6]);
577 glVertex3fv (cube[1]);
578
579 glColor3f (0.0, 1.0, 1.0);
580 glVertex3fv (cube[5]);
581 glVertex3fv (cube[4]);
582 glVertex3fv (cube[7]);
583 glVertex3fv (cube[6]);
584
585 glColor3f (1.0, 1.0, 0.0);
586 glVertex3fv (cube[5]);
587 glVertex3fv (cube[0]);
588 glVertex3fv (cube[3]);
589 glVertex3fv (cube[4]);
590
591 glColor3f (1.0, 0.0, 1.0);
592 glVertex3fv (cube[6]);
593 glVertex3fv (cube[1]);
594 glVertex3fv (cube[2]);
595 glVertex3fv (cube[7]);
596#endif /* SHADED_CUBE */
597
598 glEnd ();
599
600 glMatrixMode (GL_MODELVIEW);
601 glRotatef (5.0, 1.0, 1.0, 1.0);
602 378
603 SDL_GL_SwapBuffers (); 379 SDL_GL_SwapBuffers ();
380 timer.frame ();
604 381
605 /* Check for error conditions. */ 382 /* Check for error conditions. */
606 gl_error = glGetError (); 383 gl_error = glGetError ();
607 384
608 if (gl_error != GL_NO_ERROR) 385 if (gl_error != GL_NO_ERROR)
609 {
610 fprintf (stderr, "testgl: OpenGL error: %d\n", gl_error); 386 fprintf (stderr, "testgl: OpenGL error: %d\n", gl_error);
611 }
612 387
613 sdl_error = SDL_GetError (); 388 sdl_error = SDL_GetError ();
614 389
615 if (sdl_error[0] != '\0') 390 if (sdl_error[0] != '\0')
616 { 391 {
617 fprintf (stderr, "testgl: SDL error '%s'\n", sdl_error); 392 fprintf (stderr, "testgl: SDL error '%s'\n", sdl_error);
618 SDL_ClearError (); 393 SDL_ClearError ();
619 } 394 }
620 395
621 /* Allow the user to see what's happening */ 396 /* Allow the user to see what's happening */
622 if (slowly)
623 {
624 SDL_Delay (20);
625 }
626 SDL_Delay (20); 397 //SDL_Delay (20);
627 398
628 /* Check if there's a pending event. */ 399 /* Check if there's a pending event. */
629 while (SDL_PollEvent (&event)) 400 while (SDL_PollEvent (&event))
630 {
631 done = HandleEvent (&event); 401 done = HandleEvent (&event);
632 } 402
403
633 ++frames; 404 ++frames;
634 } 405 }
635 406
636 /* Print out the frames per second */ 407 /* Print out the frames per second */
637 this_time = SDL_GetTicks (); 408 this_time = SDL_GetTicks ();
675 { 446 {
676 if (strcmp (argv[i], "-twice") == 0) 447 if (strcmp (argv[i], "-twice") == 0)
677 { 448 {
678 ++numtests; 449 ++numtests;
679 } 450 }
680 if (strcmp (argv[i], "-logo") == 0)
681 {
682 logo = 1;
683 USE_DEPRECATED_OPENGLBLIT = SDL_FALSE;
684 }
685 if (strcmp (argv[i], "-logoblit") == 0)
686 {
687 logo = 1;
688 USE_DEPRECATED_OPENGLBLIT = SDL_TRUE;
689 }
690 if (strcmp (argv[i], "-slow") == 0) 451 if (strcmp (argv[i], "-slow") == 0)
691 { 452 {
692 slowly = 1; 453 slowly = 1;
693 } 454 }
694 if (strcmp (argv[i], "-bpp") == 0) 455 if (strcmp (argv[i], "-bpp") == 0)
713 ("Usage: %s [-twice] [-logo] [-slow] [-bpp n] [-gamma n] [-noframe] [-fsaa]\n", 474 ("Usage: %s [-twice] [-logo] [-slow] [-bpp n] [-gamma n] [-noframe] [-fsaa]\n",
714 argv[0]); 475 argv[0]);
715 exit (0); 476 exit (0);
716 } 477 }
717 } 478 }
479
718 for (i = 0; i < numtests; ++i) 480 for (i = 0; i < numtests; ++i)
719 {
720 RunGLTest (argc, argv, logo, slowly, bpp, gamma, noframe, fsaa); 481 RunGLTest (argc, argv, logo, slowly, bpp, gamma, noframe, fsaa);
721 } 482
722 return 0; 483 return 0;
723} 484}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines