made work in emscripten, and fixed transparency bug in shader
This commit is contained in:
parent
5e041ffbf0
commit
75f83bf3f6
|
@ -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() {
|
||||
|
|
BIN
gfx.png
BIN
gfx.png
Binary file not shown.
Before Width: | Height: | Size: 20 KiB After Width: | Height: | Size: 20 KiB |
|
@ -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
|
24
src/gsa.c
24
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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue