7# define MAUG_CONST const
19#define RETROGLU_PARSER_ERROR -1
21#ifndef RETROGLU_PARSER_TOKEN_SZ_MAX
22# define RETROGLU_PARSER_TOKEN_SZ_MAX 32
25#ifndef RETROGLU_TRACE_LVL
26# define RETROGLU_TRACE_LVL 0
29#ifndef RETROGLU_SPRITE_TEX_FRAMES_SZ
30# define RETROGLU_SPRITE_TEX_FRAMES_SZ 10
34# define glShininessf( side, light, f ) glMaterialf( side, light, f )
47#define RETROGLU_PARSER_STATE_NONE 0
48#define RETROGLU_PARSER_STATE_VERTEX_X 1
49#define RETROGLU_PARSER_STATE_VERTEX_Y 2
50#define RETROGLU_PARSER_STATE_VERTEX_Z 3
51#define RETROGLU_PARSER_STATE_COMMENT 4
52#define RETROGLU_PARSER_STATE_FACE_TOKEN 5
53#define RETROGLU_PARSER_STATE_FACE_VERTEX 6
54#define RETROGLU_PARSER_STATE_FACE_TEXTURE 7
55#define RETROGLU_PARSER_STATE_FACE_NORMAL 8
56#define RETROGLU_PARSER_STATE_FACE_MATERIAL 9
57#define RETROGLU_PARSER_STATE_MATERIAL_NAME 10
58#define RETROGLU_PARSER_STATE_MATERIAL_AMB 11
59#define RETROGLU_PARSER_STATE_MATERIAL_DIF 12
60#define RETROGLU_PARSER_STATE_MATERIAL_SPEC 13
61#define RETROGLU_PARSER_STATE_MATERIAL_LIB 14
62#define RETROGLU_PARSER_STATE_MTL_KD_R 15
63#define RETROGLU_PARSER_STATE_MTL_KD_G 16
64#define RETROGLU_PARSER_STATE_MTL_KD_B 17
65#define RETROGLU_PARSER_STATE_VNORMAL_X 18
66#define RETROGLU_PARSER_STATE_VNORMAL_Y 19
67#define RETROGLU_PARSER_STATE_VNORMAL_Z 20
68#define RETROGLU_PARSER_STATE_VTEXTURE_X 21
69#define RETROGLU_PARSER_STATE_VTEXTURE_Y 22
70#define RETROGLU_PARSER_STATE_VTEXTURE_Z 23
71#define RETROGLU_PARSER_STATE_MTL_KA_R 24
72#define RETROGLU_PARSER_STATE_MTL_KA_G 25
73#define RETROGLU_PARSER_STATE_MTL_KA_B 26
74#define RETROGLU_PARSER_STATE_MTL_KS_R 27
75#define RETROGLU_PARSER_STATE_MTL_KS_G 28
76#define RETROGLU_PARSER_STATE_MTL_KS_B 29
77#define RETROGLU_PARSER_STATE_MTL_KE_R 30
78#define RETROGLU_PARSER_STATE_MTL_KE_G 31
79#define RETROGLU_PARSER_STATE_MTL_KE_B 32
80#define RETROGLU_PARSER_STATE_MTL_NS 33
86#ifndef RETROGLU_FACE_VERTICES_SZ_MAX
87# define RETROGLU_FACE_VERTICES_SZ_MAX 3
90#ifndef RETROGLU_MATERIAL_NAME_SZ_MAX
91# define RETROGLU_MATERIAL_NAME_SZ_MAX 32
94#ifndef RETROGLU_MATERIAL_LIB_SZ_MAX
95# define RETROGLU_MATERIAL_LIB_SZ_MAX 32
98typedef float RETROGLU_COLOR[4];
117 char name[RETROGLU_MATERIAL_NAME_SZ_MAX];
128 uint16_t vnormal_idxs[RETROGLU_FACE_VERTICES_SZ_MAX];
129 uint16_t vtexture_idxs[RETROGLU_FACE_VERTICES_SZ_MAX];
130 uint16_t vertex_idxs_sz;
131 uint16_t material_idx;
134#define RETROGLU_VERTICES_SZ_MAX 1024
135#define RETROGLU_FACES_SZ_MAX 1024
136#define RETROGLU_MATERIALS_SZ_MAX 1024
141 uint16_t vertices_sz;
143 uint16_t vnormals_sz;
145 uint16_t vtextures_sz;
153 uint16_t materials_sz;
161#define RETROGLU_SPRITE_X 0
162#define RETROGLU_SPRITE_Y 1
164#ifndef RETROGLU_SPRITE_LIST_SZ_MAX
165# define RETROGLU_SPRITE_LIST_SZ_MAX 10
184 float vertices_front[6][2];
185 float vtexture_front[6][2];
186 float vertices_back[6][2];
187 float vtexture_back[6][2];
191 RETROGLU_COLOR color;
193#ifdef RETROGLU_NO_LISTS
196 GLint lists[RETROGLU_SPRITE_LIST_SZ_MAX];
201 float vertices[6][2];
202 float vtexture[6][2];
210#define RETROGLU_PROJ_ORTHO 0
211#define RETROGLU_PROJ_FRUSTUM 1
222#ifdef RETROFLAT_API_LIBNDS
223# define retroglu_enable_lightning()
224# define retroglu_disable_lightning()
226# define retroglu_enable_lightning() glEnable( GL_LIGHTING )
227# define retroglu_disable_lightning() glDisable( GL_LIGHTING )
241#define retroglu_push_overlay( x, y, x_f, y_f, aspect_f ) \
243 glMatrixMode( GL_PROJECTION ); \
246 retroglu_disable_lightning(); \
249 aspect_f = (float)retroflat_screen_w() / (float)retroflat_screen_h(); \
251 glOrtho( -1.0f * aspect_f, aspect_f, -1.0f, 1.0f, 0, 10.0f ); \
255 x_f = ((x) * aspect_f / retroflat_screen_w()) - (aspect_f / 2); \
257 y_f = 1.0f - ((y) * 2.0f / retroflat_screen_h()); \
267#define retroglu_whf( w, h, w_f, h_f, aspect_f ) \
268 w_f = ((w) * aspect_f / retroflat_screen_w()); \
269 h_f = ((h) * 2.0f / retroflat_screen_h());
274#define retroglu_pop_overlay() \
276 glMatrixMode( GL_MODELVIEW );
280#define retroglu_tex_px_x_to_f( px, sprite ) \
281 ((px) * 1.0 / sprite->texture.tex.w)
282#define retroglu_tex_px_y_to_f( px, sprite ) \
283 ((px) * 1.0 / sprite->texture.tex.h)
285#define retroglu_scr_px_x_to_f( px ) \
286 (float)(((px) * 1.0 / (retroflat_screen_w() / 2)) - 1.0)
287#define retroglu_scr_px_y_to_f( py ) \
288 (float)(((py) * 1.0 / (retroflat_screen_h() / 2)) - 1.0)
290#define retroglu_set_sprite_tex( sprite, texture_id, bmp_w, bmp_h ) \
291 sprite->texture_id = texture_id; \
292 sprite->texture_w = bmp_w; \
293 sprite->texture_h = bmp_h;
295#define retroglu_set_sprite_color( sprite, color_in ) \
296 memcpy( (sprite)->color, (color_in), 3 * sizeof( float ) )
308#define retroglu_parser_state( parser, new_state ) \
310 RETROGLU_TRACE_LVL, "changing parser to state: %d", new_state ); \
311 (parser)->state = new_state;
316#define RETROGLU_OBJ_TOKENS( f ) \
317 f( "v", retroglu_token_vertice ) \
318 f( "vn", retroglu_token_vnormal ) \
319 f( "f", retroglu_token_face ) \
320 f( "usemtl", retroglu_token_usemtl ) \
321 f( "newmtl", retroglu_token_newmtl ) \
322 f( "mtllib", retroglu_token_mtllib ) \
323 f( "Kd", retroglu_token_kd ) \
324 f( "Ka", retroglu_token_ka ) \
325 f( "Ks", retroglu_token_ks ) \
326 f( "Ke", retroglu_token_ks ) \
327 f( "Ns", retroglu_token_ns )
346 char token[RETROGLU_PARSER_TOKEN_SZ_MAX];
354void retroglu_init_scene( uint8_t flags );
385void retroglu_set_tile_clip(
387 uint32_t px, uint32_t py, uint32_t pw, uint32_t ph, uint8_t flags );
389void retroglu_set_sprite_clip(
391 uint32_t front_px, uint32_t front_py, uint32_t back_px, uint32_t back_py,
392 uint32_t pw, uint32_t ph, uint8_t flags );
401void retroglu_init_sprite_vertices_scale(
404void retroglu_set_sprite_pos(
423 uint32_t front_px, uint32_t front_py, uint32_t back_px, uint32_t back_py,
424 uint32_t pw, uint32_t ph, uint8_t flags );
436void retroglu_destroy_glyph_tex();
439 float x,
float y,
float z,
const RETROGLU_COLOR color,
440 const char* str,
size_t str_sz,
const char* font_str, uint8_t flags );
450 size_t s_x,
size_t s_y,
size_t d_x,
size_t d_y,
size_t w,
size_t h,
455# define RETROFLAT_COLOR_TABLE_GL( idx, name_l, name_u, r, g, b, cgac, cgad ) \
456 MAUG_CONST float RETROGLU_COLOR_ ## name_u[] = { \
457 (float)((float)r * 1.0f / 255.0f), \
458 (float)((float)g * 1.0f / 255.0f), \
459 (float)((float)b * 1.0f / 255.0f) };
463# define RETROGLU_OBJ_TOKEN_STRINGS( token, callback ) token,
477 parser->obj->
faces[parser->obj->faces_sz].vertex_idxs_sz = 0;
488 parser->obj->materials[parser->obj->materials_sz].ambient[3] = 1.0f;
489 parser->obj->materials[parser->obj->materials_sz].diffuse[3] = 1.0f;
490 parser->obj->materials[parser->obj->materials_sz].specular[3] = 1.0f;
491 parser->obj->materials[parser->obj->materials_sz].emissive[3] = 1.0f;
492 parser->obj->materials[parser->obj->materials_sz].specular_exp = 0;
493 parser->obj->materials_sz++;
494 assert( parser->obj->materials_sz <= RETROGLU_MATERIALS_SZ_MAX );
529char* g_retroglu_token_strings[] = {
534# define RETROGLU_OBJ_TOKEN_CALLBACKS( token, callback ) callback,
536retroglu_token_cb g_retroglu_token_callbacks[] = {
541void retroglu_init_scene( uint8_t flags ) {
542 debug_printf( RETROGLU_TRACE_LVL,
"initializing..." );
545 glMaterialShinyness();
546 glPolyFmt( POLY_ALPHA( 15 ) | POLY_CULL_BACK | POLY_FORMAT_LIGHT0 );
548 glEnable( GL_CULL_FACE );
549 glShadeModel( GL_SMOOTH );
552 glEnable( GL_TEXTURE_2D );
553 glEnable( GL_BLEND );
554 glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
557 glEnable( GL_DEPTH_TEST );
558 glDepthMask( GL_TRUE );
559 glDepthFunc( GL_LESS );
560 glDepthRange( 0.0f, 1.0f );
565 float aspect_ratio = 0;
567 if( 0 == args->screen_px_w ) {
575 if( 0 == args->screen_px_h ) {
586 glViewport( 0, 0, 255, 191 );
589 0, 0, (uint32_t)(args->screen_px_w), (uint32_t)(args->screen_px_h) );
591 aspect_ratio = (float)(args->screen_px_w) / (float)(args->screen_px_h);
594 glMatrixMode( GL_PROJECTION );
600 assert( 0 != args->near_plane );
602 switch( args->proj ) {
603 case RETROGLU_PROJ_FRUSTUM:
606 debug_printf( RETROGLU_TRACE_LVL,
"aspect ratio: %f", aspect_ratio );
609 -1.0f * args->rzoom * aspect_ratio, args->rzoom * aspect_ratio,
610 -1.0f * args->rzoom, args->rzoom,
611 args->near_plane, args->far_plane );
614 case RETROGLU_PROJ_ORTHO:
617 -1.0f * args->rzoom * aspect_ratio,
618 args->rzoom * aspect_ratio,
619 -1.0f * args->rzoom, args->rzoom,
620 args->near_plane, args->far_plane );
625 glMatrixMode( GL_MODELVIEW );
632 parser->load_mtl = load_mtl;
633 parser->load_mtl_data = load_mtl_data;
635 assert( NULL != parser->obj );
637 parser->token_sz = 0;
640#define RETROGLU_TOKENS_VF( f ) \
641 f( "X", VERTEX_X, vertices, vertices_sz, x, VERTEX_Y ) \
642 f( "Y", VERTEX_Y, vertices, vertices_sz, y, VERTEX_Z ) \
643 f( "Z", VERTEX_Z, vertices, vertices_sz, z, NONE ) \
644 f( "normal X", VNORMAL_X, vnormals, vnormals_sz, x, VNORMAL_Y ) \
645 f( "normal Y", VNORMAL_Y, vnormals, vnormals_sz, y, VNORMAL_Z ) \
646 f( "normal Z", VNORMAL_Z, vnormals, vnormals_sz, z, NONE ) \
647 f( "mtl Kd R", MTL_KD_R, materials, materials_sz-1, diffuse[0], MTL_KD_G ) \
648 f( "mtl Kd G", MTL_KD_G, materials, materials_sz-1, diffuse[1], MTL_KD_B ) \
649 f( "mtl Kd B", MTL_KD_B, materials, materials_sz-1, diffuse[2], NONE ) \
650 f( "mtl Ka R", MTL_KA_R, materials, materials_sz-1, ambient[0], MTL_KA_G ) \
651 f( "mtl Ka G", MTL_KA_G, materials, materials_sz-1, ambient[1], MTL_KA_B ) \
652 f( "mtl Ka B", MTL_KA_B, materials, materials_sz-1, ambient[2], NONE ) \
653 f( "mtl Ks R", MTL_KS_R, materials, materials_sz-1, specular[0], MTL_KS_G ) \
654 f( "mtl Ks G", MTL_KS_G, materials, materials_sz-1, specular[1], MTL_KS_B ) \
655 f( "mtl Ks B", MTL_KS_B, materials, materials_sz-1, specular[2], NONE ) \
656 f( "mtl Ke R", MTL_KE_R, materials, materials_sz-1, emissive[0], MTL_KE_G ) \
657 f( "mtl Ke G", MTL_KE_G, materials, materials_sz-1, emissive[1], MTL_KE_B ) \
658 f( "mtl Ke B", MTL_KE_B, materials, materials_sz-1, emissive[2], NONE ) \
659 f( "mtl Ns", MTL_NS, materials, materials_sz-1, specular_exp, NONE )
661#define RETROGLU_TOKEN_PARSE_VF( desc, cond, array, sz, val, state_next ) \
662 } else if( RETROGLU_PARSER_STATE_ ## cond == parser->state ) { \
664 parser->obj->array[parser->obj->sz].val = strtod( parser->token, NULL ); \
665 debug_printf( RETROGLU_TRACE_LVL, "vertex %d " desc ": %f", \
666 parser->obj->sz, parser->obj->array[parser->obj->sz].val ); \
667 retroglu_parser_state( parser, RETROGLU_PARSER_STATE_ ## state_next );
674 if( 0 == parser->token_sz ) {
680 parser->token[parser->token_sz] =
'\0';
682 debug_printf( RETROGLU_TRACE_LVL,
"token: %s", parser->token );
684 if( RETROGLU_PARSER_STATE_MATERIAL_LIB == parser->state ) {
687 RETROGLU_TRACE_LVL,
"parsing material lib: %s", parser->token );
689 assert( NULL != parser->load_mtl );
690 return parser->load_mtl( parser->token, parser, parser->load_mtl_data );
692 RETROGLU_TOKENS_VF( RETROGLU_TOKEN_PARSE_VF )
696 }
else if( RETROGLU_PARSER_STATE_FACE_VERTEX == parser->state ) {
699 parser->obj->
faces[parser->obj->faces_sz].vertex_idxs_sz] =
700 atoi( parser->token );
702 debug_printf( RETROGLU_TRACE_LVL,
"face %d, vertex %d: %d",
703 parser->obj->faces_sz, parser->obj->
faces[parser->obj->faces_sz].vertex_idxs_sz,
705 parser->obj->
faces[parser->obj->faces_sz].vertex_idxs_sz] );
713 }
else if( RETROGLU_PARSER_STATE_FACE_NORMAL == parser->state ) {
716 parser->obj->
faces[parser->obj->faces_sz].vnormal_idxs[
717 parser->obj->
faces[parser->obj->faces_sz].vertex_idxs_sz] =
718 atoi( parser->token );
720 debug_printf( RETROGLU_TRACE_LVL,
"face %d, normal %d: %d",
721 parser->obj->faces_sz, parser->obj->
faces[parser->obj->faces_sz].vertex_idxs_sz,
722 parser->obj->
faces[parser->obj->faces_sz].vnormal_idxs[
723 parser->obj->
faces[parser->obj->faces_sz].vertex_idxs_sz] );
731 }
else if( RETROGLU_PARSER_STATE_FACE_TEXTURE == parser->state ) {
734 parser->obj->
faces[parser->obj->faces_sz].vtexture_idxs[
735 parser->obj->
faces[parser->obj->faces_sz].vertex_idxs_sz] =
736 atoi( parser->token );
738 debug_printf( RETROGLU_TRACE_LVL,
"face %d, texture %d: %d",
739 parser->obj->faces_sz, parser->obj->
faces[parser->obj->faces_sz].vertex_idxs_sz,
740 parser->obj->
faces[parser->obj->faces_sz].vtexture_idxs[
741 parser->obj->
faces[parser->obj->faces_sz].vertex_idxs_sz] );
750 }
else if( RETROGLU_PARSER_STATE_FACE_MATERIAL == parser->state ) {
753 for( i = 0 ; parser->obj->materials_sz > i ; i++ ) {
756 "%s vs %s", parser->obj->materials[i].name, parser->token );
758 parser->obj->materials[i].name, parser->token,
759 RETROGLU_MATERIAL_NAME_SZ_MAX
761 debug_printf( RETROGLU_TRACE_LVL,
"using material: \"%s\" (%d)",
762 parser->obj->materials[i].name, i );
763 parser->material_idx = i;
769 }
else if( RETROGLU_PARSER_STATE_MATERIAL_NAME == parser->state ) {
772 RETROGLU_TRACE_LVL,
"adding material: \"%s\" at idx: %d",
773 parser->token, parser->obj->materials_sz - 1 );
775 parser->obj->materials[parser->obj->materials_sz - 1].name,
777 RETROGLU_MATERIAL_NAME_SZ_MAX );
782 while(
'\0' != g_retroglu_token_strings[i][0] ) {
784 parser->token_sz == maug_strlen( g_retroglu_token_strings[i] ) &&
786 parser->token, g_retroglu_token_strings[i],
789 retval = g_retroglu_token_callbacks[i]( parser );
799 parser->token_sz = 0;
805retroglu_append_token(
struct RETROGLU_PARSER* parser,
unsigned char c ) {
806 parser->token[parser->token_sz++] = c;
809 if( parser->token_sz >= RETROGLU_PARSER_TOKEN_SZ_MAX ) {
810 debug_printf( RETROGLU_TRACE_LVL,
"token out of bounds!" );
811 return RETROGLU_PARSER_ERROR;
822 RETROGLU_PARSER_STATE_COMMENT == parser->state &&
'\r' != c &&
'\n' != c
837 if( RETROGLU_PARSER_STATE_COMMENT == parser->state ) {
842 RETROGLU_PARSER_STATE_FACE_VERTEX == parser->state ||
843 RETROGLU_PARSER_STATE_FACE_TEXTURE == parser->state ||
844 RETROGLU_PARSER_STATE_FACE_NORMAL == parser->state
847 retval = retroglu_parse_token( parser );
851 parser->obj->
faces[parser->obj->faces_sz].material_idx =
852 parser->material_idx;
855 parser->obj->
faces[parser->obj->faces_sz].vertex_idxs_sz++;
856 parser->obj->faces_sz++;
857 assert( parser->obj->faces_sz <= RETROGLU_FACES_SZ_MAX );
860 }
else if( RETROGLU_PARSER_STATE_VNORMAL_Z == parser->state ) {
862 retval = retroglu_parse_token( parser );
864 parser->obj->vnormals_sz++;
865 assert( parser->obj->vnormals_sz <= RETROGLU_VERTICES_SZ_MAX );
868 }
else if( RETROGLU_PARSER_STATE_VERTEX_Z == parser->state ) {
870 retval = retroglu_parse_token( parser );
872 parser->obj->vertices_sz++;
873 assert( parser->obj->vertices_sz <= RETROGLU_VERTICES_SZ_MAX );
877 return retroglu_parse_token( parser );
883 if( RETROGLU_PARSER_STATE_COMMENT == parser->state ) {
888 RETROGLU_PARSER_STATE_FACE_VERTEX == parser->state ||
889 RETROGLU_PARSER_STATE_FACE_TEXTURE == parser->state ||
890 RETROGLU_PARSER_STATE_FACE_NORMAL == parser->state
893 retval = retroglu_parse_token( parser );
894 parser->obj->
faces[parser->obj->faces_sz].vertex_idxs_sz++;
898 }
else if( RETROGLU_PARSER_STATE_VNORMAL_Z == parser->state ) {
900 retval = retroglu_parse_token( parser );
902 parser->obj->vnormals_sz++;
903 assert( parser->obj->vnormals_sz <= RETROGLU_VERTICES_SZ_MAX );
906 }
else if( RETROGLU_PARSER_STATE_VERTEX_Z == parser->state ) {
908 retval = retroglu_parse_token( parser );
910 parser->obj->vertices_sz++;
911 assert( parser->obj->vertices_sz <= RETROGLU_VERTICES_SZ_MAX );
914 }
else if( RETROGLU_PARSER_STATE_MTL_KD_B == parser->state ) {
915 retval = retroglu_parse_token( parser );
921 return retroglu_parse_token( parser );
925 if( RETROGLU_PARSER_STATE_FACE_VERTEX == parser->state ) {
926 retval = retroglu_parse_token( parser );
930 }
else if( RETROGLU_PARSER_STATE_FACE_TEXTURE == parser->state ) {
931 retval = retroglu_parse_token( parser );
937 assert( RETROGLU_PARSER_STATE_FACE_NORMAL != parser->state );
940 return retroglu_append_token( parser, c );
943 return retroglu_append_token( parser, c );
954 char filename_path[RETROFLAT_PATH_MAX + 1];
959 if( NULL == parser ) {
961 assert( NULL != parser );
966 memset( filename_path,
'\0', RETROFLAT_PATH_MAX + 1 );
967 maug_snprintf( filename_path, RETROFLAT_PATH_MAX,
"%s%c%s",
972 maug_cleanup_if_not_ok();
978 while( mfile_has_bytes( &obj_file ) ) {
979 retval = obj_file.read_int( &obj_file, (uint8_t*)&c, 1, 0 );
980 maug_cleanup_if_not_ok();
982 maug_cleanup_if_not_ok();
992 "parsed %s, %u vertices, %u materials",
993 filename_path, obj->vertices_sz, obj->materials_sz );
1004 glBegin( GL_TRIANGLES );
1005 for( i = 0 ; obj->faces_sz > i ; i++ ) {
1008 glMaterialfv( GL_FRONT, GL_DIFFUSE,
1009 obj->materials[obj->
faces[i].material_idx].diffuse );
1014 glMaterialfv( GL_FRONT, GL_SPECULAR,
1015 obj->materials[obj->
faces[i].material_idx].specular );
1016 glMaterialfv( GL_FRONT, GL_EMISSION,
1017 obj->materials[obj->
faces[i].material_idx].emissive );
1019 glColor3fv( obj->materials[obj->
faces[i].material_idx].diffuse );
1022 glShininessf( GL_FRONT, GL_SHININESS,
1023 obj->materials[obj->
faces[i].material_idx].specular_exp );
1025 for( j = 0 ; obj->
faces[i].vertex_idxs_sz > j ; j++ ) {
1027 assert( 3 == obj->
faces[i].vertex_idxs_sz );
1030 obj->vnormals[obj->
faces[i].vnormal_idxs[j] - 1].x,
1031 obj->vnormals[obj->
faces[i].vnormal_idxs[j] - 1].y,
1032 obj->vnormals[obj->
faces[i].vnormal_idxs[j] - 1].z );
1044void retroglu_set_tile_clip(
1046 uint32_t px, uint32_t py, uint32_t pw, uint32_t ph, uint8_t flags
1051 float clip_tex_x = 0,
1058 clip_tex_x = retroglu_tex_px_x_to_f( px, tile );
1059 clip_tex_y = retroglu_tex_px_y_to_f( py, tile );
1060 clip_tex_w = retroglu_tex_px_x_to_f( pw, tile );
1061 clip_tex_h = retroglu_tex_px_y_to_f( ph, tile );
1066 tile->vtexture[0][RETROGLU_SPRITE_X] = clip_tex_x;
1067 tile->vtexture[0][RETROGLU_SPRITE_Y] = clip_tex_y;
1070 tile->vtexture[1][RETROGLU_SPRITE_X] = clip_tex_x + clip_tex_w;
1071 tile->vtexture[1][RETROGLU_SPRITE_Y] = clip_tex_y;
1074 tile->vtexture[2][RETROGLU_SPRITE_X] = clip_tex_x + clip_tex_w;
1075 tile->vtexture[2][RETROGLU_SPRITE_Y] = clip_tex_y + clip_tex_h;
1078 tile->vtexture[3][RETROGLU_SPRITE_X] = clip_tex_x + clip_tex_w;
1079 tile->vtexture[3][RETROGLU_SPRITE_Y] = clip_tex_y + clip_tex_h;
1082 tile->vtexture[4][RETROGLU_SPRITE_X] = clip_tex_x;
1083 tile->vtexture[4][RETROGLU_SPRITE_Y] = clip_tex_y + clip_tex_h;
1086 tile->vtexture[5][RETROGLU_SPRITE_X] = clip_tex_x;
1087 tile->vtexture[5][RETROGLU_SPRITE_Y] = clip_tex_y;
1090void retroglu_init_tile_vertices(
struct RETROGLU_TILE* tile ) {
1095 tile->vertices[0][RETROGLU_SPRITE_X] = -1;
1096 tile->vertices[0][RETROGLU_SPRITE_Y] = -1;
1099 tile->vertices[1][RETROGLU_SPRITE_X] = 1;
1100 tile->vertices[1][RETROGLU_SPRITE_Y] = -1;
1103 tile->vertices[2][RETROGLU_SPRITE_X] = 1;
1104 tile->vertices[2][RETROGLU_SPRITE_Y] = 1;
1107 tile->vertices[3][RETROGLU_SPRITE_X] = 1;
1108 tile->vertices[3][RETROGLU_SPRITE_Y] = 1;
1111 tile->vertices[4][RETROGLU_SPRITE_X] = -1;
1112 tile->vertices[4][RETROGLU_SPRITE_Y] = 1;
1115 tile->vertices[5][RETROGLU_SPRITE_X] = -1;
1116 tile->vertices[5][RETROGLU_SPRITE_Y] = -1;
1119void retroglu_set_sprite_clip(
1121 uint32_t front_px, uint32_t front_py, uint32_t back_px, uint32_t back_py,
1122 uint32_t pw, uint32_t ph, uint8_t flags
1127 float clip_tex_fx = 0,
1136 clip_tex_fx = retroglu_tex_px_x_to_f( front_px, sprite );
1137 clip_tex_fy = retroglu_tex_px_y_to_f( front_py, sprite );
1138 clip_tex_bx = retroglu_tex_px_x_to_f( back_px, sprite );
1139 clip_tex_by = retroglu_tex_px_y_to_f( back_py, sprite );
1140 clip_tex_w = retroglu_tex_px_x_to_f( pw, sprite );
1141 clip_tex_h = retroglu_tex_px_y_to_f( ph, sprite );
1146 sprite->vtexture_front[0][RETROGLU_SPRITE_X] = clip_tex_fx;
1147 sprite->vtexture_front[0][RETROGLU_SPRITE_Y] = clip_tex_fy;
1150 sprite->vtexture_front[1][RETROGLU_SPRITE_X] = clip_tex_fx + clip_tex_w;
1151 sprite->vtexture_front[1][RETROGLU_SPRITE_Y] = clip_tex_fy;
1154 sprite->vtexture_front[2][RETROGLU_SPRITE_X] = clip_tex_fx + clip_tex_w;
1155 sprite->vtexture_front[2][RETROGLU_SPRITE_Y] = clip_tex_fy + clip_tex_h;
1158 sprite->vtexture_front[3][RETROGLU_SPRITE_X] = clip_tex_fx + clip_tex_w;
1159 sprite->vtexture_front[3][RETROGLU_SPRITE_Y] = clip_tex_fy + clip_tex_h;
1162 sprite->vtexture_front[4][RETROGLU_SPRITE_X] = clip_tex_fx;
1163 sprite->vtexture_front[4][RETROGLU_SPRITE_Y] = clip_tex_fy + clip_tex_h;
1166 sprite->vtexture_front[5][RETROGLU_SPRITE_X] = clip_tex_fx;
1167 sprite->vtexture_front[5][RETROGLU_SPRITE_Y] = clip_tex_fy;
1172 sprite->vtexture_back[0][RETROGLU_SPRITE_X] = clip_tex_bx;
1173 sprite->vtexture_back[0][RETROGLU_SPRITE_Y] = clip_tex_by;
1176 sprite->vtexture_back[1][RETROGLU_SPRITE_X] = clip_tex_bx + clip_tex_w;
1177 sprite->vtexture_back[1][RETROGLU_SPRITE_Y] = clip_tex_by;
1180 sprite->vtexture_back[2][RETROGLU_SPRITE_X] = clip_tex_bx + clip_tex_w;
1181 sprite->vtexture_back[2][RETROGLU_SPRITE_Y] = clip_tex_by + clip_tex_h;
1184 sprite->vtexture_back[3][RETROGLU_SPRITE_X] = clip_tex_bx + clip_tex_w;
1185 sprite->vtexture_back[3][RETROGLU_SPRITE_Y] = clip_tex_by + clip_tex_h;
1188 sprite->vtexture_back[4][RETROGLU_SPRITE_X] = clip_tex_bx;
1189 sprite->vtexture_back[4][RETROGLU_SPRITE_Y] = clip_tex_by + clip_tex_h;
1192 sprite->vtexture_back[5][RETROGLU_SPRITE_X] = clip_tex_bx;
1193 sprite->vtexture_back[5][RETROGLU_SPRITE_Y] = clip_tex_by;
1199 retroglu_init_sprite_vertices_scale( sprite, 1.0f );
1204void retroglu_init_sprite_vertices_scale(
1211 sprite->vertices_front[0][RETROGLU_SPRITE_X] = -1.0f * scale;
1212 sprite->vertices_front[0][RETROGLU_SPRITE_Y] = -1.0f * scale;
1215 sprite->vertices_front[1][RETROGLU_SPRITE_X] = scale;
1216 sprite->vertices_front[1][RETROGLU_SPRITE_Y] = -1.0f * scale;
1219 sprite->vertices_front[2][RETROGLU_SPRITE_X] = scale;
1220 sprite->vertices_front[2][RETROGLU_SPRITE_Y] = scale;
1223 sprite->vertices_front[3][RETROGLU_SPRITE_X] = scale;
1224 sprite->vertices_front[3][RETROGLU_SPRITE_Y] = scale;
1227 sprite->vertices_front[4][RETROGLU_SPRITE_X] = -1.0f * scale;
1228 sprite->vertices_front[4][RETROGLU_SPRITE_Y] = scale;
1231 sprite->vertices_front[5][RETROGLU_SPRITE_X] = -1.0f * scale;
1232 sprite->vertices_front[5][RETROGLU_SPRITE_Y] = -1.0f * scale;
1237 sprite->vertices_back[0][RETROGLU_SPRITE_X] = scale;
1238 sprite->vertices_back[0][RETROGLU_SPRITE_Y] = -1.0f * scale;
1241 sprite->vertices_back[1][RETROGLU_SPRITE_X] = -1.0f * scale;
1242 sprite->vertices_back[1][RETROGLU_SPRITE_Y] = -1.0f * scale;
1245 sprite->vertices_back[2][RETROGLU_SPRITE_X] = -1.0f * scale;
1246 sprite->vertices_back[2][RETROGLU_SPRITE_Y] = scale;
1249 sprite->vertices_back[3][RETROGLU_SPRITE_X] = -1.0f * scale;
1250 sprite->vertices_back[3][RETROGLU_SPRITE_Y] = scale;
1253 sprite->vertices_back[4][RETROGLU_SPRITE_X] = scale;
1254 sprite->vertices_back[4][RETROGLU_SPRITE_Y] = scale;
1257 sprite->vertices_back[5][RETROGLU_SPRITE_X] = scale;
1258 sprite->vertices_back[5][RETROGLU_SPRITE_Y] = -1.0f * scale;
1263void retroglu_set_sprite_pos(
1266 sprite->translate_x = retroglu_scr_px_x_to_f( px );
1267 sprite->translate_y = retroglu_scr_px_y_to_f( py );
1274 glTranslatef( sprite->translate_x, sprite->translate_y, 0 );
1275 glRotatef( sprite->rotate_y, 0.0f, 1.0f, 0.0f );
1282#ifndef RETROGLU_NO_TEXTURES
1283# ifdef RETROGLU_NO_TEXTURE_LISTS
1287 glColor3fv( sprite->color );
1289# ifndef RETROGLU_NO_TEXTURE_LISTS
1290 glBindTexture( GL_TEXTURE_2D, sprite->texture.tex.id );
1292 maug_mlock( sprite->texture.tex.bytes_h, sprite->texture.tex.bytes );
1293 maug_cleanup_if_null_alloc( uint8_t*, sprite->texture.tex.bytes );
1294 glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA,
1295 sprite->texture.tex.w, sprite->texture.tex.h, 0,
1296 GL_RGBA, GL_UNSIGNED_BYTE,
1297 sprite->texture.tex.bytes );
1299 glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
1300 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
1301 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST );
1303 glBegin( GL_TRIANGLES );
1305 for( i = 0 ; 6 > i ; i++ ) {
1306 glTexCoord2fv( sprite->vtexture_front[i] );
1307 glVertex2fv( sprite->vertices_front[i] );
1310 for( i = 0 ; 6 > i ; i++ ) {
1311 glTexCoord2fv( sprite->vtexture_back[i] );
1312 glVertex2fv( sprite->vertices_back[i] );
1317# ifndef RETROGLU_NO_TEXTURE_LISTS
1318 glBindTexture( GL_TEXTURE_2D, 0 );
1321 if( NULL != sprite->texture.tex.bytes ) {
1322 maug_munlock( sprite->texture.tex.bytes_h, sprite->texture.tex.bytes );
1332 uint32_t front_px, uint32_t front_py, uint32_t back_px, uint32_t back_py,
1333 uint32_t pw, uint32_t ph, uint8_t flags
1335#ifdef RETROGLU_NO_LISTS
1336 sprite->parms[list_idx].front_px = front_px;
1337 sprite->parms[list_idx].front_py = front_py;
1338 sprite->parms[list_idx].back_px = back_px;
1339 sprite->parms[list_idx].back_py = back_py;
1340 sprite->parms[list_idx].pw = pw;
1341 sprite->parms[list_idx].ph = ph;
1342 sprite->parms[list_idx].flags = flags;
1345 sprite->lists[list_idx] = glGenLists( 1 );
1346 retroglu_set_sprite_clip(
1347 sprite, front_px, front_py, back_px, back_py, pw, ph, flags );
1348 glNewList( sprite->lists[list_idx], GL_COMPILE );
1357#ifdef RETROGLU_NO_LISTS
1359 retroglu_set_sprite_clip(
1361 sprite->parms[list_idx].front_px,
1362 sprite->parms[list_idx].front_py,
1363 sprite->parms[list_idx].back_px,
1364 sprite->parms[list_idx].back_py,
1365 sprite->parms[list_idx].pw,
1366 sprite->parms[list_idx].ph,
1367 sprite->parms[list_idx].flags );
1370 glCallList( sprite->lists[list_idx] );
1377#ifndef RETROGLU_NO_TEXTURES
1378 if( NULL != sprite->texture.tex.bytes_h ) {
1379 if( NULL != sprite->texture.tex.bytes ) {
1380 maug_munlock( sprite->texture.tex.bytes_h, sprite->texture.tex.bytes );
1383 maug_mfree( sprite->texture.tex.bytes_h );
1386# ifndef RETROGLU_NO_TEXTURE_LISTS
1387 if( 0 < sprite->texture.tex.id ) {
1388 glDeleteTextures( 1, (GLuint*)&(sprite->texture.tex.id) );
1396#ifndef RETROFLAT_NO_STRING
1398# include "mfont8x8.h"
1401uint32_t g_retroglu_font_tex[RETROSOFT_SETS_COUNT][RETROSOFT_GLYPHS_COUNT];
1403MERROR_RETVAL retroglu_load_glyph(
size_t set_idx,
size_t glyph_idx ) {
1406#ifndef RETROGLU_NO_TEXTURES
1408 uint8_t* bmp_px = NULL;
1412 const char* glyph_dots = gc_font8x8[set_idx][glyph_idx];
1415 bmp_px = calloc( RETROSOFT_GLYPH_W_SZ * RETROSOFT_GLYPH_H_SZ, 4 );
1416 maug_cleanup_if_null_alloc( uint8_t*, bmp_px );
1417 assert( NULL != bmp_px );
1420 for( y = 0 ; RETROSOFT_GLYPH_H_SZ > y ; y++ ) {
1421 for( x = 0 ; RETROSOFT_GLYPH_W_SZ > x ; x++ ) {
1422 i = ((RETROSOFT_GLYPH_H_SZ - y - 1) * RETROSOFT_GLYPH_W_SZ) + x;
1423 assert( i < RETROSOFT_GLYPH_W_SZ * RETROSOFT_GLYPH_H_SZ * 4 );
1425 if( 1 == ((glyph_dots[y] >> x) & 0x01) ) {
1426 bmp_px[i * 4] = 0xff;
1427 bmp_px[(i * 4) + 1] = 0xff;
1428 bmp_px[(i * 4) + 2] = 0xff;
1429 bmp_px[(i * 4) + 3] = 0xff;
1434# ifndef RETROGLU_NO_TEXTURE_LISTS
1435 assert( 0 == g_retroglu_font_tex[set_idx][glyph_idx] );
1436 glGenTextures( 1, (GLuint*)&(g_retroglu_font_tex[set_idx][glyph_idx]) );
1437 assert( 0 < g_retroglu_font_tex[set_idx][glyph_idx] );
1438 glBindTexture( GL_TEXTURE_2D, g_retroglu_font_tex[set_idx][glyph_idx] );
1441 glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA,
1442 RETROSOFT_GLYPH_W_SZ, RETROSOFT_GLYPH_H_SZ, 0,
1443 GL_RGBA, GL_UNSIGNED_BYTE, bmp_px );
1447 if( NULL != bmp_px ) {
1461#ifndef RETROGLU_NO_TEXTURES
1468 debug_printf( RETROGLU_TRACE_LVL,
"loading glyph textures..." );
1470 for( i = 0 ; RETROSOFT_SETS_COUNT > i ; i++ ) {
1471 for( j = 0 ; RETROSOFT_GLYPHS_COUNT > j ; j++ ) {
1472 retval = retroglu_load_glyph( i, j );
1473 maug_cleanup_if_not_ok();
1487void retroglu_destroy_glyph_tex() {
1489#ifndef RETROGLU_NO_TEXTURE_LISTS
1493 debug_printf( RETROGLU_TRACE_LVL,
"destroying glyph textures..." );
1495 for( i = 0 ; RETROSOFT_SETS_COUNT > i ; i++ ) {
1496 for( j = 0 ; RETROSOFT_GLYPHS_COUNT > j ; j++ ) {
1497 glDeleteTextures( 1, (GLuint*)&(g_retroglu_font_tex[i][j]) );
1506#define RETROGLU_FONT_W 0.05f
1508void retroglu_string(
1509 float x,
float y,
float z,
const RETROGLU_COLOR color,
1510 const char* str,
size_t str_sz,
const char* font_str, uint8_t flags
1512#ifndef RETROGLU_NO_TEXTURES
1514# ifdef RETROGLU_NO_TEXTURE_LISTS
1519 str_sz = maug_strlen( str );
1522 for( i = 0 ; str_sz > i ; i++ ) {
1524 if(
'\0' == str[i] ) {
1528 glColor3fv( color );
1530#ifdef RETROGLU_NO_TEXTURE_LISTS
1531 retval = retroglu_load_glyph( 0, str[i] -
' ' );
1532 maug_cleanup_if_not_ok();
1534 glBindTexture( GL_TEXTURE_2D, g_retroglu_font_tex[0][str[i] -
' '] );
1536 glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
1537 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
1538 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
1540 glBegin( GL_TRIANGLES );
1542 glTexCoord2f( 0, 0 );
1543 glVertex3f( x + (RETROGLU_FONT_W * i), y, z );
1544 glTexCoord2f( 1, 0 );
1545 glVertex3f( x + (RETROGLU_FONT_W * i) + RETROGLU_FONT_W, y, z );
1546 glTexCoord2f( 1, 1 );
1548 x + (RETROGLU_FONT_W * i) + RETROGLU_FONT_W,
1549 y + RETROGLU_FONT_W, z );
1551 glTexCoord2f( 1, 1 );
1553 x + (RETROGLU_FONT_W * i) + RETROGLU_FONT_W,
1554 y + RETROGLU_FONT_W, z );
1555 glTexCoord2f( 0, 1 );
1556 glVertex3f( x + (RETROGLU_FONT_W * i), y + RETROGLU_FONT_W, z );
1557 glTexCoord2f( 0, 0 );
1558 glVertex3f( x + (RETROGLU_FONT_W * i), y, z );
1562# ifdef RETROGLU_NO_TEXTURE_LISTS
1563 glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA,
1565 GL_RGBA, GL_UNSIGNED_BYTE, NULL );
1567 glBindTexture( GL_TEXTURE_2D, 0 );
1571# ifdef RETROGLU_NO_TEXTURE_LISTS
1584#ifndef RETROGLU_NO_ERRORS
1588 gl_retval = glGetError();
1589 if( GL_NO_ERROR != gl_retval ) {
1590 error_printf(
"GL error on %s: 0x%x", desc, gl_retval );
1591 retval = MERROR_GUI;
1593 }
while( GL_NO_ERROR != gl_retval );
1608 &(g_retroflat_state->
buffer) != bmp &&
1609 (MAUG_MHANDLE)NULL != bmp->tex.bytes_h
1611 bmp->
flags |= RETROFLAT_FLAGS_LOCK;
1612 maug_mlock( bmp->tex.bytes_h, bmp->tex.bytes );
1625 if( NULL == bmp || &(g_retroflat_state->
buffer) == bmp ) {
1629# if defined( RETROFLAT_API_SDL1 )
1630 SDL_GL_SwapBuffers();
1631# elif defined( RETROFLAT_API_SDL2 )
1632 SDL_GL_SwapWindow( g_retroflat_state->platform.window );
1633# elif defined( RETROFLAT_API_WIN16 ) || defined( RETROFLAT_API_WIN32 )
1634 SwapBuffers( g_retroflat_state->platform.hdc_win );
1635# elif defined( RETROFLAT_API_GLUT )
1638 }
else if( retroflat_bitmap_locked( bmp ) ) {
1639#ifndef RETROGLU_NO_TEXTURES
1640 bmp->
flags &= ~RETROFLAT_FLAGS_LOCK;
1641# ifndef RETROGLU_NO_TEXTURE_LISTS
1642 assert( 0 < bmp->tex.id );
1643 assert( NULL != bmp->tex.bytes );
1646 glBindTexture( GL_TEXTURE_2D, bmp->tex.id );
1647 glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, bmp->tex.w, bmp->tex.h, 0,
1648 GL_RGBA, GL_UNSIGNED_BYTE, bmp->tex.bytes );
1649 glBindTexture( GL_TEXTURE_2D, 0 );
1653 maug_munlock( bmp->tex.bytes_h, bmp->tex.bytes );
1666#ifndef RETROGLU_NO_TEXTURES
1669 MAUG_MHANDLE bmp_palette_h = (MAUG_MHANDLE)NULL;
1670 uint32_t bmp_color = 0;
1671 uint32_t* bmp_palette = NULL;
1672 MAUG_MHANDLE bmp_px_h = (MAUG_MHANDLE)NULL;
1673 uint8_t* bmp_px = NULL;
1674 off_t bmp_px_sz = 0;
1683 maug_cleanup_if_not_ok();
1686 header_bmp.magic[0] =
'B';
1687 header_bmp.magic[1] =
'M';
1688 header_bmp.info.sz = 40;
1690 retval = mfmt_read_bmp_header(
1692 &bmp_file, 0, mfile_get_sz( &bmp_file ), &bmp_flags );
1693 maug_cleanup_if_not_ok();
1695 assert( 0 < mfile_get_sz( &bmp_file ) );
1698 bmp_out->tex.w = header_bmp.info.width;
1699 bmp_out->tex.h = header_bmp.info.height;
1700 bmp_out->tex.sz = bmp_out->tex.w * bmp_out->tex.h * 4;
1701 bmp_out->tex.bpp = 24;
1704 bmp_palette_h = maug_malloc( 4, header_bmp.info.palette_ncolors );
1705 maug_cleanup_if_null_alloc( MAUG_MHANDLE, bmp_palette_h );
1707 maug_mlock( bmp_palette_h, bmp_palette );
1708 maug_cleanup_if_null_alloc( uint32_t*, bmp_palette );
1710 retval = mfmt_read_bmp_palette(
1712 bmp_palette, 4 * header_bmp.info.palette_ncolors,
1713 &bmp_file, 54 , mfile_get_sz( &bmp_file ) - 54, bmp_flags );
1714 maug_cleanup_if_not_ok();
1717 bmp_px_sz = header_bmp.info.width * header_bmp.info.height;
1718 bmp_px_h = maug_malloc( 1, bmp_px_sz );
1719 maug_cleanup_if_null_alloc( MAUG_MHANDLE, bmp_px_h );
1721 maug_mlock( bmp_px_h, bmp_px );
1722 maug_cleanup_if_null_alloc( uint8_t*, bmp_px );
1727 &bmp_file, header_bmp.px_offset,
1728 mfile_get_sz( &bmp_file ) - header_bmp.px_offset, bmp_flags );
1729 maug_cleanup_if_not_ok();
1732 debug_printf( 0,
"creating bitmap: " SIZE_T_FMT
" x " SIZE_T_FMT,
1733 bmp_out->tex.w, bmp_out->tex.h );
1734 bmp_out->tex.bytes_h = maug_malloc( bmp_out->tex.w * bmp_out->tex.h, 4 );
1735 maug_cleanup_if_null_alloc( MAUG_MHANDLE, bmp_out->tex.bytes_h );
1737 maug_mlock( bmp_out->tex.bytes_h, bmp_out->tex.bytes );
1738 maug_cleanup_if_null_alloc( uint8_t*, bmp_out->tex.bytes );
1741 for( i = 0 ; bmp_px_sz > i ; i++ ) {
1742 if( bmp_px_sz - i - 1 > bmp_px_sz ) {
1744 "pixel overflow! (" OFF_T_FMT
" of " OFF_T_FMT
" bytes!)",
1745 bmp_px_sz - i - 1, bmp_px_sz );
1746 retval = MERROR_OVERFLOW;
1751 bmp_color_idx = bmp_px[bmp_px_sz - i - 1];
1752 if( bmp_color_idx >= header_bmp.info.palette_ncolors ) {
1754 "invalid color at px " OFF_T_FMT
": %02x",
1755 bmp_px_sz - i - 1, bmp_color_idx );
1758 bmp_color = bmp_palette[bmp_color_idx];
1759 bmp_r = (bmp_color >> 16) & 0xff;
1760 bmp_g = (bmp_color >> 8) & 0xff;
1761 bmp_b = bmp_color & 0xff;
1763 bmp_out->tex.bytes[i * 4] = bmp_r;
1764 bmp_out->tex.bytes[(i * 4) + 1] = bmp_g;
1765 bmp_out->tex.bytes[(i * 4) + 2] = bmp_b;
1773 bmp_out->tex.bytes[(i * 4) + 3] = 0x00;
1775 bmp_out->tex.bytes[(i * 4) + 3] = 0xff;
1779# ifndef RETROGLU_NO_TEXTURE_LISTS
1780 glGenTextures( 1, (GLuint*)&(bmp_out->tex.id) );
1781 glBindTexture( GL_TEXTURE_2D, bmp_out->tex.id );
1782 glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, bmp_out->tex.w, bmp_out->tex.h, 0,
1783 GL_RGBA, GL_UNSIGNED_BYTE, bmp_out->tex.bytes );
1784 glBindTexture( GL_TEXTURE_2D, 0 );
1789 if( NULL != bmp_out->tex.bytes ) {
1790 maug_munlock( bmp_out->tex.bytes_h, bmp_out->tex.bytes );
1793 if( NULL != bmp_px ) {
1794 maug_munlock( bmp_px_h, bmp_px );
1797 if( NULL != bmp_px_h ) {
1798 maug_mfree( bmp_px_h );
1801 if( NULL != bmp_palette ) {
1802 maug_munlock( bmp_palette_h, bmp_palette );
1805 if( NULL != bmp_palette_h ) {
1806 maug_mfree( bmp_palette_h );
1823#ifdef RETROGLU_NO_TEXTURES
1824 error_printf(
"textures not enabled!" );
1825 retval = MERROR_GUI;
1829 error_printf(
"warning! attempting to create texture with w > 256 ("
1830 SIZE_T_FMT
"). This may not work on Win32!", w );
1834 error_printf(
"warning! attempting to create texture with h > 256 ("
1835 SIZE_T_FMT
"). This may not work on Win32!", h );
1841 debug_printf( 0,
"creating bitmap: " SIZE_T_FMT
" x " SIZE_T_FMT,
1842 bmp_out->tex.w, bmp_out->tex.h );
1843 bmp_out->tex.bytes_h =
1844 maug_malloc( bmp_out->tex.w * bmp_out->tex.h, 4 );
1845 maug_cleanup_if_null_alloc( MAUG_MHANDLE, bmp_out->tex.bytes_h );
1847 maug_mlock( bmp_out->tex.bytes_h, bmp_out->tex.bytes );
1848 maug_cleanup_if_null_lock( uint8_t*, bmp_out->tex.bytes );
1853 bmp_out->tex.w * bmp_out->tex.h *
sizeof( uint32_t ) );
1855# ifndef RETROGLU_NO_TEXTURE_LISTS
1856 glGenTextures( 1, (GLuint*)&(bmp_out->tex.id) );
1857 debug_printf( RETROFLAT_BITMAP_TRACE_LVL,
1858 "assigned bitmap texture: " UPRINTF_U32_FMT, bmp_out->tex.id );
1859 retval = retroglu_check_errors(
"gentextures" );
1860 maug_cleanup_if_not_ok();
1864 if( NULL != bmp_out->tex.bytes ) {
1865 maug_munlock( bmp_out->tex.bytes_h, bmp_out->tex.bytes );
1876#ifndef RETROGLU_NO_TEXTURES
1877 debug_printf( 1,
"destroying bitmap..." );
1879 if( NULL != bmp->tex.bytes ) {
1880 maug_munlock( bmp->tex.bytes_h, bmp->tex.bytes );
1883 if( NULL != bmp->tex.bytes_h ) {
1884 maug_mfree( bmp->tex.bytes_h );
1887# ifndef RETROGLU_NO_TEXTURE_LISTS
1888 if( 0 < bmp->tex.id ) {
1890 "destroying bitmap texture: " UPRINTF_U32_FMT, bmp->tex.id );
1891 glDeleteTextures( 1, (GLuint*)&(bmp->tex.id) );
1901 size_t s_x,
size_t s_y,
size_t d_x,
size_t d_y,
size_t w,
size_t h,
1915 assert( NULL != target->tex.bytes );
1918 assert( !retroflat_bitmap_locked( src ) );
1919 maug_mlock( src->tex.bytes_h, src->tex.bytes );
1920 for( y_iter = 0 ; h > y_iter ; y_iter++ ) {
1923 &(target->tex.bytes[(((y_iter * target->tex.w) + d_x) * 4)]),
1924 &(src->tex.bytes[(((y_iter * src->tex.w) + s_x) * 4)]),
1927 maug_munlock( src->tex.bytes_h, src->tex.bytes );
1938 size_t x,
size_t y, uint8_t flags
1942 RETROFLAT_FLAGS_BITMAP_RO ==
1943 (RETROFLAT_FLAGS_BITMAP_RO & target->
flags) ||
1944 target->tex.w <= x ||
1950 assert( NULL != target->tex.bytes );
1954 target->tex.bytes[(((y * target->tex.w) + x) * 4) + 0] =
1955 g_retroflat_state->tex_palette[color_idx][0];
1956 target->tex.bytes[(((y * target->tex.w) + x) * 4) + 1] =
1957 g_retroflat_state->tex_palette[color_idx][1];
1958 target->tex.bytes[(((y * target->tex.w) + x) * 4) + 2] =
1959 g_retroflat_state->tex_palette[color_idx][2];
1962 target->tex.bytes[(((y * target->tex.w) + x) * 4) + 3] = 0xff;
1967# define RETROFLAT_COLOR_TABLE_GL( idx, name_l, name_u, r, g, b, cgac, cgad ) \
1968 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
MERROR_RETVAL mfmt_read_bmp_px(struct MFMT_STRUCT *header, uint8_t SEG_FAR *px, off_t px_sz, mfile_t *p_file_in, uint32_t file_offset, off_t file_sz, uint8_t flags)
Read mfmt_bitmap pixels into an 8-bit memory bitmap.
#define maug_mzero(ptr, sz)
Zero the block of memory pointed to by ptr.
Definition mmem.h:62
MERROR_RETVAL mfile_open_read(const char *filename, mfile_t *p_file)
Open a file and read it into memory or memory-map it.
void mfile_close(mfile_t *p_file)
Close a file opened with mfile_open_read().
#define RETROFLAT_TXP_G
Compiler-define-overridable constant indicating the Green value of the transparency color on platform...
Definition retroflt.h:616
#define RETROFLAT_TXP_B
Compiler-define-overridable constant indicating the Blue value of the transparency color on platforms...
Definition retroflt.h:625
#define RETROFLAT_TXP_R
Compiler-define-overridable constant indicating the Red value of the transparency color on platforms ...
Definition retroflt.h:607
int8_t RETROFLAT_COLOR
Defines an index in the platform-specific color-table.
Definition retroflt.h:307
#define RETROFLAT_COLOR_TABLE(f)
This macro defines all colors supported by RetroFlat for primative operations, particularly using ret...
Definition retroflt.h:288
#define RETROFLAT_PATH_SEP
The valid path separator on the target platform.
Definition retroflt.h:745
#define RETROFLAT_FLAGS_OPAQUE
Flag for retroflat_create_bitmap() to create a bitmap without transparency.
Definition retroflt.h:361
#define RETROFLAT_OK
Certain functions return this when there was no problem.
Definition retroflt.h:327
void retroglu_parse_init(struct RETROGLU_PARSER *parser, struct RETROGLU_OBJ *obj, retroglu_mtl_cb load_mtl, void *load_mtl_data)
Initialize a RETROGLU_PARSER.
#define retroglu_parser_state(parser, new_state)
Change the parser state.
Definition retroglu.h:308
MERROR_RETVAL retroglu_parse_obj_c(struct RETROGLU_PARSER *parser, unsigned char c)
Parse OBJ data into a parser, one character at a time.
int(* retroglu_mtl_cb)(const char *filename, struct RETROGLU_PARSER *parser, void *data)
Callback to execute when its associate in RETROGLU_OBJ_TOKENS is found in an OBJ file.
Definition retroglu.h:335
#define RETROGLU_OBJ_TOKENS(f)
Table of OBJ file tokens understood by the parser.
Definition retroglu.h:316
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...
#define retroflat_screen_h()
Get the current screen height in pixels.
Definition retpltd.h:38
#define retroflat_screen_buffer()
Get the direct screen buffer or the VDP buffer if a VDP is loaded.
Definition retpltd.h:41
#define retroflat_screen_w()
Get the current screen width in pixels.
Definition retpltd.h:35
Generic image description struct.
Definition mfmt.h:62
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
struct RETROFLAT_BITMAP buffer
Off-screen buffer bitmap.
Definition retroflt.h:1272
Definition retroglu.h:120
uint16_t vertex_idxs[RETROGLU_FACE_VERTICES_SZ_MAX]
List of vertex indices from the associated RETROGLU_PARSER::vertices.
Definition retroglu.h:127
Definition retroglu.h:111
Definition retroglu.h:138
struct RETROGLU_FACE faces[RETROGLU_FACES_SZ_MAX]
List of faces from an OBJ file. Faces comprise a list of polygons denoted by index of the vertices in...
Definition retroglu.h:150
As retroglu_parse_obj_c() parses OBJ data, it populates this struct with object information.
Definition retroglu.h:342
Definition retroglu.h:213
If draw lists are disabled, this struct holds a list of params for retroglu_set_sprite_clip() so that...
Definition retroglu.h:173
Definition retroglu.h:183
Definition retroglu.h:200
Definition retroglu.h:100
Definition retroglu.h:106