Rend to transparent surface

Started by
8 comments, last by xpload 16 years, 12 months ago
Hi, is it somehow possible to use a A8R8G8B8 Surface as target for the D3DXRenderToSurface interface? I just tried, but the result was a grey-filled surface as background... P.S. Using DirectX8.1
Advertisement
Sure but have to make sure that the surface is a render target.

To do this the surface need to created with CreateRenderTarget or need to be a mipmap of a texture created with D3DUSAGE_RENDERTARGET.

Additional you should use CheckDeviceFormat to make sure that your hardware supports render targets with this format.
Sure it is render target. At least no error occurs on the check. I suggest I should try creating my own render for the case...

Additionally, I can't rend colors with alpha value(for example, a line with color D3DCOLOR_ARGB(128, 255, 0, 0) is opaque red instead of half-transparent). Should I say somehow the render, that it should handle the alpha channel too? And how should I do this?
I am not sure if I understand your problem right. If you render to a surface with an alpha canal and then use it as a texture the alpha canal is written to your render target. If you want to use it for transparency you have to set some alpha blending states depending on what you exactly want.
Not exactly. My texture has no problem being displayed transparent. But at the moment when I use it as a render target, all transparent areas become opaque grey. The effect I'm trying to achieve is, that the RTT keeps its alpha channel after the rending...
How are you drawing it exactly?

If you drew whatever you're drawing to the back buffer, does it look correct? Are all your render states correct?
The problem is, I have huge experience drawing 2D and quite a beginner in 3D and particular in Direct3D. So I don't know what really correct IS :(

I just change the render target, set my D3DUSAGE_RENDERTARGET Texture as the new rendering destination, begin scene and then comes the following code(skipped the error check for convinience):

DIFF_VERTEX verts[2];
VOID * pData;

verts[0].x = 0;
verts[0].y = 0;
verts[0].z = 0.0f;
verts[0].rhw = 1.0f;
verts[0].color = D3DCOLOR_ARGB(128, 255, 0, 0);

verts[1].x = 400;
verts[1].y = 400;
verts[1].z = 0.0f;
verts[1].rhw = 1.0f;
verts[1].color = D3DCOLOR_ARGB(128, 255, 0, 0);

m_Direct3D.GetDevice()->CreateVertexBuffer( 2 * sizeof(DIFF_VERTEX), 0, D3DFVF_XYZRHW | D3DFVF_DIFFUSE, D3DPOOL_DEFAULT, &vertexBuffer );

vertexBuffer->Lock( 0, 0, (BYTE **)&pData, 0 );

memcpy( pData, verts, sizeof(verts) );

vertexBuffer->Unlock();

m_Direct3D.GetDevice()->SetStreamSource( 0, vertexBuffer, sizeof(DIFF_VERTEX) );

m_Direct3D.GetDevice()->DrawPrimitive( D3DPT_LINELIST, 0, 1 );

vertexBuffer->Release();

Then EndScene. The next thing I do is CopyRects() from the texture's surface to the backbuffer. If there was some transparent areas on the surface, they are grey on the screen. The line that I try to draw, is at full opacity, not at half transparence. I don't really know where the problem is...
I have done something very similar to what you are talking about, I used

Textureyourrenderingto->GetSurfaceLevel(0,&srfTemp);

Then used:

D3DXLoadSurfaceFromSurface(srfTemp,NULL,&rtDest,srfNumSource,NULL,&rtSorce,D3DX_FILTER_NONE,0);//0xFFFF00FF);


to copy from one surface to another.

then Released the srfTemp surface.

The alpha info was rendered properly with this method.
Hope that was somewhat clear.

-vs

If this seems to be a new project you should think about using Direct3D 9 instead of 8. Most people including me have problems remember on every little detail of this somewhat older version. Additional most tutorials you will find in the web today are for Direct3D 9.

Coming back to your problem.

I assume that your render to the target vertices and the vertices used to render this target texture later use different formats. Have you report this changes to the Direct3D device with a SetVertexShader call?

Another possible source of your problem are the render states. If you have enable alpha blending for your texture render pass you need to disable it for your render to this texture pass or anything get blended there too.
Hmm. Thanks in every case for the replies, I see you know your job.
Actually I don't rend the texture itself. I rend ON it(on its first mip surface). The result, i.e. the surface, is just copied(CopyRects) to the screen. I now realize that this should not work at all, because surfaces don't support alpha blending. The second variant I tried out is to use D3DXSprite to map the texture to the backbuffer, which should set all necessary states to their proper states (I don't have problem displaying other see-thru textures), but the result was the same. I hope it's at least a little understandable..

This topic is closed to new replies.

Advertisement