|
DirectX9 Surface support alpha-channel and can be loaded from .png file. How can I make them draw with transparency ?
|
|
|
|
|
"A Microsoft® Direct3D® device is a state computer", you need to enable/set the render states for Transparency. see [Alpha Blending State ^] you need to use the D3DRS_ALPHABLENDABLE render state to enable alpha transparency blending and set the blending type.
|
|
|
|
|
from the above link:
The alpha value of a color controls its transparency. Enabling alpha blending allows colors, materials, and textures on a surface to be blended with transparency onto another surface.
In my game, I just need to draw .png images with alpha, the same size they are. I've got a lot of those for drawing a complicated animation. I've got about 650 images.
I find the textures interface unsuitable, because of their creation cost, and the fact they don't natively looked exactly as the images.
So, I'm using D3DxCreateSurfaceFromFile() and later ID3DDevice::StretchRect() to draw on the bacbuffer surface.
It seems to me like the SetRenderState() capabilities do not apply to DirectX9 surfaces. But I do guess there is some way to alpha-blend surfaces because they contain alpha-channel color.
|
|
|
|
|
Hanan888 wrote: The alpha value of a color controls its transparency. Enabling alpha blending allows colors, materials, and textures on a surface to be blended with transparency onto another surface.
have you seen "on a surface" to another surface. without enabling alpha blending state, you are not going to get transparency from Direct 3D, which doesnot do/skips any alpha blending calculation on the device.
Hanan888 wrote: It seems to me like the SetRenderState() capabilities do not apply to DirectX9 surfaces
have you tried?
Hanan888 wrote: So, I'm using D3DxCreateSurfaceFromFile()
AFAIK, D3DxCreateSurfaceFromFile is not dx9 API, may be you are using some wrapper which creates a surface and uses D3DXLoadSurfaceFromFile API.
|
|
|
|
|
Thank you.
Rajkumar R wrote: have you seen "on a surface" to another surface. without enabling alpha blending state, you are not going to get transparency from Direct 3D, which doesnot do/skips any alpha blending calculation on the device.
I think perhaps StretchRect() doesn't go through that processing.
this is what I tried:
pd3dDevice->SetRenderState(D3DRS_ALPHABLENDENABLE,TRUE);
pd3dDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCCOLOR);
pd3dDevice->SetRenderState(D3DRS_DESTBLEND,D3DBLEND_INVSRCCOLOR);
pd3dDevice->GetBackBuffer(0,0,D3DBACKBUFFER_TYPE_MONO,&pBackBuf);
pd3dDevice->StretchRect(sourceSurface, pSourceRect, pBackBuf,
pRectOnBackbuffer,D3DTEXF_NONE);
I use surfaces in the A8R8G8B8 format, load from PNG images with alpha-channels.
saw no effect.
This is how I create the source surfaces:
device->CreateOffscreenPlainSurface(width,height, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT,
&surface, NULL);
Rajkumar R wrote: AFAIK, D3DxCreateSurfaceFromFile is not dx9 API, may be you are using some wrapper which creates a surface and uses D3DXLoadSurfaceFromFile API.
Sorry for the typo, it's D3DXLoadSurfaceFromFile() .
|
|
|
|
|
I think so, StretchRect replaces the surface color values without doing alpha blending, i was thinking on IDirectDrawSurface:Blt which supports that.
I think you need to go to texture only (collection of surface), consider using [ID3DXSprite Interface^] which made ease displaying the 2d textures. to reduce the cost of texture creation, i think you create a single texture with only one level and load surface of that level each time using D3DXLoadSurfaceFromFile, while you can get the surface of the texture level with IDirect3DTexture9::GetSurfaceLevel
|
|
|
|
|
Thanks again for your help.
Rajkumar R wrote: i was thinking on IDirectDrawSurface:Blt which supports that
I don't think DirectDrawSurface support any alpha-blending. It support color-keying - setting a specific color not to be shown. Also, AFAIK DirectDrawSurface cannot be loaded from .PNG file.
It seems I'm gonna use the sprite interface with textures.
AFAIK, all textures must be power of 2 in size which will force me to alter the resource files.
Also, with the many images I have, it's kinda slow and I'm looking for anything that speeds up the loading.
|
|
|
|
|
Hanan888 wrote: I don't think DirectDrawSurface support any alpha-blending
see, [IDirectDrawSurface::Blt^] and see the DDBLT_ALPHASRC flag.
Hanan888 wrote: Also, with the many images I have, it's kinda slow and I'm looking for anything that speeds up the loading.
i think you can use *.dds, which stores exactly in surface format.
|
|
|
|
|
Rajkumar R wrote: see, [IDirectDrawSurface::Blt^] and see the DDBLT_ALPHASRC flag.
Are you sure this applies to the latest SDK? couldn't find it in any branch of the MSDN documentation tree.
|
|
|
|
|
Hanan888 wrote: Are you sure this applies to the latest SDK?
yep, but not in Direct3D 9(though 9 is not latest) since directdraw interfaces are outdated in direct3d9. It is used latest directshow sdk, where VMR7 is supported by this IDirectDrawSurface interfaces while VMR9 is supported by IDirect3DSurface9 interfaces. Haven't you seen this
"The IDirectDrawSurface interface is exposed on DirectDrawSurface objects that are used in the DirectShow multimedia streaming APIs" in that link. you can also refer some samples in DirectShow how custom allocator are implemented to mix various video streams much similar like your requirement.
|
|
|
|
|
Hi,
I have a CView form on which i put some text, but when i minimised the frame the text dispappear. My question is what should i do to prevent the erase of my Text. in other words, when i'll minimize the frame, i dont wanna lose the text.
Thx !!
"The Ultimate Limit Is Only Your Imagination."
|
|
|
|
|
Blood_HaZaRd wrote: but when i minimised the frame the text dispappear
assume the text disappears when you restore after a minimise, window won't remember the text you previously draw, you need to draw always in WM_PAINT handler.
|
|
|
|
|
yes i know that i have to put the code in tyh WM_Paint. But in my app the user can draw many shapes like 100 ellispe etc so i have to store the positions of all the ellipses and redraw them. So that will use a lot of time, which is a bad thing.
is there any other suggestions like saving what is drew into a CDC var or sth else ?
"The Ultimate Limit Is Only Your Imagination."
modified on Sunday, June 1, 2008 6:44 AM
|
|
|
|
|
Blood_HaZaRd wrote: yes i know that i have to put the code in tyh WM_Paint
i wonder why it then disappears
Blood_HaZaRd wrote: is there any other suggestions like saving what is drew into a CDC var or sth else ?
you can use double buffering approach, draw in in-memory dc and copy to on-screen dc, you can determine the portion of client region that is changed and selectively copy/update the window instead of complete client region.
|
|
|
|
|
"i wonder why it then disappears"
I used to put it there but i delete the code in order to try sth else.
and about the doucble buffering could u telle me how ?? coz i'am newbie in such manipulations
Thx
"The Ultimate Limit Is Only Your Imagination."
|
|
|
|
|
Anyway you have to store all the objects into your internal datastructure, but to reduce the number of drawing you can use cached bitmap (double buffering), [CMemDC class^] shows the usage within paint handler, but you need to store across paint.
PS: MFC feature pack also has CMemDC implementation
|
|
|
|
|
Well, whatever the difficulty, the content info has to be stored somewhere before it can be stored used to redraw the window. The question realy is: 'Who writes the Code for it:- Bill Gates or you.'
Actually, Bill Gates provided a framework for retaining and storing those things, it's called the underlying Document. With each screen drawing action, you should write your actions to the Document, and then render the document to the screen. There is a very good tutorial about precisely this as part of the MFC Help System, it's called 'Scribble'. I reccommend that you take a few hours out to do this tutorial, and all your questions regarding this (and more) will be answered.
Regards
Bram van Kampen
|
|
|
|
|
Hi all,
does somebody know how could i erase an ellipse from the interace??
Let's say that i have 2 buttoms the first one for drawing an ellispe and the second one for erasing the ellipse that i drew or any other shapes.
Thx
"The Ultimate Limit Is Only Your Imagination."
|
|
|
|
|
If you are drawing directly from the button a call to UpdateDiialog or UpdateWindow will do it.
But the problem is that on this way (drawing directly from the button code) if you minimize and restore the elipse will be away as well.
I would make it:
Button "Draw" -> Set a bool, bPaintEll = TRUE;
Button "Erase" -> Reset the bool, bPainEll = FALSE;
and then in your OnDraw (for Views) or your OnPaint (for dialogs)
if (bPaintEll)
{
function or direct code to draw the ellipse
}
With it, every time you call Invalidate and UpdateWindow it will be erased and repainted (if needed), and when you have it on the screen and you go to another app or minimize, it will be repainted (if needed) alone.
Greetings.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
“The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet.” - Michael A. Jackson
Rating helpfull answers is nice, but saying thanks can be even nicer.
|
|
|
|
|
In VC++ 2008 I add a string "m\xb2" (square meter), it display as expected in the string talbe of resource editor. When I use s.LoadString to load and display it, it becomes m2.
Any way to solve it?
|
|
|
|
|
Try executing this code.
AfxMessageBox(_T("m\xb2"));
AfxMessageBox(_T("m\\xb2"));
Hint: '\' is used to specify escape characters.
Nobody can give you wiser advice than yourself. - Cicero
.·´¯`·->Rajesh<-·´¯`·.
Codeproject.com: Visual C++ MVP
|
|
|
|
|
The former one works as expected.
I've tried to subsitute \xb2 with \\xb2 in the string table, but no help.
|
|
|
|
|
OK - I overlooked your query previously. Resource editor is appending zeros after the slash. It looks like a bug to me (or may be a feature )
Try hard-coding the string in your program.
Nobody can give you wiser advice than yourself. - Cicero
.·´¯`·->Rajesh<-·´¯`·.
Codeproject.com: Visual C++ MVP
|
|
|
|
|
Strange. This works for me in both VS 2005 and 2008. I tried both UNICODE and ANSI mode to make sure that wasn't an issue.
When I add it through the resource editor, it converts it immediately to m².
Anyone who thinks he has a better idea of what's good for people than people do is a swine.
- P.J. O'Rourke
|
|
|
|
|
I have a custom control. Now i want to use it in another application. How to do that
Regards, Eswari
|
|
|
|