Now with GLFW Events
Joshy
Code: Select all
' glFrameWorkEvents.bas
' test for the GLFW and events
#include once "inc/nativeminilib.bi"
#include once "inc/glfweventlib.bi"
#include once "inc/gllib.bi"
' create VM
dim as HSQUIRRELVM vm = sq_open(1024)
' register native mini lib
register_nativeminilib(vm)
' register opengl framework
register_glfweventlib(vm)
' register opengl
register_gllib(vm)
' register opengl util
register_glulib(vm)
SetHandlers(vm)
' load, compile and run a script
if SQ_FAILED(RunScriptFromFile(vm,"glFrameWorkEvents.nut")) then
? "error: RunScriptFromFile() !":beep
end if
' delete VM
sq_close(vm)
test script:
Code: Select all
/*
glFrameWorkEvent.nut
test for: GLFW events
*/
function WindowResizeEvent(w,h) {
local title = "windowsize = " + w + " x " + h
GLFW.SetWindowTitle(title)
if (w<1) w=1
if (h<1) h=1
GL.Viewport(0,0,w,h)
GL.MatrixMode(GL.PROJECTION)
GL.LoadIdentity()
GLU.Perspective(45.0, w/h,0.1, 100.0)
GL.MatrixMode(GL.MODELVIEW)
GL.LoadIdentity()
}
function MouseMoveEvent(x,y) {
local title = "mousepos = " + x + " , " + y
GLFW.SetWindowTitle(title)
}
function MouseButtonEvent(button,state) {
local title = "mousebutton[" + button + "] = " + state
GLFW.SetWindowTitle(title)
}
function MouseWheelEvent(wheelpos) {
local title = "mousewheel = " + wheelpos
GLFW.SetWindowTitle(title)
}
function KeyEvent(key,state) {
local title = "key[" + key + "] = " + state
GLFW.SetWindowTitle(title)
}
// half of the desktop
GLFW.OpenWindow(GLFW.DESKTOP_WIDTH/2,GLFW.DESKTOP_HEIGHT/2)
// centered on desktop
GLFW.SetWindowPos(GLFW.DESKTOP_WIDTH/4,GLFW.DESKTOP_HEIGHT/4)
GLFW.SetWindowTitle("GLFW event test resize window or use mouse or keyboard")
local rot=0.0
// turn off VSync (60Hz. on my box)
GLFW.SwapInterval(0)
GL.ClearColor(0.5,0.25,0,1)
while (GLFW.WindowOpen()==true) {
GL.Clear(GL.COLOR_BUFFER_BIT | GL.DEPTH_BUFFER_BIT)
GL.LoadIdentity()
GL.Translatef(0, 0, -2)
GL.Rotatef(rot,1,0,0)
GL.Rotatef(rot,0,1,0)
GL.Rotatef(rot,0,0,1)
GL.Begin(GL.QUADS)
GL.Color3f(1, 0, 0); GL.Vertex3f(-0.5,-0.5, 0)
GL.Color3f(0, 1, 0); GL.Vertex3f( 0.5,-0.5, 0)
GL.Color3f(0, 0, 1); GL.Vertex3f( 0.5, 0.5, 0)
GL.Color3f(0, 1, 1); GL.Vertex3f(-0.5, 0.5, 0)
GL.End()
GLFW.SwapBuffers()
GLFW.Sleep(1.0/100.0)
rot+=1.0
}