//
// a simple debugtext example.
//
use tksdl;
use tkopengl;
int numframesrendered = 0;
function onDraw() {
//
// Render graphics
//
float dt = FPS.precision;
// Clear the screen
glClearColor(0, 0, 0.2, 1);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
//
// Test simple debug text
//
DebugText.Draw(10, 10, "hello, debugtext world.", #ff10f010, #ff008000);
//
// Test custom debug text
//
DebugText.BindTexture();
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_COLOR, GL_ONE_MINUS_SRC_COLOR);
zglInitOrtho(1, 1);
glLoadIdentity();
zglColorARGB(#ffffa040);
DebugText.DrawScaled3f(-0.8, 0.3, 0, (1.0/200), (1.0/100), "hello, scaled debugtext world.");
if( !(++numframesrendered & 127) )
{
trace "FPS.real=" + FPS.real;
}
}
function onMouse(int _x, int _y, int _cbs, int _nbs) {
//
// Handle mouse event
//
print "[dbg] onMouse: x="+_x+" y="+_y+" cbs="+_cbs+" nbs="+_nbs;
}
function onReopen() {
//
// Handle window resize
//
DebugText.OnReopen();
}
function onKeyboard(Key _k) {
//
// Handle keyboard event
//
trace "[dbg] onKeyboard: k.code="+_k.code+" k.mod="+_k.mod+" k.name=\""+_k.name+"\".";
switch(_k.pressed)
{
case VKEY_ESCAPE:
SDL.exitEventLoop();
break;
}
}
function main() {
// Open desktop window
Viewport.openWindow(640, 480);
Viewport.caption = "debugtext.tsl example";
// Bind onMouse, onKeyboard, onDraw, onReopen callback functions
use callbacks;
// Set FPS limiter
FPS.tickInterval = 1000.0/30;
FPS.limit = 30;
// Load textures
onReopen();
// Execute main event loop
trace "[dbg] entering eventloop";
SDL.eventLoop();
}