source: golgotha/src/golg/g1_render.hh @ 80

Last change on this file since 80 was 80, checked in by Sam Hocevar, 12 years ago
  • Adding the Golgotha source code. Not sure what's going to be interesting in there, but since it's all public domain, there's certainly stuff to pick up.
File size: 6.8 KB
Line 
1/********************************************************************** <BR>
2  This file is part of Crack dot Com's free source code release of
3  Golgotha. <a href="http://www.crack.com/golgotha_release"> <BR> for
4  information about compiling & licensing issues visit this URL</a>
5  <PRE> If that doesn't help, contact Jonathan Clark at
6  golgotha_source@usa.net (Subject should have "GOLG" in it)
7***********************************************************************/
8
9#ifndef G1_RENDER_HH
10#define G1_RENDER_HH
11
12#include "arch.hh"
13#include "math/num_type.hh"
14#include "player_type.hh"
15#include "r1_vert.hh"
16#include "tex_id.hh"
17
18class g1_screen_box
19{
20public:
21  i4_float x1,y1,x2,y2;
22  i4_float z1,z2,w;
23  w32 object_id;            // same as global id of object
24};
25
26
27struct g1_selectable_list
28{
29  enum { MAX=64 };
30  w32 t_recent;
31  g1_screen_box recent[MAX];
32  g1_screen_box *add()   { return t_recent<MAX-1 ? recent + (t_recent++) : 0; }
33  g1_selectable_list() { t_recent=0; }
34};
35
36class g1_post_draw_quad_class
37{
38public:
39  w16 vert_ref[4];  // if vert_ref[3]=0xffff then it is a tri
40  g1_post_draw_quad_class() { ; }
41  g1_post_draw_quad_class(w16 a, w16 b, w16 c, w16 d)
42  {
43    vert_ref[0]=a;
44    vert_ref[1]=b;
45    vert_ref[2]=c;
46    vert_ref[3]=d;
47  }
48};
49
50class g1_quad_object_class;
51class i4_transform_class;
52class g1_sprite_class;
53class i4_3d_point_class;
54class r1_render_api_class;
55class cell_shadow_poly_list;
56class g1_map_vertex_class;
57class g1_map_cell_class;
58class i4_transform_class;
59class g1_quad_class;
60class g1_draw_context_class;
61class g1_object_class;
62class g1_map_class;
63class i4_draw_context_class;
64class i4_font_class;
65
66typedef g1_quad_class *(*g1_tint_modify_function_type)(g1_quad_class *in, g1_player_type player);
67typedef void (*g1_get_ambient_function_type)(i4_transform_class *object_to_world,
68                                        i4_float &ar, i4_float &ag, i4_float &ab);
69
70// this is the default function for handling tinted polygons
71g1_quad_class *g1_tint_modify_function(g1_quad_class *in, g1_player_type player);
72
73// default method for getting ambient lighting, reads from the map
74void g1_get_ambient_function(i4_transform_class *object_to_world,
75                             i4_float &ar, i4_float &ag, i4_float &ab);
76
77enum { G1_REVERSE_POINTS=2};
78
79class g1_render_class
80{
81public:
82  g1_selectable_list *current_selectable_list;
83  g1_selectable_list *last_selectable_list;
84
85  enum { WIREFRAME, TEXTURED, SOLID } draw_mode;
86
87  static i4_bool main_draw;
88
89  static i4_float scale_x, scale_y, ooscale_x, ooscale_y,
90    center_x, center_y;
91
92  static r1_render_api_class *r_api;
93
94  // this number will be >0 && <=1, it use to interpolate object position on fast frame
95  // rates i.e. draw_x = (lx-x)*frame_ration + lx
96  float frame_ratio;
97
98
99  i4_font_class *rendered_font;
100
101  g1_tint_modify_function_type tint_modify;
102  g1_get_ambient_function_type get_ambient;
103
104  static sw8 render_damage_level;
105
106  float calculate_frame_ratio();
107  void set_render_damage_level(sw8 level) { render_damage_level = level; }
108
109  void render_object(g1_quad_object_class *obj,
110                     i4_transform_class   *object_to_view,
111                     i4_transform_class   *object_to_world = 0,
112                     i4_float             texture_scale = 1.0,                     
113                     int                  player_num = -1,         // -1 is no player
114                     sw32                 current_frame = 0,
115                     g1_screen_box        *outline = 0,
116                     w32                  option_flags = 0);
117
118  void render_object_polys(g1_quad_object_class *obj,
119                           i4_transform_class *object_to_view,
120                           sw32 current_frame = 0);
121
122
123  // draws a sprite on the screen nearest to view, sprite_width is in pixels
124  void render_near_sprite(float px, float py,
125                          r1_texture_handle tex,
126                          float sprite_width=0.1, float sprite_height=0.1,
127                          float s1=0, float t1=0, float s2=1, float t2=1);
128
129  // draws a sprite on the at the specifed z, (it is projected) sprite_width is world-space size
130  void render_sprite(const i4_3d_vector &view_space_position,
131                     r1_texture_handle tex,
132                     float sprite_width=0.1, float sprite_height=0.1,
133                     float s1=0, float t1=0, float s2=1, float t2=1);
134
135  void render_3d_line(const i4_3d_point_class &v1,
136                      const i4_3d_point_class &v2,
137                      i4_color color1,
138                      i4_color color2,
139                      i4_transform_class *t,
140                      i4_bool draw_in_front_of_everything=i4_F);
141
142  void draw_outline(g1_screen_box *outline, g1_object_class *for_who);
143
144  void post_draw_quads();
145
146  sw32 add_post_draw_vert(r1_vert &a);
147  sw32 add_post_draw_quad(g1_post_draw_quad_class &q);
148
149  void add_smoke_vert(i4_float x, i4_float y, i4_float z,
150                      i4_float r, i4_float g, i4_float b,
151                      i4_float alpha)
152  {
153    r1_vert a;
154 
155    a.v.x=x;
156    a.v.y=y;
157    a.v.z=z;
158
159    a.r=r;
160    a.g=g;
161    a.b=b;
162    a.a=alpha;
163 
164    add_post_draw_vert(a);
165  }
166
167  void add_translucent_trail(i4_transform_class *t,
168                             i4_3d_point_class *spots, int t_spots,
169                             float start_width, float end_width,
170                             float start_alpha, float end_alpha,
171                             w32 sc, w32 ec);
172
173  /*  void draw_building(g1_draw_context_class *context,
174                     g1_map_cell_class *cell,
175                     w16 x, w16 y,
176                     g1_map_vertex_class *v1,
177                     g1_map_vertex_class *v2,
178                     g1_map_vertex_class *v3,
179                     g1_map_vertex_class *v4,
180                     i4_bool p_or_span); */
181
182  void draw_rectangle(int x1, int y1, int x2, int y2, i4_color color,
183                      i4_draw_context_class &context);
184                     
185
186  // this routine transform all 4 verts (in place) and clip the resulting quad and render it
187  void clip_render_quad(g1_quad_class *q, r1_vert *verts,
188                        i4_transform_class *t,
189                        int current_frame);
190
191  void install_font();
192  void uninstall_font();
193
194  g1_render_class()
195  {
196    rendered_font=0;
197    draw_mode=TEXTURED;
198    tint_modify=g1_tint_modify_function;
199    get_ambient=g1_get_ambient_function;
200    current_selectable_list=0;
201  }
202
203  i4_bool project_point(const i4_3d_point_class &p, r1_vert &v, i4_transform_class *transform);
204};
205
206void g1_setup_tri_texture_coords(r1_vert *tri1, r1_vert *tri2,
207                                 int cell_rotation, int cell_is_mirrored);
208
209extern g1_render_class g1_render;
210
211#endif
212
Note: See TracBrowser for help on using the repository browser.