7# define MAUG_CONST const
20#ifndef RETROGLU_TRACE_LVL
21# define RETROGLU_TRACE_LVL 0
24#ifndef RETROGLU_SPRITE_TEX_FRAMES_SZ
25# define RETROGLU_SPRITE_TEX_FRAMES_SZ 10
29# define glShininessf( side, light, f ) glMaterialf( side, light, f )
32typedef float RETROGLU_COLOR[4];
39#define RETROGLU_SPRITE_X 0
40#define RETROGLU_SPRITE_Y 1
42#ifndef RETROGLU_SPRITE_LIST_SZ_MAX
43# define RETROGLU_SPRITE_LIST_SZ_MAX 10
62 float vertices_front[6][2];
63 float vtexture_front[6][2];
64 float vertices_back[6][2];
65 float vtexture_back[6][2];
71#ifdef RETROGLU_NO_LISTS
74 int32_t lists[RETROGLU_SPRITE_LIST_SZ_MAX];
87#ifdef RETROFLAT_API_LIBNDS
88# define retroglu_enable_lightning()
89# define retroglu_disable_lightning()
91# define retroglu_enable_lightning() glEnable( GL_LIGHTING )
92# define retroglu_disable_lightning() glDisable( GL_LIGHTING )
105#define retroglu_pop_overlay() \
107 glMatrixMode( GL_MODELVIEW );
111#define retroglu_tex_px_x_to_f( px, sprite ) \
112 ((px) * 1.0 / sprite->texture.tex.w)
113#define retroglu_tex_px_y_to_f( px, sprite ) \
114 ((px) * 1.0 / sprite->texture.tex.h)
116#define retroglu_scr_px_x_to_f( px ) \
117 (float)(((px) * 1.0 / (retroflat_screen_w() / 2)) - 1.0)
118#define retroglu_scr_px_y_to_f( py ) \
119 (float)(((py) * 1.0 / (retroflat_screen_h() / 2)) - 1.0)
121#define retroglu_set_sprite_tex( sprite, texture_id, bmp_w, bmp_h ) \
122 sprite->texture_id = texture_id; \
123 sprite->texture_w = bmp_w; \
124 sprite->texture_h = bmp_h;
126#define retroglu_set_sprite_color( sprite, color_in ) \
127 memcpy( (sprite)->color, (color_in), 3 * sizeof( float ) )
129void retroglu_set_tile_clip(
131 uint32_t px, uint32_t py, uint32_t pw, uint32_t ph, uint8_t
flags );
133void retroglu_set_sprite_clip(
135 uint32_t front_px, uint32_t front_py, uint32_t back_px, uint32_t back_py,
136 uint32_t pw, uint32_t ph, uint8_t
flags );
145void retroglu_init_sprite_vertices_scale(
148void retroglu_set_sprite_pos(
167 uint32_t front_px, uint32_t front_py, uint32_t back_px, uint32_t back_py,
168 uint32_t pw, uint32_t ph, uint8_t
flags );
180void retroglu_destroy_glyph_tex();
183 float x,
float y,
float z,
const RETROGLU_COLOR color,
184 const char* str,
size_t str_sz,
const char* font_str, uint8_t
flags );
194 size_t s_x,
size_t s_y,
size_t d_x,
size_t d_y,
size_t w,
size_t h,
199 size_t x,
size_t y, uint8_t
flags );
203# define RETROFLAT_COLOR_TABLE_GL( idx, name_l, name_u, r, g, b, cgac, cgad ) \
204 MAUG_CONST float RETROGLU_COLOR_ ## name_u[] = { \
205 (float)((float)r * 1.0f / 255.0f), \
206 (float)((float)g * 1.0f / 255.0f), \
207 (float)((float)b * 1.0f / 255.0f) };
211void retroglu_set_tile_clip(
213 uint32_t px, uint32_t py, uint32_t pw, uint32_t ph, uint8_t
flags
218 float clip_tex_x = 0,
225 clip_tex_x = retroglu_tex_px_x_to_f( px, tile );
226 clip_tex_y = retroglu_tex_px_y_to_f( py, tile );
227 clip_tex_w = retroglu_tex_px_x_to_f( pw, tile );
228 clip_tex_h = retroglu_tex_px_y_to_f( ph, tile );
233 tile->vtexture[0][RETROGLU_SPRITE_X] = clip_tex_x;
234 tile->vtexture[0][RETROGLU_SPRITE_Y] = clip_tex_y;
237 tile->vtexture[1][RETROGLU_SPRITE_X] = clip_tex_x + clip_tex_w;
238 tile->vtexture[1][RETROGLU_SPRITE_Y] = clip_tex_y;
241 tile->vtexture[2][RETROGLU_SPRITE_X] = clip_tex_x + clip_tex_w;
242 tile->vtexture[2][RETROGLU_SPRITE_Y] = clip_tex_y + clip_tex_h;
245 tile->vtexture[3][RETROGLU_SPRITE_X] = clip_tex_x + clip_tex_w;
246 tile->vtexture[3][RETROGLU_SPRITE_Y] = clip_tex_y + clip_tex_h;
249 tile->vtexture[4][RETROGLU_SPRITE_X] = clip_tex_x;
250 tile->vtexture[4][RETROGLU_SPRITE_Y] = clip_tex_y + clip_tex_h;
253 tile->vtexture[5][RETROGLU_SPRITE_X] = clip_tex_x;
254 tile->vtexture[5][RETROGLU_SPRITE_Y] = clip_tex_y;
257void retroglu_init_tile_vertices(
struct RETROGLU_TILE* tile ) {
262 tile->vertices[0][RETROGLU_SPRITE_X] = -1;
263 tile->vertices[0][RETROGLU_SPRITE_Y] = -1;
266 tile->vertices[1][RETROGLU_SPRITE_X] = 1;
267 tile->vertices[1][RETROGLU_SPRITE_Y] = -1;
270 tile->vertices[2][RETROGLU_SPRITE_X] = 1;
271 tile->vertices[2][RETROGLU_SPRITE_Y] = 1;
274 tile->vertices[3][RETROGLU_SPRITE_X] = 1;
275 tile->vertices[3][RETROGLU_SPRITE_Y] = 1;
278 tile->vertices[4][RETROGLU_SPRITE_X] = -1;
279 tile->vertices[4][RETROGLU_SPRITE_Y] = 1;
282 tile->vertices[5][RETROGLU_SPRITE_X] = -1;
283 tile->vertices[5][RETROGLU_SPRITE_Y] = -1;
286void retroglu_set_sprite_clip(
288 uint32_t front_px, uint32_t front_py, uint32_t back_px, uint32_t back_py,
289 uint32_t pw, uint32_t ph, uint8_t
flags
294 float clip_tex_fx = 0,
303 clip_tex_fx = retroglu_tex_px_x_to_f( front_px, sprite );
304 clip_tex_fy = retroglu_tex_px_y_to_f( front_py, sprite );
305 clip_tex_bx = retroglu_tex_px_x_to_f( back_px, sprite );
306 clip_tex_by = retroglu_tex_px_y_to_f( back_py, sprite );
307 clip_tex_w = retroglu_tex_px_x_to_f( pw, sprite );
308 clip_tex_h = retroglu_tex_px_y_to_f( ph, sprite );
313 sprite->vtexture_front[0][RETROGLU_SPRITE_X] = clip_tex_fx;
314 sprite->vtexture_front[0][RETROGLU_SPRITE_Y] = clip_tex_fy;
317 sprite->vtexture_front[1][RETROGLU_SPRITE_X] = clip_tex_fx + clip_tex_w;
318 sprite->vtexture_front[1][RETROGLU_SPRITE_Y] = clip_tex_fy;
321 sprite->vtexture_front[2][RETROGLU_SPRITE_X] = clip_tex_fx + clip_tex_w;
322 sprite->vtexture_front[2][RETROGLU_SPRITE_Y] = clip_tex_fy + clip_tex_h;
325 sprite->vtexture_front[3][RETROGLU_SPRITE_X] = clip_tex_fx + clip_tex_w;
326 sprite->vtexture_front[3][RETROGLU_SPRITE_Y] = clip_tex_fy + clip_tex_h;
329 sprite->vtexture_front[4][RETROGLU_SPRITE_X] = clip_tex_fx;
330 sprite->vtexture_front[4][RETROGLU_SPRITE_Y] = clip_tex_fy + clip_tex_h;
333 sprite->vtexture_front[5][RETROGLU_SPRITE_X] = clip_tex_fx;
334 sprite->vtexture_front[5][RETROGLU_SPRITE_Y] = clip_tex_fy;
339 sprite->vtexture_back[0][RETROGLU_SPRITE_X] = clip_tex_bx;
340 sprite->vtexture_back[0][RETROGLU_SPRITE_Y] = clip_tex_by;
343 sprite->vtexture_back[1][RETROGLU_SPRITE_X] = clip_tex_bx + clip_tex_w;
344 sprite->vtexture_back[1][RETROGLU_SPRITE_Y] = clip_tex_by;
347 sprite->vtexture_back[2][RETROGLU_SPRITE_X] = clip_tex_bx + clip_tex_w;
348 sprite->vtexture_back[2][RETROGLU_SPRITE_Y] = clip_tex_by + clip_tex_h;
351 sprite->vtexture_back[3][RETROGLU_SPRITE_X] = clip_tex_bx + clip_tex_w;
352 sprite->vtexture_back[3][RETROGLU_SPRITE_Y] = clip_tex_by + clip_tex_h;
355 sprite->vtexture_back[4][RETROGLU_SPRITE_X] = clip_tex_bx;
356 sprite->vtexture_back[4][RETROGLU_SPRITE_Y] = clip_tex_by + clip_tex_h;
359 sprite->vtexture_back[5][RETROGLU_SPRITE_X] = clip_tex_bx;
360 sprite->vtexture_back[5][RETROGLU_SPRITE_Y] = clip_tex_by;
366 retroglu_init_sprite_vertices_scale( sprite, 1.0f );
371void retroglu_init_sprite_vertices_scale(
378 sprite->vertices_front[0][RETROGLU_SPRITE_X] = -1.0f * scale;
379 sprite->vertices_front[0][RETROGLU_SPRITE_Y] = -1.0f * scale;
382 sprite->vertices_front[1][RETROGLU_SPRITE_X] = scale;
383 sprite->vertices_front[1][RETROGLU_SPRITE_Y] = -1.0f * scale;
386 sprite->vertices_front[2][RETROGLU_SPRITE_X] = scale;
387 sprite->vertices_front[2][RETROGLU_SPRITE_Y] = scale;
390 sprite->vertices_front[3][RETROGLU_SPRITE_X] = scale;
391 sprite->vertices_front[3][RETROGLU_SPRITE_Y] = scale;
394 sprite->vertices_front[4][RETROGLU_SPRITE_X] = -1.0f * scale;
395 sprite->vertices_front[4][RETROGLU_SPRITE_Y] = scale;
398 sprite->vertices_front[5][RETROGLU_SPRITE_X] = -1.0f * scale;
399 sprite->vertices_front[5][RETROGLU_SPRITE_Y] = -1.0f * scale;
404 sprite->vertices_back[0][RETROGLU_SPRITE_X] = scale;
405 sprite->vertices_back[0][RETROGLU_SPRITE_Y] = -1.0f * scale;
408 sprite->vertices_back[1][RETROGLU_SPRITE_X] = -1.0f * scale;
409 sprite->vertices_back[1][RETROGLU_SPRITE_Y] = -1.0f * scale;
412 sprite->vertices_back[2][RETROGLU_SPRITE_X] = -1.0f * scale;
413 sprite->vertices_back[2][RETROGLU_SPRITE_Y] = scale;
416 sprite->vertices_back[3][RETROGLU_SPRITE_X] = -1.0f * scale;
417 sprite->vertices_back[3][RETROGLU_SPRITE_Y] = scale;
420 sprite->vertices_back[4][RETROGLU_SPRITE_X] = scale;
421 sprite->vertices_back[4][RETROGLU_SPRITE_Y] = scale;
424 sprite->vertices_back[5][RETROGLU_SPRITE_X] = scale;
425 sprite->vertices_back[5][RETROGLU_SPRITE_Y] = -1.0f * scale;
430void retroglu_set_sprite_pos(
433 sprite->translate_x = retroglu_scr_px_x_to_f( px );
434 sprite->translate_y = retroglu_scr_px_y_to_f( py );
441 glTranslatef( sprite->translate_x, sprite->translate_y, 0 );
442 glRotatef( sprite->rotate_y, 0.0f, 1.0f, 0.0f );
449#ifndef RETROGLU_NO_TEXTURES
450# ifdef RETROGLU_NO_TEXTURE_LISTS
454 glColor3fv( sprite->color );
456# ifndef RETROGLU_NO_TEXTURE_LISTS
457 glBindTexture( GL_TEXTURE_2D, sprite->texture.tex.id );
459 maug_mlock( sprite->texture.tex.bytes_h, sprite->texture.tex.bytes );
460 maug_cleanup_if_null_alloc( uint8_t*, sprite->texture.tex.bytes );
461 glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA,
462 sprite->texture.tex.w, sprite->texture.tex.h, 0,
463 GL_RGBA, GL_UNSIGNED_BYTE,
464 sprite->texture.tex.bytes );
466 glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
467 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
468 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST );
470 glBegin( GL_TRIANGLES );
472 for( i = 0 ; 6 > i ; i++ ) {
473 glTexCoord2fv( sprite->vtexture_front[i] );
474 glVertex2fv( sprite->vertices_front[i] );
477 for( i = 0 ; 6 > i ; i++ ) {
478 glTexCoord2fv( sprite->vtexture_back[i] );
479 glVertex2fv( sprite->vertices_back[i] );
484# ifndef RETROGLU_NO_TEXTURE_LISTS
485 glBindTexture( GL_TEXTURE_2D, 0 );
488 if( NULL != sprite->texture.tex.bytes ) {
489 maug_munlock( sprite->texture.tex.bytes_h, sprite->texture.tex.bytes );
499 uint32_t front_px, uint32_t front_py, uint32_t back_px, uint32_t back_py,
500 uint32_t pw, uint32_t ph, uint8_t
flags
502#ifdef RETROGLU_NO_LISTS
503 sprite->parms[list_idx].front_px = front_px;
504 sprite->parms[list_idx].front_py = front_py;
505 sprite->parms[list_idx].back_px = back_px;
506 sprite->parms[list_idx].back_py = back_py;
507 sprite->parms[list_idx].pw = pw;
508 sprite->parms[list_idx].ph = ph;
509 sprite->parms[list_idx].flags =
flags;
512 sprite->lists[list_idx] = glGenLists( 1 );
513 retroglu_set_sprite_clip(
514 sprite, front_px, front_py, back_px, back_py, pw, ph,
flags );
515 glNewList( sprite->lists[list_idx], GL_COMPILE );
524#ifdef RETROGLU_NO_LISTS
526 retroglu_set_sprite_clip(
528 sprite->parms[list_idx].front_px,
529 sprite->parms[list_idx].front_py,
530 sprite->parms[list_idx].back_px,
531 sprite->parms[list_idx].back_py,
532 sprite->parms[list_idx].pw,
533 sprite->parms[list_idx].ph,
534 sprite->parms[list_idx].flags );
537 glCallList( sprite->lists[list_idx] );
544#ifndef RETROGLU_NO_TEXTURES
545 if( NULL != sprite->texture.tex.bytes_h ) {
546 if( NULL != sprite->texture.tex.bytes ) {
547 maug_munlock( sprite->texture.tex.bytes_h, sprite->texture.tex.bytes );
550 maug_mfree( sprite->texture.tex.bytes_h );
553# ifndef RETROGLU_NO_TEXTURE_LISTS
554 if( 0 < sprite->texture.tex.id ) {
555 glDeleteTextures( 1, (GLuint*)&(sprite->texture.tex.id) );
563# define RETROFLAT_COLOR_TABLE_GL( idx, name_l, name_u, r, g, b, cgac, cgad ) \
564 extern MAUG_CONST float RETROGLU_COLOR_ ## name_u[];
int MERROR_RETVAL
Return type indicating function returns a value from this list.
Definition merror.h:19
int8_t RETROFLAT_COLOR
Defines an index in the platform-specific color-table.
Definition retroflt.h:325
#define RETROFLAT_COLOR_TABLE(f)
This macro defines all colors supported by RetroFlat for primative operations, particularly using ret...
Definition retroflt.h:306
void retroglu_prerender_sprite(struct RETROGLU_SPRITE *sprite, int list_idx, uint32_t front_px, uint32_t front_py, uint32_t back_px, uint32_t back_py, uint32_t pw, uint32_t ph, uint8_t flags)
If lists are enabled, prerender the sprite to a list using the given params to retroglu_set_sprite_cl...
void retroglu_draw_sprite(struct RETROGLU_SPRITE *sprite)
Draw the given sprite. This function never uses a list, and can therefore be used to create a draw li...
void retroglu_init_sprite_vertices(struct RETROGLU_SPRITE *sprite)
Setup the sprite vertices for the poly the sprite will be drawn on. This should be called once when t...
void retroglu_jitrender_sprite(struct RETROGLU_SPRITE *sprite, int list_idx)
If lists are enabled, render the sprite list at list_idx. Otherwise, draw the sprite using retroglu_d...
Platform-specific bitmap structure. retroflat_bitmap_ok() can be used on a pointer to it to determine...
Definition retpltd.h:21
uint8_t flags
Platform-specific bitmap flags.
Definition retpltd.h:25
If draw lists are disabled, this struct holds a list of params for retroglu_set_sprite_clip() so that...
Definition retroglu.h:51