BlueGit

timfa frameworkv3

Files

frameworkv3 / framework / engine / TEMP_FOR_REFERENCE_main.js

TEMP_FOR_REFERENCE_main.js

It begins
timfa Tim · pushed by timfa · 2 years ago
8e521cb1 History
TEMP_FOR_REFERENCE_main.js 1.7 KiB Download Raw
1// main.js
2window.onload = init;
3
4class Vector2
5{
6 constructor (x, y)
7 {
8 this.x = x;
9 this.y = y;
10 }
11}
12
13const canvas = document.getElementById('canvas');
14canvas.width = window.innerWidth;
15canvas.height = window.innerHeight;
16
17// Create the renderer (it will load default shaders if not provided)
18const renderer = new Renderer(canvas, "bumpmap_vert", "bumpmap_frag");
19
20const spriteImage = new Image();
21spriteImage.src = 'sprite.png';
22
23const normalImage = new Image();
24normalImage.src = 'normal.png';
25
26const position = new Vector2(200, 200);
27
28const scale = new Vector2(0.4, 0.4);
29var angle = 45;
30var texture;
31var normalTexture;
32
33// TODO: See if we can use the old Framework way of loading images, better than this
34spriteImage.onload = () =>
35{
36 texture = renderer.loadTexture(spriteImage);
37};
38
39normalImage.onload = () =>
40{
41 normalTexture = renderer.loadTexture(normalImage);
42};
43
44function init ()
45{
46 setInterval(() =>
47 {
48 drawLoop();
49 }, 10);
50}
51
52
53function drawLoop ()
54{
55 angle += 0.3;
56
57 // Update the light direction
58 const angleInRadians = (angle % 360) * (Math.PI / 180);
59 const lightDirection = [
60 Math.cos(angleInRadians),
61 Math.sin(angleInRadians),
62 0.2 // A default z-component for the light direction, adjust as needed
63 ];
64
65 renderer.bindTexture(normalTexture, renderer.gl.TEXTURE1);
66 // Render your sprite
67 renderer.render(
68 texture,
69 position,
70 scale,
71 0,
72 canvas.width,
73 canvas.height,
74 {
75 'u_normalMap': { unit: 1 }, // Example uniform
76 'u_lightDirection': [lightDirection[0], lightDirection[1], lightDirection[2]]
77 }
78 );
79}