View Full Version : Platform Game (What are you working on?)
Michael Clease
03-06-2007, 00:01
I made the TGA files this morning had to go out so haven't done the code yet.
Whats the fastest way to draw 20*15 textured quads on screen? Is a display list the way to go?
FUNCTION DrawLvl()
local BackX AS DWORD
local Backy AS DWORD
local Backz AS DWORD
local LvlCharPos as DWORD
TBGL_UseTexture 1 ' Turn on textures
TBGL_PUSHMATRIX
TBGL_Translate -21, 14, 0
LvlCharPos = 0
For BackY = 1 to 15
for BackX = 19 to 0 step -1
InCR LvlCharPos
TBGL_BindTexture CurrentLvl(LvlCharPos) 'LvlChar
TBGL_Translate 2, 0, 0
TBGL_BeginPoly %GL_QUADS ' Start polygon Building my quad based on 4 vertexes
TBGL_Color 255,255,255 ' Set RGB colour to white
TBGL_TexCoord2d 0,0 ' Set texture coordinate
TBGL_Vertex -1,-1,0 ' Add Vertex
TBGL_TexCoord2d 1,0 ' Set texture coordinate
TBGL_Vertex 1,-1,0 ' Add Vertex
TBGL_TexCoord2d 1,1 ' Set texture coordinate
TBGL_Vertex 1, 1,0 ' Add Vertex
TBGL_TexCoord2d 0,1 ' Set texture coordinate
TBGL_Vertex -1, 1,0 ' Add Vertex
TBGL_EndPoly ' Ends polygon definition
Next
TBGL_Translate -40, -2, 0
Next
TBGL_POPMATRIX
END FUNCTION
The display list is a good way to go, but if you have a new graphics card, it doesn't make that much difference really.
you can see the speed comparisons in this thread:
http://community.thinbasic.com/index.php?topic=871.msg6107;topicseen#new
Michael Hartlef
03-06-2007, 09:11
If you can sort them by the texture index and use TBGL_BindTexture only when you chnage it, that could speed up something. Also make sure that your texture size has a power of 8.
Petr Schreiber
03-06-2007, 12:12
Hi,
both kryton and Mike are correct ( only one thing - power of 2 should be enough ).
20 * 15 quads = 20 * 15 * 4 quad polys = 1200 vertices. This can be handled using "model shaders" ( virtual m15 model ) perfectly. I will post code later this day with explanations ;)
Bye,
Petr
Michael Clease
03-06-2007, 12:26
If you compare the code I turn textures on and off on entering and exiting shifted the color keyword all that changed the frame rate from about 270-280 to about 295 - 305 FPS. I think its better to optimise as i go.
FUNCTION DrawLvl()
local BackX AS DWORD
local Backy AS DWORD
local LvlCharPos as DWORD Value 0
TBGL_UseTexture 1 ' Turn on textures
TBGL_PUSHMATRIX
TBGL_Translate -21, 14, 0
TBGL_Color 255,255,255 ' Set RGB colour to white
For BackY = 1 to 15
for BackX = 19 to 0 step -1
InCR LvlCharPos
TBGL_BindTexture CurrentLvl(LvlCharPos) 'LvlChar
TBGL_Translate 2, 0, 0
TBGL_BeginPoly %GL_QUADS ' Start polygon Building my quad based on 4 vertexes
TBGL_TexCoord2d 0,0 ' Set texture coordinate
TBGL_Vertex -1,-1,0 ' Add Vertex
TBGL_TexCoord2d 1,0 ' Set texture coordinate
TBGL_Vertex 1,-1,0 ' Add Vertex
TBGL_TexCoord2d 1,1 ' Set texture coordinate
TBGL_Vertex 1, 1,0 ' Add Vertex
TBGL_TexCoord2d 0,1 ' Set texture coordinate
TBGL_Vertex -1, 1,0 ' Add Vertex
TBGL_EndPoly ' Ends polygon definition
Next
TBGL_Translate -40, -2, 0
Next
TBGL_POPMATRIX
TBGL_UseTexture 0 ' Turn on textures
END FUNCTION
Petr Schreiber
03-06-2007, 12:35
Hi Abraxas,
its your game, code it as you need!
Trick with color is good, tbgl_m15DrawModel detects automatically redundant use of color assigment and sends to card only whats necessary.
Just for fun, here is code:
Put this after tbgl_ShowWindow:
' -- We need 1 model, with 1200 vertices
tbgl_m15InitModelBuffers 1, 20 * 15 * 4
%MYLEVEL = 1
Than use this to create geometry ( call before rendering loop ):
FUNCTION CreateLevelModel( modelSlot as long )
local BackX AS DWORD
local Backy AS DWORD
local Backz AS DWORD
local LvlCharPos as DWORD
' -- 20 * 15 * 4 quads equals to 1200 vertices, this allows to optimize render later
tbgl_m15SetModelVertexcount( modelSlot, 1200 )
' -- Assigns white color to all vertices in range [1, 1200]
tbgl_m15SetVertexRGB( modelSlot, 1, 1200, 255, 255, 255)
local vertexID as long ' -- To temporary store vertex index
local transX, transY as single ' -- Simple offset instead of matrix work
transX -= 21
transY += 14
LvlCharPos = 0
For BackY = 1 to 15
for BackX = 19 to 0 step -1
incr vertexID ' -- Increases vertex index to write in this cycle
InCR LvlCharPos
TBGL_m15SetVertexTexN( modelSlot, vertexID, vertexID+3, CurrentLvl(LvlCharPos) ) ' -- Sets index to whole quad in one go
transX += 2
TBGL_m15SetVertexTexXY( modelSlot, vertexID+0, 0, 0 ) ' -- UV coords
TBGL_m15SetVertexTexXY( modelSlot, vertexID+1, 1, 0 )
TBGL_m15SetVertexTexXY( modelSlot, vertexID+2, 1, 1 )
TBGL_m15SetVertexTexXY( modelSlot, vertexID+3, 0, 1 )
TBGL_m15SetVertexXYZ( modelSlot, vertexID+0, transX-1, transY-1, 0 ) ' -- XYZ coords
TBGL_m15SetVertexXYZ( modelSlot, vertexID+1, transX+1, transY-1, 0 )
TBGL_m15SetVertexXYZ( modelSlot, vertexID+2, transX+1, transY+1, 0 )
TBGL_m15SetVertexXYZ( modelSlot, vertexID+3, transX-1, transY+1, 0 )
TBGL_m15SetVertexPStop( modelSlot, vertexID+3, 1 ) ' End of polygon
Next
transX -= 40
transY -= 2
Next
END FUNCTION
( call it like CreateLevelModel(%MYLEVEL)) and than to draw your model just use:
tbgl_m15DrawModel %MYLEVEL
I think you could get even higher framerate, but it is not tested as I didn't have rest of your code :)
Have fun,
Petr
Michael Clease
04-06-2007, 01:30
thanks for the really good example, works great (1 fix below) frame rates of about 930 -950.
I couldnt work out why it wasnt working so i cut it down to a 2 * 2, that showed a triangle, finally worked out that the index wasnt increasing for the next poly. Helped me understand the code better though.
TBGL_m15SetVertexPStop( modelSlot, vertexID+3, 1 ) ' End of polygon
vertexID += 3
Next
thanks again.
ABX
Petr Schreiber
04-06-2007, 16:12
Hi,
sorry for the bug, I had no chance to test it deeper.
I think framerate is quite ok now :)
Bye,
Petr
Michael Clease
04-06-2007, 17:04
thank you for your help and if you hadnt made the mistake i wouldnt have learn more about the routine and models
Might be a good idea to split the thread from post 5 where I hijacked it.
thanks
ErosOlmi
04-06-2007, 17:28
...
Might be a good idea to split the thread from post 5 where I hijacked it.
...
Done :)
Maybe you can post here some images of your game when its status go on. I'm very curious about it.
Ciao
Eros