// ===========================================================================================================
static int colour_set_id = 0;
+static int world_theme_id = 0;
static v3f colour_sets[][4] =
{
},
};
+static struct world_theme
+{
+ const char *name;
+ v3f colour_bg;
+ vg_tex2d *tex_tiles;
+}
+world_themes[] =
+{
+ {
+ "Wood",
+ {},
+ &tex_tiles_wood
+ },
+ {
+ "Minimal",
+ {},
+ &tex_tiles_min
+ },
+ {
+ "Lab",
+ {},
+ &tex_tiles_lab
+ }
+};
+
static void colour_code_v3( char const cc, v3f target )
{
if( cc >= 'a' && cc <= 'z' )
}
}
+static void render_sprite( enum sprites_auto_combine_index id, v3f pos )
+{
+ struct vg_sprite *sp = &sprites_auto_combine[ id ];
+
+ glUniform4fv( SHADER_UNIFORM( shader_sprite, "uUv" ), 1, sp->uv_xywh );
+ glUniform3f( SHADER_UNIFORM( shader_sprite, "uPos" ), pos[0], pos[1], pos[2] * world.st.world_transition );
+
+ draw_mesh( 0, 2 );
+}
+
void vg_render(void)
{
glViewport( 0,0, vg_window_x, vg_window_y );
int const empty_start = circle_base+32;
int const empty_count = circle_base+32*2;
+ struct world_theme *theme = &world_themes[ world_theme_id ];
+
if( !world.initialzed )
return;
// Bind textures
vg_tex2d_bind( &tex_tile_data, 0 );
glUniform1i( SHADER_UNIFORM( shader_tile_main, "uTexGlyphs" ), 0 );
-
- vg_tex2d_bind( &tex_wood, 1 );
+
+ vg_tex2d_bind( theme->tex_tiles, 1 );
glUniform1i( SHADER_UNIFORM( shader_tile_main, "uTexWood" ), 1 );
render_tiles( colour_default, colour_default );
vg_tex2d_bind( &tex_tile_data, 0 );
glUniform1i( SHADER_UNIFORM( shader_tile_main, "uTexGlyphs" ), 0 );
- vg_tex2d_bind( &tex_wood, 1 );
+ // TODO: is this needed to be rebinded?
+ vg_tex2d_bind( theme->tex_tiles, 1 );
glUniform1i( SHADER_UNIFORM( shader_tile_main, "uTexWood" ), 1 );
glUniform1f( SHADER_UNIFORM( shader_tile_main, "uForeground" ), 1.0f );
if( vg_get_button_up( "primary" ) )
world_button_exec( NULL, NULL, NULL, NULL );
+
+ // SPRITES
+ // ========================================================================================================
+ SHADER_USE( shader_sprite );
+ glUniformMatrix3fv( SHADER_UNIFORM( shader_sprite, "uPv" ), 1, GL_FALSE, (float *)vg_pv );
+
+ vg_tex2d_bind( &tex_sprites, 0 );
+ glUniform1i( SHADER_UNIFORM( shader_sprite, "uTexMain" ), 0 );
+
+ for( int i = 0; i < world.tile_special_count; i ++ )
+ {
+ struct render_cmd *cmd = &world.cmd_buf_specials[i];
+ struct cell *cell = cmd->ptr;
+
+ if( cell->config == k_cell_type_split )
+ {
+ v2f center = { cmd->pos[0] + 0.5f, cmd->pos[1] + 0.5f };
+
+ v3f p0 = { 0.0f, 0.0f, 4.0f };
+ v3f p1 = { 0.0f, 0.0f, 4.0f };
+
+ v2_add( center, (v2f){ -0.25f, -0.25f }, p0 );
+ v2_add( center, (v2f){ 0.25f, -0.25f }, p1 );
+
+ render_sprite( k_sprite_jack_1, p0 );
+ render_sprite( k_sprite_jack_2, p1 );
+ }
+ }
// TEXT ELEMENTS
// ========================================================================================================
// SUB SPLITTER DIRECTION
// ========================================================================================================
- // TODO: Make this sprites probably
glUniform4f( SHADER_UNIFORM( shader_tile_colour, "uColour" ), 0.9f, 0.35f, 0.1f, 0.75f );
draw_mesh( cell->state & FLAG_FLIP_FLOP? 5: 4, 1 );
}
}
+
+ // LIGHT FLARES
+ // ========================================================================================================
+ glBlendFunc(GL_ONE, GL_ONE);
+ glBlendEquation(GL_FUNC_ADD);
+
+ SHADER_USE( shader_sprite );
+
+ vg_tex2d_bind( &tex_sprites, 0 );
+ glUniform1i( SHADER_UNIFORM( shader_sprite, "uTexMain" ), 0 );
+ for( int i = 0; i < world.tile_special_count; i ++ )
+ {
+ struct render_cmd *cmd = &world.cmd_buf_specials[i];
+ struct cell *cell = cmd->ptr;
+
+ if( cell->config == k_cell_type_split )
+ {
+ v2f center = { cmd->pos[0] + 0.5f, cmd->pos[1] + 0.5f };
+
+ v3f p0 = { 0.0f, 0.0f, 12.0f };
+ v3f p1 = { 0.0f, 0.0f, 12.0f };
+
+ v2_add( center, (v2f){ -0.25f, -0.25f }, p0 );
+ v2_add( center, (v2f){ 0.25f, -0.25f }, p1 );
+
+ if( cell->state & FLAG_FLIP_FLOP )
+ render_sprite( k_sprite_flare_y, p1 );
+ else
+ render_sprite( k_sprite_flare_b, p0 );
+ }
+ }
+
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+ glBlendEquation(GL_FUNC_ADD);
+
// I/O ARRAYS
// ========================================================================================================
//glEnable(GL_BLEND);
-
+ SHADER_USE( shader_tile_colour );
+
for( int i = 0; i < arrlen( world.io ); i ++ )
{
struct cell_terminal *term = &world.io[ i ];
.persistent = 1
});
+ vg_convar_push( (struct vg_convar){
+ .name = "theme",
+ .data = &world_theme_id,
+ .data_type = k_convar_dtype_i32,
+ .opt_i32 = { .min = 0, .max = vg_list_size( world_themes )-1, .clamp = 1 },
+ .persistent = 1,
+ });
+
// Combined quad, long quad / empty circle / filled circle mesh
{
float combined_mesh[6*6 + 32*6*3] = {
vg_tex2d tex_tile_data = { .path = "textures/tileset.qoi" };
vg_tex2d tex_tile_detail = { .path = "textures/tile_overlays.qoi" };
-vg_tex2d tex_wood = { .path = "textures/wood.qoi" };
+
+vg_tex2d tex_tiles_wood = { .path = "textures/tile_wood.qoi" };
+vg_tex2d tex_tiles_min = { .path = "textures/tile_minimal.qoi" };
+vg_tex2d tex_tiles_lab = { .path = "textures/tile_lab.qoi" };
+
vg_tex2d tex_ball_noise = { .path = "textures/bnoise.qoi" };
vg_tex2d tex_monofur = { .path = "textures/ascii.qoi", .flags = VG_TEXTURE_NO_MIP };
vg_tex2d tex_unkown = { .path = "textures/unkown.qoi" };
vg_tex2d tex_buttons = { .path = "textures/buttons.qoi" };
vg_tex2d tex_sprites = { .path = "textures/autocombine.qoi" };
-vg_tex2d *texture_list[] = { &tex_tile_detail, &tex_tile_data, &tex_wood, &tex_ball_noise, &tex_monofur, &tex_unkown, &tex_buttons, &tex_ubuntu, &tex_sprites };
+vg_tex2d *texture_list[] = {
+ &tex_tile_detail,
+ &tex_tile_data,
+ &tex_tiles_wood,
+ &tex_tiles_min,
+ &tex_tiles_lab,
+ &tex_ball_noise,
+ &tex_monofur,
+ &tex_unkown,
+ &tex_buttons,
+ &tex_ubuntu,
+ &tex_sprites
+};
#include "sprites_autocombine.h"
"float shadow = exp(-((shadow_coords_sqr.x+shadow_coords_sqr.y)-0.0125)*15.0);"
"vec3 marble_comp = uColour*0.9 + (noise_sample.x*0.7+pow(rim_light,3.0)*2.0) * 0.1;"
- "vec4 colour_comp = mix( vec4(0.74,0.53,0.34,shadow), vec4(marble_comp,1.0), circle_factor );"
+ //"vec4 colour_comp = mix( vec4(0.74,0.53,0.34,shadow), vec4(marble_comp,1.0), circle_factor );"
+ "vec4 colour_comp = mix( vec4(0.2,0.2,0.2,shadow), vec4(marble_comp,1.0), circle_factor );"
"FragColor = colour_comp;"
"}"
""
"void main()"
"{"
- "vec3 shadowing_colour = vec3( 0.93, 0.88536, 0.8184 ) * 0.97;"
+ //"vec3 shadowing_colour = vec3( 0.93, 0.88536, 0.8184 ) * 0.97;"
+ "vec3 shadowing_colour = vec3( 0.8, 0.8, 0.8 );"
+
"vec4 glyph = texture( uTexGlyphs, aTexCoords.xy );"
"vec4 wood = texture( uTexWood, aTexCoords.zw );"
"vec4 wood_secondary = texture( uTexWood, aTexCoords.zw + 0.25 );"
"vec3 wood_comp = mix( wood_secondary.rgb * shadowing_colour, wood.rgb, clamp( glyph.b * 2.0 - 1.0, 0.0, 1.0 ) );"
- "vec3 shadows = mix( vec3( 0.85, 0.7344, 0.561 ), vec3(1.0,1.0,1.0), glyph.r );"
+ //"vec3 shadows = mix( vec3( 0.85, 0.7344, 0.561 ), vec3(1.0,1.0,1.0), glyph.r );"
+ "vec3 shadows = mix( shadowing_colour, vec3(1.0,1.0,1.0), glyph.r );"
"vec4 output_regular = vec4( wood_comp * shadows, mix( glyph.a, glyph.b, uForeground ) );"
// VERTEX
"layout (location=0) in vec2 a_co;" // quad mesh
- "layout (location=1) in vec4 ins_uv;" // instanced data (uv)
- "layout (location=2) in vec3 ins_pos;" // position + scale
+ "uniform vec4 uUv;"
+ "uniform vec3 uPos;"
""
"uniform mat3 uPv;"
""
""
"void main()"
"{"
- "vec2 vertex_world = ins_uv.zw * a_co * ins_pos.z + ins_pos.xy;"
+ "vec2 vertex_world = uUv.zw * (a_co-0.5) * uPos.z + uPos.xy;"
"gl_Position = vec4( uPv * vec3( vertex_world, 1.0 ), 1.0 );"
- "aTexCoords = ins_uv.xy + (a_co+0.5)*ins_uv.zw;"
+ "aTexCoords = uUv.xy + a_co*uUv.zw;"
"}",
// FRAGMENT
"uniform sampler2D uTexMain;"
- "uniform vec4 uColour;"
"out vec4 FragColor;"
""
"in vec2 aTexCoords;"
""
"void main()"
"{"
- "vec4 glyph = texture( uTexGlyphs, aTexCoords );"
- "FragColor = glyph;"
+ "vec4 texture_sample = texture( uTexMain, aTexCoords );"
+ "FragColor = texture_sample;"
"}"
,
- UNIFORMS({ "uPv", "uTexMain", "uColour" })
+ UNIFORMS({ "uPv", "uTexMain", "uUv", "uPos" })
)
void vg_register(void)
SHADER_INIT( shader_wire );
SHADER_INIT( shader_buttons );
SHADER_INIT( shader_sdf );
+ SHADER_INIT( shader_sprite );
}
/*
-static enum sprites_auto_combine_index
+enum sprites_auto_combine_index
{
k_sprite_donut,
+ k_sprite_flare_b,
+ k_sprite_flare_y,
k_sprite_jack_1,
k_sprite_jack_2,
k_sprite_peg,
static struct vg_sprite sprites_auto_combine[] =
{
- { 0, 0, 8192, 8192 },
- { 8192, 0, 4096, 4096 },
- { 12288, 0, 4096, 4096 },
- { 16384, 0, 4096, 4096 },
+ {{ 0.000000, 0.000000, 0.125000, 0.125000 }},
+ {{ 0.125000, 0.000000, 0.125000, 0.125000 }},
+ {{ 0.250000, 0.000000, 0.125000, 0.125000 }},
+ {{ 0.375000, 0.000000, 0.062500, 0.062500 }},
+ {{ 0.437500, 0.000000, 0.062500, 0.062500 }},
+ {{ 0.500000, 0.000000, 0.062500, 0.062500 }}
};
\ No newline at end of file
return 0;
}
- fprintf( fp, "static enum %s_index\n{\n", argv[3] );
+ fprintf( fp, "enum %s_index\n{\n", argv[3] );
// Load images
// -----------
u8 *dest = (u8 *)malloc( 1024*1024*4 );
- // Clear (temp)
for( int i = 0; i < 1024*1024; i ++ )
{
dest[ i*4 + 0 ] = 0;
dest[ i*4 + 1 ] = 0;
- dest[ i*4 + 2 ] = 128;
- dest[ i*4 + 3 ] = 255;
+ dest[ i*4 + 2 ] = 0;
+ dest[ i*4 + 3 ] = 0;
}
struct region
};
int stack_h = 0;
- int sf = 64;
-
for( int i = 0; i < num_images; i ++ )
{
struct image_src *psrc = &source_images[ i ];
if( (pregion->p0[ 0 ] + psrc->x <= pregion->p1[0]) && (pregion->p0[ 1 ] + psrc->y <= pregion->p1[1]) )
{
// Passed, add image and create subdivisions
- fprintf( fp, "\t{ %hu, %hu, %hu, %hu },\n",
- (u16)(sf * pregion->p0[0]),
- (u16)(sf * pregion->p0[1]),
- (u16)(sf * psrc->x),
- (u16)(sf * psrc->y)
+ fprintf( fp, "\t{{ %f, %f, %f, %f }}",
+ (float)pregion->p0[0] / 1024.0f,
+ (float)pregion->p0[1] / 1024.0f,
+ (float)psrc->x / 1024.0f,
+ (float)psrc->y / 1024.0f
);
+ if( i != num_images-1 )
+ fputs( ",\n", fp );
+ else
+ fputc( '\n', fp );
+
// Write image
for( int y = 0; y < psrc->y; y ++ )
{
GLuint name;
};
-#pragma pack(push,1)
struct vg_sprite
{
- u16 uvx, uvy, w, h;
+ v4f uv_xywh;
};
-#pragma pack(pop)
static void vg_tex2d_bind( vg_tex2d *tex, u32 id )
{