/Code/Angel/Libraries/glfw/support/visualbasic/examples/Triangle.bas

http://angel-engine.googlecode.com/ · Basic · 101 lines · 57 code · 20 blank · 24 comment · 0 complexity · 10b4f39c9007bdef93b91c3963ba9f8c MD5 · raw file

  1. Attribute VB_Name = "Program"
  2. '========================================================================
  3. ' This is a small test application for GLFW.
  4. ' The program opens a window (640x480), and renders a spinning colored
  5. ' triangle (it is controlled with both the GLFW timer and the mouse). It
  6. ' also calculates the rendering speed (FPS), which is displayed in the
  7. ' window title bar.
  8. '========================================================================
  9. Private Sub Main()
  10. Dim running, frames, Ok As Long
  11. Dim x, y, width, height As Long
  12. Dim t0, t, fps As Double
  13. Dim titlestr As String
  14. ' Initialize GLFW
  15. Ok = glfwInit
  16. ' Open OpenGL window
  17. Ok = glfwOpenWindow(640, 480, 0, 0, 0, 0, 0, 0, GLFW_WINDOW)
  18. If Ok = 0 Then
  19. glfwTerminate
  20. End
  21. End If
  22. ' Enable sticky keys
  23. glfwEnable (GLFW_STICKY_KEYS)
  24. ' Disable vertical sync (on cards that support it)
  25. glfwSwapInterval 0
  26. ' Main loop
  27. running = 1
  28. frames = 0
  29. t0 = glfwGetTime
  30. While running = 1
  31. ' Get time and mouse position
  32. t = glfwGetTime
  33. glfwGetMousePos x, y
  34. ' Calculate and display FPS (frames per second)
  35. If (t - t0) > 1# Or frames = 0 Then
  36. fps = frames / (t - t0)
  37. titlestr = "Spinning Triangle (" + Str(Round(fps, 1)) + " FPS)"
  38. glfwSetWindowTitle titlestr
  39. t0 = t
  40. frames = 0
  41. End If
  42. frames = frames + 1
  43. ' Get window size (may be different than the requested size)
  44. glfwGetWindowSize width, height
  45. If height <= 0 Then height = 1
  46. ' Set viewport
  47. glViewport 0, 0, width, height
  48. ' Clear color buffer
  49. glClearColor 0#, 0#, 0#, 0#
  50. glClear GL_COLOR_BUFFER_BIT
  51. ' Select and setup the projection matrix
  52. glMatrixMode GL_PROJECTION
  53. glLoadIdentity
  54. gluPerspective 65#, width / height, 1#, 100#
  55. ' Select and setup the modelview matrix
  56. glMatrixMode GL_MODELVIEW
  57. glLoadIdentity
  58. gluLookAt 0#, 1#, 0#, 0#, 20#, 0#, 0#, 0#, 1#
  59. ' Draw a rotating colorful triangle
  60. glTranslatef 0#, 14#, 0#
  61. glRotatef 0.3 * x + t * 100#, 0#, 0#, 1#
  62. glBegin GL_TRIANGLES
  63. glColor3f 1#, 0#, 0#
  64. glVertex3f -5#, 0#, -4#
  65. glColor3f 0#, 1#, 0#
  66. glVertex3f 5#, 0#, -4#
  67. glColor3f 0#, 0#, 1#
  68. glVertex3f 0#, 0#, 6#
  69. glEnd
  70. ' Swap buffers
  71. glfwSwapBuffers
  72. ' Check if the ESC key was pressed or the window was closed
  73. If glfwGetKey(GLFW_KEY_ESC) = 1 Or glfwGetWindowParam(GLFW_OPENED) = 0 Then
  74. running = 0
  75. End If
  76. Wend
  77. ' Close OpenGL window and terminate GLFW
  78. glfwTerminate
  79. ' Exit program
  80. End
  81. End Sub