Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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...

Posted

DirectDraw supposedly has no Alpha-Blending ability. You could work around this by trying to use GDI+

IntPtr MyDC = MySurface.GetDC();
Graphics MyDraw = Graphics.FromhDC(MyDC);

//Use pens and stuff with DD

MyDraw.Dispose();
MySurface.ReleaseDC(MyDC);

.Net allows software to be written for any version of Windows and not break like Unmanaged applications unless using Unmanaged procedures like APIs. If your program uses large amounts of memory but releases it when something else needs it, then what's the problem?
  • 2 weeks later...
Posted

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.

Posted
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
.Net allows software to be written for any version of Windows and not break like Unmanaged applications unless using Unmanaged procedures like APIs. If your program uses large amounts of memory but releases it when something else needs it, then what's the problem?
  • 4 weeks later...
Posted
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?
Posted

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

.Net allows software to be written for any version of Windows and not break like Unmanaged applications unless using Unmanaged procedures like APIs. If your program uses large amounts of memory but releases it when something else needs it, then what's the problem?
Posted
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.
Posted

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:

device.RenderState.Lighting = true;
device.RenderState.Ambient = System.Drawing.Color.FromArgb(128, 255, 255, 255);

 

Material material = new Material();
material.Ambient = material.Diffuse = Color.FromArgb(alphaValue, 255, 255, 255);
device.RenderState.DiffuseMaterialSource = ColorSource.Material;
device.Material = material;

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...