Some question on blending texture

Started by
1 comment, last by LYH1 17 years, 4 months ago
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_ALPHABLENDENABLE, 1);
  DXDraw.D3DDevice7.SetRenderState(D3DRENDERSTATE_SRCBLEND, Integer(D3DBLEND_DestALPHA));
  DXDraw.D3DDevice7.SetRenderState(D3DRENDERSTATE_DESTBLEND, Integer(D3DBLEND_INVDestALPHA));

  DXDraw.D3DDevice7.SetTextureStageState(0,D3DTSS_ALPHAOP,Integer(D3DTOP_MODULATE));
  DXDraw.D3DDevice7.SetTextureStageState(0,D3DTSS_ALPHAARG1,Integer(D3DTA_TEXTURE));

  DXDraw.D3DDevice7.SetTextureStageState(1,D3DTSS_COLOROP,Integer(D3DTOP_MODULATE));
  DXDraw.D3DDevice7.SetTextureStageState(1,D3DTSS_COLORARG1,Integer(D3DTA_TEXTURE));
  DXDraw.D3DDevice7.SetTextureStageState(1,D3DTSS_TEXCOORDINDEX,0);

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


  DXDraw.D3DDevice7.SetTexture(0,nil);
    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);

  DXDraw.D3DDevice7.SetTexture(1,nil);
    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);
  End;

  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);


I love delphi more than C
Advertisement
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.
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.
I love delphi more than C

This topic is closed to new replies.

Advertisement