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

Comparing libgender/test.C (file contents):
Revision 1.57 by root, Sun Oct 10 14:15:15 2004 UTC vs.
Revision 1.58 by root, Sun Oct 10 19:50:37 2004 UTC

10static GLuint global_texture = 0; 10static GLuint global_texture = 0;
11 11
12#include "util.h" 12#include "util.h"
13#include "entity.h" 13#include "entity.h"
14#include "txtprt_import.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 15
32/**********************************************************************/ 16/**********************************************************************/
33 17
34view camera; 18view camera;
35vec3 camera_velocity; 19vec3 camera_velocity;
341 glShadeModel (GL_SMOOTH); 325 glShadeModel (GL_SMOOTH);
342 326
343 glEnable (GL_LIGHTING); 327 glEnable (GL_LIGHTING);
344 glEnable (GL_LIGHT0); 328 glEnable (GL_LIGHT0);
345 329
346 cgc = cgCreateContext (); 330 init_shaders ();
347
348 vsh_profile = CG_PROFILE_ARBVP1;
349 //if (cgGLIsProfileSupported (CG_PROFILE_VP30)) vsh_profile = CG_PROFILE_VP30;
350 //if (cgGLIsProfileSupported (CG_PROFILE_VP40)) vsh_profile = CG_PROFILE_VP40;
351 fsh_profile = CG_PROFILE_ARBFP1;
352 //if (cgGLIsProfileSupported (CG_PROFILE_FP30)) fsh_profile = CG_PROFILE_FP30;
353 //if (cgGLIsProfileSupported (CG_PROFILE_FP40)) fsh_profile = CG_PROFILE_FP40;
354
355 vsh = cgCreateProgramFromFile (cgc, CG_SOURCE, "vsh.cg", vsh_profile, 0, 0);
356 CheckCgError ();
357 cgGLLoadProgram (vsh);
358 CheckCgError ();
359 mv = cgGetNamedParameter (vsh, "WorldProj");
360 mvp = cgGetNamedParameter (vsh, "WorldViewProj");
361 lightpos = cgGetNamedParameter (vsh, "LightPos");
362 CheckCgError ();
363
364 CGparameter g_Texture; // the texture parameter
365
366
367 fsh = cgCreateProgramFromFile (cgc, CG_SOURCE, "fsh.cg", fsh_profile, 0, 0);
368 Texture t("o.jpg");
369 g_Texture = cgGetNamedParameter(fsh, "Texture"); // the texture cg-warper ;)
370 cgGLSetTextureParameter(g_Texture, t.texture); // Bind the texture number 999 to g_Texture
371 CheckCgError ();
372 cgGLLoadProgram (fsh);
373 CheckCgError ();
374
375 cgGLBindProgram (vsh);
376 CheckCgError ();
377 cgGLBindProgram (fsh);
378 CheckCgError ();
379 331
380 /* Loop until done. */ 332 /* Loop until done. */
381 start_time = SDL_GetTicks (); 333 start_time = SDL_GetTicks ();
382 frames = 0; 334 frames = 0;
383 335
396 camera.u = cross (camera.d, right); 348 camera.u = cross (camera.d, right);
397 349
398 camera.p = camera.p - camera.d * (camera_velocity_factor * timer.diff) * camera_velocity.z; 350 camera.p = camera.p - camera.d * (camera_velocity_factor * timer.diff) * camera_velocity.z;
399 camera.p = camera.p - camera.u * (camera_velocity_factor * timer.diff) * camera_velocity.y; 351 camera.p = camera.p - camera.u * (camera_velocity_factor * timer.diff) * camera_velocity.y;
400 352
401 cgGLSetParameter4f (lightpos, camera.p.x, camera.p.y, camera.p.z, 1);
402
403 glBindTexture (GL_TEXTURE_2D, t.texture);
404 cgGLEnableTextureParameter (g_Texture); // Enable the texture parameter
405 353
406#if 0 354#if 0
407 static GLfloat ry; 355 static GLfloat ry;
408 ry += 0.001; 356 ry += 0.001;
409 camera.d.x = cos (ry); 357 camera.d.x = cos (ry);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines