PDA

View Full Version : spider animation (again)



zak
17-07-2010, 11:46
in the example posted by Eros (August 25, 2008) here:
http://community.thinbasic.com/index.php?topic=1983.0
there is a spider animation , and for just fun i want to draw 5 spiders (or more) so i have used the tbgl_translate and a loop from -4 to 0, i want to draw also a galaxy so as it is the home of the spiders.
some notes:
1- the galaxy picture appears as dim and not as vivid like the original picture.
2- other criticism, reviews ?? appreciated.

Petr Schreiber
17-07-2010, 11:56
Hi Zak,

pretty scary render of invasion :)

The reason you had galaxy dark was that you did not disabled lighting.

If you change the Square procedure to following, you will see the galaxy will be as bright as it should:


Function square()

' -- Enable texturing, but just for the part of code
TBGL_PushState %TBGL_TEXTURING

' -- Disable lighting, but just for part of code
TBGL_PushStateProtect %TBGL_LIGHTING

' -- Bind texture #2
TBGL_BindTexture 2
TBGL_Color 255,255,255
TBGL_Translate 2.5, 1, -1

TBGL_BeginPoly %GL_QUADS ' Starts polygon definition based on 4 vertexes

TBGL_TexCoord2D 0.0, 0.0 : TBGL_Vertex -2, -2, 0.0
TBGL_TexCoord2D 1.0, 0.0 : TBGL_Vertex 2, -2, 0.0
TBGL_TexCoord2D 1.0, 1.0 : TBGL_Vertex 2, 2, 0.0
TBGL_TexCoord2D 0.0, 1.0 : TBGL_Vertex -2, 2, 0.0

TBGL_EndPoly ' Ends polygon definition

TBGL_PopStateProtect
TBGL_PopState

End Function



Petr

Petr Schreiber
17-07-2010, 12:01
One more thing,

I have seen in your code stuff like:


TBGL_UseTexture 2 : TBGL_BindTexture 2


That is not entirely correct. TBGL_UseTexture was made obsolete (as help file says) mainly due its confusing name which leads to situation people use it like you did.
The replacement is TBGL_UseTexturing, which is slightly more clear.

So the correct variation to your code would be:


TBGL_UseTexturing(%TRUE) ' -- Enables texturing generally
TBGL_BindTexture(2) ' -- Binds texture #2 to be used

zak
17-07-2010, 12:14
thanks Petr,
now the galaxy appears bright as it should be.
how much you estimate the pc will overloaded from many many spiders we may display ??
thanks

Petr Schreiber
18-07-2010, 11:14
Hi Zak,

it depends!

From purely technological view, your spiders are rendered using the most straightforward approach - via the predefined primitives. They are currently handled using Vertex Arrays.
If you render the same shape multiple times, you could take advantage of display lists - one for head, and one for each leg part.

To maximize the performance, and reduce the FOR/NEXT overhead, you could consider recreating the scene using scene-entity system. That assures the bigger part runs at compiled speed.

The whole overhead highly depends on how many spiders are in the view, and how often do you switch states (enabling/disabling texturing, changing textures). If we go into extreme, it would be advantageous to render just heads first, with once bound texture 1, and then all the legs, which have no texture. But fact is code gets complicated this way.

The raw performance varies, depends on model "batch" size, and graphic card performance.
For example my "record" with GeForce 9500GT was rendering of 8 000 000 polygons at smooth speed. But on the other side, Intel cards I could test have problems even with scenes under 100 000 polygons.*

There is ellegant approach on modern cards, called "geometry instancing", which provides even better performance for multiple "stamps" of same object in the scene. But this technique is limited to modern models of GeForces and Radeons.


Petr

* Lighted, textured, colored