heres the code that i currently have
_Device.RenderState.AlphaBlendEnable = True
_Device.RenderState.SourceBlend = Blend.SourceAlpha
_Device.RenderState.DestinationBlend = Blend.InvSourceAlpha
renderSprite.Begin(SpriteFlags.AlphaBlend)
renderSprite.Transform = Matrix.Scaling(CType(screenWidth, Single) / CType(backgroundSource.Width, Single), CType(screenHeight, Single), CType(backgroundSource.Height, Single), 0)
renderSprite.Draw(backgroundTexture, backgroundSource, ObjectCenter, ObjectCenter, SpriteColor)
renderSprite.Transform = Matrix.Identity
_device.RenderState.AlphaBlendEnable = True
renderSprite.Draw(buttonTextureOff, offSource, UI_Screen.ObjectCenter, New Vector3(0, 0, 1), System.Drawing.Color.FromArgb(100, Color.White))
_device.RenderState.AlphaBlendEnable = False
renderSprite.End()
heres the stuff that i tried for the alpha parts of creating the device
'_Device.RenderState.AlphaSourceBlend = Blend.SourceAlpha 'none of the above changes did anything at all to the following results. 'renderSprite.Draw(buttonTextureOff, offSource, UI_Screen.ObjectCenter,
'_Device.RenderState.AlphaDestinationBlend = Blend.InvSourceAlpha
'_Device.RenderState.AlphaBlendOperation = BlendOperation.Max
'_Device.RenderState.AlphaSourceBlend = Blend.SourceAlpha
'_Device.RenderState.AlphaDestinationBlend = Blend.Zero
'_Device.RenderState.AlphaTestEnable = True
'_Device.RenderState.SeparateAlphaBlendEnabled = True
'
'_Device.RenderState.AlphaFunction = Compare.Greater
'_Device.RenderState.AlphaTestEnable = True
'_Device.RenderState.AlphaDestinationBlend = Blend.InvSourceAlpha
'_Device.RenderState.SourceBlend = Blend.SourceAlpha
'_Device.TextureState(0).ColorOperation = TextureOperation.Modulate
'_Device.TextureState(0).ColorArgument1 = TextureArgument.TextureColor
'_Device.TextureState(0).ColorArgument2 = TextureArgument.Diffuse
'_Device.TextureState(0).AlphaOperation = TextureOperation.SelectArg1
'_Device.TextureState(0).AlphaArgument1 = TextureArgument.TextureColor
and for rendering the sprite
'renderSprite.Draw(buttonTextureOff, offSource, UI_Screen.ObjectCenter, New Vector3(0, 0, 1), System.Drawing.Color.FromArgb(100, Color.white)) nothing: all white no opacity
'renderSprite.Draw(buttonTextureOff, offSource, UI_Screen.ObjectCenter, New Vector3(0, 0, 1), System.Drawing.Color.FromArgb(100, nothing)) nothing: all white no transparency
'renderSprite.Draw(buttonTextureOff, offSource, UI_Screen.ObjectCenter, New Vector3(0, 0, 1), System.Drawing.Color.FromArgb(100, Color.Black)) nothing: all black no transparency
'renderSprite.Draw(buttonTextureOff, offSource, UI_Screen.ObjectCenter, New Vector3(0, 0, 1), System.Drawing.Color.FromArgb(100, Color.Violet)) nothing: all violet no transparency
'renderSprite.Draw(buttonTextureOff, offSource, UI_Screen.ObjectCenter, New Vector3(0, 0, 1), System.Drawing.Color.white nothing: all white no transparency
'renderSprite.Draw(buttonTextureOff, offSource, UI_Screen.ObjectCenter, New Vector3(0, 0, 1), System.Drawing.Color.white) nothing: all white no transparency
renderSprite.Draw(buttonTextureOff, offSource, UI_Screen.ObjectCenter, New Vector3(0, 0, 1), System.Drawing.Color.FromArgb(0, Color.Violet)) nothing, its not shown at all
my image textures in the file are all black.
im using the august sdk. although it did the same with the april as well.
I also noticed that you are using the Draw method of the Sprite object. Try using Draw2D (since you are going with a 2D solution in this case). If you wish to work with the Draw method (for possible 3D implementation later), you may need to change the values of some arguments in that method. The 3D element adds another factor when drawing textures. Unfortunately, I haven't begun to deal with 3D texture drawing.
Ok, so back to the presentation parameters.
I have my presentation parameters set to the following:
// Set generic presentation parameters PresentParams.SwapEffect = SwapEffect.Discard;PresentParams.EnableAutoDepthStencil = true;PresentParams.AutoDepthStencilFormat = DepthFormat.D16;PresentParams.PresentationInterval = PresentInterval.One;PresentParams.Windowed = true; |
I then use the following method to draw my sprites with some experimental effects:
SpriteController.Begin( SpriteFlags.AlphaBlend); float xv = 0; int av = 0; float rv = 0; float sv = 0; for (int passes = 0; passes <= 50; passes += 1){ Point NewPoint = new Point((int)xv, SpritePoint1.Y); // Ensure the alpha value does not go below 0 if (av > 255) { av = 255; } // Ensure sv does not become negative if (sv < 0) { sv = 0; } if (sv > 2) { sv = 2; } // Make the top most layer full opaque if (passes == 50) { av = 255; }NewPoint.X = SpritePoint1.X + ( int)xv;SpriteController.Draw2D(sprite.Texture, new Rectangle(0, 0, sprite.Width, sprite.Height), new Rectangle(0, 0, (int)(sprite.Width * sv), (int)(sprite.Height * sv)), new Point(20, 2), rv, NewPoint, Color.FromArgb(av, 255, 255, 255));xv += 0f; av += 5; rv += 0.01f; sv += 0.04f; //2 / (50 / 2);} //SpriteController.Draw2D(texTest, new Point(0, 0), 0, SpritePoint1, Color.FromArgb(150, 255, 255, 255));SpriteController.Draw2D(sprite.Texture, new Rectangle(0, 0, sprite.Width, sprite.Height), new Rectangle(0, 0, sprite.Width, sprite.Height), new Point(0, 0), Color.FromArgb(200, 155, 255, 150)); //SpriteController.Draw2D(texTest, new Point(0, 0), 0, SpritePoint2, Color.FromArgb(200, 155, 255, 150));SpriteController.End(); |
In addition to all this, I'm using the following method to load my sprite (texture):
m_texture = TextureLoader.FromFile(device, m_sourceFile, 0, 0, 0, Usage.Dynamic, Format.Unknown, Pool.Default, Filter.None, Filter.None, m_maskColor.ToArgb(), ref m_imageInformation); |
The sprite draw method I included above, draws textures with varying opacities and works on my machine.
Some notes:
1. SpriteController is simply an instance object of the Sprite class.
2. The
sprite |
m_texture |
sprite.Texture |
Hope this works for you and helps.
If not, try using your code (if not done already) in the Managed DirectX sample project since that project has everything setup properly. You need to make sure that you have everything setup to properly dispose and restore DirectX resources (such as adding event handlers for the Device.OnDeviceReset() event and the Form.OnPaint() event.
I'm not sure what your level of DirectX and/or C# is; so hopefully I'm not speaking complete greek here (or should I say "geek", lol geek-speak...) Anyway, let me know if any of this doesn't work or if you still run into problems getting the varying opacity working for drawing textures. I'd hate to see a good idea go to waste!
As I write this now, I realize that your last post was on 8 Aug and it is now almost October; so I'm probably a little late with this, but perhaps some programmer browsing the internet in need of help will come across this and find some benefit. We shall have to see... At least that way I won't feel like I've completely wasted my time.
- Aaron Misner