9 bool leftPressed, rightPressed;
12 // ////////////////////////////////////////////////////////////////////////// //
13 // this is called when vccrun need to refresh/redraw the screen
15 GLVideo.depthTest = false;
17 GLVideo.glSetColor(1, 1, 1);
19 GLVideo.clearScreen();
21 GLVideo.color = 0xff_ff_ff;
22 drawer.drawDoomBox(boxPoint, 16);
26 // ////////////////////////////////////////////////////////////////////////// //
27 // this is called on each event
28 void onEvent (ref event_t evt) {
29 if (evt.type == ev_closequery) { GLVideo.requestQuit(); writeln("exiting (", evt.data1, ")"); return; }
30 if (evt.type == ev_keyup && ((evt.keycode == K_q && evt.bCtrl) || evt.keycode == K_ESCAPE)) {
31 // call this to stop event loop
32 GLVideo.requestQuit();
36 if (evt.type == ev_keydown || evt.type == ev_keyup) {
37 switch (evt.keycode) {
40 case K_BUTTON_DPAD_LEFT:
41 leftPressed = (evt.type == ev_keydown);
46 case K_BUTTON_DPAD_RIGHT:
47 rightPressed = (evt.type == ev_keydown);
52 if (evt.type == ev_joystick) {
53 print("jidx=%d; dx=%d; dy=%d", evt.joyidx, evt.dx, evt.dy);
58 // ////////////////////////////////////////////////////////////////////////// //
59 // this is called on each new frame (kind of timer)
62 if (leftPressed && boxPoint.x > 0) boxPoint.x -= 1;
63 if (rightPressed && boxPoint.x < 800) boxPoint.x += 1;
64 // request screen refresh
65 // do not call `onDraw()` manuslly, use this API instead!
66 GLVideo.requestRefresh();
71 drawer = SpawnObject(SimpleDraw);
72 scope(exit) delete drawer;
79 boxPoint = vector(400, 300);
81 // milliseconds in one frame
82 // `onNewFrame()` will be called with roughly this interval
83 GLVideo.frameTime = int(1000/30); // 30 FPS
85 GLVideo.openScreen("Simple Gfx Demo", 800, 600);
86 scope(exit) GLVideo.closeScreen();
87 //GLVideo.swapInterval = 0; // turn off VSync
88 GLVideo.swapInterval = 1; // turn on VSync
89 GLVideo.runEventLoop();