Sign in to follow this  
homojedi

HUD problems

Recommended Posts

homojedi    121
Greetings, Im attempting to draw a hud, and for a while i though i had it working from switching from orthographic back to projection...until i tried it with an alpha image..it seems it doesn't draw the alpha but all the 3d objects behind it arent being drawn, its like the alpha layer is a layer itself obstructing the scene. Im using DevIL but i must admit only having rudimentary knowledge of it here is the convert paramters i am using "ilConvertImage(IL_RGBA, IL_UNSIGNED_BYTE)" and just in case its my switch from orthographic to projection here
glMatrixMode( GL_PROJECTION );//
	glPushMatrix();
	glLoadIdentity();//
	glDisable( GL_LIGHTING ); 
	gluOrtho2D( 0.0, 1024, 768, 0.0 ); 

	glMatrixMode( GL_MODELVIEW );//
	glLoadIdentity();//

	glColor3f( 1,1,1 );
	glBegin(GL_QUADS);
	glTexCoord2i(0, 0); glVertex2i(0,   0);
	glTexCoord2i(0, 1); glVertex2i(0,   768);
	glTexCoord2i(1, 1); glVertex2i(1024, 768);
	glTexCoord2i(1, 0); glVertex2i(1024, 0);
	glEnd( );

	//Switch back to our projection mode
	glMatrixMode( GL_PROJECTION );
	glEnable( GL_LIGHTING );
	//Finish our calls above
	glPopMatrix( );
	//Switch back to our model matrix to continue with out 3D scene
	glMatrixMode( GL_MODELVIEW );

does anyone have any idea whats going on? cheers

Share this post


Link to post
Share on other sites
MENTAL    383
Daft question: are you actually creating your HUD graphics with a transparency (alpha) channel? It looks like you're using ilConvertImage to add an alpha channel, but then that will just be filled with 100% maximum opacity.

And have you setup the blend mode properly?

Share this post


Link to post
Share on other sites
homojedi    121
Quote:

Daft question: are you actually creating your HUD graphics with a transparency (alpha) channel? It looks like you're using ilConvertImage to add an alpha channel, but then that will just be filled with 100% maximum opacity.

And have you setup the blend mode properly?


Daft response: erm...probably not...how would i set up blend properly?
here is my image set up code


ilGenImages(1, &ImageName); /* Generation of one image name */
ilBindImage(ImageName); /* Binding of image name */
ILboolean success = ilLoadImage( "flock.jpg" ); /* Loading of image "image.jpg" */


if (success) /* If no error occured: */
{
success = ilConvertImage(IL_RGB, IL_UNSIGNED_BYTE); /* Convert every colour component into
unsigned byte. If your image contains alpha channel you can replace IL_RGB with IL_RGBA */

if (!success)
{
/* Error occured */
exit( 1 );
}

}

glGenTextures( 1, &image ); /* Texture name generation */
glBindTexture(GL_TEXTURE_2D, image); /* Binding of texture name */
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); /* We will use linear
interpolation for magnification filter */

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); /* We will use linear
interpolation for minifying filter */

glTexImage2D(GL_TEXTURE_2D, 0, ilGetInteger(IL_IMAGE_BPP), ilGetInteger(IL_IMAGE_WIDTH),ilGetInteger(IL_IMAGE_HEIGHT), 0, ilGetInteger(IL_IMAGE_FORMAT), GL_UNSIGNED_BYTE, ilGetData()); /* Texture specification */

ilDeleteImages( 1, &ImageName );

Share this post


Link to post
Share on other sites
MENTAL    383
Okay, first of all, drop the converting to RGBA. You only need to start messing around like that if you're going to be controlling transparency on a per-pixel basis (and if you are, you set those values in an image editor and save to a format that has it's own alpha channel, such as PNG or TGA).

Load your texture as a normal image. When it comes to drawing HUD elements, specify the transparency using glColor4f (1.0f, 1.0f, 1.0f, alpha), where alpha is of course between 0 (invisible) and 1 (solid).

Preceed the start of the HUD drawing with:


glEnable (GL_BLEND);
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

DRAW HUD HERE

glDisable (GL_BLEND);




Regarding the glColor4f, you can use this to control transparency on a per-element basis. If you have some elements that should be see-through and some that shouldn't, then just make another call to glColor4f before drawing it.

The usual rules about disabling depth testing and depth writes still apply :)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this