This directory contains Visual Basic bindings for the GLFW v2.4.x Windows DLL, and Visual Basic example programs. For further information on how to use GLFW you should read the GLFW documentation.
Using GLFW is slightly different from what Visual Basic users may be used to, since GLFW replaces much of the functionality already built in to Visual Basic. For instance, mouse clicks and key presses that occur in a GLFW window are handled completely by GLFW, and in order to handle such events you have to rely on GLFW functionality. While this may feel odd at first, it does not necessarily have to be a disadvantage.
The most important thing to comprehend is the way a GLFW "main loop" works. Unlike ordinary Visual Basic programs, which are largely event based, GLFW programs usually have a core loop that runs "forever" (until aborted for some reason). To understand how it works, please look at the supplied example programs. You should also read the GLFW Users Guide, which explains how to use GLFW (regardless of programming language).
In order to use GLFW from a Visual Basic project, you need to add the file glfw.bas to your project (add existing module). It contains all the necessary constant, structure and function definitions. You also have to copy the file glfw.dll to your project directory.
Typically you want to call OpenGL functions from your Visual Basic program too. Threfore there are also bindings for opengl32.dll and glu32.dll included in this distribution, namely opengl32.bas and glu32.bas. Note that these files have not been tested fully, so there may be bugs in them (please report them if you find them).
If you wish to make a "pure" GLFW project (no forms), you can create a a new module, in which you place a procedure named 'Main':
Private Sub Main()
End Sub
Then select Project Properties, and under the General tab, in the Startup Object field, select Sub Main. This is how the example programs are meant to be used.
It is of course possible to mix Visual Basic forms and GLFW code. For instance you can have a form button that starts your OpenGL program by initializing GLFW, opening a GLFW window and entering a GLFW main loop etc.
In principle, the GLFW functions can be called with the same syntax as described in the GLFW Reference Manual. The primary difference is that some GLFW functions are treated as Visual Basic subroutines ("Sub"), which means that you should not use parentheses around the argument list. The functions that are treated as subroutines are functions that, in 'C' terms, return "void" (in other words, nothing). An example is the glfwGetMousePos function, which should be called like this:
glfwGetMousePos xpos, ypos
To be honest, my knowledge in Visual Basic is quite limited, so there may be other options and other things to consider. Have a look at the example programs for examples of how to call GLFW functions.
GLFW callback functions are very similar to Visual Basic event subroutines (e.g. Private Sub Command1_Click()). The primary difference is that you have to specify the functions manually, using GLFW functions (such as glfwSetMousePosCallback). GLFW callback functions, once registered, are called only when glfwSwapBuffers or glfwPollEvents are called (if there are any corresponding events pending).
Creating callback functions is pretty simple. All you need to do is to declare a subroutine as specified in the GLFW Reference Manual, but of course translated to Visual Basic. For instance a mouse position callback function should, in 'C' language, be:
void GLFWCALL MyFun( int xpos, int ypos)
Never mind the GLFWCALL thing (it has to do with 'C' language calling conventions). In Visual Basic, this translates into:
Private Sub MyFun(ByVal xpos As Long, ByVal ypos As Long)
To register the callback function you should use the AddressOf operator, like this:
glfwSetMousePosCallback AddressOf MyFun
Done!
My name is Marcus Geelnard, marcus.geelnard@home.se. Please contact me if you have any problems with GLFW, or any questions at all concerning compiling or using GLFW.
The GLFW web site can be found here: http://glfw.sourceforge.net/. It contains the latest version of GLFW, news and other information that is useful for OpenGL development.