Results 1 to 3 of 3

Thread: looking for an example script of...

  1. #1

    looking for an example script of...

    the abaility to switch from 3D view to 2D in opengl mode.

    for an example, during the first set of code, you do 3d stuff, and then in the second set of code, you put in some 2D drawing stuff.

    for an example if you wanted to make a shmup game with 3d background and then you put the 2d game sprites on it. or a 1st person vehacular with 2d drawing hud.

    it might sound like a newbish question, but seriously, how could this be done?

  2. #2
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,128
    Rep Power
    732

    Re: looking for an example script of...

    Welcome to ThinBASIC!,

    your question is interesting, and it has quite simple solution.

    ThinBASIC allows you to work with OpenGL using TBGL module. It is not just OpenGL wrapper, but it uses OpenGL for rendering, which makes it possible to combine TBGL and OpenGL commands.

    TBGL makes some of the classic tasks easier for you as a coder, so it offers TBGL_RenderMatrix2D and TBGL_RenderMatrix3D commands.

    TBGL_RenderMatrix2D allows you to specify custom 2D coordinate system - per pixel precise, or completely custom.
    TBGL_RenderMatrix3D enables 3D mode of the rendering.

    The following example shows how to use these 2 commands, and it also demonstrates use of entity system, which you might find a big helper for game projects:
    [code=thinbasic]
    Uses "TBGL"

    Begin Const
    ' -- Scene IDs
    %sScene = 1

    ' -- Entity IDs
    %eCamera = 1
    %eLight
    %eBox
    End Const

    Function TBMAIN()
    Local hWnd As DWord
    Local FrameRate As Double

    ' -- Create and show window
    hWnd = TBGL_CREATEWINDOWEX("TBGL script - press ESC to quit", 640, 480, 32, %TBGL_WS_WINDOWED Or %TBGL_WS_CLOSEBOX)
    TBGL_SHOWWINDOW

    ' -- Create scene
    TBGL_SCENECREATE(%sScene)

    ' -- Create basic entities
    ' -- Create camera to look from 15, 15, 15 to 0, 0, 0
    TBGL_ENTITYCREATECAMERA(%sScene, %eCamera)
    TBGL_ENTITYSETPOS(%sScene, %eCamera, 15, 15, 15)
    TBGL_ENTITYSETTARGETPOS(%sScene, %eCamera, 0, 0, 0)

    ' -- Create point light
    TBGL_ENTITYCREATELIGHT(%sScene, %eLight)
    TBGL_ENTITYSETPOS(%sScene, %eLight, 15, 10, 5)

    ' -- Create something to look at
    TBGL_ENTITYCREATEBOX(%sScene, %eBox, 0, 1, 1, 1, 0, 255, 128, 0)
    TBGL_ENTITYSETPOS(%sScene, %eBox, 0, 0, 0)

    ' -- Resets status of all keys
    TBGL_RESETKEYSTATE()

    ' -- Main loop
    While TBGL_ISWINDOW(hWnd)
    FrameRate = TBGL_GETFRAMERATE

    TBGL_CLEARFRAME
    TBGL_RENDERMATRIX3D ' -- Enable 3D drawing mode

    TBGL_SCENERENDER(%sScene) ' -- Render scene

    TBGL_RENDERMATRIX2D(0,0,1,1) ' -- Enable 2D drawing mode with custom coordinates

    ' -- Render 2 lines using immediate mode
    TBGL_USELIGHTING %FALSE
    TBGL_COLOR 255, 255, 255
    TBGL_BEGINPOLY %GL_LINES
    TBGL_VERTEX 0.5, 0.0
    TBGL_VERTEX 0.5, 1.0
    TBGL_VERTEX 0.0, 0.5
    TBGL_VERTEX 1.0, 0.5
    TBGL_ENDPOLY
    TBGL_USELIGHTING %TRUE

    TBGL_DRAWFRAME

    ' -- ESCAPE key to exit application
    If TBGL_GETWINDOWKEYSTATE(hWnd, %VK_ESCAPE) Then Exit While

    ' -- Object manipulation
    If TBGL_GETWINDOWKEYSTATE(hWnd, %VK_LEFT) Then
    TBGL_ENTITYTURN(%sScene, %eBox, 0,-90/FrameRate, 0)
    ElseIf TBGL_GETWINDOWKEYSTATE(hWnd, %VK_RIGHT) Then
    TBGL_ENTITYTURN(%sScene, %eBox, 0, 90/FrameRate, 0)
    End If

    Wend

    TBGL_DESTROYWINDOW
    End Function
    [/code]

    Let us know if it is what you want. I am not sure what kind of game is "shmup game".
    I also recommend to use latest ThinBASIC beta if you do not use it already. It has the latest features inside, like sprite system for example.
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

  3. #3

    Re: looking for an example script of...

    Hello and welcome,

    yes you can do that easily. Like Petr said, use the RenderMatrix commands to switch.

    And for using sprites with TBGL, I suggest looking at the source of AstroCrusher here:

    http://community.thinbasic.com/index.php?topic=2738.0

    If you need more, just ask. There are stupid questions, only stupid answers

    Michael

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
  •