diff --git a/examples/gsa_simple.c b/examples/gsa_simple.c index 9d6bb38..721b7f9 100644 --- a/examples/gsa_simple.c +++ b/examples/gsa_simple.c @@ -9,7 +9,7 @@ void init() { sprites[1].x = 10; sprites[1].y = 100; - maps[0].tiles[20][1] = 2; + maps[0].tiles[20][1] = 1; } void tick() { diff --git a/gfx.png b/gfx.png index fcdb274..b9465fd 100644 Binary files a/gfx.png and b/gfx.png differ diff --git a/meson.build b/meson.build index 190d9e1..7ff324f 100644 --- a/meson.build +++ b/meson.build @@ -62,11 +62,12 @@ add_project_arguments('-Wall', language : 'c') add_project_arguments('-Wextra', language : 'c') add_project_arguments('-Werror', language : 'c') +lib = static_library('skunkworks', skunk_sources, include_directories: 'include', dependencies: deps) if host_machine.system() == 'emscripten' - executable('skunktest', skunk_sources, include_directories: 'include', dependencies: deps, link_args: ['-lglfw', '-lGL', '-s', 'USE_GLFW=3'], name_suffix: 'html') + executable('skunktest', link_with: lib, include_directories: 'include', dependencies: deps, link_args: ['-lglfw', '-lGL', '-s', 'USE_GLFW=3'], name_suffix: 'html') + executable('gsa', 'examples/gsa_simple.c', embed_gfx, link_with: lib, include_directories: 'include', dependencies: deps, link_args: ['-lglfw', '-lGL', '-s', 'USE_GLFW=3', '-s', 'ALLOW_MEMORY_GROWTH', '-s', 'FULL_ES3'], name_suffix: 'html') else - lib = static_library('skunkworks', skunk_sources, include_directories: 'include', dependencies: deps) executable('skunktest', 'src/test.c', link_with: lib, include_directories: 'include', dependencies: deps) executable('gsa', 'examples/gsa_simple.c', embed_gfx, link_with: lib, include_directories: 'include', dependencies: deps) endif \ No newline at end of file diff --git a/src/gsa.c b/src/gsa.c index c10a70e..281def9 100644 --- a/src/gsa.c +++ b/src/gsa.c @@ -15,25 +15,28 @@ struct gsa_map maps[MAX_TILEMAPS]; struct sw_image8 *_gfx; struct sw_window *_win; -static char *vert_source = "#version 450\n\ +static char *vert_source = "#version 300 es\n\ +precision highp float;\ in vec2 pos;\ in vec2 tex_coord;\ -layout(location = 0) out vec2 out_tex_coord;\ +out vec2 out_tex_coord;\ void main() {\ gl_Position = vec4((pos / vec2(152, -88)) - vec2(1, -1), 0.f, 1.f);\ out_tex_coord = tex_coord;\ }\ "; -static char *frag_source = "#version 450\n\ -layout(location = 0) in vec2 tex_coord;\ +static char *frag_source = "#version 300 es\n\ +precision highp float;\ +in vec2 out_tex_coord;\ uniform sampler2D tex;\ uniform vec4 palette[256];\ out vec4 color;\ void main(){\ -int r = int(texture(tex, tex_coord).r * 255);\ +int r = int(texture(tex, out_tex_coord).r * 255.f);\ if(r > 0)\ color = palette[r];\ +else discard;\ }\ "; @@ -56,7 +59,6 @@ int gsa_main(int argc, char *argv[]) { (void)argc; (void)argv; u32 tex; - struct sw_image8 *img; i32 max_components; sw_log("Initialising GameSkunkAdvance v0.0"); @@ -68,9 +70,8 @@ int gsa_main(int argc, char *argv[]) { glGetIntegerv(GL_MAX_VERTEX_UNIFORM_COMPONENTS, &max_components); sw_log("GL_MAX_VERTEX_UNIFORM_COMPONENTS: %i", max_components); - img = sw_image8_load_png("gfx.png"); - memcpy(palette, img->palette, sizeof(img->palette)); - sw_debug("%08X", img->palette[1]); + memcpy(palette, _gfx->palette, sizeof(_gfx->palette)); + sw_debug("%08X", _gfx->palette[1]); glGenTextures(1, &tex); glBindTexture(GL_TEXTURE_2D, tex); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); @@ -78,15 +79,14 @@ int gsa_main(int argc, char *argv[]) { glTexImage2D( GL_TEXTURE_2D, 0, - GL_RED, + GL_R8, 4096, 4096, 0, GL_RED, GL_UNSIGNED_BYTE, - img->_data + _gfx->_data ); - sw_image8_destroy(img); glGenBuffers(1, &vao); glBindVertexArray(vao); diff --git a/src/image32.c b/src/image32.c index 47af531..64a803d 100644 --- a/src/image32.c +++ b/src/image32.c @@ -7,7 +7,7 @@ #include "png.h" #include "vec2i.h" -void png_read_fn(png_structp png, png_bytep out, png_size_t count); +static void png_read_fn(png_structp png, png_bytep out, png_size_t count); struct sw_image32 *sw_image32_create(struct sw_vec2i size) { struct sw_image32 *image; @@ -103,7 +103,7 @@ sw_color32 sw_image32_get(struct sw_image32 *image, struct sw_vec2i pos) { /* private */ -void png_read_fn(png_structp png, png_bytep out, png_size_t count) { +static void png_read_fn(png_structp png, png_bytep out, png_size_t count) { struct sw_filebuffer *buf; buf = png_get_io_ptr(png); diff --git a/src/image8.c b/src/image8.c index d638c05..696dd79 100644 --- a/src/image8.c +++ b/src/image8.c @@ -8,7 +8,7 @@ #include "png.h" #include "vec2i.h" -void png_read_fn(png_structp png, png_bytep out, png_size_t count); +static void png_read_fn(png_structp png, png_bytep out, png_size_t count); struct sw_image8 *sw_image8_create(struct sw_vec2i size) { struct sw_image8 *image; @@ -117,7 +117,7 @@ sw_color8 sw_image8_get(struct sw_image8 *image, struct sw_vec2i pos) { /* private */ -void png_read_fn(png_structp png, png_bytep out, png_size_t count) { +static void png_read_fn(png_structp png, png_bytep out, png_size_t count) { struct sw_filebuffer *buf; buf = png_get_io_ptr(png);