Advertisement Jump to content
Sign in to follow this  

Problems - ALPHA BLENDING in C# & DX9

This topic is 4912 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi there, I've got some problems using alpha blending in c# and managed directx 9. My Problem is the following: I define a (for example) a simple triangle like this: m_Vertices[0].Position = new Vector3(0.0f, 0.5f, 0.0f); m_Vertices[0].Color = Color.FromArgb(255, 255, 255, 255).ToArgb(); m_Vertices[0].TexCoords = new Vector2(0.5f, 0.0f); m_Vertices[1].Position = new Vector3(-0.5f, -0.5f, 0.0f); m_Vertices[1].Color = Color.FromArgb(255, 255, 255, 255).ToArgb(); m_Vertices[1].TexCoords = new Vector2(0.0f, 1.0f); m_Vertices[2].Position = new Vector3(0.5f, -0.5f, 0.0f); m_Vertices[2].Color = Color.FromArgb(255, 255, 255, 255).ToArgb(); m_Vertices[2].TexCoords = new Vector2(1.0f, 1.0f); Vertexbuffer etc. are also setup an everything is all right till now. NOW, I want to use the alpha value in the vertex color to set transparency. HOW THE HELL DOES THIS PIECE OF XXXX WORKS? Actually these are my renderstates: DeviceD3D.RenderState.AlphaBlendEnable = true; DeviceD3D.RenderState.SourceBlend = Blend.SourceColor; DeviceD3D.RenderState.DestinationBlend = Blend.InvSourceColor; I can accomplish transparenc by adding a damn material, setting a new renderstate an render that damn triangle. BUT I want to use the alpha value in the color of my vertices. The so famous DX SDK does not give me a working example! Please help ... before I get mad thx

Share this post

Link to post
Share on other sites
Hi there codex01,
How are you doing?
Seems you are a little tense...

[The Problem]
Alpha blending without using light?

[The Solution]
"Color can be defined with or without alpha values. Color without alpha is RGB; color with alpha is stored as ARGB. Vertex data, material data and texture data can be used to give object's transparency. The frame buffer can also be used to generate transparency effects."

Here is some code you can look at

using System;
using System.Drawing;
using System.Windows.Forms;
using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;

namespace Engine
public class Core
#region Members
private Window window;
private VertexBuffer vb;
private Matrix matWorld;

#region Methods
public Core()
window = new Window();

window.D3DDevice.RenderState.AlphaBlendEnable = true;
window.D3DDevice.RenderState.SourceBlend = Blend.SourceAlpha;
window.D3DDevice.RenderState.DestinationBlend = Blend.SourceAlpha;

CustomVertex.PositionColored[] triangle = new CustomVertex.PositionColored[3];
triangle[0] = new CustomVertex.PositionColored(-1.0f, 0.0f, 0.0f, Color.FromArgb(255, 255, 0, 0).ToArgb());
triangle[1] = new CustomVertex.PositionColored(-1.0f, 2.0f, 0.0f, Color.FromArgb(127, 255, 0, 0).ToArgb());
triangle[2] = new CustomVertex.PositionColored( 1.0f, 0.0f, 0.0f, Color.FromArgb(127, 255, 0, 0).ToArgb());
vb = new VertexBuffer(typeof(CustomVertex.PositionColored), 3, window.D3DDevice, Usage.WriteOnly, CustomVertex.PositionColored.Format, Pool.Managed);
vb.SetData(triangle, 0, LockFlags.None);

window.D3DDevice.RenderState.Lighting = false;
private void Update()
matWorld.Translate(0.0f, 0.0f, 0.0f);
private void Render()
window.D3DDevice.Transform.World = matWorld;
window.D3DDevice.SetStreamSource(0, vb, 0);
window.D3DDevice.VertexFormat = CustomVertex.PositionColored.Format;
window.D3DDevice.DrawPrimitives(PrimitiveType.TriangleStrip, 0, 1);
public void Run()

I hope this helps you.
Keep cool.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!