Skip to main content
gamedev.net
🔒 Locked

Cannot create a normal texture

Started by aewarnick Mar 20, 2005 at 5:29 PM 6 replies 850+ views
Original Post
aewarnick
aewarnick
Everything works out great if I use the mipmap method but when I use glTexImage2D I get a runtime error on that line if the image is not a power of 2. Did I do this right? If the image is 256x256 everything is great, anything not a power of 2 creates a runtime error.
uint CalcGlPowOf2(uint s)
		{
			uint v= 16;
			while(v < s)
				v*=2;
			return v;
		}

		void CreateGLTex()
		{
			glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
			AUX_RGBImageRec* Image= auxDIBImageLoad("bmp.bmp");
			glGenTextures(1, &glTex);
			glBindTexture(GL_TEXTURE_2D, glTex);
			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
			//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
			glTexImage2D(GL_TEXTURE_2D, 0, bpp/8, CalcGlPowOf2(Image->sizeX), CalcGlPowOf2(Image->sizeY), 0, GL_RGB, GL_UNSIGNED_BYTE, Image->data);
			//gluBuild2DMipmaps(GL_TEXTURE_2D, 3, Image->sizeX, Image->sizeY, GL_RGB, GL_UNSIGNED_BYTE, Image->data);
			if (Image)
	{
		if (Image->data)
		{
			free(Image->data);
		}

		free(Image);
	}
		}
C++->
_the_phantom_
_the_phantom_
all normal textures must be a power-of-two for them to work via glTexImage2d(), the glu function resizes them internally if it isnt before passing them to OGL.
Drew_Benton
Drew_Benton
You could also use NeHe's IPicture and modify it some to get what you want if you have non-power of 2 images.
aewarnick
aewarnick
Did you look at the code? This calculates the next power of 2:
uint CalcGlPowOf2(uint s)
{
uint v= 16;
while(v < s)
v*=2;
return v;
}
C++->
_the_phantom_
_the_phantom_
yes, thats nice... now, lets say you load a 100*100 texture in and you tell it that its 256*256.. where the rest of the data coming from?
aewarnick
aewarnick
So I have to pad the image, I got it. Thanks.
C++->
MARS_999
MARS_999
Quote:
Original post by aewarnick
So I have to pad the image, I got it. Thanks.


I am not 100% sure on this, but I wouldn't just pad the normalmap with crap data... I am thinking you need to sample or do some kind of interpolation between the 1st and 2nd vertex position and divide it by however many pixels you are missing so the map is not so jumpy... Maybe I am wrong. Ask Phantom see what he says.
_the_phantom_
_the_phantom_
well, its not a normal map he's loading (At least I dont think so anyways, heh, I thought it might have been from the topic title), but yes, if you pad with crap you'll need to adjust the texture coords so you dont go outside your desired image.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.