… | |
… | |
10 | static GLuint global_texture = 0; |
10 | static 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 | |
|
|
16 | CGcontext cgc; |
|
|
17 | CGprogram vsh, fsh; |
|
|
18 | CGparameter mv, mvp, lightpos; |
|
|
19 | CGprofile vsh_profile, fsh_profile; |
|
|
20 | |
|
|
21 | static 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 | |
34 | view camera; |
18 | view camera; |
35 | vec3 camera_velocity; |
19 | vec3 camera_velocity; |
… | |
… | |
152 | |
136 | |
153 | void draw_floor (int size, int dx, int dy, int dz) |
137 | void draw_floor (int size, int dx, int dy, int dz) |
154 | { |
138 | { |
155 | int x, z, ry; |
139 | int x, z, ry; |
156 | |
140 | |
157 | for (x = 0; x < 100; x++) |
141 | for (x = 0; x < 10; x++) |
158 | { |
142 | { |
159 | for (z = 0; z < 100; z++) |
143 | for (z = 0; z < 10; z++) |
160 | { |
144 | { |
161 | vector<vertex2d> pts; |
145 | vector<vertex2d> pts; |
162 | pts.push_back (vertex2d (point ( 0, 0, 0), vec3 (0, 1, 0), texc (0, 0))); |
146 | pts.push_back (vertex2d (point ( 0, 0, 0), vec3 (0, 1, 0), texc (0, 0))); |
163 | pts.push_back (vertex2d (point ( 0, 0, size), vec3 (0, 1, 0), texc (0, 1))); |
147 | pts.push_back (vertex2d (point ( 0, 0, size), vec3 (0, 1, 0), texc (0, 1))); |
164 | pts.push_back (vertex2d (point (size, 0, size), vec3 (0, 1, 0), texc (1, 1))); |
148 | pts.push_back (vertex2d (point (size, 0, size), vec3 (0, 1, 0), texc (1, 1))); |
165 | pts.push_back (vertex2d (point (size, 0, 0), vec3 (0, 1, 0), texc (1, 0))); |
149 | pts.push_back (vertex2d (point (size, 0, 0), vec3 (0, 1, 0), texc (1, 0))); |
166 | |
150 | |
167 | geometry_quads *q = new geometry_quads; |
151 | geometry_quads *q = new geometry_quads; |
|
|
152 | q->m = new simple_material; |
168 | q->set (pts); |
153 | q->set (pts); |
169 | entity *e = new entity (q); |
154 | entity *e = new entity (q); |
170 | e->move (vec3 (dx + x * size, dy, dz + z * size)); |
155 | e->move (vec3 (dx + x * size, dy, dz + z * size)); |
171 | e->show (); |
156 | e->show (); |
172 | } |
157 | } |
… | |
… | |
180 | entity *e = new entity (q); |
165 | entity *e = new entity (q); |
181 | e->move (vec3 (10, 3, -4)); |
166 | e->move (vec3 (10, 3, -4)); |
182 | e->show (); |
167 | e->show (); |
183 | } |
168 | } |
184 | |
169 | |
|
|
170 | extern void draw_level (); |
185 | int |
171 | int |
186 | RunGLTest (int argc, char *argv[], |
172 | RunGLTest (int argc, char *argv[], |
187 | int logo, int slowly, int bpp, float gamma, int noframe, int fsaa) |
173 | int logo, int slowly, int bpp, float gamma, int noframe, int fsaa) |
188 | { |
174 | { |
189 | int i; |
175 | int i; |
… | |
… | |
296 | |
282 | |
297 | /* Set the gamma for the window */ |
283 | /* Set the gamma for the window */ |
298 | if (gamma != 0.0) |
284 | if (gamma != 0.0) |
299 | SDL_SetGamma (gamma, gamma, gamma); |
285 | SDL_SetGamma (gamma, gamma, gamma); |
300 | |
286 | |
|
|
287 | entity *planet = new entity (new geometry_sphere (10)); |
|
|
288 | planet->move (vec3 (0, 0, -20)); |
|
|
289 | planet->show (); |
|
|
290 | |
|
|
291 | #if 1 |
301 | for (int i = 0; i < 1; i++) |
292 | for (int i = 0; i < 20; i++) |
302 | { |
293 | { |
303 | // load a entity |
294 | // load a entity |
304 | txtprt_parser p; |
295 | txtprt_parser p; |
305 | geometry *g; |
296 | geometry *g; |
306 | try |
297 | try |
… | |
… | |
315 | entity *e = new entity (g); |
306 | entity *e = new entity (g); |
316 | e->move (vec3 (i*5, -3, -i*10)); |
307 | e->move (vec3 (i*5, -3, -i*10)); |
317 | e->show (); |
308 | e->show (); |
318 | } |
309 | } |
319 | |
310 | |
|
|
311 | { |
|
|
312 | entity *planet = new entity (new geometry_sphere (1e9)); |
|
|
313 | planet->move (vec3 (0, 0, -1.5e9)); |
|
|
314 | planet->show (); |
|
|
315 | } |
|
|
316 | |
|
|
317 | { |
|
|
318 | entity *planet = new entity (new geometry_sphere (4e15)); |
|
|
319 | planet->move (vec3 (0, 0, 1e17)); |
|
|
320 | planet->show (); |
|
|
321 | } |
|
|
322 | |
320 | draw_floor (10, -500, -10, -1000); |
323 | draw_floor (10, -500, -10, -1000); |
|
|
324 | draw_level (); |
321 | //draw_test_nurb (); |
325 | //draw_test_nurb (); |
|
|
326 | #endif |
322 | |
327 | |
|
|
328 | //camera.orig.x = 108; camera.orig.y = 0; camera.orig.z = -368; |
323 | camera.orig.x = camera.orig.y = camera.orig.z = 0; |
329 | camera.orig.x = 0; camera.orig.y = 0; camera.orig.z = 0; |
324 | camera.p = point (0, 0, 10); |
330 | camera.p = point (0, 0, 10); |
325 | camera.d = vec3 (0, 0, -1); |
331 | camera.d = vec3 (0, 0, -1); |
326 | camera.u = vec3 (0, 1, 0); |
332 | camera.u = vec3 (0, 1, 0); |
327 | camera.w = w; camera.h = h; |
333 | camera.w = w; camera.h = h; |
328 | camera.fov = 35; |
334 | camera.fov = 35; |
329 | camera.z_near = 1.; |
335 | camera.z_near = 1.; |
330 | |
336 | |
331 | glMatrixMode (GL_MODELVIEW); |
|
|
332 | glLoadIdentity (); |
|
|
333 | |
|
|
334 | glEnable (GL_CULL_FACE); |
337 | glEnable (GL_CULL_FACE); |
335 | glEnable (GL_DEPTH_TEST); |
|
|
336 | |
338 | |
337 | glShadeModel (GL_SMOOTH); |
339 | init_shaders (); |
338 | |
340 | |
339 | glEnable (GL_LIGHTING); |
341 | osama_material osa_mat; |
340 | glEnable (GL_LIGHT0); |
|
|
341 | |
|
|
342 | cgc = cgCreateContext (); |
|
|
343 | |
|
|
344 | vsh_profile = CG_PROFILE_ARBVP1; |
|
|
345 | //if (cgGLIsProfileSupported (CG_PROFILE_VP30)) vsh_profile = CG_PROFILE_VP30; |
|
|
346 | //if (cgGLIsProfileSupported (CG_PROFILE_VP40)) vsh_profile = CG_PROFILE_VP40; |
|
|
347 | fsh_profile = CG_PROFILE_ARBFP1; |
|
|
348 | //if (cgGLIsProfileSupported (CG_PROFILE_FP30)) fsh_profile = CG_PROFILE_FP30; |
|
|
349 | //if (cgGLIsProfileSupported (CG_PROFILE_FP40)) fsh_profile = CG_PROFILE_FP40; |
|
|
350 | |
|
|
351 | vsh = cgCreateProgramFromFile (cgc, CG_SOURCE, "vsh.cg", vsh_profile, 0, 0); |
|
|
352 | CheckCgError (); |
|
|
353 | cgGLLoadProgram (vsh); |
|
|
354 | CheckCgError (); |
|
|
355 | mv = cgGetNamedParameter (vsh, "WorldProj"); |
|
|
356 | mvp = cgGetNamedParameter (vsh, "WorldViewProj"); |
|
|
357 | lightpos = cgGetNamedParameter (vsh, "LightPos"); |
|
|
358 | CheckCgError (); |
|
|
359 | |
|
|
360 | CGparameter g_Texture; // the texture parameter |
|
|
361 | |
|
|
362 | |
|
|
363 | fsh = cgCreateProgramFromFile (cgc, CG_SOURCE, "fsh.cg", fsh_profile, 0, 0); |
|
|
364 | Texture t("o.jpg"); |
|
|
365 | g_Texture = cgGetNamedParameter(fsh, "Texture"); // the texture cg-warper ;) |
|
|
366 | cgGLSetTextureParameter(g_Texture, t.texture); // Bind the texture number 999 to g_Texture |
|
|
367 | CheckCgError (); |
|
|
368 | cgGLLoadProgram (fsh); |
|
|
369 | CheckCgError (); |
|
|
370 | |
|
|
371 | cgGLBindProgram (vsh); |
|
|
372 | CheckCgError (); |
|
|
373 | cgGLBindProgram (fsh); |
|
|
374 | CheckCgError (); |
|
|
375 | |
342 | |
376 | /* Loop until done. */ |
343 | /* Loop until done. */ |
377 | start_time = SDL_GetTicks (); |
344 | start_time = SDL_GetTicks (); |
378 | frames = 0; |
345 | frames = 0; |
379 | |
346 | |
… | |
… | |
392 | camera.u = cross (camera.d, right); |
359 | camera.u = cross (camera.d, right); |
393 | |
360 | |
394 | camera.p = camera.p - camera.d * (camera_velocity_factor * timer.diff) * camera_velocity.z; |
361 | camera.p = camera.p - camera.d * (camera_velocity_factor * timer.diff) * camera_velocity.z; |
395 | camera.p = camera.p - camera.u * (camera_velocity_factor * timer.diff) * camera_velocity.y; |
362 | camera.p = camera.p - camera.u * (camera_velocity_factor * timer.diff) * camera_velocity.y; |
396 | |
363 | |
397 | cgGLSetParameter4f (lightpos, camera.p.x, camera.p.y, camera.p.z, 1); |
364 | osa_mat.begin (); |
398 | |
|
|
399 | glBindTexture (GL_TEXTURE_2D, t.texture); |
|
|
400 | cgGLEnableTextureParameter (g_Texture); // Enable the texture parameter |
|
|
401 | |
|
|
402 | #if 0 |
|
|
403 | static GLfloat ry; |
|
|
404 | ry += 0.001; |
|
|
405 | camera.d.x = cos (ry); |
|
|
406 | camera.d.z = sin (ry); |
|
|
407 | //camera.d.y = sin (ry * 0.1); |
|
|
408 | #endif |
|
|
409 | |
365 | |
410 | camera.begin (); |
366 | camera.begin (); |
411 | camera.pass (view::DEPTH); |
367 | camera.pass (view::DEPTH); |
|
|
368 | camera.pass (view::POSTDEPTH); |
412 | camera.pass (view::LIGHTED); |
369 | camera.pass (view::LIGHTED); |
413 | camera.end (); |
370 | camera.end (); |
414 | |
371 | |
415 | SDL_GL_SwapBuffers (); |
372 | SDL_GL_SwapBuffers (); |
416 | timer.frame (); |
373 | timer.frame (); |
417 | |
374 | |
|
|
375 | osa_mat.end (); |
418 | /* Check for error conditions. */ |
376 | /* Check for error conditions. */ |
419 | gl_error = glGetError (); |
377 | gl_error = glGetError (); |
420 | |
378 | |
421 | if (gl_error != GL_NO_ERROR) fprintf (stderr, "testgl: OpenGL error: %d\n", gl_error); |
379 | if (gl_error != GL_NO_ERROR) fprintf (stderr, "testgl: OpenGL error: %d\n", gl_error); |
422 | |
380 | |
… | |
… | |
460 | |
418 | |
461 | /* Destroy our GL context, etc. */ |
419 | /* Destroy our GL context, etc. */ |
462 | SDL_Quit (); |
420 | SDL_Quit (); |
463 | return (0); |
421 | return (0); |
464 | } |
422 | } |
465 | |
|
|
466 | int |
423 | int |
467 | main (int argc, char *argv[]) |
424 | main (int argc, char *argv[]) |
468 | { |
425 | { |
469 | int i, logo; |
426 | int i, logo; |
470 | int numtests; |
427 | int numtests; |