diff --git a/sunpy/__init__.js b/sunpy/__init__.js new file mode 100644 index 0000000..a2a0bdb --- /dev/null +++ b/sunpy/__init__.js @@ -0,0 +1,4 @@ +// Map +import "./core/__init__.js"; +import "./node/__init__.js"; +import "./canvas/__init__.js"; \ No newline at end of file diff --git a/sunpy/canvas/__init__.js b/sunpy/canvas/__init__.js new file mode 100644 index 0000000..8eef80a --- /dev/null +++ b/sunpy/canvas/__init__.js @@ -0,0 +1,10 @@ +// Depends +import "../core/__init__.js"; +import "../node/__init__.js"; + +// Map +import "./entity.js"; +import "./helpers.js"; +import "./renderer.js"; + +import "./gl/texture.js"; \ No newline at end of file diff --git a/sunpy/canvas/entity.js b/sunpy/canvas/entity.js index 7cc2d03..fcabbfe 100644 --- a/sunpy/canvas/entity.js +++ b/sunpy/canvas/entity.js @@ -8,5 +8,11 @@ export class Sprite extends Entity { constructor(image) { if (!(image instanceof Image)) throw TypeError("Image has to be instance of `Image`"); + + this.image = image; + } + + async render(renderNode) { + } } \ No newline at end of file diff --git a/sunpy/canvas/gl/shaders/texture.fs b/sunpy/canvas/gl/shaders/texture.fs new file mode 100644 index 0000000..54717fc --- /dev/null +++ b/sunpy/canvas/gl/shaders/texture.fs @@ -0,0 +1,9 @@ +precision mediump float; + +uniform sampler2D u_texture; + +varying vec2 v_texcoord; + +void main() { + gl_FragColor = texture2D(u_texture, v_texcoord); +} \ No newline at end of file diff --git a/sunpy/canvas/gl/shaders/texture.vs b/sunpy/canvas/gl/shaders/texture.vs new file mode 100644 index 0000000..3e4366d --- /dev/null +++ b/sunpy/canvas/gl/shaders/texture.vs @@ -0,0 +1,11 @@ +attribute vec4 position; +attribute vec2 texcoord; + +uniform mat4 u_matrix; + +varying vec2 v_texcoord; + +void main() { + gl_Position = u_matrix * position; + v_texcoord = texcoord; +} \ No newline at end of file diff --git a/sunpy/canvas/gl/texture.js b/sunpy/canvas/gl/texture.js new file mode 100644 index 0000000..449be84 --- /dev/null +++ b/sunpy/canvas/gl/texture.js @@ -0,0 +1,23 @@ +//const fs = await (await fetch("./shaders/texture.fs")).text(); + +export async function compile() { + /* + const fs = await (await fetch("./shaders/texture.fs")).text(); + const vs = await (await fetch("./shaders/texture.vs")).text(); + */ + + const fs = import("./shaders/texture.fs"); + const vs = import("./shaders/texture.vs"); + + window.fs = fs; + window.vs = vs; + console.log("done"); +} + +export function drawImage(gl, tex, texWidth, texHeight, dstX, dstY) { + gl.bindTexture(gl.TEXTURE_2D, tex); + + gl.useProgram(program); // TODO + + +} \ No newline at end of file diff --git a/sunpy/canvas/helpers.js b/sunpy/canvas/helpers.js new file mode 100644 index 0000000..e69de29 diff --git a/sunpy/core/__init__.js b/sunpy/core/__init__.js new file mode 100644 index 0000000..5da60eb --- /dev/null +++ b/sunpy/core/__init__.js @@ -0,0 +1,3 @@ +// Map +import "./utils.js" +import "./vector.js"; \ No newline at end of file diff --git a/sunpy/node/__init__.js b/sunpy/node/__init__.js new file mode 100644 index 0000000..063c5b4 --- /dev/null +++ b/sunpy/node/__init__.js @@ -0,0 +1,7 @@ +// Map +import "./node.js"; +import "./propertyreader.js"; + +import "./nodes/basenode.js"; +import "./nodes/swapnode.js"; +import "./nodes/propertynode.js"; \ No newline at end of file diff --git a/sunpy/orep/__init__.js b/sunpy/orep/__init__.js new file mode 100644 index 0000000..90611ad --- /dev/null +++ b/sunpy/orep/__init__.js @@ -0,0 +1,2 @@ +// Map +import "./orep.js"; \ No newline at end of file diff --git a/sunpy/orep/orep.js b/sunpy/orep/orep.js index 866fa19..69b13b7 100644 --- a/sunpy/orep/orep.js +++ b/sunpy/orep/orep.js @@ -1,13 +1,3 @@ import { RenderNode } from "../canvas/renderer.js"; - -/* -var onloadOld = onload || (() => {}); -onload = () => { - onloadOld(); - init(); -} - -function init() { - -} -*/ \ No newline at end of file +import { compile } from "../canvas/gl/texture.js"; +window.compile = compile; diff --git a/tests/init.html b/tests/init.html index d64ae1b..133ccf5 100644 --- a/tests/init.html +++ b/tests/init.html @@ -11,7 +11,7 @@ console.log("TEST - onload defined before module load"); } - + +