DirectX Surface with variable opacity?

nogger

Newcomer
Joined
Jun 29, 2003
Messages
5
Hi, I would like to create a simple blend-in and -out effect for my program.

I'm using CSharp DirectDraw with DirectX SDK 9.0 .... can anyone maybe tell me how to create a surface, for example filled with black and variable alpha channel so I can control the opacity of the surface?

thanks for your help...
 
DirectDraw supposedly has no Alpha-Blending ability. You could work around this by trying to use GDI+
C#:
IntPtr MyDC = MySurface.GetDC();
Graphics MyDraw = Graphics.FromhDC(MyDC);

//Use pens and stuff with DD

MyDraw.Dispose();
MySurface.ReleaseDC(MyDC);
 
I search for the same feature with some sort of alpha-blendning under DirectDraw. I tested AndreRyan code and it works, you get the control over it in "GDI+ mode", but it is VERY slow. I tested to only draw a few lines on the screen and the frame rate drops direct to a level where it is unacceptable low.

But because DD9 is the same as DD7 so this must be an old problem, there must be someone out there with some old C++ or VB code that can be translated into C# and MDX.
 
You can use a DLL called VBDABL, it was designed for Visual Basic 6 users to let them use Alpha Blending in DD7, you may be able to use it in C#. There may be some Alpha Blending in Direct Draw code for C++ lying around on the Net somewhere
 
I have now tested to code it in Direct3D and it works, but I'm afraid I do it the wrong way. When I want to change the alpha value now have I looked the vertexbuffer and changed the color there. But what I can see from examples of older Direcx version (I havn't found anything about DX9) is it done without using the vertexbuffer, but I have problem converting it to csharp. Can anyone show me some code how to do this the right way in DX9 and csharp?
 
VertexBuffers are supposed to be rather slow and take up a lot of memory. I read a remedy for this is to have and array of vertexes and just assign the required array to a single VertexBuffer (This also gives an advantage of not having to reload all the buffers if the user Alt+Tabs) and just keep changing the source array. You'd probably alter the vertex array and on the next pass the new values will be used but the effect may be global depending on how you manage you're meshes/vertexs.

I don't have any tutorials on this though but it doesn't appear to be too difficult
 
So it is no way to alter the opacity with Renderstate or some other flags that you can find in the Direct3D Device class? I'm looking for a simple and fast way to do this. It must be someone here that knows how to do this.
 
I found the solution to the problem myself. If anyone else wants to know how, this is how I did it. I use Material to set the alpha value. But Material needs Light to work so I started to setup the Ambient value under RenderState. Then can I set the DiffuseMaterialSource value to ColorSource.Material and set the materials color Ambient and Diffuse to the alphavalue I want.

This result in the code something like this:
C#:
device.RenderState.Lighting = true;
device.RenderState.Ambient = System.Drawing.Color.FromArgb(128, 255, 255, 255);

C#:
Material material = new Material();
material.Ambient = material.Diffuse = Color.FromArgb(alphaValue, 255, 255, 255);
device.RenderState.DiffuseMaterialSource = ColorSource.Material;
device.Material = material;
 
Are you saying this makes the surface transparent? If so could you post the whole class or program?
 
Back
Top