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

Comparing libgender/test.C (file contents):
Revision 1.5 by root, Sun Oct 3 02:38:33 2004 UTC vs.
Revision 1.6 by root, Sun Oct 3 03:03:37 2004 UTC

19#include "entity.h" 19#include "entity.h"
20 20
21#include "txtprt_import.h" 21#include "txtprt_import.h"
22 22
23/**********************************************************************/ 23/**********************************************************************/
24
25view camera;
24 26
25void 27void
26HotKey_ToggleFullScreen (void) 28HotKey_ToggleFullScreen (void)
27{ 29{
28 SDL_Surface *screen; 30 SDL_Surface *screen;
87 89
88 printf ("focus\n"); 90 printf ("focus\n");
89 break; 91 break;
90 92
91 case SDL_KEYDOWN: 93 case SDL_KEYDOWN:
94
95 if (event->key.keysym.sym == SDLK_UP)
96 camera.p.z -= 1;
97 if (event->key.keysym.sym == SDLK_DOWN)
98 camera.p.z += 1;
99 if (event->key.keysym.sym == SDLK_LEFT)
100 camera.p.x -= 1;
101 if (event->key.keysym.sym == SDLK_RIGHT)
102 camera.p.x += 1;
103
92 if (event->key.keysym.sym == SDLK_ESCAPE) 104 if (event->key.keysym.sym == SDLK_ESCAPE)
93 {
94 done = 1; 105 done = 1;
95 }
96 106
97 if ((event->key.keysym.sym == SDLK_g) && 107 if ((event->key.keysym.sym == SDLK_g) &&
98 (event->key.keysym.mod & KMOD_CTRL)) 108 (event->key.keysym.mod & KMOD_CTRL))
99 {
100 HotKey_ToggleGrab (); 109 HotKey_ToggleGrab ();
101 }
102 110
103 if ((event->key.keysym.sym == SDLK_z) && 111 if ((event->key.keysym.sym == SDLK_z) &&
104 (event->key.keysym.mod & KMOD_CTRL)) 112 (event->key.keysym.mod & KMOD_CTRL))
105 {
106 HotKey_Iconify (); 113 HotKey_Iconify ();
107 }
108 114
109 if ((event->key.keysym.sym == SDLK_RETURN) && 115 if ((event->key.keysym.sym == SDLK_RETURN) &&
110 (event->key.keysym.mod & KMOD_ALT)) 116 (event->key.keysym.mod & KMOD_ALT))
111 {
112 HotKey_ToggleFullScreen (); 117 HotKey_ToggleFullScreen ();
113 }
114 118
115 printf ("key '%s' pressed\n", SDL_GetKeyName (event->key.keysym.sym));
116 break; 119 break;
117 120
118 case SDL_QUIT: 121 case SDL_QUIT:
119 done = 1; 122 done = 1;
120 break; 123 break;
121 } 124 }
122 125
123 return (done); 126 return (done);
124}
125
126void
127SDL_GL_Enter2DMode ()
128{
129 SDL_Surface *screen = SDL_GetVideoSurface ();
130
131 /* Note, there may be other things you need to change,
132 depending on how you have your OpenGL state set up.
133 */
134 glPushAttrib (GL_ENABLE_BIT);
135 glDisable (GL_DEPTH_TEST);
136 glDisable (GL_CULL_FACE);
137 glEnable (GL_TEXTURE_2D);
138
139 /* This allows alpha blending of 2D textures with the scene */
140 glEnable (GL_BLEND);
141 glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
142
143 glViewport (0, 0, screen->w, screen->h);
144
145 glMatrixMode (GL_PROJECTION);
146 glPushMatrix ();
147 glLoadIdentity ();
148
149 glOrtho (0.0, (GLdouble) screen->w, (GLdouble) screen->h, 0.0, 0.0, 1.0);
150
151 glMatrixMode (GL_MODELVIEW);
152 glPushMatrix ();
153 glLoadIdentity ();
154
155 glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
156}
157
158void
159SDL_GL_Leave2DMode ()
160{
161 glMatrixMode (GL_MODELVIEW);
162 glPopMatrix ();
163
164 glMatrixMode (GL_PROJECTION);
165 glPopMatrix ();
166
167 glPopAttrib ();
168} 127}
169 128
170/* Quick utility function for texture creation */ 129/* Quick utility function for texture creation */
171static int 130static int
172power_of_two (int input) 131power_of_two (int input)
356 315
357 /* Set the gamma for the window */ 316 /* Set the gamma for the window */
358 if (gamma != 0.0) 317 if (gamma != 0.0)
359 SDL_SetGamma (gamma, gamma, gamma); 318 SDL_SetGamma (gamma, gamma, gamma);
360 319
361 view v;
362 v.p = point (0, 0, 0); 320 camera.p = point (0, 0, 10);
363 v.d = vec3 (0, 0, -1); 321 camera.d = vec3 (0, 0, -1);
364 v.u = vec3 (0, 1, 0); 322 camera.u = vec3 (0, 1, 0);
365 v.w = w; v.h = h; 323 camera.w = w; camera.h = h;
366 v.fov = 90; 324 camera.fov = 90;
367 325
368 glMatrixMode (GL_MODELVIEW); 326 glMatrixMode (GL_MODELVIEW);
369 glLoadIdentity (); 327 glLoadIdentity ();
370 328
371 glEnable (GL_DEPTH_TEST); 329 glEnable (GL_DEPTH_TEST);
372 330
373 glDepthFunc (GL_LESS); 331 glDepthFunc (GL_LESS);
374 332
375 glShadeModel (GL_SMOOTH); 333 glShadeModel (GL_SMOOTH);
376 GLfloat ambient[4] = { 1, 1, 1, 1 }; 334
377 glEnable (GL_LIGHTING); 335 glEnable (GL_LIGHTING);
336 glEnable (GL_CULL_FACE);
337
338 GLfloat lightc[4] = { 1, 0.1, 0.1, 1 };
339 //glLightf (GL_LIGHT0, GL_QUADRATIC_ATTENUATION);
340 glLightfv (GL_LIGHT0, GL_DIFFUSE, lightc);
341 glEnable (GL_LIGHT0);
378 glEnable (GL_COLOR_MATERIAL); 342 glEnable (GL_COLOR_MATERIAL);
379 glLightModelfv (GL_LIGHT_MODEL_AMBIENT, ambient);
380 343
381 /* Loop until done. */ 344 /* Loop until done. */
382 start_time = SDL_GetTicks (); 345 start_time = SDL_GetTicks ();
383 frames = 0; 346 frames = 0;
384 while (!done) 347 while (!done)
388 SDL_Event event; 351 SDL_Event event;
389 352
390 /* Do our drawing, too. */ 353 /* Do our drawing, too. */
391 glClearColor (0.0, 0.0, 0.0, 1.0); 354 glClearColor (0.0, 0.0, 0.0, 1.0);
392 glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 355 glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
356
357 GLfloat lightp[4];
358 lightp[0] = camera.p.x;
359 lightp[1] = camera.p.y;
360 lightp[2] = camera.p.z;
361 lightp[3] = 1;
362 glLightfv (GL_LIGHT0, GL_POSITION, lightp);
393 363
394#if 0 364#if 0
395 static GLfloat ry; 365 static GLfloat ry;
396 ry += 0.03; 366 ry += 0.03;
397 v.d.x = cos (ry); 367 v.d.x = cos (ry);
398 v.d.z = sin (ry); 368 v.d.z = sin (ry);
399#endif 369#endif
400 370
401 draw_context c; 371 draw_context c;
402 v.draw (c); 372 camera.draw (c);
403 373
404 SDL_GL_SwapBuffers (); 374 SDL_GL_SwapBuffers ();
405 375
406 /* Check for error conditions. */ 376 /* Check for error conditions. */
407 gl_error = glGetError (); 377 gl_error = glGetError ();

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines