Archived

This topic is now archived and is closed to further replies.

Rendering a Surface

This topic is 5505 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello all, Anyone know how to render a surface onto an object? Or do I need to convert a surface into a texture first so that it can be rendered onto an object. If so, how? Or am I totally going in the wrong direction? I''m trying to combine small bitmaps onto one large bitmap in memory before I create a texture out of them. I looked into multitexturing, but the individual small bitmaps I have need to appear in different exact places on the main texture. Is this possible with multitexturing?

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
quote:
Original post by Green
Hello all,

Anyone know how to render a surface onto an object?
Or do I need to convert a surface into a texture first so that it can be rendered onto an object. If so, how?
When you say Surface, I''m thinking you are meaning the IDirectSurface8 surfaces. Here''s a Hierarchial map of how Textures/Surfaces are organized:

IBaseTexture8 -> ITexture8 =>IDirectSurface8

-> means derived
=> means contains.

When you create a texture, a surface is created inside of it. You can create all sorts of textures, ones with rendertargetable Surfaces or ones with Cubemaps , etc. etc.. You simply call a method (function) of the texture to lock the surface associated with teh textue.

However, I have found no way to wrap a valid texture object around a surface already in memory, So I create a texture with a surface with the properties I need. There are a ton of D3DX functions to do this.

If you are going to update it once, then you could use a CopyRects call to copy the surface into the texture surface. If you plan on doing it intermittantly, I suggest looking at the UpdateTexture functions in D3DX. If you plan on updating the texture once a frame, I suggest creating a texture that has a rendertarget surface and rendering to the surface with the device object.

quote:
Original post by Green
I''m trying to combine small bitmaps onto one large bitmap in memory before I create a texture out of them. I looked into multitexturing, but the individual small bitmaps I have need to appear in different exact places on the main texture. Is this possible with multitexturing?
Multitexturing means blending different textures to the same spot on geometry. Maybe you should look into CopyRects() unless you are doing a lot of this, in which case I suggest doing this design time.

Share this post


Link to post
Share on other sites
Thank you for your speedy reply.


I'll do what you sugested:

_______________________________________________________
If you plan on updating the texture once a frame, I suggest creating a texture that has a rendertarget surface and rendering to the surface with the device object.
________________________________________________________

Question:

I'll create a texture with D3DUSAGE_RENDERTARGET for usage. I can do that, but...

How now do I render to this surface?


[edited by - Green on November 19, 2002 10:16:24 PM]

Share this post


Link to post
Share on other sites
ok, looking into this...

CopyRects uses surfaces.
UpdateTexture uses IDirect3DBaseTexture.

If I create a render taget texture, how do I use the above functions? I guess I cant!

CopyRects gives me the flexibility I need for selecting parts of different bit maps and copying them to specific places. CopyRects uses IDirect3DSurface8, so I am back to the same question,

How to convert a IDirect3DSurface8 into a texture so I can render it onto an object?

[edited by - Green on November 19, 2002 11:07:24 PM]

[edited by - Green on November 19, 2002 11:17:10 PM]

Share this post


Link to post
Share on other sites
//Ok I''m trying this:
//I have two textures whith which i create surfaces for. I then copy rect from the second surface to the first. Then I set texture with the first and render an object. However the copying doesnt seem to be taking place. Please help if you can. Thanks in advance.

D3DLOCKED_RECT pLockedRect;

RECT Rectangle[1];
Rectangle[0].left = 0;
Rectangle[0].top = 0;
Rectangle[0].right = 10;
Rectangle[0].bottom = 10;

POINT PointsArray[1];
PointsArray[0].x = 5;
PointsArray[0].y = 5;

IDirect3DSurface8* aSurface[2];

m_pTexture[0]->LockRect(0,&pLockedRect,NULL,0);

m_pTexture[0]->GetSurfaceLevel(0,&aSurface[0]);
m_pTexture[1]->GetSurfaceLevel(0,&aSurface[1]);

aSurface[0]->LockRect(&pLockedRect,NULL,0);
aSurface[1]->LockRect(&pLockedRect,NULL,0);

m_pD3DDevice->CopyRects(aSurface[1],&Rectangle[0],1,aSurface[0],&PointsArray[0]);

aSurface[0]->UnlockRect();
aSurface[1]->UnlockRect();

aSurface[0]->Release();
aSurface[1]->Release();

m_pTexture[0]->UnlockRect(0);

//Now I set texture to m_pTexture[0] and render it onto an object, but I dont get the copy? Agrh!

Share this post


Link to post
Share on other sites
Yes, got that, but I have only one function that uses rectangle.

m_pD3DDevice->CopyRects(aSurface[1],&Rectangle[0],1,aSurface[0],&PointsArray[0]);

Where does the other one go? I''m sorry that I''m not getting this, please bear with me!

Share this post


Link to post
Share on other sites
Yes I understand arrays. I can make 2 rectangles :
RECT Rectangle[2]
Rectangle[0] and Rectangle[1]

but I am only using one. Where do I put the other?

Share this post


Link to post
Share on other sites
wait a sec, after going back and reading your code you only have one ''Rectangle'', why is it an array?

sorry about the RECT Rectangle[2] thing i assumed that since there was a [1] thing there would be more than one rectangle. my bad

other than that, i don''t know how you are trying to code what, so i''ll let someone who knows what they are talking about tell ya.

Share this post


Link to post
Share on other sites
Eventually I''ll have larger arrays of rectangles and surfaces. But for now started with one rectangle and two surfaces.

I''m trying to figure out how to apply multiple small bit maps in exact places onto one texture and then render an object using that texture.

Thank you for your time billybob.

Share this post


Link to post
Share on other sites
I don''t think you have to do any locking when using CopyRects(), just give it the surfaces from the texture (using your same variable names):


m_pTexture[0]->GetSurfaceLevel(0,&aSurface[0]);
m_pTexture[1]->GetSurfaceLevel(0,&aSurface[1]);

m_pD3DDevice->CopyRects(aSurface[1],&Rectangle[0],1,aSurface[0],&PointsArray[0]);

aSurface[0]->Release();
aSurface[1]->Release();


Also you should check the return value of the CopyRects() call to make sure it''s not failing, there are some restrictions, for example both textures need to use the same pixel format.

Share this post


Link to post
Share on other sites