00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00049
00050
00051
00052
00053
00054
00055
00056 #define BT_OPAQUE 0
00057 #define BT_ADD 1
00058 #define BT_BLEND 2
00059 #define BT_MODULATE 3
00060 #define BT_ALPHATEST 4
00061 #define BT_MODULATE2X 5
00062 #define BT_NONE -1
00063
00064
00065 #define ZB_NONE 0
00066 #define ZB_LESS 1
00067 #define ZB_LESSEQUAL 2
00068 #define ZB_EQUAL 3
00069 #define ZB_GREATEREQUAL 4
00070 #define ZB_GREATER 5
00071
00072
00073 #define PT_POINTS 0
00074 #define PT_LINES 1
00075 #define PT_LINESTRIP 2
00076 #define PT_LINELOOP 3
00077 #define PT_TRIANGLES 4
00078 #define PT_TRIANGLESTRIP 5
00079 #define PT_TRIANGLEFAN 6
00080 #define PT_QUADS 7
00081
00082
00083 #define CULL_NONE 0
00084 #define CULL_CW 1
00085 #define CULL_CCW 2
00086
00087
00088 #define SF_CENTERED 1
00089 #define SF_RIGHT 2
00090
00091
00092 #define WF_NONE 0
00093 #define WF_RECT 1
00094 #define WF_SINE 2
00095 #define WF_RECT2D 3
00096 #define WF_SINE2D 4
00097
00098
00099 #define COLOR_BLACK 0xFF000000
00100 #define COLOR_WHITE 0xFFFFFFFF
00101
00102
00103
00104
00105 #define GL_FOG_DISTANCE_MODE_NV 0x855A
00106 #define GL_EYE_RADIAL_NV 0x855B
00107 #define GL_EYE_PLANE_ABSOLUTE_NV 0x855C
00108
00109
00110
00111
00112
00113
00114
00115 #ifndef OMICRONTYPES_RENDER_DEFINED
00116 #define OMICRONTYPES_RENDER_DEFINED
00117
00118
00119
00120
00121 typedef ulong color_t;
00122
00123 typedef struct triangle_s
00124 {
00125 ulong vertices[3];
00126 vec2_t uv[3];
00127 } triangle_t;
00128
00129 typedef struct mesh_s
00130 {
00131 vertex_t *verts;
00132 triangle_t *tris;
00133
00134 ulong nVerts;
00135 ulong nTris;
00136 } mesh_t;
00137
00138 typedef struct light_s
00139 {
00140 vec3_t pos;
00141 color_t color;
00142 vec3_t attn;
00143 } light_t;
00144
00145 typedef struct lensflare_s
00146 {
00147 float position;
00148 float size;
00149 float angle;
00150 color_t color;
00151 sshort texture;
00152 ushort blendttype;
00153 } lensflare_t;
00154
00155 typedef struct shader_waveform_s
00156 {
00157 ushort type;
00158 float freq, phase;
00159 float amplitude, bias;
00160 } shader_waveform_t;
00161
00162 typedef struct shaderpass_s
00163 {
00164 bool lightmap;
00165 bool lighting;
00166 bool twosided;
00167 bool nodepth;
00168 bool shiny;
00169
00170 bool matrix;
00171 bool color;
00172
00173 bool fog;
00174 bool ignorediffuse;
00175
00176 sshort texture;
00177 ushort blendtype;
00178
00179
00180 float rotation;
00181 float angle;
00182 float scrollx, scrolly;
00183 float offsetx, offsety;
00184 float soffsetx, soffsety;
00185
00186 float scalex, scaley;
00187 shader_waveform_t
00188 scalewavex, scalewavey;
00189
00190 color_t color1, color2;
00191 shader_waveform_t
00192 colorwave;
00193
00194 ushort minfilter;
00195 ushort magfilter;
00196 ushort texwrapu;
00197 ushort texwrapv;
00198 } shaderpass_t;
00199
00200 typedef struct shader_s
00201 {
00202 char name[64];
00203 ushort passcount;
00204 shaderpass_t passes[8];
00205 bool dynamic;
00206 } shader_t;
00207
00208 typedef struct font_s
00209 {
00210 int texture;
00211 class image_c *images[255];
00212 uchar widths[255];
00213
00214 ushort width;
00215 ushort height;
00216
00217 shader_t *shader;
00218 } font_t;
00219
00224 class renderer_c
00225 {
00226 private:
00227
00228 struct state_s
00229 {
00230
00231 color_t bgcolor;
00232 bool autoclear;
00233
00234 color_t currentcolor;
00235 vec4_t currentcolorvec;
00236 sshort targettexture;
00237 sshort lightmap;
00238 const struct shader_s *currentshader;
00239
00240 sshort texminfilter;
00241 sshort texmagfilter;
00242 sshort texwrapu;
00243 sshort texwrapv;
00244
00245 sshort blendtype;
00246 sshort zbuffertype;
00247
00248 bool spheremapping;
00249
00250 bool fog;
00251
00252 bool font_bold;
00253 bool font_italic;
00254 color_t font_color;
00255 };
00256
00257 state_s state;
00258
00259 vertex_t *drawverts;
00260 ulong drawvertcount;
00261
00262 bool isinrender;
00263
00264
00265
00266
00267 vec3_c viewPos,
00268 viewTarget,
00269 viewUp;
00270
00271 vec3_c viewDir,
00272 viewRight,
00273 viewUp2;
00274
00275 float viewWidth,
00276 viewHeight;
00277
00278 plane_t viewFrustum[6];
00279
00280 float fov;
00281 float viewDepth;
00282
00283 void
00284 make_frustum();
00285
00286 bool
00287 query_glext(const char *name);
00288
00289 public:
00290
00291
00292
00293 void
00294 set_viewpos(const vec3_t pos)
00295 {
00296 AssertThis;
00297 AssertReturn1(pos);
00298 viewPos = pos;
00299 }
00300
00301 vec3_c
00302 get_viewpos()
00303 {
00304 AssertThisValue(vec3_c());
00305 return viewPos;
00306 }
00307
00308
00309
00310 void
00311 set_viewtarget(const vec3_t pos)
00312 {
00313 AssertThis;
00314 AssertReturn1(pos);
00315 viewTarget = pos;
00316 }
00317
00318 vec3_c
00319 get_viewtarget()
00320 {
00321 AssertThisValue(vec3_c());
00322 return viewTarget;
00323 }
00324
00325
00326
00327 void
00328 set_viewup(const vec3_t pos)
00329 {
00330 AssertThis;
00331 AssertReturn1(pos);
00332
00333 viewUp = pos;
00334 }
00335
00336 vec3_c
00337 get_viewup()
00338 {
00339 AssertThisValue(vec3_c());
00340 return viewUp;
00341 }
00342
00343 const plane_t *
00344 get_viewfrustum()
00345 {
00346 AssertThisV;
00347 return viewFrustum;
00348 }
00349
00350 vec3_c
00351 get_viewdir()
00352 {
00353 AssertThisValue(vec3_c());
00354 return viewDir;
00355 }
00356
00357 vec3_c
00358 get_viewright()
00359 {
00360 AssertThisValue(vec3_c());
00361 return viewRight;
00362 }
00363
00364 vec3_c
00365 get_viewup2()
00366 {
00367 AssertThisValue(vec3_c());
00368 return viewUp2;
00369 }
00370
00371 float
00372 get_viewwidth()
00373 {
00374 AssertThisValue(640);
00375 return viewWidth;
00376 }
00377
00378 float
00379 get_viewheight()
00380 {
00381 AssertThisValue(480);
00382 return viewHeight;
00383 }
00384
00385 float
00386 get_viewdepth()
00387 {
00388 AssertThisV;
00389 return viewDepth;
00390 }
00391
00392 void
00393 set_viewdepth(float depth)
00394 {
00395 AssertThis;
00396 viewDepth = depth;
00397 }
00398
00399 void
00400 set_fov(float f)
00401 {
00402 AssertThis;
00403 fov = f;
00404 }
00405
00406 float
00407 get_fov()
00408 {
00409 AssertThisValue(90);
00410 return fov;
00411 }
00412
00413 color_t
00414 get_bgcolor()
00415 {
00416 AssertThisV;
00417 return state.bgcolor;
00418 }
00419
00420 void
00421 set_bgcolor(color_t c)
00422 {
00423 AssertThis;
00424 state.bgcolor = c;
00425 }
00426
00427
00428
00429
00430 slong
00431 view_clipbox(const bbox_t *bbox);
00432
00433 slong
00434 view_clipsphere(const vec3_t pos, float radius);
00435
00436 slong
00437 view_clippoint(const vec3_t in);
00438
00439 public:
00440
00441 renderer_c();
00442 ~renderer_c();
00443
00444 void
00445 render();
00446
00447 void
00448 reset_charmode();
00449
00450 void
00451 need_vertices(ulong count);
00452
00453 void
00454 use_vertices(const vertex_t *verts, ulong count);
00455
00456 void
00457 push_vertices(ushort type, ulong count);
00458
00459 public:
00460
00461 struct shader_s *notfoundshader;
00462
00463 void
00464 view_2d(float width, float height);
00465
00466 void
00467 view_3d();
00468
00469 void
00470 clear_color();
00471
00472 void
00473 clear_depth();
00474
00475
00476
00479 void
00480 render_verts(const vertex_t *verts, ulong count, ushort type);
00481
00484 void
00485 render_quad(const vertex_t *verts);
00486
00487 void
00488 render_line_vec(const vec3_t v1, const vec3_t v2);
00489
00490 void
00491 render_line2d(float x, float y, float x2, float y2);
00492
00493
00494
00497 void
00498 draw_pic( float x1, float y1, float x2, float y2, float u1,
00499 float v1, float u2, float v2, sshort texture, ushort blendtype);
00500
00503 void
00504 draw_pic_shader(float x1, float y1, float x2, float y2,
00505 float u1, float v1, float u2, float v2, const shader_t *shader);
00506
00508 void
00509 draw_rotated_pic(float angle, float x1, float y1, float width,
00510 float height, float u1, float v1, float u2, float v2,
00511 sshort texture, ushort blendtype);
00512
00514 void
00515 draw_rotated_pic_shader(float angle, float x1, float y1,
00516 float width, float height, float u1, float v1, float u2, float v2,
00517 const shader_t *shader);
00518
00520 void
00521 draw_billboard(const vec3_t pos, const vec2_t size,
00522 sshort texture, ushort blendtype);
00523
00525 void
00526 draw_billboard_shader(const vec3_t pos, const vec2_t size,
00527 const shader_t *shader);
00528
00529
00530
00531
00532 void
00533 draw_rotated_billboard(const vec3_t pos, const vec2_t size, float angle,
00534 sshort texture, ushort blendtype);
00535
00536 void
00537 draw_rotated_billboard_shader(const vec3_t pos, const vec2_t size,
00538 float angle, const shader_t *shader);
00539
00543 void
00544 draw_lensflares(const lensflare_t *flare, const vec2_t pos, ulong count, float intensity);
00545
00549 float
00550 draw_char(float x, float y, float size, char c, const font_t *fnt);
00551
00554 float
00555 get_stringwidth(const char *c, const font_t *fnt);
00556
00559 ushort
00560 get_string_pixelwidth(const char *c, const font_t *fnt);
00561
00563 void
00564 draw_string(float x, float y, float size, const char *c,
00565 const font_t *fnt, ulong flags);
00566
00567
00568
00570 void
00571 set_color(color_t color);
00572
00574 color_t
00575 get_color() { AssertThisV; return state.currentcolor; };
00576
00578 void
00579 set_blending(ushort blendtype);
00580
00582 void
00583 set_zbuffer(ushort buftype);
00584
00586 void
00587 set_zwrite(bool enable);
00588
00590 void
00591 set_culling(ushort cullmode);
00592
00594 void
00595 set_fog(bool enable);
00596
00598 void
00599 set_fog_params(float near, float far, color_t color);
00600
00601 void
00602 set_lightmap(sshort i);
00603
00605 void
00606 set_target_texture(sshort n);
00607
00609 void
00610 set_target_backbuffer();
00611
00613 void
00614 set_spheremapping(bool enable);
00615
00616 void
00617 use_shader(const shader_t *shader);
00618
00619 void
00620 set_texture_params(sshort minfilter, sshort magfilter,
00621 sshort wrapu, sshort wrapv);
00622
00623
00624 font_t *font_createfromimage_fixed(class image_c *img, uchar width);
00625 void font_free(font_t *fnt);
00626 };
00627
00628 #endif // _OMICRONTYPES_RENDER_DEFINED
00629
00630
00631
00632
00633
00634
00635
00636
00637
00639 color_t color_from_floats(float r, float g, float b, float a);
00640
00642 color_t color_from_vec(const vec4_t in);
00643
00645 void color_to_vec(color_t color, vec4_t out);
00646
00648 color_t color_interpolate(color_t color1, color_t color2, float frac);
00649
00651
00656 shader_t *shader_create_simple(ushort blendtype, sshort texture);
00657
00659
00663 shader_t *shader_create();
00664
00666
00707 void shader_init(shader_t *shader, ushort blendtype, sshort texture);
00708
00710
00713 void shader_initstage(shader_t *shad, ushort n);
00714
00715
00718 float shader_get_waveform_frac(const shader_waveform_t *wf);
00719
00722 shader_t *shader_load(const char *fname);
00723
00724
00725
00726
00727
00728
00729
00730
00731
00732
00733