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; |
5 | |
8 | |
6 | #include "SDL.h" |
9 | #include "SDL.h" |
7 | |
10 | |
8 | #include "SDL_opengl.h" |
11 | #include "SDL_opengl.h" |
9 | |
12 | |
… | |
… | |
23 | /**********************************************************************/ |
26 | /**********************************************************************/ |
24 | |
27 | |
25 | view camera; |
28 | view camera; |
26 | vec3 camera_velocity; |
29 | vec3 camera_velocity; |
27 | float camera_velocity_factor = 10; |
30 | float camera_velocity_factor = 10; |
|
|
31 | |
|
|
32 | ShMatrix4x4f mvp, mv; |
|
|
33 | ShPoint3f light_pv; |
|
|
34 | ShProgram vsh, fsh; |
|
|
35 | |
|
|
36 | void |
|
|
37 | init_shaders() { |
|
|
38 | { |
|
|
39 | vsh = SH_BEGIN_PROGRAM("gpu:vertex") |
|
|
40 | ShInputNormal3f normal; |
|
|
41 | ShInputPosition4f p; |
|
|
42 | |
|
|
43 | ShOutputPoint4f ov; |
|
|
44 | ShOutputNormal3f on; |
|
|
45 | ShOutputVector3f lvv; |
|
|
46 | ShOutputPosition4f opd; |
|
|
47 | |
|
|
48 | opd = mvp | p; |
|
|
49 | on = normalize(mv | normal); |
|
|
50 | ov = -normalize(mv | p); |
|
|
51 | lvv = normalize(lightPos - (mv | p)(0,1,2)); |
|
|
52 | SH_END; |
|
|
53 | } |
|
|
54 | // declare and initialize diffuse color |
|
|
55 | ShColor3f kd = ShColor3f(0.5, 0.7, 0.9); |
|
|
56 | { |
|
|
57 | fsh = SH_BEGIN_PROGRAM("gpu:fragment") |
|
|
58 | ShInputVector4f v; |
|
|
59 | ShInputNormal3f n; |
|
|
60 | ShInputVector3f lvv; |
|
|
61 | ShInputPosition4f p; |
|
|
62 | |
|
|
63 | ShOutputColor3f out; |
|
|
64 | out(0,1,2) = Globals::color * dot(normalize(n), normalize(lvv)); |
|
|
65 | |
|
|
66 | |
|
|
67 | SH_END; |
|
|
68 | } |
|
|
69 | } |
|
|
70 | |
28 | |
71 | |
29 | void |
72 | void |
30 | HotKey_ToggleFullScreen (void) |
73 | HotKey_ToggleFullScreen (void) |
31 | { |
74 | { |
32 | SDL_Surface *screen; |
75 | SDL_Surface *screen; |
… | |
… | |
357 | glMatrixMode (GL_MODELVIEW); |
400 | glMatrixMode (GL_MODELVIEW); |
358 | glLoadIdentity (); |
401 | glLoadIdentity (); |
359 | |
402 | |
360 | glEnable (GL_CULL_FACE); |
403 | glEnable (GL_CULL_FACE); |
361 | glEnable (GL_DEPTH_TEST); |
404 | glEnable (GL_DEPTH_TEST); |
|
|
405 | shInit(); |
|
|
406 | shSetBackend("arb"); |
|
|
407 | glEnable(GL_VERTEX_PROGRAM_ARB); |
|
|
408 | glEnable(GL_FRAGMENT_PROGRAM_ARB); |
|
|
409 | |
|
|
410 | init_shaders(); |
|
|
411 | shBind(vsh); |
|
|
412 | shBind(fsh); |
362 | glShadeModel (GL_SMOOTH); |
413 | glShadeModel (GL_SMOOTH); |
363 | |
414 | |
364 | glEnable (GL_LIGHTING); |
415 | glEnable (GL_LIGHTING); |
365 | //GLfloat lightc[4] = { 1, 0.1, 0.1, 1 }; |
416 | //GLfloat lightc[4] = { 1, 0.1, 0.1, 1 }; |
366 | //glLightf (GL_LIGHT0, GL_QUADRATIC_ATTENUATION); |
417 | //glLightf (GL_LIGHT0, GL_QUADRATIC_ATTENUATION); |