Buchempfehlung
MySQL kurz & gut
MySQL kurz & gut
Das preiswerte Taschen- buch stellt MySQL-rele- vante Inhalte systematisch und knapp dar, sodass es sich optimal zum Nach- schlagen beim Pro- grammieren eignet. [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 + Teapot

Uploader:Mitgliedcsde_rats
Datum/Zeit:11.07.2008 19:18:42

#Ifdef __FB_WIN32__
    #Include "windows.bi"
#EndIf


#Include "gl/gl.bi"
#Include "gl/glu.bi"
#Include "gl/glfw.bi"

declare sub glutWireTeapot Lib "glut32" alias "glutWireTeapot" (byval size as GLdouble)
declare sub glutSolidTeapot Lib "glut32" Alias "glutSolidTeapot" (byval size as GLdouble)

Dim Shared As Integer wireframe, halt

'----------------------------------------------------------------------
' 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...
        If Not halt Then glRotatef(60.0 * t, 0.0f, 1.0f, 0.0f)
        If wireframe Then
            glPolygonMode(GL_FRONT, GL_LINE)
            glutWireTeapot(5)
        Else
            glPolygonMode(GL_FRONT, GL_FILL)
            glutSolidTeapot(5)
        EndIf

    End Sub

'----------------------------------------------------------------------
' main() - Program entry point
'----------------------------------------------------------------------
    Function main (argc As Integer, argv As ZString Ptr Ptr) As Integer
        Dim As Integer ok        ' Flag telling if the window was opened
        Dim As Integer glfwmajor ' GLFW major version
        Dim As Integer glfwminor ' GLFW minor version
        Dim As Integer glfwrev   ' GLFW revision

        ' Initialize GLFW
        If glfwInit() = GL_FALSE Then
            Print "Cannot initialise GLFW!"
            Return 0
        EndIf

        ' 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

        glfwOpenWindowHint(GLFW_FSAA_SAMPLES, 8)

        ' 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 ok = GL_FALSE Then
            Print "could not open window!"
            glfwTerminate()
            Return 0
        EndIf

        ' Set window title
        glfwSetWindowTitle("My OpenGL program")

        ' Enable sticky keys
        glfwEnable(GLFW_STICKY_KEYS)

        glfwSwapInterval(60)

        ' 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
            If glfwGetKey(GLFW_KEY_ESC) = GL_TRUE Then Exit Do
            If glfwGetWindowParam(GLFW_OPENED) = GL_FALSE Then Exit Do

            If glfwGetKey(Asc("D")) = GL_TRUE Then wireframe = IIf(wireframe, 0, -1)
            If glfwGetKey(GLFW_KEY_SPACE) = GL_TRUE Then halt = IIf(halt, 0, -1)
        Loop

        ' Terminate GLFW
        glfwTerminate()

        ' Exit program
        Return 0
    End Function

End main(__FB_ARGC__, __FB_ARGV__)