Advertisement

Transparency in VGA

Started by November 10, 1999 06:44 AM
1 comment, last by [GaNoN] 25 years, 3 months ago
There's a pretty good tutorial on exactly this over at FlipCode. Check it out here.

Good luck!

Starfall

I am creating a VGA game in DJGGP and are wondering how I could efficiently do transparency. I don't really know how to make the palette to do this. This is the code I have written.

#include
#include
#include
#include
#include

typedef unsigned char byte;
byte *vram;
int i;

void SetGraphMode();
void DisplayVram();
void spalette(int colour,int red,int green,int blue);

void SetGraphMode(){
__dpmi_regs regs;
regs.x.ax = 0x13;
__dpmi_int(0x10,&regs);
};

void DisplayVram(){
dosmemput(vram,64000,0xa0000);
}

void main(){
SetGraphMode();
vram = (byte*)malloc(64000);
memset(vram,0,64000);
for(i=0;i<10;i++){
spalette(i,int(6.1*i),0,0);
}
for(i=0;i<10;i++){
spalette(i+10,0,int(6.1*i),0);
}
for(i=0;i<10;i++){
spalette(i+20,0,0,int(6.1*i));
}
for(i=0;i<10;i++){
spalette(i+30,int(6.1*i),int(6.1*i),0);
}
for(i=0;i<10;i++){
spalette(i+40,int(6.1*i),0,int(6.1*i));
}
for(i=0;i<10;i++){
spalette(i+50,0,int(6.1*i),int(6.1*i));
}
for(i=0;i<60;i++){
spalette(i+60,int(6.1*i),int(6.1*i),int(6.1*i));
}
for(i = 0;i<80;i++){
vram=i;<BR> }<BR> DisplayVram();<BR> bioskey(0);<BR>}<P>void spalette(int colour,int red,int green,int blue){<BR> __dpmi_regs regs;<BR> regs.x.ax=0x1010;<BR> regs.x.bx=colour;<BR> regs.h.dh=red;<BR> regs.h.ch=green;<BR> regs.h.cl=blue;<BR> __dpmi_int(0x10,&regs);<BR>}<P>If ne1 could suggest a good way plz reply

Advertisement
To do full fledged alpha blending in 8-bit color you'd essentially need a 256x256 CLUT
for each transparency level (I.e. a table that for each possible source and destination pair hold the new pixel color for each possible alpha value). This amounts to 256x256x256 = 16MB of CLUT. If you're looking to do a 50/50 blend, a single 256x256 clut is sufficient.

Obviously tradeoffs can be made. For example, ordering your palette so that colors that "nearly match" are close to each other, you can treat them as identical when blending, reducing each CLUT to e.g. 64x64 entries (Entry 0 covers colors 0,1,2 and 3, Entry 1 covers 4,5,6 and 7). Limiting the amount of alpha levels also help. 16 levels or less is enough for some applications. I.e. 64x64x16=64K of CLUT.

Finally, may I suggest that true color IS the only way to get the really "crisp" look.

/Niels

<b>/NJ</b>

This topic is closed to new replies.

Advertisement