Results 1 to 1 of 1

Thread: NeHe Lesson 05

  1. #1
    Member matthew's Avatar
    Join Date
    Mar 2007
    Location
    England
    Age
    48
    Posts
    490
    Rep Power
    68

    NeHe Lesson 05

    NeHe Lesson 05 will Display a Coloured Pyramid and Cube and Rotate them.

    [code=thinbasic]
    ' NeHe Lesson 05

    uses "UI" ' MessageBox Functions
    uses "TBGL" ' thinBASIC OpenGL Library

    ' Create MessageBox
    dim fullScreen as long
    fullScreen = msgbox(0, "Would you like to Run in Fullscreen Mode?", %MB_YESNO or %MB_ICONINFORMATION, "Start FullScreen?")

    select case fullScreen

    ' Create FullScreen Display, Return Handle.
    case %IDYES
    dim hWnd as dword
    hWnd = tbgl_createwindowex("", 1024, 768, 32, 1)

    ' Create Windowed Display, Return Handle.
    case %IDNO
    dim hWnd as dword
    hWnd = tbgl_createwindowex("NeHe Lesson 05 - Press 'Esc' to Quit", 640, 480, 16, 0)

    end select

    ' Declare Variables here

    dim rtri as single ' Pyramid Rotation
    dim rquad as single ' Cube Rotation

    dim frameRate as integer ' Timing Variable

    tbgl_showwindow ' Show Display

    TBGL_GetAsyncKeyState(-1) ' Reset all Keys

    ' Start Main Loop
    while tbgl_iswindow(hWnd)

    frameRate = tbgl_getframerate

    tbgl_clearframe ' Clear Display
    tbgl_camera 0,0,1,0,0,0 ' Default Camera, View From 0,0,1 To 0,0,0.

    tbgl_translate -1.5, 0.0, -6.0 ' Move Left 1.5 Units, Into the Screen 6 Units
    tbgl_rotate rtri, 0.0, 1.0, 0.0 ' Y-Axis Rotation

    tbgl_beginpoly %GL_TRIANGLES ' Drawing Using Triangles

    ' Front Triangle
    TBGL_Color 255, 0, 0 ' Red
    TBGL_Vertex 0.0, 1.0, 0.0 ' Top
    TBGL_Color 0, 255, 0 ' Green
    TBGL_Vertex -1.0, -1.0, 1.0 ' Bottom Left
    TBGL_Color 0, 0, 255 ' Blue
    TBGL_Vertex 1.0, -1.0, 1.0 ' Bottom Right

    ' Right Triangle
    TBGL_Color 255, 0, 0 ' Red
    TBGL_Vertex 0.0, 1.0, 0.0 ' Top
    TBGL_Color 0, 0, 255 ' Blue
    TBGL_Vertex 1.0, -1.0, 1.0 ' Bottom Left
    TBGL_Color 0, 255, 0 ' Green
    TBGL_Vertex 1.0, -1.0, -1.0 ' Bottom Right

    ' Back Triangle
    TBGL_Color 255, 0, 0 ' Red
    TBGL_Vertex 0.0, 1.0, 0.0 ' Top
    TBGL_Color 0, 255, 0 ' Green
    TBGL_Vertex 1.0, -1.0, -1.0 ' Bottom Left
    TBGL_Color 0, 0, 255 ' Blue
    TBGL_Vertex -1.0, -1.0, -1.0 ' BottomRight

    ' Left Triangle
    TBGL_Color 255, 0, 0 ' Red
    TBGL_Vertex 0.0, 1.0, 0.0 ' Top
    TBGL_Color 0, 255, 0 ' Green
    TBGL_Vertex -1.0, -1.0, -1.0 ' Bottom Left
    TBGL_Color 0, 0, 255 ' Blue
    TBGL_Vertex -1.0, -1.0, 1.0 ' Bottom Right

    TBGL_EndPoly

    tbgl_resetmatrix ' Reset Current Matrix
    tbgl_camera 0,0,1,0,0,0 ' Default Camera, View From 0,0,1 To 0,0,0.
    TBGL_Translate 1.5, 0.0, -7.0 ' Move Right 1.5 Units, Into the Screen 7 Units.
    TBGL_Rotate rquad, 1.0, 1.0, 1.0 ' X,Y & Z Axis Rotations.

    TBGL_BeginPoly %GL_QUADS ' Drawing using Quads

    ' Top Quad
    TBGL_Color 0, 255, 0 ' Green
    TBGL_Vertex 1.0, 1.0, -1.0 ' Top Right
    TBGL_Vertex -1.0, 1.0, -1.0 ' Top Left
    TBGL_Vertex -1.0, 1.0, 1.0 ' Bottom Left
    TBGL_Vertex 1.0, 1.0, 1.0 ' Bottom Right

    ' Bottom Quad
    TBGL_Color 255, 127, 0 ' Orange
    TBGL_Vertex 1.0, -1.0, 1.0 ' Top Right
    TBGL_Vertex -1.0, -1.0, 1.0 ' Top left
    TBGL_Vertex -1.0, -1.0, -1.0 ' Bottom Left
    TBGL_Vertex 1.0, -1.0, -1.0 ' Bottom Right

    ' Front Quad
    TBGL_Color 255, 0, 0 ' Red
    TBGL_Vertex 1.0, 1.0, 1.0 ' Top Right
    TBGL_Vertex -1.0, 1.0, 1.0 ' Top Left
    TBGL_Vertex -1.0, -1.0, 1.0 ' Bottom Left
    TBGL_Vertex 1.0, -1.0, 1.0 ' Bottom Right

    ' Back Quad
    TBGL_Color 255, 255, 0 ' Yellow
    TBGL_Vertex 1.0, -1.0, -1.0 ' Bottom Left
    TBGL_Vertex -1.0, -1.0, -1.0 ' Bottom Right
    TBGL_Vertex -1.0, 1.0, -1.0 ' Top Right
    TBGL_Vertex 1.0, 1.0, -1.0 ' Top Left

    ' Left Quad
    TBGL_Color 0, 0, 255 ' Blue
    TBGL_Vertex -1.0, 1.0, -1.0 ' Top Right
    TBGL_Vertex -1.0, -1.0, -1.0 ' Top Left
    TBGL_Vertex -1.0, -1.0, 1.0 ' Bottom Left
    TBGL_Vertex -1.0, 1.0, 1.0 ' Bottom Right

    ' Right Quad
    TBGL_Color 255, 0, 255 ' Violet
    TBGL_Vertex 1.0, 1.0, -1.0 ' Top Right
    TBGL_Vertex 1.0, 1.0, 1.0 ' Top Left
    TBGL_Vertex 1.0, -1.0, 1.0 ' Bottom Left
    TBGL_Vertex 1.0, -1.0, -1.0 ' Bottom Right

    TBGL_EndPoly

    rtri += ( 36.0 / frameRate ) ' Increase Triangle Rotation
    rquad -= ( 27.0 / frameRate ) ' Increase Quad Rotation

    tbgl_drawframe ' Display anything

    if tbgl_getasynckeystate(%VK_ESCAPE) then exit while

    wend

    tbgl_destroywindow ' Closes Display
    [/code]

    Update
    This Lesson was updated on 29th June 2007 when you Run the Application it will now ask you whether you want to use a FullScreen or Windowed Display.

    It also uses 'tbgl_getframerate' to Regulate Speed on different Graphics Cards.
    Attached Images Attached Images

Similar Threads

  1. NeHe Lesson 01
    By matthew in forum TBGL Tutorials
    Replies: 1
    Last Post: 16-03-2007, 06:38
  2. NeHe Lesson 03
    By matthew in forum TBGL Tutorials
    Replies: 0
    Last Post: 16-03-2007, 01:01
  3. NeHe Lesson 02
    By matthew in forum TBGL Tutorials
    Replies: 0
    Last Post: 16-03-2007, 00:57

Members who have read this thread: 0

There are no members to list at the moment.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •