Buchempfehlung
Windows-Programmierung. Das Entwicklerhandbuch zur WIN32-API
Windows-Programmierung. Das Entwicklerhandbuch zur WIN32-API
"Der" Petzold, das über 1000 Seiten starke Standardwerk zum Win32-API - besonders nützlich u. a. bei der GUI-Programmierung in FreeBASIC! [Mehr Infos...]
FreeBASIC-Chat
Es sind Benutzer im FreeBASIC-Chat online.
(Stand:  )
FreeBASIC bei Twitter
Twitter FreeBASIC-Nachrichten jetzt auch über Twitter erhalten. Follow us!

fb:porticula NoPaste

Info
Info / Hilfe
Liste
Übersicht / Liste
Neu
Datei hochladen
Suche
Quellcode suchen
Download
Dateidownload

GLFW Basecode, win error?!?

Uploader:Mitgliedcsde_rats
Datum/Zeit:07.07.2008 18:11:24

#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

        ' Initialize GLFW
        glfwInit()

        ' 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
            25, _                ' 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
            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()