This commit is contained in:
Kbz-8 2024-01-30 22:22:47 +01:00
parent 94f3838df3
commit f9e9538159
4 changed files with 27 additions and 18 deletions

View File

@ -93,4 +93,5 @@ function loadShader(gl, type, source)
return shader;
}
export let shaderInfos = null;
export { initShaderProgram };

View File

@ -16,10 +16,18 @@ class Segment
* @param {CanvasRenderingContext2D} ctx
*/
draw(ctx)
{
if(this.gl instanceof CanvasRenderingContext2D)
{
ctx.moveTo(this.start.x, this.start.y);
ctx.lineTo(this.stop.x, this.stop.y);
}
else if(this.gl instanceof WebGLRenderingContext)
{
}
else
alert('Unknown rendering context type');
}
from_json(data)
{

View File

@ -7,8 +7,8 @@ import HomeView from "./views/HomeView.js";
import RegisterView from "./views/accounts/RegisterView.js";
import LogoutView from "./views/accounts/LogoutView.js";
import GameOfflineView from "./views/GameOfflineView.js";
import GameView from "./views/GameView.js";
//import GameView from "./views/GameView3D.js";
//import GameView from "./views/GameView.js";
import GameView from "./views/GameView3D.js";
import PageNotFoundView from './views/PageNotFoundView.js'

View File

@ -2,6 +2,7 @@ import { client } from "../index.js";
import { Game } from "../api/game/Game.js";
import AbstractView from "./abstracts/AbstractView.js";
import { initShaderProgram } from "../3D/shaders.js"
import shaderInfos from "../3D/shaders.js"
import { initBuffers } from "../3D/buffers.js"
import "../3D/maths/gl-matrix-min.js"
@ -16,7 +17,6 @@ export default class extends AbstractView
this.gl = null;
this.shader_prog = null;
this.buffers = null;
this.programInfo = null;
}
initGL()
@ -33,7 +33,7 @@ export default class extends AbstractView
this.shader_prog = initShaderProgram(this.gl);
this.buffers = initBuffers(this.gl);
this.programInfo = {
shaderInfos = {
program: this.shader_prog,
attribLocations: {
vertexPosition: this.gl.getAttribLocation(this.shader_prog, "aPos"),
@ -90,16 +90,16 @@ export default class extends AbstractView
this.setPositionAttribute();
this.setNormalAttribute();
this.gl.useProgram(this.programInfo.program);
this.gl.useProgram(shaderInfos.program);
this.gl.uniformMatrix4fv(
this.programInfo.uniformLocations.projectionMatrix,
shaderInfos.uniformLocations.projectionMatrix,
false,
projectionMatrix
);
// rendering player bar
this.renderCube(0.0, -5.0, -8.0, 0.0, 5);
//this.game.draw(this.gl);
//this.renderCube(1, 0, -15);
}
renderCube(x, y, z, angle = 0, sx = 1, sy = 1, sz = 1)
@ -130,12 +130,12 @@ export default class extends AbstractView
mat4.transpose(normalMatrix, normalMatrix);
this.gl.uniformMatrix4fv(
this.programInfo.uniformLocations.modelViewMatrix,
shaderInfos.uniformLocations.modelViewMatrix,
false,
modelViewMatrix
);
this.gl.uniformMatrix4fv(
this.programInfo.uniformLocations.normalMatrix,
shaderInfos.uniformLocations.normalMatrix,
false,
normalMatrix,
);
@ -155,17 +155,17 @@ export default class extends AbstractView
const offset = 0;
this.gl.bindBuffer(this.gl.ARRAY_BUFFER, this.buffers.normal);
this.gl.vertexAttribPointer(
this.programInfo.attribLocations.vertexNormal,
shaderInfos.attribLocations.vertexNormal,
numComponents,
type,
normalize,
stride,
offset,
);
this.gl.enableVertexAttribArray(this.programInfo.attribLocations.vertexNormal);
this.gl.enableVertexAttribArray(shaderInfos.attribLocations.vertexNormal);
}
setPositionAttribute(programInfo)
setPositionAttribute()
{
const numComponents = 3;
const type = this.gl.FLOAT;
@ -175,14 +175,14 @@ export default class extends AbstractView
this.gl.bindBuffer(this.gl.ARRAY_BUFFER, this.buffers.vertex);
this.gl.bindBuffer(this.gl.ELEMENT_ARRAY_BUFFER, this.buffers.index);
this.gl.vertexAttribPointer(
this.programInfo.attribLocations.vertexPosition,
shaderInfos.attribLocations.vertexPosition,
numComponents,
type,
normalize,
stride,
offset
);
this.gl.enableVertexAttribArray(this.programInfo.attribLocations.vertexPosition);
this.gl.enableVertexAttribArray(shaderInfos.attribLocations.vertexPosition);
}
render_game()