gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

Beginners > Sprite translucency

#26138 - Wriggler - Wed Sep 08, 2004 1:42 pm

Hi guys,

How would I go about making a sprite translucent (e.g. semi-transparent) against all background layers?

I've taken a look at the REG_BLDMOD register, but I don't really understand it. If anybody could lend any simple code, or link to a good tutorial that would be fantastic.

Thanks in advance,

Ben

#26147 - poslundc - Wed Sep 08, 2004 2:55 pm

Have a look at http://www.thepernproject.com/English/tutorial_4.html#4 and let us know if there is a specific part of the explanation that is confusing you.

Keep in mind that there is only one blend register, which means you can blend only one collection of objects (your sprites, for example) against another collection (BGs 1 and 2, for example).

Dan.

#26352 - Wriggler - Mon Sep 13, 2004 5:44 pm

I've read the article on The Pern Project and had a look at Tonc's tutorial's as well. I'm just at a bit of loss as exactly what values I should be putting into REG_BLDMOD and REG_COLY. Just a small code sample would probably clear things up quite a lot.

thanks

Eaben

#26355 - Ethos - Mon Sep 13, 2004 6:05 pm

For Transparency with regards to sprites, I think its better to set the sprites you want to be semi-transparent by setting the transparency bits (10,11) to 01 in attribute 0 (bytes 1 and 2), as described in the Cowbite Virtual HW specs.

You still have to set the target/source layers and values with REG_BLDMOD and REG_COLEV.

#26439 - cappeca - Wed Sep 15, 2004 5:46 pm

Set the sprites as semi-transparent like Ethos said, and get an emulator where you can play with the registers during game (Mappy or VBA can do it). That will let you get a feeling of what you can do. Once you get the effect you want, put the values on the registers in your code.

And be careful with sprites priority, because that might mess things up a little. The Pern Project doesn't mention it.

#26654 - yaustar - Wed Sep 22, 2004 12:49 am

You be better looking at the Cowbite Spec for the details...
http://www.cs.rit.edu/~tjh8300/CowBite/CowBiteSpec.htm#Graphics%20Hardware%20Registers
Scroll down a bit to find BLDMOD

Code:
        //set the transperancy of the first layer
        SET_BLENDING(BLEND_BG2, BLEND_BG0 | BLEND_SPRITES | BLEND_BG1 | BLEND_BG3, ALPHA_BLEND);// BG2 is the layer that is being blended
        SET_COEFF(5, 10);//set the coefficient for alpha blending

Code:
#define SOURCE_SHIFT(n) ((n) << 0)
#define TARGET_SHIFT(n) ((n) << 8)

//REG_BLDMOD supplement header file by yaustar 02/10/2003

#define BLEND_BG0 0x1
#define BLEND_BG1 0x2
#define BLEND_BG2 0x4
#define BLEND_BG3 0x8

#define BLEND_SPRITES 0x10
#define BLEND_BACK 0x20

#define ALL_OFF 0x0
#define ALPHA_BLEND 0x40
#define LIGHTEN 0x80
#define DARKEN 0xC0

#define SET_BLENDING(s,t,m) REG_BLDMOD = (SOURCE_SHIFT(s) | TARGET_SHIFT(t) | m)

//REG_COLEV supplement header file by yaustar 02/10/2003
//eg of usage SET_BLENDING(BLEND_BG0, BLEND_BG1, ALPHA_BLEND);

#define SET_COEFF(s,t) REG_COLEV = (SOURCE_SHIFT(s) | TARGET_SHIFT(t))
//s + t MUST equal to 16 or <16 for a darkening effect or >16 for a lighting effect

//key: s = source, t = target, m = mode

_________________
[Blog] [Portfolio]

#26694 - Miked0801 - Thu Sep 23, 2004 10:10 pm

Of ghost it by turning it off and on each tic. Poor man's transparency, but it gives you multiple levels :)