lbirkert / svelte-ogl

typed port of OGL to svelte components.

Home Page:https://lbirkert.com/svelte-ogl/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

svelte-ogl

A port of OGL to Svelte. Fully typed.

npm i -D svelte-ogl

Example

<script lang="ts">
	import { Canvas, Camera, Mesh, Scene } from "svelte-ogl";
	import { Program, Plane } from "ogl";

	const uniforms = {
		time: { value: 0 },
	};
</script>

<Canvas
	on:render={(e) => uniforms.time.value = e.detail.time / 1000}
>
	<Camera />

	<Scene>
		<Mesh
			program={(gl) => new Program(gl, {
				vertex: /* glsl */ `
                		attribute vec2 uv;
                		attribute vec2 position;
                		varying vec2 vUv;

                		void main() {
               				vUv = uv;
               				gl_Position = vec4(position, 0, 1);
                		}
                		`,
                		fragment: /* glsl */ `
                		precision highp float;
                		uniform float time;

                		void main() {
                    			gl_FragColor = vec4(vUv * sin(time), 1, 1);
                		}
                		`,
				uniforms
			})}
			geometry={(gl) =>
				new Plane(gl, {
				width: 2,
				height: 2
			})}
		/>
	</Scene>
</Canvas>

Report Bug

Please refer to the issues page!

Feature Request

Please refer to the issues page!

About

typed port of OGL to svelte components.

https://lbirkert.com/svelte-ogl/

License:MIT License


Languages

Language:Svelte 66.1%Language:TypeScript 24.4%Language:JavaScript 6.9%Language:HTML 2.2%Language:CSS 0.4%