Browse Source

initialize webgl in a really shitty unoptimized way

master
blackle 3 years ago
parent
commit
f49d5b8ff8
3 changed files with 12 additions and 2 deletions
  1. +4
    -1
      Makefile
  2. +3
    -1
      gtk-webkit.c
  3. +5
    -0
      index.html

+ 4
- 1
Makefile View File

@ -10,7 +10,7 @@ shader.h : shader.frag Makefile
mono ./shader_minifier.exe --preserve-externals shader.frag -o shader.h
# not using `pkg-config --libs` here because it will include too many libs
gtk-webkit.elf : gtk-webkit.c Makefile
gtk-webkit.elf : gtk-webkit.c index.html.inc Makefile
gcc -o $@ $< `pkg-config --cflags webkit2gtk-4.0` -lgobject-2.0 -lgtk-3 -lwebkit2gtk-4.0 -no-pie -fno-plt -Os -std=gnu11 -nostartfiles -nostdlib
gtk-opengl.elf : gtk-opengl.c shader.h Makefile
@ -28,6 +28,9 @@ gtk-opengl : gtk-opengl_opt.elf.packed
xlib-opengl : xlib-opengl_opt.elf.packed
mv $< $@
index.html.inc : index.html
cat index.html | xxd -i > index.html.inc
echo ", 0" >> index.html.inc
#all the rest of these rules just takes a compiled elf file and generates a packed version of it with vondehi
%_opt.elf : %.elf Makefile


+ 3
- 1
gtk-webkit.c View File

@ -22,7 +22,9 @@ gboolean on_load_changed(WebKitWebView *web_view, WebKitLoadEvent load_event, Gt
return TRUE;
}
static char* html = "<style>html{cursor:none;overflow:hidden}body{transform:translateY(460px) rotate(20deg);font-family:FreeSans;font-size:150}</style>this is an html page! 😊<br><i style=\"font-size:50px;margin-left:100\">with webgl!</i>";
static char html[] = {
#include "index.html.inc"
};
void _start() {
asm volatile("sub $8, %rsp\n");


+ 5
- 0
index.html View File

@ -0,0 +1,5 @@
<style>*{margin:0px;padding:0px;overflow:hidden;}</style>
<canvas id="webgl" width="1920" height="1080"></canvas>
<script>
function sP(r,e,t){var a=r.createProgram(),o=function(e,t){var o=r.createShader("vertex"==e?r.VERTEX_SHADER:r.FRAGMENT_SHADER);r.shaderSource(o,t),r.compileShader(o),r.attachShader(a,o)};return o("vertex",e),o("fragment",t),r.linkProgram(a),a}function atsf(r,e,t,a,o){r.bindBuffer(r.ARRAY_BUFFER,r.createBuffer()),r.bufferData(r.ARRAY_BUFFER,new Float32Array(o),r.STATIC_DRAW);var i=r.getAttribLocation(e,t);r.enableVertexAttribArray(i),r.vertexAttribPointer(i,a,r.FLOAT,!1,0,0)}function dr(){var r=document.getElementById("webgl").getContext("webgl"),e=sP(r,"attribute vec2 ps;void main(){gl_Position=vec4(ps,0.,1.);}","void main(){gl_FragColor=vec4(gl_FragCoord.x/1920.,0.5,1.,1.);}");r.useProgram(e),atsf(r,e,"ps",2,[-1,1,1,1,-1,-1,1,-1]),r.drawArrays(r.TRIANGLE_STRIP,0,4)}setTimeout(dr,10),dr();
</script>

Loading…
Cancel
Save