Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!

1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


Member Since 10 Jun 2006
Offline Last Active Nov 24 2013 06:39 PM

Topics I've Started

Overlapping sprites with transparency

18 February 2012 - 10:22 AM

Posted Image

Using XNA 4.
I'm rendering a bunch of overlapping sprites to the screen based on a calculated layerDepth.
Any sprites that might conceal the player I draw with a transparent color in the draw function.
Is there a way to prevent visible overlapping edges in this scenario? (See corner block sides "doubling up" against the other transparent pieces)
Basically, I'd like the three partially-transparent walls to look like one object, without seeing the sides of the walls that you wouldn't normally see, if they were fully opaque.

[XNA] Manual "Premultiply Alpha" rendering issue

24 October 2011 - 02:45 PM

I'm using XNA4, and I was rendering everything perfectly to screen using spritebatches on premultiplied alpha PNG's.
Decided to forego the Content.Load that XNA provides and use Texture2D.FromStream in order to dynamically load PNGs, in order for the artist to test graphical changes quicker without recompiling.

In doing so I had to find some code in order to convert the Texture2D to a "premultiplied alpha" format, which is what XNA4 defaults to normally.

This is the code I found from: http://jakepoz.com/jake_poznanski__speeding_up_xna.html
// Blah blah
Texture2D t = Texture2D.FromStream(graphicsDevice, titleStream);
// Blah blah

            blendColor = new BlendState();
            blendColor.ColorWriteChannels = ColorWriteChannels.Red | ColorWriteChannels.Green | ColorWriteChannels.Blue;
            blendColor.AlphaDestinationBlend = Blend.Zero;
            blendColor.ColorDestinationBlend = Blend.Zero;
            blendColor.AlphaSourceBlend = Blend.SourceAlpha;
            blendColor.ColorSourceBlend = Blend.SourceAlpha;

            blendAlpha = new BlendState();
            blendAlpha.ColorWriteChannels = ColorWriteChannels.Alpha;
            blendAlpha.AlphaDestinationBlend = Blend.Zero;
            blendAlpha.ColorDestinationBlend = Blend.Zero;
            blendAlpha.AlphaSourceBlend = Blend.One;
            blendAlpha.ColorSourceBlend = Blend.One;

                RenderTarget2D target = new RenderTarget2D(graphicsDevice, t.Width, t.Height);
                    SpriteBatch spriteBatch = new SpriteBatch(graphicsDevice);

                    // Multiply each color by the source alpha, and write in just the color values into the final texture  
                    spriteBatch.Begin(SpriteSortMode.Immediate, blendColor);
                    spriteBatch.Draw(t, t.Bounds, Color.White);

                    // Now copy over the alpha values from the PNG source texture to the final one, without multiplying them  
                    spriteBatch.Begin(SpriteSortMode.Immediate, blendAlpha);
                    spriteBatch.Draw(t, t.Bounds, Color.White);
                t = target as Texture2D;

Using this code, everything renders correctly just as it did before the switch-over.
However, now when I resize the game window (or maximize/restore the window) the rendering breaks, and all textures end up black. The only thing that still renders is the HUD, where I used DrawString().
This did not happen previously.
Infact, I can comment out all of the Premultiply Alpha code from above, and the issue goes away, except now that I'm not using a "premultiplied alpha" texture, the rendering is funky.

What is the issue that is going on, here? I have a feeling it has to do with changing the RenderTarget, but I'm not entirely sure.

Matching words with wildcards

12 October 2009 - 11:58 AM

I'm not entirely sure if there is a fast, simple way to do this... I'm thinking regex is probably the simplest way of doing this. What I need to do is be able to compare strings that may or may not have wildcard characters in them. For instance I may have a list of >strings< like this: 11225 1123? 48622 55* 785?? 99745 And I will be trying to match other strings to this list. I will loop through the list looking for a match. There will only be one possible match in the list, and I will be comparing one at a time until I find a match. * is a wildcard that any number of any characters can match ? is a wildcard that matches any single character in its place anyone good with regular expressions? Thanks

[.net] C#, HSL and PNGs

01 September 2006 - 09:31 PM

I'm using C#, .NET 2.0, I'm using GDI+ for my image stuff I'm needing to adjust the hue saturation and luminance of a PNG that's loaded into memory. I'm also needing to keep transparency information intact. Anyone have any good methods of doing this?

Project Basics

10 June 2006 - 07:50 AM

Me and some friends are wanting to start a project together and I'm trying to get some basic guidelines drawn up so we all have a place to start. What we're thinking about is an isometric multiplayer RPG game using DirectX, programmed in C#. It would be nice if it ran on Linux and Windows, and essentially free of any royalty stuff with formats. (Ignore that we're using DirectX for now.. I hear it's just easier to work with for now.. if we ever want to port to linux we could always include an opengl option) With that in mind, what formats should we use for images, sounds, music, etc. I'm thinking music could be OGG, but what about images and small sounds? Should all sounds use OGG, or is something like wav better suited? For images we need something that is high quality, and will be good with directx. Also something decent in size (obviously nothing like BMPs). I think PNG? Would that be the best to use? Programming-wise.. what sort of database should we use? It should be able to handle a large amount of data accessing quick and easily. I have experience with MySQL, but i'm not sure if that's the best suited for this project Are there also any sites that provide free pre-made graphics and sounds we could use until we made our own? also any tutorials on making this sort of thing would be great