Sign in to follow this  

White texture help

This topic is 4416 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Been racking me brains up half the night with the dreaded evil white quad monster. Im trying to get 2 textured quads to load but for some reason i can only get one texture to display if i add this to the enable texture function which just selects the currect texture for that quad both textures work fine on my machine but only one displays on others. These two lines are inside the init function already so i dont see why this would make the second quad work all of a sudden when i add this to the enable texture funtion even though its already defined in initialise. glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST); It has to be something insanely stupid but im to thick to see it :( heres the draw, init and enable/add texture functions, Globals GLuint texture[20]; int n_textures = 0; Initialise function
void Init()
{
glEnable(GL_DEPTH_TEST);//enables the depth test
	glShadeModel(GL_SMOOTH);					
	glClearColor(0.0f, 0.3f, 0.3f, 0.0f);				
	glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);	

	glEnable(GL_TEXTURE_2D);

//Enables all the modes for texturing to work properly and sets the active texture to the id thats passed in
	glEnable(GL_TEXTURE_2D);
	glEnable(GL_ALPHA_TEST); //enable aplha test to allow textures to appear see through
	glAlphaFunc(GL_GREATER, 0.0); 
	glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
}




Enable and disable texture,
void ENABLE_TEXTURE(int id)
{
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, texture[id]);
}

void DISABLE_TEXTURE()
{
glDisable(GL_TEXTURE_2D);
}




int Add_Texture(TGAFILE *Act_text)
{
glGenTextures(1, &texture[n_textures]);
glBindTexture(GL_TEXTURE_2D, texture[n_textures]);

glTexImage2D(GL_TEXTURE_2D, 0, 4, Act_text->imageWidth, 
			 Act_text->imageHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, 
			 Act_text->imageData);

n_textures++;

free(Act_text->imageData);

return (n_textures - 1);
}



Share this post


Link to post
Share on other sites
You're using glTexImage2D(*), so your textures needs to be to the power of two (i.e. 64x64, 128x128, 128x256, 256x256, 800x600, etc.)

Try using gluBuild2DMipmaps(*) instead and see if that fixes your problem. It will scale the texture to the nearest power of two for you.

Share this post


Link to post
Share on other sites
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);

should be in your add texture function after you bind the texture. not in your glinit functino, that only affects the bound texture

Share this post


Link to post
Share on other sites
Strange but i added gluBuild2DMipmaps(); instead of the other way and this corrects the white squares even though the textures are fine =/.

I tried adding them two lines to the add texture function but the white squares still appear.

Should i just leave it as it is with gluBuild2dMipmaps ? not sure how id fix it otherwise.

thx again
fishy

Share this post


Link to post
Share on other sites
First question - why would you load two white squares as 1024x1024 textures? For testing purposes only? Because otherwise 4x4 or 8x8 would be sufficient.

Secondly -

glEnable(GL_ALPHA_TEST); //enable aplha test to allow textures to appear see through
glAlphaFunc(GL_GREATER, 0.0);

I think this can be omitted in your case. Alpha testing is not the same as alpha blending (which I suppose you're having in mind; or these lines are simply redundant in the snippet) and unless you're adding a custom alpha channel to the textures themselves, this will be - in most cases at least - unneccessary.

Share this post


Link to post
Share on other sites
Quote:
Im trying to get 2 textured quads to load but for some reason i can only get one texture to display if i add this to the enable texture function which just selects the currect texture for that quad both textures work fine on my machine but only one displays on others. These two lines are inside the init function already so i dont see why this would make the second quad work all of a sudden when i add this to the enable texture funtion even though its already defined in initialise.
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);


these (and other things) ->glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
have to be added or else u will only get the default (white) texture

cuase the texture aint complete otherwise check the opengl spec (www.opengl.org)
the section about texture completeness

Share this post


Link to post
Share on other sites

This topic is 4416 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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