Jump to content
  • Advertisement
Sign in to follow this  

Some question on blending texture

This topic is 4252 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

I want to write a routine that can read a 8bit qrayscale bitmap as alpha channel and blend to the current canvas, the problem is it take the 8bit qrayscale bitmap as color information with no alpha information. How to set the 8bit texture's color information to corroperate with alphaop arg1? (I dont mix them to RGBA first because I will use different texture as alpha channel in runtime) Here is the code that take the 8bit texture as alphachannel result is the black color surface alphablend with texture in texture stage1.
  DXDraw.D3DDevice7.SetRenderState(D3DRENDERSTATE_SRCBLEND, Integer(D3DBLEND_DestALPHA));



  C := RGBA_MAKE($ff,$ff,$ff,$ff);
  FVertex[0].Color:= C;
  FVertex[1].Color:= C;
  FVertex[2].Color:= C;
  FVertex[3].Color:= C;

    If NOT CanFindTexture(mask) Then {when no texture in list try load it}
    If NOT LoadTextures(mask) Then Exit; {on error occurr out}
        I := FD2DTexture.Find(mask.Name);
  If I = -1 Then Exit;
  DXDraw.D3DDevice7.SetTexture(0, FD2DTexture.Texture.D2DTexture.Surface.IDDSurface7);

    If NOT CanFindTexture(Image) Then {when no texture in list try load it}
    If NOT LoadTextures(Image) Then Exit; {on error occurr out}
        I := FD2DTexture.Find(Image.Name);
  If I = -1 Then Exit;

  DXDraw.D3DDevice7.SetTexture(1, FD2DTexture.Texture.D2DTexture.Surface.IDDSurface7);
  DXDraw.D3DDevice7.SetRenderState(D3DRENDERSTATE_COLORKEYENABLE, Ord(FD2DTexture.Texture.D2DTexture.Transparent));

  If (Image.PatternHeight <> 0) Or (Image.PatternWidth <> 0) Then Begin
    R := Image.PatternRects[Pattern];
    SrcX := 1 / FD2DTexture.Texture.D2DTexture.Surface.Width;
    SrcY := 1 / FD2DTexture.Texture.D2DTexture.Surface.Height;
    FD2DTexture.Texture.FloatX1 := SrcX * R.Left;
    FD2DTexture.Texture.FloatY1 := SrcY * R.Top;
    FD2DTexture.Texture.FloatX2 := SrcX * (R.Right-1);
    FD2DTexture.Texture.FloatY2 := SrcY * (R.Bottom-1);

  FVertex[0].tu:= FD2DTexture.Texture.FloatX1;
  FVertex[0].tv:= FD2DTexture.Texture.FloatY1;
  FVertex[1].tu:= FD2DTexture.Texture.FloatX2;
  FVertex[1].tv:= FD2DTexture.Texture.FloatY1;
  FVertex[2].tu:= FD2DTexture.Texture.FloatX1;
  FVertex[2].tv:= FD2DTexture.Texture.FloatY2;
  FVertex[3].tu:= FD2DTexture.Texture.FloatX2;
  FVertex[3].tv:= FD2DTexture.Texture.FloatY2;

  FVertex[0].sx:= R.Left-0.5;
  FVertex[0].sy:= R.Top-0.5;
  FVertex[1].sx:= R.Right-0.5;
  FVertex[1].sy:= R.Top-0.5;
  FVertex[2].sx:= R.Left-0.5;
  FVertex[2].sy:= R.Bottom-0.5;
  FVertex[3].sx:= R.Right-0.5;
  FVertex[3].sy:= R.Bottom-0.5;

  DXDraw.D3DDevice7.DrawPrimitive(D3DPT_TRIANGLESTRIP, D3DFVF_TLVERTEX, FVertex, 4, D3DDP_WAIT);

Share this post

Link to post
Share on other sites
DX7 and VB? {ET faints}

Phew, just had a horrible nightmare. What, you mean it's real? Okay, okay. I don't have a good solution, but there are things you could try. But anything I say may not be applicable to this situation (DX7).

First, you're leaving partial stages, which you shouldn't do. You haven't specified a colour op for the first stage and and alpha op for the second. What do you expect them to do? I'm not saying that adding them will solve your problem, but leaving them out is a clear error.

I thought of suggesting trying D3DTOP_DOTPRODUCT3 to replicate into the alpha, but reading the docs, I'm not sure that'd work (DX9 docs, comment about DX7). It might still be worth trying.

Probably the best way to go about it would be to use an alpha texture. I didn't fully understand what you said there about the use of the textures. Are you using the same data for both colour and alpha? In that case, you might have to duplicate it.

I hope some of this would help.

Share this post

Link to post
Share on other sites
THX for reply, I am using DelphiX .(Seems already outdated when everyone talking HLSL)
The problem resloved, just alphablend them one more time only and I got the result.

Share this post

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

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!