Results 1 to 10 of 10

Thread: Transparent colors (BLT)

  1. #1

    Thread Starter
    Member Onyx_Black's Avatar
    Join Date
    Nov 2001
    Location
    In my computer
    Posts
    42

    Unhappy Transparent colors (BLT)

    How do make a color transparent when using BLT in Directx 7
    I’m trying to write a tile engine and need to make a color transparent so I can overlay
    My tiles. Please help!
    Cool site for VB gaming dev :-

    http://rookscape.com/vbgaming/tutorials.php

  2. #2
    Frenzied Member Jotaf98's Avatar
    Join Date
    Jun 2000
    Location
    I'm not gonna give you my IP address! Ok... Portugal, South-Western Europe, 3rd rock from the sun (our star is easy to find, a 47 Ursae Majoris in the Milky Way :p )
    Posts
    1,457
    After creating the surface, use this:

    VB Code:
    1. 'Set the color key to black
    2.     Dim Key As DDCOLORKEY
    3.     Key.low = 0
    4.     Key.high = Key.low
    5.     DestSurface.SetColorKey DDCKEY_SRCBLT, Key

    This way, black will be the transparent color
    Code:
    Temp = Me.GetIQ()
    'Error 9: Overflow
    'DON'T PANIC! :eek:

    To learn how to use realistic effects in your games like fire, rain, snow and magic effects, read my article on particles systems here.


    Jotaf's Theories!
    "Cats land on their feet. Toast lands peanut butter side down. A cat with toast strapped to its back will hover above the ground in a state of quantum indecision."

  3. #3
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    If you are using 16-bit colour, take a look here:

    http://www.vbexplorer.com/directx4vb/

    He has code for 16 bit colour keys (that one only works in 24- and 32- bit colour).
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  4. #4
    Frenzied Member Jotaf98's Avatar
    Join Date
    Jun 2000
    Location
    I'm not gonna give you my IP address! Ok... Portugal, South-Western Europe, 3rd rock from the sun (our star is easy to find, a 47 Ursae Majoris in the Milky Way :p )
    Posts
    1,457
    The code I gave you uses black no matter what the color depth is, unless it's 8-bits and you have a really weird palette
    Code:
    Temp = Me.GetIQ()
    'Error 9: Overflow
    'DON'T PANIC! :eek:

    To learn how to use realistic effects in your games like fire, rain, snow and magic effects, read my article on particles systems here.


    Jotaf's Theories!
    "Cats land on their feet. Toast lands peanut butter side down. A cat with toast strapped to its back will hover above the ground in a state of quantum indecision."

  5. #5
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    Yea, it will work there but for other colours forget it
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  6. #6
    Frenzied Member Jotaf98's Avatar
    Join Date
    Jun 2000
    Location
    I'm not gonna give you my IP address! Ok... Portugal, South-Western Europe, 3rd rock from the sun (our star is easy to find, a 47 Ursae Majoris in the Milky Way :p )
    Posts
    1,457
    Why would you need any other colors?
    Code:
    Temp = Me.GetIQ()
    'Error 9: Overflow
    'DON'T PANIC! :eek:

    To learn how to use realistic effects in your games like fire, rain, snow and magic effects, read my article on particles systems here.


    Jotaf's Theories!
    "Cats land on their feet. Toast lands peanut butter side down. A cat with toast strapped to its back will hover above the ground in a state of quantum indecision."

  7. #7

    Thread Starter
    Member Onyx_Black's Avatar
    Join Date
    Nov 2001
    Location
    In my computer
    Posts
    42

    Thanks Guys - One more thing

    Can anyone help my with Orthogonal tile engines. I can make nice square one, and I’ve nearly got an orthogonal engine but I’m missing something. I’m using an offset to overlap my tiles.

    For example.

    ---------------------------------------------------------------------------
    Do the first line of tiles,

    Then on the next line I move the tiles along half a tile’s width so that the edges line up.
    The space between lines is half a tile’s height

    And move it back to the same place as the fist tile, on the third line

    And so on.

    ------------------------------------------------------------------------------
    If you didn’t understand that, don’t worry, I can’t explain anything

    But when moving tiles, the movement isn’t looking right!!!

    ** Could someone give me a example or some theory **
    Cool site for VB gaming dev :-

    http://rookscape.com/vbgaming/tutorials.php

  8. #8
    Frenzied Member Jotaf98's Avatar
    Join Date
    Jun 2000
    Location
    I'm not gonna give you my IP address! Ok... Portugal, South-Western Europe, 3rd rock from the sun (our star is easy to find, a 47 Ursae Majoris in the Milky Way :p )
    Posts
    1,457
    Hum, I understand why you'd use diagonal tiles for a fake 3D effect, but I can't see why you'd wanna use ortogonal tiles - you can easily simulate that with fast square tiles
    Code:
    Temp = Me.GetIQ()
    'Error 9: Overflow
    'DON'T PANIC! :eek:

    To learn how to use realistic effects in your games like fire, rain, snow and magic effects, read my article on particles systems here.


    Jotaf's Theories!
    "Cats land on their feet. Toast lands peanut butter side down. A cat with toast strapped to its back will hover above the ground in a state of quantum indecision."

  9. #9
    Lively Member
    Join Date
    Aug 2006
    Posts
    65

    Re: Transparent colors (BLT)

    Why am I getting... User defined type not defined.. for

    Dim Key As DDCOLORKEY

  10. #10
    Elite Hacker Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,349

    Re: Transparent colors (BLT)

    Quote Originally Posted by HaLLa
    Why am I getting... User defined type not defined.. for

    Dim Key As DDCOLORKEY
    Its because you didn't goto the menu in Project > References > and DirectX7 For Visual Basic Type Library.

    Why are you even using DirectDraw at all? DirectDraw is very old, and very limited in capabilities. Although still fast. DD was designed for older cards that was more for 2D than 3D. They got rid of it in DX8 but brought it back in DX9 for those who were still using DX7 just for people to use DirectDraw.

    Instead of DD, use Direct3D (DX8) using a TLVertex so the Z coordinate is ignored by the computer. That way you can do nifty special effects and have more control over your 2D sprites:

    VB Code:
    1. 'This is the Flexible-Vertex-Format description for a 2D vertex (Transformed and Lit)
    2. Const FVF = D3DFVF_XYZRHW Or D3DFVF_TEX1 Or D3DFVF_DIFFUSE Or D3DFVF_SPECULAR
    3.  
    4. 'This structure describes a transformed and lit vertex - it's identical to the DirectX7 type "D3DTLVERTEX"
    5. Private Type TLVERTEX
    6.     X As Single
    7.     Y As Single
    8.     Z As Single
    9.     rhw As Single
    10.     color As Long
    11.     specular As Long
    12.     tu As Single
    13.     tv As Single
    14. End Type

    And on top of that, you don't need no stupid multiple color keys and tons of code just to pull off transparency. In Direct3D you just set one color that you want transparent when loading a texture, and these two lines of code in the initialization so the computer knows how its gonna be transparent.

    VB Code:
    1. D3DDevice.SetRenderState D3DRS_ALPHAREF, 255
    2.     D3DDevice.SetRenderState D3DRS_ALPHAFUNC, D3DCMP_GREATEREQUAL

    I also have a Massive DX 2D tutorial in my signature.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width