1 | #include <stdlib.h> |
1 | #include <stdlib.h> |
2 | #include <stdio.h> |
2 | #include <stdio.h> |
3 | #include <string.h> |
3 | #include <string.h> |
4 | #include <math.h> |
4 | #include <math.h> |
5 | #include <sh/sh.hpp> |
|
|
6 | |
|
|
7 | using namespace SH; |
|
|
8 | |
5 | |
9 | #include "SDL.h" |
6 | #include "SDL.h" |
10 | |
|
|
11 | #include "SDL_opengl.h" |
7 | #include "SDL_opengl.h" |
12 | |
|
|
13 | /* Undefine this if you want a flat cube instead of a rainbow cube */ |
|
|
14 | #define SHADED_CUBE |
|
|
15 | |
|
|
16 | /* Define this to be the name of the logo image to use with -logo */ |
|
|
17 | #define LOGO_FILE "icon.bmp" |
|
|
18 | |
8 | |
19 | static SDL_Surface *global_image = NULL; |
9 | static SDL_Surface *global_image = NULL; |
20 | static GLuint global_texture = 0; |
10 | static GLuint global_texture = 0; |
21 | |
11 | |
22 | #include "entity.h" |
12 | #include "entity.h" |
… | |
… | |
26 | /**********************************************************************/ |
16 | /**********************************************************************/ |
27 | |
17 | |
28 | view camera; |
18 | view camera; |
29 | vec3 camera_velocity; |
19 | vec3 camera_velocity; |
30 | float camera_velocity_factor = 10; |
20 | float camera_velocity_factor = 10; |
31 | |
|
|
32 | ShColor3f color = ShColor3f(.5, 0.9, 0.2); |
|
|
33 | ShPoint3f lightPos = ShPoint3f(0.0, 0.0, 10.0); |
|
|
34 | ShMatrix4x4f mvp; |
|
|
35 | ShProgram vsh, fsh; |
|
|
36 | |
|
|
37 | void |
|
|
38 | init_shaders () |
|
|
39 | { |
|
|
40 | { |
|
|
41 | vsh = SH_BEGIN_PROGRAM ("gpu:vertex") |
|
|
42 | ShInputNormal3f normal; |
|
|
43 | ShInputPosition4f p; |
|
|
44 | |
|
|
45 | ShOutputPoint4f ov; |
|
|
46 | ShOutputNormal3f on; |
|
|
47 | ShOutputVector3f lvv; |
|
|
48 | ShOutputPosition4f opd; |
|
|
49 | |
|
|
50 | opd = mvp | p; |
|
|
51 | on = normalize (mvp | normal); |
|
|
52 | ov = -normalize (mvp | p); |
|
|
53 | lvv = normalize (lightPos - (mvp | p) (0, 1, 2)); |
|
|
54 | SH_END; |
|
|
55 | } |
|
|
56 | |
|
|
57 | // declare and initialize diffuse color |
|
|
58 | ShColor3f kd = ShColor3f (0.5, 0.7, 0.9); |
|
|
59 | |
|
|
60 | { |
|
|
61 | fsh = SH_BEGIN_PROGRAM ("gpu:fragment") |
|
|
62 | ShInputVector4f v; |
|
|
63 | ShInputNormal3f n; |
|
|
64 | ShInputVector3f lvv; |
|
|
65 | ShInputPosition4f p; |
|
|
66 | |
|
|
67 | ShOutputColor3f out; |
|
|
68 | out (0, 1, 2) = color * dot (normalize (n), normalize (lvv)); |
|
|
69 | SH_END; |
|
|
70 | } |
|
|
71 | } |
|
|
72 | |
21 | |
73 | void |
22 | void |
74 | HotKey_ToggleFullScreen (void) |
23 | HotKey_ToggleFullScreen (void) |
75 | { |
24 | { |
76 | SDL_Surface *screen; |
25 | SDL_Surface *screen; |
… | |
… | |
401 | glMatrixMode (GL_MODELVIEW); |
350 | glMatrixMode (GL_MODELVIEW); |
402 | glLoadIdentity (); |
351 | glLoadIdentity (); |
403 | |
352 | |
404 | glEnable (GL_CULL_FACE); |
353 | glEnable (GL_CULL_FACE); |
405 | glEnable (GL_DEPTH_TEST); |
354 | glEnable (GL_DEPTH_TEST); |
406 | shInit(); |
|
|
407 | shSetBackend("arb"); |
|
|
408 | glEnable(GL_VERTEX_PROGRAM_ARB); |
355 | glEnable(GL_VERTEX_PROGRAM_ARB); |
409 | glEnable(GL_FRAGMENT_PROGRAM_ARB); |
356 | glEnable(GL_FRAGMENT_PROGRAM_ARB); |
410 | |
357 | |
411 | init_shaders(); |
|
|
412 | shBind(vsh); |
|
|
413 | shBind(fsh); |
|
|
414 | glShadeModel (GL_SMOOTH); |
358 | glShadeModel (GL_SMOOTH); |
415 | |
359 | |
416 | glEnable (GL_LIGHTING); |
360 | glEnable (GL_LIGHTING); |
417 | //GLfloat lightc[4] = { 1, 0.1, 0.1, 1 }; |
361 | //GLfloat lightc[4] = { 1, 0.1, 0.1, 1 }; |
418 | //glLightf (GL_LIGHT0, GL_QUADRATIC_ATTENUATION); |
362 | //glLightf (GL_LIGHT0, GL_QUADRATIC_ATTENUATION); |