transparent-cube

Minimal cross-platform native/wasm graphics example.
Log | Files | Refs | README | LICENSE

commit 1539bdcf09db13476f3a29ae9553590a7fa4ab99
parent 1b1ff8075ecf699293259b93ad3e581956044d62
Author: Amin Mesbah <dev@aminmesbah.com>
Date:   Sun, 23 Jun 2019 11:12:04 -0700

Resize the webgl viewport

Diffstat:
Mjs/imports.js | 3+++
Msrc/game.c | 1+
Msrc/webgl.h | 6++++++
Mwasm_js_implemented_symbols.txt | 1+
4 files changed, 11 insertions(+), 0 deletions(-)

diff --git a/js/imports.js b/js/imports.js @@ -143,6 +143,9 @@ imports["webglUseProgram"] = function(program_id) { imports["webglVertexAttribPointer"] = function(index, size, type, normalized, stride, offset) { gl.vertexAttribPointer(index, size, type, normalized, stride, offset); } +imports["webglViewport"] = function(x, y, width, height) { + gl.viewport(x, y, width, height); +} imports["js_read_entire_file"] = function(name, name_len, out_buf) { let file_name = utf8decoder.decode(memory.subarray(name, name + name_len)) diff --git a/src/game.c b/src/game.c @@ -121,6 +121,7 @@ void game_init(struct GameState *game_state, u32 screen_width, u32 screen_height void game_update_and_render(struct GameState *game_state, float dt, u32 screen_width, u32 screen_height) { + glViewport(0, 0, screen_width, screen_height); #if 1 { glClearColor(0.1f, 0.1f, 0.1f, 1.0f); diff --git a/src/webgl.h b/src/webgl.h @@ -40,6 +40,7 @@ void webglUniform3f(i32 location, f32 x, f32 y, f32 z); void webglUniformMatrix4fv(i32 location, const f32 data[static 16]); void webglUseProgram(i32 program); void webglVertexAttribPointer(i32 index, i32 size, i32 type, i32 normalized, i32 stride, i32 offset); +void webglViewport(i32 x, i32 y, i32 width, i32 height); #define GL_DEPTH_BUFFER_BIT 0x00000100 #define GL_COLOR_BUFFER_BIT 0x00004000 @@ -269,4 +270,9 @@ inline void glVertexAttribPointer(GLuint index, GLint size, GLenum type, GLboole webglVertexAttribPointer(WEBGL_CAST_I32(index), WEBGL_CAST_I32(size), WEBGL_CAST_I32(type), WEBGL_CAST_I32(normalized), WEBGL_CAST_I32(stride), WEBGL_CAST_I32(pointer)); } +inline void glViewport(GLint x, GLint y, GLsizei width, GLsizei height) +{ + webglViewport(x, y, WEBGL_CAST_I32(width), WEBGL_CAST_I32(height)); +} + #undef WEBGL_CAST_I32 diff --git a/wasm_js_implemented_symbols.txt b/wasm_js_implemented_symbols.txt @@ -32,5 +32,6 @@ webglUniform3f webglUniformMatrix4fv webglUseProgram webglVertexAttribPointer +webglViewport js_read_entire_file js_print