fb:porticula NoPaste
GLFW Basecode, win error?!? 2
Uploader: | csde_rats |
Datum/Zeit: | 07.07.2008 19:18:49 |
#Include "gl/gl.bi"
#Include "gl/glu.bi"
#Include "gl/glfw.bi"
'----------------------------------------------------------------------
' DrawScene() - Main OpenGL drawing function that is called each frame
'----------------------------------------------------------------------
Sub DrawScene ()
Dim As Integer w, h
Dim As Double t
' Get current time
t = glfwGetTime()
' Get window size
glfwGetWindowSize(@w, @h)
' Make sure that height is non-zero to avoid division by zero
h = IIf(h < 1, 1, h)
' Set viewport
glViewport(0, 0, w, h)
' Clear color and depht buffers
glClearColor(0.0f, 0.0f, 0.0f, 0.0f)
glClear(GL_COLOR_BUFFER_BIT Or GL_DEPTH_BUFFER_BIT)
' Set up projection matrix
glMatrixMode(GL_PROJECTION) ' Select projection matrix
glLoadIdentity() ' Start with an identity matrix
gluPerspective( _ ' Set perspective view
65.0f, _ ' Field of view = 65 degrees
Cast(Double, w) / Cast(Double, h), _ ' Window aspect (assumes square pixels)
1.0f, _ ' Near Z clipping plane
100.0f _ ' Far Z clippling plane
)
' Set perspective view
glMatrixMode(GL_MODELVIEW) ' Select modelview matrix
glLoadIdentity() ' Start with an identity matrix
gluLookAt( _ ' Set camera position and orientation
0.0f, 0.0f, 10.0f, _ ' Camera position (x,y,z)
0.0f, 0.0f, 0.0f, _ ' View point (x,y,z)
0.0f, 1.0f, 0.0f _ ' Up-vector (x,y,z)
)
' Here is where actual OpenGL rendering calls would begin...
End Sub
'----------------------------------------------------------------------
' main() - Program entry point
'----------------------------------------------------------------------
Function main () As Integer
Dim As Integer ok ' Flag telling if the window was opened
Dim As Integer running ' Flag telling if the program is running
Dim As Integer glfwmajor ' GLFW major version
Dim As Integer glfwminor ' GLFW minor version
Dim As Integer glfwrev ' GLFW revision
' Initialize GLFW
glfwInit()
' Check version
glfwGetVersion(@glfwmajor, @glfwminor, @glfwrev)
If (glfwmajor < GLFW_VERSION_MAJOR) Or _
(glfwminor < GLFW_VERSION_MINOR) Or _
(glfwrev < GLFW_VERSION_REVISION) Then
Print "GLFW Library too old!"
glfwTerminate()
Return 0
EndIf
' Open window
ok = glfwOpenWindow( _
640, 480, _ ' Width and height of window
8, 8, 8, _ ' Number of red, green, and blue bits for color buffer
8, _ ' Number of bits for alpha buffer
24, _ ' Number of bits for depth buffer (Z-buffer)
0, _ ' Number of bits for stencil buffer
GLFW_WINDOW _ ' We want a desktop window (could be GLFW_FULLSCREEN)
)
' If we could not open a window, exit now
If Not ok Then
Print "could not open window!"
glfwTerminate()
Return 0
EndIf
' Set window title
glfwSetWindowTitle("My OpenGL program")
' Enable sticky keys
glfwEnable(GLFW_STICKY_KEYS)
' Main rendering loop
Do
' Call our rendering function
DrawScene()
' Swap front and back buffers (we use a double buffered display)
glfwSwapBuffers()
' Check if the escape key was pressed, or if the window was closed
running = Not (glfwGetKey(GLFW_KEY_ESC) Or glfwGetWindowParam(GLFW_OPENED))
Loop While running
' Terminate GLFW
glfwTerminate()
' Exit program
Return 0
End Function
End main()