--- libgender/test.C 2004/10/10 00:00:52 1.53 +++ libgender/test.C 2004/10/16 14:48:48 1.61 @@ -13,22 +13,6 @@ #include "entity.h" #include "txtprt_import.h" -CGcontext cgc; -CGprogram vsh, fsh; -CGparameter mv, mvp, lightpos; -CGprofile vsh_profile, fsh_profile; - -static void CheckCgError (void) -{ - CGerror err = cgGetError (); - - if (err != CG_NO_ERROR) - { - printf("CG error: %s\n", cgGetErrorString (err)); - exit(1); - } -} - /**********************************************************************/ view camera; @@ -154,9 +138,9 @@ { int x, z, ry; - for (x = 0; x < 100; x++) + for (x = 0; x < 10; x++) { - for (z = 0; z < 100; z++) + for (z = 0; z < 10; z++) { vector pts; pts.push_back (vertex2d (point ( 0, 0, 0), vec3 (0, 1, 0), texc (0, 0))); @@ -165,6 +149,7 @@ pts.push_back (vertex2d (point (size, 0, 0), vec3 (0, 1, 0), texc (1, 0))); geometry_quads *q = new geometry_quads; + q->m = new simple_material; q->set (pts); entity *e = new entity (q); e->move (vec3 (dx + x * size, dy, dz + z * size)); @@ -182,6 +167,7 @@ e->show (); } +extern void draw_level (); int RunGLTest (int argc, char *argv[], int logo, int slowly, int bpp, float gamma, int noframe, int fsaa) @@ -298,7 +284,12 @@ if (gamma != 0.0) SDL_SetGamma (gamma, gamma, gamma); - for (int i = 0; i < 1; i++) + entity *planet = new entity (new geometry_sphere (10)); + planet->move (vec3 (0, 0, -20)); + planet->show (); + +#if 1 + for (int i = 0; i < 20; i++) { // load a entity txtprt_parser p; @@ -317,10 +308,25 @@ e->show (); } + { + entity *planet = new entity (new geometry_sphere (1e9)); + planet->move (vec3 (0, 0, -1.5e9)); + planet->show (); + } + + { + entity *planet = new entity (new geometry_sphere (4e15)); + planet->move (vec3 (0, 0, 1e17)); + planet->show (); + } + draw_floor (10, -500, -10, -1000); + draw_level (); //draw_test_nurb (); +#endif - camera.orig.x = camera.orig.y = camera.orig.z = 0; + //camera.orig.x = 108; camera.orig.y = 0; camera.orig.z = -368; + camera.orig.x = 0; camera.orig.y = 0; camera.orig.z = 0; camera.p = point (0, 0, 10); camera.d = vec3 (0, 0, -1); camera.u = vec3 (0, 1, 0); @@ -328,50 +334,11 @@ camera.fov = 35; camera.z_near = 1.; - glMatrixMode (GL_MODELVIEW); - glLoadIdentity (); - glEnable (GL_CULL_FACE); - glEnable (GL_DEPTH_TEST); - - glShadeModel (GL_SMOOTH); - glEnable (GL_LIGHTING); - glEnable (GL_LIGHT0); + init_shaders (); - cgc = cgCreateContext (); - - vsh_profile = CG_PROFILE_ARBVP1; - //if (cgGLIsProfileSupported (CG_PROFILE_VP30)) vsh_profile = CG_PROFILE_VP30; - //if (cgGLIsProfileSupported (CG_PROFILE_VP40)) vsh_profile = CG_PROFILE_VP40; - fsh_profile = CG_PROFILE_ARBFP1; - //if (cgGLIsProfileSupported (CG_PROFILE_FP30)) fsh_profile = CG_PROFILE_FP30; - //if (cgGLIsProfileSupported (CG_PROFILE_FP40)) fsh_profile = CG_PROFILE_FP40; - - vsh = cgCreateProgramFromFile (cgc, CG_SOURCE, "vsh.cg", vsh_profile, 0, 0); - CheckCgError (); - cgGLLoadProgram (vsh); - CheckCgError (); - mv = cgGetNamedParameter (vsh, "WorldProj"); - mvp = cgGetNamedParameter (vsh, "WorldViewProj"); - lightpos = cgGetNamedParameter (vsh, "LightPos"); - CheckCgError (); - - CGparameter g_Texture; // the texture parameter - - - fsh = cgCreateProgramFromFile (cgc, CG_SOURCE, "fsh.cg", fsh_profile, 0, 0); - Texture t("o.jpg"); - g_Texture = cgGetNamedParameter(fsh, "Texture"); // the texture cg-warper ;) - cgGLSetTextureParameter(g_Texture, t.texture); // Bind the texture number 999 to g_Texture - CheckCgError (); - cgGLLoadProgram (fsh); - CheckCgError (); - - cgGLBindProgram (vsh); - CheckCgError (); - cgGLBindProgram (fsh); - CheckCgError (); + osama_material osa_mat; /* Loop until done. */ start_time = SDL_GetTicks (); @@ -394,27 +361,18 @@ camera.p = camera.p - camera.d * (camera_velocity_factor * timer.diff) * camera_velocity.z; camera.p = camera.p - camera.u * (camera_velocity_factor * timer.diff) * camera_velocity.y; - cgGLSetParameter4f (lightpos, camera.p.x, camera.p.y, camera.p.z, 1); - - glBindTexture (GL_TEXTURE_2D, t.texture); - cgGLEnableTextureParameter (g_Texture); // Enable the texture parameter - -#if 0 - static GLfloat ry; - ry += 0.001; - camera.d.x = cos (ry); - camera.d.z = sin (ry); - //camera.d.y = sin (ry * 0.1); -#endif + osa_mat.begin (); camera.begin (); camera.pass (view::DEPTH); + camera.pass (view::POSTDEPTH); camera.pass (view::LIGHTED); camera.end (); SDL_GL_SwapBuffers (); timer.frame (); + osa_mat.end (); /* Check for error conditions. */ gl_error = glGetError (); @@ -462,7 +420,6 @@ SDL_Quit (); return (0); } - int main (int argc, char *argv[]) {