1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
/*
* Copyright © 2009 Eric Anholt
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*
* Authors:
* Eric Anholt <eric@anholt.net>
*
*/
#define GL_GLEXT_PROTOTYPES
#include <GL/glew.h>
#include <glu3.h>
struct revolved_object {
GLuint vbo, array_obj, shadow_array_obj;
int pos_offset, norm_offset, tangent_offset, texcoord_offset;
int elements_offset, elements_vert_stride;
int num_verts, num_steps;
/* Maximum distance from center of revolution to a vertex. */
float radius;
};
enum ground_uniform_list {
GROUND_UNIFORM_MV,
GROUND_UNIFORM_MVP,
GROUND_UNIFORM_LIGHT_EYE,
GROUND_UNIFORM_LIGHT_MVP,
GROUND_UNIFORM_SHADOW_SAMPLER,
GROUND_UNIFORM_MAX
};
enum shadow_uniform_list {
SHADOW_UNIFORM_MVP,
SHADOW_UNIFORM_MAX
};
struct uniform_desc {
const char *name;
GLint location;
};
#define NUM_RINGS 27
extern struct uniform_desc ground_uniforms[GROUND_UNIFORM_MAX];
extern struct uniform_desc shadow_uniforms[SHADOW_UNIFORM_MAX];
extern GLuint ground_prog, shadow_prog;
extern GLUmat4 projection;
extern GLUmat4 world_to_eye, world_to_shadow_texcoords;
extern GLUvec4 light_world, light_eye;
extern GLUmat4 ring_obj_to_world[NUM_RINGS];
extern struct revolved_object ring;
extern GLUvec4 ring_bounding_sphere_center_world;
extern float ring_bounding_sphere_radius;
extern GLuint shadow_tex;
extern GLUmat4 world_to_light_ndc;
void do_ring_drawelements(void);
/* matrix.c */
void mult_m4_p4(float *result, const float *mat4, const float *point4);
void mult_m4_m4(float *result, const float *a4, const float *b4);
void init_m4_x_rotate(float *mat4, float x_rads);
void init_m4_y_rotate(float *mat4, float y_rads);
void init_m4_z_rotate(float *mat4, float z_rads);
void init_m4_translate(float *mat4, float x, float y, float z);
void init_m4_perspective(float *mat4, float fovy, float aspect,
float near, float far);
void print_m4(const float *mat4, const char *name);
void print_GLUvec4(char *desc, const GLUvec4 *vec);
void print_GLUmat4(char *desc, const GLUmat4 *m);
void make_sphere_frustum(GLUmat4 *mat,
GLUvec4 *center,
float radius);
/* load_texture.c */
GLuint load_texture_rgb(const char *filename);
/* ground.c */
void draw_ground(void);
void setup_ground(void);
/* shadow_map.c */
void generate_rings_shadowmap(void);
|