commit 1066509cd372b54bc3323abc416eec22420b8e0a
parent 0638febb6ce2ac15f7d8acece64f19739270bec9
Author: amin <dev@aminmesbah.com>
Date: Sun, 23 Jun 2019 18:12:04 +0000
Resize the webgl viewport
FossilOrigin-Name: 3f3db863eaf650750b3a4eab02398e6038e8895b61f07b6d13a38a102fd713bd
Diffstat:
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