Skip to content

Commit

Permalink
...
Browse files Browse the repository at this point in the history
  • Loading branch information
memoryleak47 committed Oct 14, 2020
1 parent 127b62a commit b0c5594
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
1 change: 1 addition & 0 deletions web/site/src/draw/mod.js
Expand Up @@ -4,6 +4,7 @@ export function init() {
e2.canvas = document.getElementById("main-canvas");
e2.canvas.width = window.innerWidth;
e2.canvas.height = window.innerHeight;
e2.gl = e2.canvas.getContext("webgl");

playermod.init();
// tilemap.init();
Expand Down
16 changes: 8 additions & 8 deletions web/site/src/draw/player/init.js
@@ -1,8 +1,8 @@
export function init() {
var canvas = e2.canvas;
var gl = canvas.getContext("webgl");
export var state = {};

e2.gl = gl;
export function init() {
var gl = e2.gl;
state.gl = gl;

const vsSource = `
attribute vec2 aVertexPosition;
Expand All @@ -28,7 +28,7 @@ export function init() {
`;

const shaderProgram = initShaderProgram(gl, vsSource, fsSource);
e2.programInfo = {
state.programInfo = {
program: shaderProgram,
attribLocations: {
vertexPosition: gl.getAttribLocation(shaderProgram, 'aVertexPosition'),
Expand All @@ -49,12 +49,12 @@ export function init() {
1.0, 0.0,
];
const tc = [r.slice(0, 6), r.slice(2,8), r.slice(0, 6), r.slice(2,8)].flat();
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(tc), gl.STATIC_DRAW);
e2.buffers = {
state.gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(tc), gl.STATIC_DRAW);
state.buffers = {
position: gl.createBuffer(),
textureCoord: textureCoordBuffer,
};
e2.texture = loadTexture(gl, './file.png');
state.texture = loadTexture(gl, './file.png');
}

function initShaderProgram(gl, vsSource, fsSource) {
Expand Down
13 changes: 6 additions & 7 deletions web/site/src/draw/player/mod.js
@@ -1,11 +1,10 @@
export { init } from "./init.js";
import { player_rect, game_to_screen_point } from "./math.js";
import { init, state } from "./init.js";
import { player_rect } from "./math.js";

export function draw() {
var gl = e2.gl;
var buffers = e2.buffers;
var programInfo = e2.programInfo;
export { init }

export function draw() {
const { gl, programInfo, buffers, texture } = state;
gl.bindBuffer(gl.ARRAY_BUFFER, buffers.position);

const r0 = player_rect(0);
Expand Down Expand Up @@ -57,7 +56,7 @@ export function draw() {

gl.useProgram(programInfo.program);
gl.activeTexture(gl.TEXTURE0);
gl.bindTexture(gl.TEXTURE_2D, e2.texture);
gl.bindTexture(gl.TEXTURE_2D, texture);
gl.uniform1i(programInfo.uniformLocations.uSampler, 0);

{
Expand Down

0 comments on commit b0c5594

Please sign in to comment.