Skip to content

Commit

Permalink
Cleanup debug
Browse files Browse the repository at this point in the history
  • Loading branch information
raub committed Oct 31, 2023
1 parent 242f508 commit 797cac3
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 50 deletions.
75 changes: 30 additions & 45 deletions examples/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,55 +2,48 @@

import Img from 'image-raub';
import gl from 'webgl-raub';
import glfw, { Document, platformDevice } from 'glfw-raub';
import { Document } from 'glfw-raub';
import { View } from 'qml-raub';


Document.setWebgl(gl);
const document = new Document({ vsync: true, autoEsc: true });
const release = () => document.makeCurrent();

const icon = new Img(__dirname + '/qml.png');
icon.on('load', () => { document.icon = (icon as unknown as typeof document.icon); });
document.title = 'QML';

console.log('p', document.platformContext, document.platformWindow, document.platformDevice);

const release = () => document.makeCurrent();

release();
View.init(process.cwd(), document.platformWindow, document.platformContext, document.platformDevice);

const ui = new View({ width: document.w, height: document.h, file: 'qml/gui.qml' });
release();

// document.on('mousedown', ui.mousedown.bind(ui));
// document.on('mouseup', ui.mouseup.bind(ui));
// document.on('mousemove', ui.mousemove.bind(ui));
// document.on('keydown', ui.keydown.bind(ui));
// document.on('keyup', ui.keyup.bind(ui));
// document.on('wheel', ui.wheel.bind(ui));

// document.on('resize', ({width, height}) => ui.wh = [width, height]);

// ui.on('mousedown', e => console.log('[>mousedown]', e));
// ui.on('mouseup', e => console.log('[>mouseup]', e));
// // ui.on('mousemove', e => console.log('[mousemove]', e));
// ui.on('keydown', e => console.log('[>keydown]', e));
// ui.on('keyup', e => console.log('[>keyup]', e));
// ui.on('wheel', e => console.log('[>wheel]', e));

// ui.on('ohai', data => {
// console.log('RECV', data);
// ui.set('myButton1', 'text', `${Date.now()}`);
// ui.invoke('myButton1', 'func', [{ uid: 'dwad2312414', value: 17 }]);
// });

// let texture = gl.createTexture();
document.on('mousedown', ui.mousedown.bind(ui));
document.on('mouseup', ui.mouseup.bind(ui));
document.on('mousemove', ui.mousemove.bind(ui));
document.on('keydown', ui.keydown.bind(ui));
document.on('keyup', ui.keyup.bind(ui));
document.on('wheel', ui.wheel.bind(ui));

document.on('resize', ({width, height}) => ui.wh = [width, height]);

ui.on('mousedown', e => console.log('[>mousedown]', e));
ui.on('mouseup', e => console.log('[>mouseup]', e));
// ui.on('mousemove', e => console.log('[mousemove]', e));
ui.on('keydown', e => console.log('[>keydown]', e));
ui.on('keyup', e => console.log('[>keyup]', e));
ui.on('wheel', e => console.log('[>wheel]', e));

ui.on('ohai', data => {
console.log('RECV', data);
ui.set('myButton1', 'text', `${Date.now()}`);
ui.invoke('myButton1', 'func', [{ uid: 'dwad2312414', value: 17 }]);
});

let texture = ui.textureId === null ? gl.createTexture() : new gl.WebGLTexture(ui.textureId);
console.log('tid0', ui.textureId);
// let texture = new gl.WebGLTexture(ui.textureId || 0);

ui.on('reset', (texId: number) => {
console.log('tid1', texId);
release();
texture = texId ? new gl.WebGLTexture(texId) : gl.createTexture();
});
Expand Down Expand Up @@ -85,8 +78,7 @@ const shaders = {
uniform vec2 size;
void main() {
vec2 uv = gl_FragCoord.xy / size.xy;
// gl_FragColor = texture2D(tex, uv);
gl_FragColor = (vec4(1.0, 0.0, 0.0, 1.0) + texture2D(tex, uv)) * 0.5;
gl_FragColor = texture2D(tex, uv);
}
`,
} as const;
Expand Down Expand Up @@ -194,26 +186,19 @@ const drawScene = () => {
const tick = () => {
setTimeout(tick, 16);

// View.update();
View.update();
release();

drawScene();
// (glfw.testScene as (w: number, h: number) => void)(document.width, document.height);
document.swapBuffers();

glfw.pollEvents();



// requestAnimFrame(tick);
requestAnimFrame(tick);
};

const start = () => {
initShaders();
initBuffers();

// gl.clearColor(0.0, 1.0, 0.0, 1.0);
// gl.enable(gl.DEPTH_TEST);
gl.clearColor(0.0, 0.0, 0.0, 1.0);
gl.enable(gl.DEPTH_TEST);

tick();
};
Expand Down
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
},
"dependencies": {
"addon-tools-raub": "^7.4.0",
"deps-qmlui-raub": "^3.1.0",
"deps-qmlui-raub": "^3.1.1",
"segfault-raub": "^2.1.2"
},
"devDependencies": {
Expand Down

0 comments on commit 797cac3

Please sign in to comment.