fixing WebGL warnings
This commit is contained in:
@ -1,6 +1,4 @@
|
||||
import { shaderInfos } from "../3D/shaders.js"
|
||||
|
||||
function renderCube(ctx, x, y, z, angle = 0, sx = 1, sy = 1, sz = 1)
|
||||
function renderCube(ctx, shader_infos, x, y, z, angle = 0, sx = 1, sy = 1, sz = 1)
|
||||
{
|
||||
const modelMatrix = mat4.create();
|
||||
|
||||
@ -23,18 +21,12 @@ function renderCube(ctx, x, y, z, angle = 0, sx = 1, sy = 1, sz = 1)
|
||||
[sx, sy, sz]
|
||||
);
|
||||
|
||||
mat4.translate(
|
||||
modelMatrix,
|
||||
modelMatrix,
|
||||
[-1, 0, 0] // wtf, this works ?
|
||||
);
|
||||
|
||||
const normalMatrix = mat4.create();
|
||||
mat4.invert(normalMatrix, modelMatrix);
|
||||
mat4.transpose(normalMatrix, normalMatrix);
|
||||
|
||||
ctx.uniformMatrix4fv(shaderInfos.uniformLocations.modelMatrix, false, modelMatrix);
|
||||
ctx.uniformMatrix4fv(shaderInfos.uniformLocations.normalMatrix, false, normalMatrix);
|
||||
ctx.uniformMatrix4fv(shader_infos.uniformLocations.modelMatrix, false, modelMatrix);
|
||||
ctx.uniformMatrix4fv(shader_infos.uniformLocations.normalMatrix, false, normalMatrix);
|
||||
|
||||
ctx.drawElements(ctx.TRIANGLES, 36, ctx.UNSIGNED_SHORT, 0);
|
||||
}
|
||||
|
@ -44,7 +44,7 @@ export function initShaderProgram(gl)
|
||||
gl.attachShader(prog, fragmentShader);
|
||||
gl.linkProgram(prog);
|
||||
|
||||
shaderInfos = {
|
||||
const shaderInfos = {
|
||||
program: prog,
|
||||
attribLocations: {
|
||||
vertexPosition: gl.getAttribLocation(prog, "aPos"),
|
||||
@ -64,7 +64,7 @@ export function initShaderProgram(gl)
|
||||
return null;
|
||||
}
|
||||
|
||||
return prog;
|
||||
return shaderInfos;
|
||||
}
|
||||
|
||||
function loadShader(gl, type, source)
|
||||
@ -83,5 +83,3 @@ function loadShader(gl, type, source)
|
||||
|
||||
return shader;
|
||||
}
|
||||
|
||||
export let shaderInfos;
|
||||
|
Reference in New Issue
Block a user