Quote: "Huh? are you sure? i don't think IDs have anything to do with the z order"
Yo, sure I'm sure.
It is some sort of default z-order, that can be used to cleverly stablish your own z-order system, and override the distance from the camera.
However, sometimes this can lead to unexpected 'why is my object behind this if it is in front', as we are not aware of the IDs being used.
Having automatic IDs generation (lowest free available) is interesting and surely it makes things easier, but for a total control, you'll finally find yourself manually assigning IDs for groups of objects.
Here is a function that came in with DGDK 7.3:
Quote: "dbSetGlobalObjectCreationMode( 2 );
"Add this at the top of your program and all objects handled in your application use 'sort by object order' rather than 'sort by texture number'."
What this means is that there is no expensive bubble sort each time new objects are introduced into the engine, and so loading and main loop performance may increase slightly.
The downside is that the GPU will be asked to continually swap textures back and forth with no care to render all objects that share a common texture.
In some cases, this will degrade performance based on your scene complexity. Either way, it is another little tweak you may wish to experiment with to gain a few extra FPS from your projects."
That function switches the ID role from 'Texture IDs'(default) to 'Object IDs', and I can tell it has something to say regarding z-write and z-read.
I use the default 'Texture IDs' mode, as I already had built things around it.
I strongly recommend to run this
dbDisableObjectZRead example:
#include "DarkGDK.h"
void DarkGDK ( void )
{
dbCreateBitmap (1,dbScreenWidth(), dbScreenHeight());
dbPrint ( "Testing Draw To Back : Testing Draw To Back : Testing Draw To Back");
dbPrint ( "Testing Draw To Back : Testing Draw To Back : Testing Draw To Back");
dbPrint ( "Testing Draw To Back : Testing Draw To Back : Testing Draw To Back");
dbPrint ( "Testing Draw To Back : Testing Draw To Back : Testing Draw To Back");
dbPrint ( "Testing Draw To Back : Testing Draw To Back : Testing Draw To Back");
dbPrint ( "Testing Draw To Back : Testing Draw To Back : Testing Draw To Back");
dbPrint ( "Testing Draw To Back : Testing Draw To Back : Testing Draw To Back");
dbPrint ( "Testing Draw To Back : Testing Draw To Back : Testing Draw To Back");
dbPrint ( "Testing Draw To Back : Testing Draw To Back : Testing Draw To Back");
dbPrint ( "Testing Draw To Back : Testing Draw To Back : Testing Draw To Back");
dbPrint ( "Testing Draw To Back : Testing Draw To Back : Testing Draw To Back");
dbPrint ( "Testing Draw To Back : Testing Draw To Back : Testing Draw To Back");
dbPrint ( "Testing Draw To Back : Testing Draw To Back : Testing Draw To Back");
dbPrint ( "Testing Draw To Back : Testing Draw To Back : Testing Draw To Back");
dbPrint ( "Testing Draw To Back : Testing Draw To Back : Testing Draw To Back");
dbPrint ( "Testing Draw To Back : Testing Draw To Back : Testing Draw To Back");
dbPrint ( "Testing Draw To Back : Testing Draw To Back : Testing Draw To Back");
dbPrint ( "Testing Draw To Back : Testing Draw To Back : Testing Draw To Back");
dbPrint ( "Testing Draw To Back : Testing Draw To Back : Testing Draw To Back");
dbPrint ( "Testing Draw To Back : Testing Draw To Back : Testing Draw To Back");
dbPrint ( "Testing Draw To Back : Testing Draw To Back : Testing Draw To Back");
dbPrint ( "Testing Draw To Back : Testing Draw To Back : Testing Draw To Back");
dbPrint ( "Testing Draw To Back : Testing Draw To Back : Testing Draw To Back");
dbPrint ( "Testing Draw To Back : Testing Draw To Back : Testing Draw To Back");
dbPrint ( "Testing Draw To Back : Testing Draw To Back : Testing Draw To Back");
dbPrint ( "Testing Draw To Back : Testing Draw To Back : Testing Draw To Back");
dbPrint ( "Testing Draw To Back : Testing Draw To Back : Testing Draw To Back");
dbPrint ( "Testing Draw To Back : Testing Draw To Back : Testing Draw To Back");
dbPrint ( "Testing Draw To Back : Testing Draw To Back : Testing Draw To Back");
dbGetImage (1,0,0,dbScreenWidth(), dbScreenHeight());
dbCLS();
dbPrint ( "Object : Object : Object : Object : Object : Object : Object");
dbPrint ( "Object : Object : Object : Object : Object : Object : Object");
dbPrint ( "Object : Object : Object : Object : Object : Object : Object");
dbPrint ( "Object : Object : Object : Object : Object : Object : Object");
dbPrint ( "Object : Object : Object : Object : Object : Object : Object");
dbPrint ( "Object : Object : Object : Object : Object : Object : Object");
dbPrint ( "Object : Object : Object : Object : Object : Object : Object");
dbPrint ( "Object : Object : Object : Object : Object : Object : Object");
dbPrint ( "Object : Object : Object : Object : Object : Object : Object");
dbPrint ( "Object : Object : Object : Object : Object : Object : Object");
dbPrint ( "Object : Object : Object : Object : Object : Object : Object");
dbPrint ( "Object : Object : Object : Object : Object : Object : Object");
dbPrint ( "Object : Object : Object : Object : Object : Object : Object");
dbPrint ( "Object : Object : Object : Object : Object : Object : Object");
dbPrint ( "Object : Object : Object : Object : Object : Object : Object");
dbPrint ( "Object : Object : Object : Object : Object : Object : Object");
dbPrint ( "Object : Object : Object : Object : Object : Object : Object");
dbPrint ( "Object : Object : Object : Object : Object : Object : Object");
dbPrint ( "Object : Object : Object : Object : Object : Object : Object");
dbPrint ( "Object : Object : Object : Object : Object : Object : Object");
dbPrint ( "Object : Object : Object : Object : Object : Object : Object");
dbPrint ( "Object : Object : Object : Object : Object : Object : Object");
dbPrint ( "Object : Object : Object : Object : Object : Object : Object");
dbGetImage ( 2,0,0,dbScreenWidth()/2,dbScreenHeight()/2);
dbCLS();
dbPrint ( "Testing Draw To Front : Testing Draw To Front : Testing Draw To Front : Testing Draw To Front");
dbPrint ( "Testing Draw To Front : Testing Draw To Front : Testing Draw To Front : Testing Draw To Front");
dbPrint ( "Testing Draw To Front : Testing Draw To Front : Testing Draw To Front : Testing Draw To Front");
dbPrint ( "Testing Draw To Front : Testing Draw To Front : Testing Draw To Front : Testing Draw To Front");
dbPrint ( "Testing Draw To Front : Testing Draw To Front : Testing Draw To Front : Testing Draw To Front");
dbPrint ( "Testing Draw To Front : Testing Draw To Front : Testing Draw To Front : Testing Draw To Front");
dbPrint ( "Testing Draw To Front : Testing Draw To Front : Testing Draw To Front : Testing Draw To Front");
dbPrint ( "Testing Draw To Front : Testing Draw To Front : Testing Draw To Front : Testing Draw To Front");
dbPrint ( "Testing Draw To Front : Testing Draw To Front : Testing Draw To Front : Testing Draw To Front");
dbPrint ( "Testing Draw To Front : Testing Draw To Front : Testing Draw To Front : Testing Draw To Front");
dbPrint ( "Testing Draw To Front : Testing Draw To Front : Testing Draw To Front : Testing Draw To Front");
dbPrint ( "Testing Draw To Front : Testing Draw To Front : Testing Draw To Front : Testing Draw To Front");
dbGetImage ( 3,0,0,dbScreenWidth()/2,dbScreenHeight()/5);
dbCLS();
dbDeleteBitmap (1);
dbSetCurrentBitmap (0);
//Here is actual code
dbSyncOn();
dbSyncRate (60);
dbAutoCamOff();
dbColorBackdrop (0);
dbPositionCamera(0,0,-7.7);
//make plain to use for drawing to the back
dbMakeObjectPlane(1,12,8);
dbTextureObject(1, 1);
dbSetObjectTransparency (1,1);
//make object for middle drawing
dbMakeObjectSphere(2,5);
dbTextureObject(2, 2);
dbPositionObject(2,0,0,5);
//draw in front
dbMakeObjectPlane( 3,500,500);
dbPositionObject(3, 0, -50, 1000);
dbTextureObject (3, 3);
dbDisableObjectZRead (3);
dbSetObjectTransparency (3, 1);
int direction = 1;
do
{
if (direction == 1)
{
//dbPositionObject( 2,0,0,dbObjectPositionZ(2) + .05);
dbPositionObject( 1,0,0,dbObjectPositionZ(1) + .05);
//if (dbObjectPositionZ(2) >= 7)
if (dbObjectPositionZ(1) >= 7)
{
direction = 0;
}
}
if (direction == 0)
{
//dbPositionObject( 2,0,0,dbObjectPositionZ(2) - .05);
dbPositionObject( 1,0,0,dbObjectPositionZ(1) - .05);
//if (dbObjectPositionZ(2) <= -2)
if (dbObjectPositionZ(1) <= -2)
{
direction = 1;
}
}
if (dbSpaceKey()== 0)
{
dbDisableObjectZRead(1);
}
else
{
dbEnableObjectZRead (1);
}
if (dbReturnKey() == 0)
{
dbDisableObjectZRead(3);
}
else
{
dbEnableObjectZRead (3);
}
dbSetCursor(5,5);
dbPrint ( dbStr(dbObjectPositionZ(2)));
dbSetCursor (5,20);
if (dbObjectPositionZ(1) >= 2.5)
{
dbPrint ( "Sphere is behind plain");
}
if (dbObjectPositionZ(1) <= 1 )
{
dbPrint ( "Sphere is in front of plain");
}
dbPrint(dbStr(dbScreenFPS()));
dbSync();
}while (dbEscapeKey()==0);
}
The texture ID decides which object is in front.
Lower IDs will appear behind higher ones, hold 'Space' and 'Enter' to change z-order priority between the planes and the sphere.