skinned gui srgb option

main
Dominik Madarász 2024-03-26 20:15:30 +01:00
parent 3b69af1247
commit b8be40e489
13 changed files with 44 additions and 39 deletions

View File

@ -1668,6 +1668,9 @@ typedef struct spine_t spine_t;
void spine_render(spine_t *p, vec3 offset, unsigned flags);
void spine_animate(spine_t *p, float delta);
void ui_spine(spine_t *p);
enum ATLAS_FLAGS {
ATLAS_SRGB = 2,
};
typedef struct atlas_frame_t {
unsigned delay;
vec4 sheet;
@ -1755,7 +1758,7 @@ typedef struct skinned_t {
atlas_t atlas;
float scale;
} skinned_t;
guiskin_t gui_skinned(const char *asefile, float scale);
guiskin_t gui_skinned(const char *asefile, float scale, bool load_as_srgb);
bool steam_init(unsigned app_id);
void steam_tick();
void steam_trophy(const char *trophy_id, bool redeem);

View File

@ -9,7 +9,7 @@
void demo_kids(vec3 offs) {
// init
static texture_t kids; do_once kids = texture( "spriteSheetExample.png", TEXTURE_LINEAR );
static texture_t kids; do_once kids = texture( "spriteSheetExample.png", TEXTURE_LINEAR|TEXTURE_SRGB );
static vec3 pos[2] = {{490,362},{442,362}}, vel[2] = {0};
static int row[2] = {0,3}, frame[2] = {0};
static int inputs[2][4] = {{KEY_W,KEY_A,KEY_S,KEY_D},{KEY_UP,KEY_LEFT,KEY_DOWN,KEY_RIGHT}};
@ -39,7 +39,7 @@ void demo_kids(vec3 offs) {
void demo_hud() {
// draw pixel-art hud, 16x16 ui element, scaled and positioned in resolution-independant way
static texture_t inputs; do_once inputs = texture( "prompts_tilemap_34x24_16x16x1.png", TEXTURE_LINEAR );
static texture_t inputs; do_once inputs = texture( "prompts_tilemap_34x24_16x16x1.png", TEXTURE_LINEAR|TEXTURE_SRGB );
float spritesheet[3] = {17,34,24}, offset[2] = {0, - 2*absf(sin(window_time()*5))}; // sprite cell and animation
float scale[2] = {3, 3}, tile_w = 16 * scale[0], tile_h = 16 * scale[1]; // scaling
float position[3] = {window_width() - tile_w, window_height() - tile_h, window_height() }; // position in screen-coordinates (x,y,z-index)

View File

@ -3,7 +3,7 @@
int main() {
window_create(75.0, 0 );
gui_pushskin(gui_skinned("golden.ase", 3.0f)); // x3 scale
gui_pushskin(gui_skinned("golden.ase", 3.0f, 1)); // x3 scale, sRGB enabled
skinned_t *skinned = (skinned_t*)gui_userdata();
vec4 pos = vec4(400,400,100, 30);

View File

@ -150,10 +150,10 @@ int main(int argc, char **argv) {
if(do_cats) NUM_SPRITES/=2; // cat-sprite+cat-shadow == 2 sprites
// load sprites and sheets
kids = texture( "spriteSheetExample.png", TEXTURE_LINEAR );
catImage = texture( "cat.png", TEXTURE_LINEAR ); //
shadowImage = texture( "cat-shadow.png", TEXTURE_LINEAR );
inputs = texture( "prompts_tilemap_34x24_16x16x1.png", TEXTURE_LINEAR );
kids = texture( "spriteSheetExample.png", TEXTURE_LINEAR|TEXTURE_SRGB );
catImage = texture( "cat.png", TEXTURE_LINEAR|TEXTURE_SRGB ); //
shadowImage = texture( "cat-shadow.png", TEXTURE_LINEAR|TEXTURE_SRGB );
inputs = texture( "prompts_tilemap_34x24_16x16x1.png", TEXTURE_LINEAR|TEXTURE_SRGB );
// load all fx files, including subdirs
fx_load("fx**.fs");

View File

@ -1,5 +1,4 @@
uniform sampler2D u_texture;
uniform float u_gamma; /// set:2.2
in vec2 vTexCoord;
in vec4 vColor;
@ -54,5 +53,4 @@ void main() {
vec4 texColor = texture_AA2(u_texture, vTexCoord);
if(texColor.a < 0.9) discard;
fragColor = vColor * texColor;
fragColor.rgb = pow(fragColor.rgb, vec3(u_gamma));
}

View File

@ -1,5 +1,4 @@
uniform sampler2D texture0; /*unit0*/
uniform float u_inv_gamma;
uniform vec4 u_tint;
uniform int u_has_tex;
@ -13,5 +12,4 @@ void main() {
} else {
fragcolor = u_tint;
}
fragcolor.rgb = pow( fragcolor.rgb, vec3( u_inv_gamma ) ); // defaults: 1.0/2.2 gamma
}

View File

@ -18104,6 +18104,11 @@ API void ui_spine(spine_t *p);
// ----------------------------------------------------------------------------
// atlas api
enum ATLAS_FLAGS {
ATLAS_SRGB = 2,
};
typedef struct atlas_frame_t {
unsigned delay;
vec4 sheet;
@ -18245,7 +18250,7 @@ typedef struct skinned_t {
// - "_hover" (ex. "slider_cursor_hover")
// - "_press"
//
API guiskin_t gui_skinned(const char *asefile, float scale);
API guiskin_t gui_skinned(const char *asefile, float scale, bool load_as_srgb);
#line 0
#line 1 "v4k_steam.h"
@ -364094,7 +364099,7 @@ API void gui_drawrect( texture_t spritesheet, vec2 tex_start, vec2 tex_end, int
#define v42v2(rect) vec2(rect.x,rect.y), vec2(rect.z,rect.w)
void gui_drawrect( texture_t texture, vec2 tex_start, vec2 tex_end, int rgba, vec2 start, vec2 end ) {
static int program = -1, vbo = -1, vao = -1, u_inv_gamma = -1, u_tint = -1, u_has_tex = -1, u_window_width = -1, u_window_height = -1;
static int program = -1, vbo = -1, vao = -1, u_tint = -1, u_has_tex = -1, u_window_width = -1, u_window_height = -1;
float gamma = window_get_gamma();
vec2 dpi = ifdef(osx, window_dpi(), vec2(1,1));
if( program < 0 ) {
@ -364103,7 +364108,6 @@ void gui_drawrect( texture_t texture, vec2 tex_start, vec2 tex_end, int rgba, ve
program = shader(vs, fs, "", "fragcolor" , NULL);
ASSERT(program > 0);
u_inv_gamma = glGetUniformLocation(program, "u_inv_gamma");
u_tint = glGetUniformLocation(program, "u_tint");
u_has_tex = glGetUniformLocation(program, "u_has_tex");
u_window_width = glGetUniformLocation(program, "u_window_width");
@ -364122,7 +364126,6 @@ void gui_drawrect( texture_t texture, vec2 tex_start, vec2 tex_end, int rgba, ve
GLenum texture_type = texture.flags & TEXTURE_ARRAY ? GL_TEXTURE_2D_ARRAY : GL_TEXTURE_2D;
glUseProgram( program );
glUniform1f( u_inv_gamma, (gamma + !gamma) );
glBindVertexArray( vao );
@ -364551,9 +364554,9 @@ void skinned_getscissorrect(void* userdata, const char *skin, const char *fallba
dims->w -= (skinsize.y - coresize.y);
}
guiskin_t gui_skinned(const char *asefile, float scale) {
guiskin_t gui_skinned(const char *asefile, float scale, bool load_as_srgb) {
skinned_t *a = REALLOC(0, sizeof(skinned_t));
a->atlas = atlas_create(asefile, 0);
a->atlas = atlas_create(asefile, load_as_srgb?ATLAS_SRGB:0);
a->scale = scale?scale:1.0f;
guiskin_t skin={0};
skin.userdata = a;
@ -375862,7 +375865,6 @@ static void sprite_render_meshes_group(batch_group_t* sprites, int alpha_key, in
}
shader_bind(sprite_program);
shader_mat44("u_mvp", mvp);
shader_float("u_gamma", window_get_gamma() + !window_get_gamma());
// set (unit 0) in the uniform texture sampler, and render batch
glActiveTexture(GL_TEXTURE0);
@ -376946,7 +376948,7 @@ atlas_t atlas_create(const char *inifile, unsigned flags) {
else if( strend(k, "bitmap") ) {
const char *text = v;
array(char) bin = base64_decode(text, strlen(text));
a.tex = texture_from_mem(bin, array_count(bin), 0);
a.tex = texture_from_mem(bin, array_count(bin), flags&ATLAS_SRGB ? TEXTURE_SRGB : 0);
array_free(bin);
}
#if 0
@ -377070,7 +377072,7 @@ void sprite_edit(sprite_t *s) {
sprite_t* sprite_new(const char *ase, int bindings[6]) {
sprite_t *s = obj_new(sprite_t, {bindings[0],bindings[1],bindings[2],bindings[3]}, {bindings[4],bindings[5]});
atlas_t own = atlas_create(ase, 0);
atlas_t own = atlas_create(ase, ATLAS_SRGB);
memcpy(s->a = MALLOC(sizeof(atlas_t)), &own, sizeof(atlas_t)); // s->a = &s->own;
return s;
}

View File

@ -6,7 +6,7 @@ API void gui_drawrect( texture_t spritesheet, vec2 tex_start, vec2 tex_end, int
#define v42v2(rect) vec2(rect.x,rect.y), vec2(rect.z,rect.w)
void gui_drawrect( texture_t texture, vec2 tex_start, vec2 tex_end, int rgba, vec2 start, vec2 end ) {
static int program = -1, vbo = -1, vao = -1, u_inv_gamma = -1, u_tint = -1, u_has_tex = -1, u_window_width = -1, u_window_height = -1;
static int program = -1, vbo = -1, vao = -1, u_tint = -1, u_has_tex = -1, u_window_width = -1, u_window_height = -1;
float gamma = window_get_gamma();
vec2 dpi = ifdef(osx, window_dpi(), vec2(1,1));
if( program < 0 ) {
@ -15,7 +15,6 @@ void gui_drawrect( texture_t texture, vec2 tex_start, vec2 tex_end, int rgba, ve
program = shader(vs, fs, "", "fragcolor" , NULL);
ASSERT(program > 0);
u_inv_gamma = glGetUniformLocation(program, "u_inv_gamma");
u_tint = glGetUniformLocation(program, "u_tint");
u_has_tex = glGetUniformLocation(program, "u_has_tex");
u_window_width = glGetUniformLocation(program, "u_window_width");
@ -34,7 +33,6 @@ void gui_drawrect( texture_t texture, vec2 tex_start, vec2 tex_end, int rgba, ve
GLenum texture_type = texture.flags & TEXTURE_ARRAY ? GL_TEXTURE_2D_ARRAY : GL_TEXTURE_2D;
glUseProgram( program );
glUniform1f( u_inv_gamma, (gamma + !gamma) );
glBindVertexArray( vao );
@ -463,9 +461,9 @@ void skinned_getscissorrect(void* userdata, const char *skin, const char *fallba
dims->w -= (skinsize.y - coresize.y);
}
guiskin_t gui_skinned(const char *asefile, float scale) {
guiskin_t gui_skinned(const char *asefile, float scale, bool load_as_srgb) {
skinned_t *a = REALLOC(0, sizeof(skinned_t));
a->atlas = atlas_create(asefile, 0);
a->atlas = atlas_create(asefile, load_as_srgb?ATLAS_SRGB:0);
a->scale = scale?scale:1.0f;
guiskin_t skin={0};
skin.userdata = a;

View File

@ -62,4 +62,4 @@ typedef struct skinned_t {
// - "_hover" (ex. "slider_cursor_hover")
// - "_press"
//
API guiskin_t gui_skinned(const char *asefile, float scale);
API guiskin_t gui_skinned(const char *asefile, float scale, bool load_as_srgb);

View File

@ -280,7 +280,6 @@ static void sprite_render_meshes_group(batch_group_t* sprites, int alpha_key, in
}
shader_bind(sprite_program);
shader_mat44("u_mvp", mvp);
shader_float("u_gamma", window_get_gamma() + !window_get_gamma());
// set (unit 0) in the uniform texture sampler, and render batch
glActiveTexture(GL_TEXTURE0);
@ -1364,7 +1363,7 @@ atlas_t atlas_create(const char *inifile, unsigned flags) {
else if( strend(k, "bitmap") ) {
const char *text = v;
array(char) bin = base64_decode(text, strlen(text));
a.tex = texture_from_mem(bin, array_count(bin), 0);
a.tex = texture_from_mem(bin, array_count(bin), flags&ATLAS_SRGB ? TEXTURE_SRGB : 0);
array_free(bin);
}
#if 0
@ -1488,7 +1487,7 @@ void sprite_edit(sprite_t *s) {
sprite_t* sprite_new(const char *ase, int bindings[6]) {
sprite_t *s = obj_new(sprite_t, {bindings[0],bindings[1],bindings[2],bindings[3]}, {bindings[4],bindings[5]});
atlas_t own = atlas_create(ase, 0);
atlas_t own = atlas_create(ase, ATLAS_SRGB);
memcpy(s->a = MALLOC(sizeof(atlas_t)), &own, sizeof(atlas_t)); // s->a = &s->own;
return s;
}

View File

@ -83,6 +83,11 @@ API void ui_spine(spine_t *p);
// ----------------------------------------------------------------------------
// atlas api
enum ATLAS_FLAGS {
ATLAS_SRGB = 2,
};
typedef struct atlas_frame_t {
unsigned delay;
vec4 sheet;

View File

@ -11249,7 +11249,7 @@ API void gui_drawrect( texture_t spritesheet, vec2 tex_start, vec2 tex_end, int
#define v42v2(rect) vec2(rect.x,rect.y), vec2(rect.z,rect.w)
void gui_drawrect( texture_t texture, vec2 tex_start, vec2 tex_end, int rgba, vec2 start, vec2 end ) {
static int program = -1, vbo = -1, vao = -1, u_inv_gamma = -1, u_tint = -1, u_has_tex = -1, u_window_width = -1, u_window_height = -1;
static int program = -1, vbo = -1, vao = -1, u_tint = -1, u_has_tex = -1, u_window_width = -1, u_window_height = -1;
float gamma = window_get_gamma();
vec2 dpi = ifdef(osx, window_dpi(), vec2(1,1));
if( program < 0 ) {
@ -11258,7 +11258,6 @@ void gui_drawrect( texture_t texture, vec2 tex_start, vec2 tex_end, int rgba, ve
program = shader(vs, fs, "", "fragcolor" , NULL);
ASSERT(program > 0);
u_inv_gamma = glGetUniformLocation(program, "u_inv_gamma");
u_tint = glGetUniformLocation(program, "u_tint");
u_has_tex = glGetUniformLocation(program, "u_has_tex");
u_window_width = glGetUniformLocation(program, "u_window_width");
@ -11277,7 +11276,6 @@ void gui_drawrect( texture_t texture, vec2 tex_start, vec2 tex_end, int rgba, ve
GLenum texture_type = texture.flags & TEXTURE_ARRAY ? GL_TEXTURE_2D_ARRAY : GL_TEXTURE_2D;
glUseProgram( program );
glUniform1f( u_inv_gamma, (gamma + !gamma) );
glBindVertexArray( vao );
@ -11706,9 +11704,9 @@ void skinned_getscissorrect(void* userdata, const char *skin, const char *fallba
dims->w -= (skinsize.y - coresize.y);
}
guiskin_t gui_skinned(const char *asefile, float scale) {
guiskin_t gui_skinned(const char *asefile, float scale, bool load_as_srgb) {
skinned_t *a = REALLOC(0, sizeof(skinned_t));
a->atlas = atlas_create(asefile, 0);
a->atlas = atlas_create(asefile, load_as_srgb?ATLAS_SRGB:0);
a->scale = scale?scale:1.0f;
guiskin_t skin={0};
skin.userdata = a;
@ -23017,7 +23015,6 @@ static void sprite_render_meshes_group(batch_group_t* sprites, int alpha_key, in
}
shader_bind(sprite_program);
shader_mat44("u_mvp", mvp);
shader_float("u_gamma", window_get_gamma() + !window_get_gamma());
// set (unit 0) in the uniform texture sampler, and render batch
glActiveTexture(GL_TEXTURE0);
@ -24101,7 +24098,7 @@ atlas_t atlas_create(const char *inifile, unsigned flags) {
else if( strend(k, "bitmap") ) {
const char *text = v;
array(char) bin = base64_decode(text, strlen(text));
a.tex = texture_from_mem(bin, array_count(bin), 0);
a.tex = texture_from_mem(bin, array_count(bin), flags&ATLAS_SRGB ? TEXTURE_SRGB : 0);
array_free(bin);
}
#if 0
@ -24225,7 +24222,7 @@ void sprite_edit(sprite_t *s) {
sprite_t* sprite_new(const char *ase, int bindings[6]) {
sprite_t *s = obj_new(sprite_t, {bindings[0],bindings[1],bindings[2],bindings[3]}, {bindings[4],bindings[5]});
atlas_t own = atlas_create(ase, 0);
atlas_t own = atlas_create(ase, ATLAS_SRGB);
memcpy(s->a = MALLOC(sizeof(atlas_t)), &own, sizeof(atlas_t)); // s->a = &s->own;
return s;
}

View File

@ -4171,6 +4171,11 @@ API void ui_spine(spine_t *p);
// ----------------------------------------------------------------------------
// atlas api
enum ATLAS_FLAGS {
ATLAS_SRGB = 2,
};
typedef struct atlas_frame_t {
unsigned delay;
vec4 sheet;
@ -4312,7 +4317,7 @@ typedef struct skinned_t {
// - "_hover" (ex. "slider_cursor_hover")
// - "_press"
//
API guiskin_t gui_skinned(const char *asefile, float scale);
API guiskin_t gui_skinned(const char *asefile, float scale, bool load_as_srgb);
#line 0
#line 1 "v4k_steam.h"