About Store Forum Documentation Contact



Post Reply 
Draw3D image disappears at distance
Author Message
Randy Offline
Member

Post: #1
Draw3D image disappears at distance
I am using Image.Draw3D for drawing player names.

Close to camera it looks ok -

[Image: 3dtext1.png]

But on big distances image becomes invisible -

[Image: 3dtext2.png]

[Image: 3dtext3.png]

Image was created manually:

Code:
(*tmp_image).create2D(256, 256, IMAGE_B8G8R8A8);

and letters drawing by tmp_image->color() method

Imported images works fine at every distance, so I think problem in manually created image.

How can I fix this problem?
09-21-2011 07:48 PM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #2
RE: Draw3D image disappears at distance
Use D.text
09-21-2011 08:56 PM
Find all posts by this user Quote this message in a reply
Zervox Offline
Member

Post: #3
RE: Draw3D image disappears at distance
also remember color might need setting alpha.
image.draw3D(color,size,angle,position,ALPHA_NONE); ?
(This post was last modified: 09-21-2011 09:07 PM by Zervox.)
09-21-2011 09:06 PM
Find all posts by this user Quote this message in a reply
Randy Offline
Member

Post: #4
RE: Draw3D image disappears at distance
(09-21-2011 08:56 PM)Esenthel Wrote:  Use D.text
In this case player names will be visible through objects and terrain.
I think billboards is the best solution.

The question is - what property of Image class responsible for rendering distance?
09-21-2011 09:16 PM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #5
RE: Draw3D image disappears at distance
there is D.textDepth or similar
09-21-2011 09:37 PM
Find all posts by this user Quote this message in a reply
Rofar Offline
Member

Post: #6
RE: Draw3D image disappears at distance
You can do some ray casting and check for collisions with objects from the camera to the player to determine whether or not to display the text. That's what I do.
09-21-2011 10:44 PM
Find all posts by this user Quote this message in a reply
Randy Offline
Member

Post: #7
RE: Draw3D image disappears at distance
(09-21-2011 09:37 PM)Esenthel Wrote:  there is D.textDepth or similar

Thanks!
I found PosToScreen() + D.textDepth() + D.text() is very useful combination for player names/chat clouds drawing, but how about setting image distance draw parameter? Is it a secret? )
09-21-2011 10:49 PM
Find all posts by this user Quote this message in a reply
llynx Offline
Member

Post: #8
RE: Draw3D image disappears at distance
(09-21-2011 10:49 PM)Randy Wrote:  Thanks!
I found PosToScreen() + D.textDepth() + D.text() is very useful combination for player names/chat clouds drawing, but how about setting image distance draw parameter? Is it a secret? )

It's a function you should create that would fit your aesthetic requirements.
09-21-2011 11:22 PM
Find all posts by this user Quote this message in a reply
Randy Offline
Member

Post: #9
RE: Draw3D image disappears at distance
(09-21-2011 11:22 PM)llynx Wrote:  
(09-21-2011 10:49 PM)Randy Wrote:  how about setting image distance draw parameter? Is it a secret? )

It's a function you should create that would fit your aesthetic requirements.

Engine automatically manages visibility of image (see screenshots), i just want to know how to configure it's parameters.
09-21-2011 11:43 PM
Find all posts by this user Quote this message in a reply
Driklyn Offline
Member

Post: #10
RE: Draw3D image disappears at distance
(09-21-2011 09:37 PM)Esenthel Wrote:  there is D.textDepth or similar

Wow, never knew...
09-22-2011 12:12 AM
Find all posts by this user Quote this message in a reply
Zervox Offline
Member

Post: #11
RE: Draw3D image disappears at distance
(09-21-2011 11:43 PM)Randy Wrote:  
(09-21-2011 11:22 PM)llynx Wrote:  
(09-21-2011 10:49 PM)Randy Wrote:  how about setting image distance draw parameter? Is it a secret? )

It's a function you should create that would fit your aesthetic requirements.

Engine automatically manages visibility of image (see screenshots), i just want to know how to configure it's parameters.
Did you try the alpha tip?
09-22-2011 07:35 AM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #12
RE: Draw3D image disappears at distance
Maybe you haven't called image.updateMipMaps
09-22-2011 08:54 AM
Find all posts by this user Quote this message in a reply
Randy Offline
Member

Post: #13
RE: Draw3D image disappears at distance
(09-22-2011 08:54 AM)Esenthel Wrote:  Maybe you haven't called image.updateMipMaps

Yes, now it's works!
(Previously I called .updateMipMaps() before .unlock() and it makes nothing without error)

But another question - Draw3D() automatically stretch image height equally to width, is it configurable?

Here a testing example of my code, based on '03 - World with Character.cpp' tutorial

replace

Code:
STRUCT(Player , Game::Chr)    

.....

};

with

Code:
STRUCT(Player , Game::Chr) // extend character structure by defining a player class based on the character
//{
   Memx<Game::Item> items;
   virtual Memx<Game::Obj>* itemContainer() {Memx<Game::Obj> &items=T.items; return &items;} // override default method of character, to return proper item container

           void updateItems(); // update items actions
   virtual Bool update     (); // here we'll update the player

   Player();
   UInt drawPrepare();
   void drawBlend();
   Image * img;
};

Image * CreateImage(Color col)
{    
    Image * tmp_image = new Image;
    (*tmp_image).create2D(256, 32, IMAGE_B8G8R8A8);
    
    tmp_image->lock();

    for (int x=0; x < tmp_image->x(); x++)
        for (int y=0; y<tmp_image->y(); y++)
        {
            Color c = col;
            tmp_image->color(x, y, c);
        }
    
    tmp_image->unlock();
    
    tmp_image->updateMipMaps(); // remove this to make image auto-disappearing at distance
    
    return tmp_image;
}

// Constructor
Player::Player()
{
    img = CreateImage(RED);
}

UInt Player::drawPrepare()
{
    UInt ret = super::drawPrepare();
    return IndexToFlag(RM_BLEND);
}

void Player::drawBlend()
{    
    SetMatrix();
    img->draw3D(Color(255,255,255,255), 1, 0, pos()+Vec(0,2,0));    
}

As you can see, red picture is always square.
(09-21-2011 09:06 PM)Zervox Wrote:  also remember color might need setting alpha.
image.draw3D(color,size,angle,position,ALPHA_NONE); ?

Default mode=ALPHA_BLEND_DEC gives best results (fits my aesthetic requirements ; )
(This post was last modified: 09-22-2011 04:40 PM by Randy.)
09-22-2011 04:31 PM
Find all posts by this user Quote this message in a reply
Post Reply