#include once "glfw3.bi"

sub _init_ constructor
	if glfwInit()=0 then
		dim as integer hFile = FreeFile()
		open err for output as #hFile
		print #hFile,"error: glfwInit() !"
		beep:sleep
		close #hFile
		end 1
	end if
end sub

sub _exit_ destructor
	glfwTerminate()
end sub

function CreateWindow(w as integer,h as integer,title as zstring ptr,fullscreen as integer=0) as GLFWwindow ptr
	dim as GLFWmonitor ptr mon=0
	if fullscreen then mon = glfwGetPrimaryMonitor()
	return glfwCreateWindow(w,h,title,mon,0)
end function

sub FramebufferSizeCallback CALLBACK (win as GLFWwindow ptr, w as integer, h as integer)
	glViewport(0,0,w,h)
end sub


dim as GLFWwindow ptr win = CreateWindow(800,600,"test01",1)
glfwSetFramebufferSizeCallback(win,@FramebufferSizeCallback)
glfwMakeContextCurrent(win)
while glfwWindowShouldClose(win)=0 and glfwGetKey(win,GLFW_KEY_ESCAPE)=0
	glfwSwapBuffers(win)
	glfwWaitEvents()
	glfwGetKey(win,GLFW_KEY_ESCAPE)
Wend