Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Sean Voisen committed Feb 25, 2018
0 parents commit 62462c2
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 0 deletions.
29 changes: 29 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Wasm Image Viewer</title>
<style>
html, body {
padding: 0;
margin: 0;
}
</style>
</head>
<body>
<canvas id="canvas" class="canvas"></canvas>
<script type="text/javascript">
const canvas = document.getElementById('canvas');
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
</script>
<script type="text/javascript" src="renderer.js"></script>
<script type="text/javascript" src="main.js"></script>
<script type="text/javascript">
Module.canvas = canvas;
ImageViewer.run(canvas);
</script>
</body>
</html>
20 changes: 20 additions & 0 deletions main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const ImageViewer = {};
(function (ImageViewer) {
'use strict';

function Program(canvas) {
const init = Module.initializeOpenGL(canvas.width, canvas.height);
};

Program.prototype.render = function () {

};

Program.prototype.invalidate = function () {
window.requestAnimationFrame(this.render.bind(this));
}

ImageViewer.run = function (canvas) {
new Program(canvas);
};
})(ImageViewer || (ImageViewer = {}));
14 changes: 14 additions & 0 deletions makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
CC=emcc
SRC=renderer.cpp
CFLAGS=-Werror -std=c++11 -O2 -g0
EMSCRIPTEN_FLAGS=-s USE_WEBGL2=1
OUTPUT=renderer.js

all: $(SRC) $(OUTPUT)

$(OUTPUT): $(SRC)
$(CC) $(SRC) $(CFLAGS) $(EMSCRIPTEN_FLAGS) --post-js renderer_post.js -o $(OUTPUT)

clean:
rm $(OUTPUT)
rm $(OUTPUT).mem
26 changes: 26 additions & 0 deletions renderer.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include <iostream>
#include <GLES3/gl3.h>
#include <GLES2/gl2ext.h>
#include <SDL/SDL.h>

#include <emscripten.h>

SDL_Surface* screen;

extern "C" {

int EMSCRIPTEN_KEEPALIVE initializeOpenGL(int width, int height) {
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER) == 0) {
screen = SDL_SetVideoMode(width, height, 0, SDL_OPENGL);
} else {
std::cerr << "Error initializing SDL: " << SDL_GetError() << std::endl;
return 0;
}

glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glViewport(0, 0, width, height);

return 1;
}

}
1 change: 1 addition & 0 deletions renderer_post.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Module['initializeOpenGL'] = Module.cwrap('initializeOpenGL', 'number', ['number', 'number']);

0 comments on commit 62462c2

Please sign in to comment.