Texture From Surface.

if that surface belongs to a texture, you can just go surface.GetContainer() to get the texture that contains it.

from what i know, to render to a texture u must create a texture, then get the level of the texture u want to render to (which would be a surface) and then render to that surface. that results in the texture containing the surface containing the render.

as in

C#:
// being "display" the D3D Device
// and being "renderedTexture" created with the RenderTarget flag

Surface renderedSurface=renderedTexture.GetSurfaceLevel(0);
display.SetRenderTarget(0, renderedSurface);

// do render here
// clean up if needed

after rendering, if you set the render target back to the backbuffer (Device.GetBackBuffer()), then you can set the "renderedTexture" object to be a texture for a primitive and voilá :D
 
Last edited:
Sorry about the stupid question but

How do i render a surface then? (the surface does not belong to a texture so i have to render it onto a texture or can i say tex.getsurface(0).fromSurface or something like that to set the surface on the destination texture equal to the surface that i created.
 
what do you want to do afterall?

- Surfaces cannot be applied as a map on polygons. Textures are there for that.
- Textures are composed of various levels which can be retrieved as Surfaces.
to render to a Surface, just do Device.SetRenderTarget(0, SURFACE);
- The only Textures that have Surfaces that can be rendered to are the ones created with the RenderTarget flag
- These being said, to render to a Texture, u get the Surface of a level and render to that surface.

btw, the last post showed how to render to a texture.
 
Sorry

Menge said:
what do you want to do afterall?

- Surfaces cannot be applied as a map on polygons. Textures are there for that.
- Textures are composed of various levels which can be retrieved as Surfaces.
to render to a Surface, just do Device.SetRenderTarget(0, SURFACE);
- The only Textures that have Surfaces that can be rendered to are the ones created with the RenderTarget flag
- These being said, to render to a Texture, u get the Surface of a level and render to that surface.

btw, the last post showed how to render to a texture.
What i need is the code to render to the surface... From a surface. The previous quote shows how to set the surface of the texture as the render target so i can effectivly Draw on the Texture now i allready have a surface that i want to draw on the texture, Thinking about it could i not go ...
Visual Basic:
Public Function GetScreenTexture() as texture
Dim tTex as texture
Dim Surf1 as Surface = tTex.GetSurfaceLevel(0)
Dim Surf2 as surface = Device.CreateOffscreenPlainSurface(Screen.width,Screen.Height,Sceen.Format,Pool.Systemmemory)
Device.GetFrontBuffer(0,Surf2)
Surf1 = Surf2
Return tTex
End Function
or i guess could i not just ignore creating surf2 and go strait to Device.GetFrontBuffer(0,Surf1) ?
 
your code is a bit weird. there's no GetFrontBuffer function in the Device class. ur not being quite clear to me, so i'll give out the 3 options that i understood.

1) if you want to copy the screen of what was last rendered right? if that's so, all you need to do is:

C#:
Surface FrontBufferCopy = Device.CreateOffscreenPlainSurface(WIDTH, HEIGHT, FORMAT, POOL);
Device.GetFrontBufferData(0, FrontBufferCopy);
// according to the documentation, now FrontBufferCopy has a copy of the Front Buffer

2) if you want to copy the contents of a surface to another one, you may use the Device.UpdateSurface(source as Surface, dest as Surface) method.

3) if you want to actually render to a surface, then follow on below :)

to create a plain renderable surface:
C#:
// to create the surface
Surface RenderSurface = Device.CreateRenderTarget(WIDTH, HEIGHT, FORMAT, MultiSampleType.None, 0, true);

to render to that surface:
C#:
Device.SetRenderTarget(0, RenderSurface);
// whatever you render between the BeginScene() and EndScene() calls WILL end up on RenderSurface

to go back to the original backbuffer while keeping what was rendered on the old buffer:
C#:
Surface BackBuffer = Device.GetBackBuffer();
Device.SetRenderTarget(0, BackBuffer);
// whatever you render after this will end up on the backbuffer

i hope ONE of these 3 will help ya out
 
Sorry

The Function i ment was getFrontBufferData (Too tired i think) (*notes 1Am, ya time to think about bed....) For Clarity What i want to do simply is Create a Texture From the screen. This being the Third thread on this subject and still no workable solution for me.... OK The Second thread (Started by thePentiumGuy i believe) got me to Device.GetFrontBufferData(0,Surface) Now all i want is to Make a texture out of that surface.... So that i can render a VertexBuffer using that texture,... Im sorry that my questions are hard to understand what im getting at (and usually simple to solve), And thank you all for your patience.
 
This was solved?

Menge said:
ok, glad this was solved for ya.

next time, try to be more concise and clear on what you are asking. doing so usually gets questions answered quicker :)
Yes im Sorry that my question was a little less than concise. However i still dont see the answer to it here. I still need to make a texture out of a surface. And i dont see the answer here it may be with that locking a surface as a render target but then What i need to know is how do i render the surface onto it.
 
Thank you Menge

Menge said:
well you might want to read my 3 option post again. the code's all there.
Im am just out of it this week (probably may have something to do with the leaky oil tank across the street... Oh well, Thank you for your help. the Update Surface method should work i think.
 
Back
Top