Help with sprites2...

Started by
5 comments, last by devronious 18 years, 4 months ago
I got my sprite to transform correctly, but I'm having trouble getting the alpha to blend properly. I've got a proper texture that has transparency. I set color to white on the draw method for the sprite. My other problem is that I set the sprite to 0,0,0 and it looks great when I spin my view around and everything. But when I set SpriteFlags.Billboard on the Sprite.Begin method the sprite completely dissapears. Frustrated with sprites, Devin
Advertisement
I'm guessing that you're using C#, but the C++ API is probably similar, so:

For alphablending, have you passed the C# equivalent of D3DXSPRITE_ALPHABLEND to Sprite.Begin()?

For billboarding, have you called the C# equivalent of ID3DXSprite::SetWorldViewLH or ID3DXSprite::SetWorldViewRH first before rendering?
Oh cool, thanks, I did pass the alpha blending but didn't set the worldview portion before billboard.

Thanks for helping me see that.
OK, I'm about to go crazy. I can't for the life of me figure out what's wrong with the alpha. I've checked the texture and it's good. I've checked all the settings and I see nothing wrong there. Is there something with sprites that I'm missing? My other draw funcs in my render loop draw with alpha blending, it's just the sprite that wont go alpha!!!
Could be a problem with your render states, but I don't know enough about the Sprite interface to tell you what it manages automatically.
Here's what I have set for render states:


[source lang=c#]     this.device.RenderState.SourceBlend = Blend.SourceAlpha; //set the source to be the source's alpha            this.device.RenderState.DestinationBlend = Blend.InvSourceAlpha; //set the destination to be the inverse of the source's alpha            this.device.RenderState.AlphaBlendEnable = true; //enable             this.texture = TextureLoader.FromFile(device, "tex.bmp");



and here's what I have set to render the sprite:

[source lang=c#]        public void Draw()        {            this.surfacesprite.sprite.SetWorldViewLH(this.device.Transform.World, this.device.Transform.View);            this.surfacesprite.sprite.Begin(SpriteFlags.AlphaBlend | SpriteFlags.ObjectSpace | SpriteFlags.Billboard | SpriteFlags.SortDepthBackToFront);            foreach (Vector3 pos in this.SpritePositions)                this.surfacesprite.DrawModulated(pos, 45f);            this.surfacesprite.sprite.End();        }        public void DrawModulated(Vector3 position, float angle)        {            if ((CurrentTexture + 1) == NumberOfTextures)                CurrentTexture = 0;            else CurrentTexture += 1;            SurfaceTexture tex = surfacetextures[CurrentTexture];            this.sprite.Draw(tex.texture, tex.center, position, Color.White.ToArgb());        }
The sdk docs for alphablend arg says this:

Enables alpha blending with RenderStateManager.AlphaTestEnable set to true (for nonzero alpha). SourceAlpha is the source blend state, and InvSourceAlpha is the destination blend state in calls to RenderStateManager. The Font class requires this flag to be set when drawing text.

This topic is closed to new replies.

Advertisement