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?
Petr Schreiber
22-09-2009, 20:25
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:
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
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 (http://community.thinbasic.com/index.php?topic=2899.msg21972#msg21972) if you do not use it already. It has the latest features inside, like sprite system for example.
Michael Hartlef
22-09-2009, 21:45
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