--- libgender/test.C 2004/10/03 02:38:33 1.5 +++ libgender/test.C 2004/10/03 04:00:51 1.9 @@ -22,6 +22,8 @@ /**********************************************************************/ +view camera; + void HotKey_ToggleFullScreen (void) { @@ -89,30 +91,31 @@ break; case SDL_KEYDOWN: + + if (event->key.keysym.sym == SDLK_UP) + camera.p.z -= 1; + if (event->key.keysym.sym == SDLK_DOWN) + camera.p.z += 1; + if (event->key.keysym.sym == SDLK_LEFT) + camera.p.x -= 1; + if (event->key.keysym.sym == SDLK_RIGHT) + camera.p.x += 1; + if (event->key.keysym.sym == SDLK_ESCAPE) - { - done = 1; - } + done = 1; if ((event->key.keysym.sym == SDLK_g) && (event->key.keysym.mod & KMOD_CTRL)) - { - HotKey_ToggleGrab (); - } + HotKey_ToggleGrab (); if ((event->key.keysym.sym == SDLK_z) && (event->key.keysym.mod & KMOD_CTRL)) - { - HotKey_Iconify (); - } + HotKey_Iconify (); if ((event->key.keysym.sym == SDLK_RETURN) && (event->key.keysym.mod & KMOD_ALT)) - { - HotKey_ToggleFullScreen (); - } + HotKey_ToggleFullScreen (); - printf ("key '%s' pressed\n", SDL_GetKeyName (event->key.keysym.sym)); break; case SDL_QUIT: @@ -123,50 +126,6 @@ return (done); } -void -SDL_GL_Enter2DMode () -{ - SDL_Surface *screen = SDL_GetVideoSurface (); - - /* Note, there may be other things you need to change, - depending on how you have your OpenGL state set up. - */ - glPushAttrib (GL_ENABLE_BIT); - glDisable (GL_DEPTH_TEST); - glDisable (GL_CULL_FACE); - glEnable (GL_TEXTURE_2D); - - /* This allows alpha blending of 2D textures with the scene */ - glEnable (GL_BLEND); - glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - - glViewport (0, 0, screen->w, screen->h); - - glMatrixMode (GL_PROJECTION); - glPushMatrix (); - glLoadIdentity (); - - glOrtho (0.0, (GLdouble) screen->w, (GLdouble) screen->h, 0.0, 0.0, 1.0); - - glMatrixMode (GL_MODELVIEW); - glPushMatrix (); - glLoadIdentity (); - - glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL); -} - -void -SDL_GL_Leave2DMode () -{ - glMatrixMode (GL_MODELVIEW); - glPopMatrix (); - - glMatrixMode (GL_PROJECTION); - glPopMatrix (); - - glPopAttrib (); -} - /* Quick utility function for texture creation */ static int power_of_two (int input) @@ -358,12 +317,11 @@ if (gamma != 0.0) SDL_SetGamma (gamma, gamma, gamma); - view v; - v.p = point (0, 0, 0); - v.d = vec3 (0, 0, -1); - v.u = vec3 (0, 1, 0); - v.w = w; v.h = h; - v.fov = 90; + camera.p = point (0, 0, 10); + camera.d = vec3 (0, 0, -1); + camera.u = vec3 (0, 1, 0); + camera.w = w; camera.h = h; + camera.fov = 90; glMatrixMode (GL_MODELVIEW); glLoadIdentity (); @@ -373,10 +331,14 @@ glDepthFunc (GL_LESS); glShadeModel (GL_SMOOTH); - GLfloat ambient[4] = { 1, 1, 1, 1 }; + glEnable (GL_LIGHTING); + + //GLfloat lightc[4] = { 1, 0.1, 0.1, 1 }; + //glLightf (GL_LIGHT0, GL_QUADRATIC_ATTENUATION); + //glLightfv (GL_LIGHT0, GL_DIFFUSE, lightc); + glEnable (GL_LIGHT0); glEnable (GL_COLOR_MATERIAL); - glLightModelfv (GL_LIGHT_MODEL_AMBIENT, ambient); /* Loop until done. */ start_time = SDL_GetTicks (); @@ -391,6 +353,13 @@ glClearColor (0.0, 0.0, 0.0, 1.0); glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + GLfloat lightp[4]; + lightp[0] = camera.p.x; + lightp[1] = camera.p.y; + lightp[2] = camera.p.z; + lightp[3] = 1; + glLightfv (GL_LIGHT0, GL_POSITION, lightp); + #if 0 static GLfloat ry; ry += 0.03; @@ -399,7 +368,8 @@ #endif draw_context c; - v.draw (c); + c.mode = draw_context::LIGHTED; + camera.draw (c); SDL_GL_SwapBuffers (); @@ -418,7 +388,7 @@ } /* Allow the user to see what's happening */ - SDL_Delay (20); + //SDL_Delay (20); /* Check if there's a pending event. */ while (SDL_PollEvent (&event)) @@ -465,13 +435,13 @@ // load a entity txtprt_parser p; - entity_base *e; + entity *e; try { e = p.read ("test.blasc"); } catch (txtprt_i_exception & e) { cout << "ERR: " << e.msg << endl; } - world.add (e); + e->show (); logo = 0; slowly = 0;