Color 255 for transparency on models and brush entities?

Discuss programming topics for the various GPL'd game engine sources.
Post Reply
MDave
Posts: 76
Joined: Mon Dec 17, 2007 7:08 pm

Color 255 for transparency on models and brush entities?

Post by MDave »

Is this possible? Reason why is so I can use effects like fences and ladders without using an obscene amount of triangles and verts. Also nice hair / muzzle flash effects :)

I've tried using glEnable (GL_ALPHA_TEST) and glDisable (GL_ALPHA_TEST) before and after rendering a model respectfully, but there is no change. Is there anything I'm forgetting?

Oh, I'm not using a super duper engine with support for all the formats that can use alpha transparency. Just looking for a simple method of doing it in good old glquake. Reason is so I can learn how the engine works easier :)
scar3crow
InsideQC Staff
Posts: 1054
Joined: Tue Jan 18, 2005 8:54 pm
Location: Alabama

Post by scar3crow »

Also nice hair / muzzle flash effects
What the hell kinda weapon you makin?!

All aside, no clue, I just wanted to say that.
mh
Posts: 2292
Joined: Sat Jan 12, 2008 1:38 am

Post by mh »

Alpha test should do it... it's what's done for sprites, and the principle is the same... you might also need a glDepthMask before and after, though...

Couple of points to note, however:

* Alpha test will give you a hard edge, you might want to experiment with GL_BLEND for hair and muzzleflashes

* You'll probably also want to set colour 255 to 0 in VID_SetPalette; like so:

Code: Select all

void VID_SetPalette (unsigned char *palette)
{
	byte	*pal;
	unsigned r,g,b;
	unsigned v;
	unsigned short i;
	unsigned *table;

	// 8 8 8 encoding
	pal = palette;
	table = d_8to24table;

	for (i = 0; i < 256; i++)
	{
		r = pal[0];
		g = pal[1];
		b = pal[2];
		pal += 3;

		v = (255 << 24) + (r << 0) + (g << 8) + (b << 16);
		*table++ = v;
	}

	// 255 is transparent
	d_8to24table[255] = 0;
}
Otherwise you'll have pink fringes around your opaque parts, which is just plain silly.
We had the power, we had the space, we had a sense of time and place
We knew the words, we knew the score, we knew what we were fighting for
MDave
Posts: 76
Joined: Mon Dec 17, 2007 7:08 pm

Post by MDave »

Thanks for the tips! However, its still not working :(

Am I setting it in the right place, in R_DrawAliasModel?

Code: Select all

	glEnable (GL_ALPHA_TEST);
	R_SetupAliasFrame (currententity->frame, paliashdr);
	glDisable (GL_ALPHA_TEST);
mh
Posts: 2292
Joined: Sat Jan 12, 2008 1:38 am

Post by mh »

That looks correct, and I've just tested it out and got it working. The only additional code was setting some 255 texels in the skin.

Image

I suspect your skins are being uploaded as GL_RGB, whereas you need to upload them as GL_RGBA. Look in GL_Upload32 and change this line:

Code: Select all

samples = alpha ? gl_alpha_format : gl_solid_format;
to this:

Code: Select all

samples = GL_RGBA;
(There's no real advantage to uploading as GL_RGB on a modern card so you may as well get rid of the "samples" variable and hard-code GL_RGBA instead).
We had the power, we had the space, we had a sense of time and place
We knew the words, we knew the score, we knew what we were fighting for
MDave
Posts: 76
Joined: Mon Dec 17, 2007 7:08 pm

Post by MDave »

Thanks, that did it!

Here's my result :)

Image

Now I'll do what you suggested, use glBlendFunc to make the muzzle flash (and possibly the edges of the palm tree leaves) smoother :)
mh
Posts: 2292
Joined: Sat Jan 12, 2008 1:38 am

Post by mh »

Looking good! :D
We had the power, we had the space, we had a sense of time and place
We knew the words, we knew the score, we knew what we were fighting for
Urre
Posts: 1109
Joined: Fri Nov 05, 2004 2:36 am
Location: Moon
Contact:

Post by Urre »

Cool to see the result after getting help in action, I'd like to see more of that on these forums :)
I was once a Quake modder
Post Reply