Open GL texturing issue

Associate
Joined
10 Mar 2009
Posts
13
Hi, i'm pretty new to this open GL business but i'm trying to map some .raw textures onto some geometry.

Both the height and normal texture files are using both width and height of 1024.

I've managed to load the normal texture on using the pixel depth of 4 but when i load the height texture using the same format of 4, it appears tiled even when using "glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);"
for both T and S.

I can't seem to use any other number for pixel depth since it gives me a memory error and my code breaks.

Heres my loading code:

Code:
int LoadRAWTexture ( char *filename, pImageTexture input)
{
	FILE *file;
	int i,j,k,done=0;
	int stride = input->width * input->pixel_depth;					// Size Of A Row (Width * Bytes Per Pixel)
	unsigned char *p = NULL;

	file = fopen(filename, "rb");							// Open "filename" For Reading Bytes
	if( file != NULL )
	{//if the file is not empty-or does exist-
		for( i = input->height-1; i >= 0 ; i-- )
		{//image loads from bottom up in GLSL so flip
			p = input->data + (i * stride );
			for ( j = 0; j < input->width ; j++ )
			{
				for ( k = 0 ; k < input->pixel_depth-1 ; k++, p++, done++ )
				{
					*p = fgetc(file);
				}
				*p = 255; p++;
			}
		}
		fclose(file);
	}
	else
	{
		MessageBox(NULL,"Error loading Colour Textures!","Colour Texture Issue",MB_OK | MB_ICONINFORMATION);
	}
	return done;
}

And my building code:

Code:
void LoadTexture (pImageTexture tex,int slot)
{
	if (slot == 1)
	{//then its height

		glBindTexture(GL_TEXTURE_2D, texture[slot]);
		glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
		glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
		glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
		glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);

		glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, tex->width, tex->height, 0, GL_RGBA, GL_UNSIGNED_BYTE, tex->data);
	}
}

and this is what i'm using to call it:

Code:
height = AllocateTextureBuffer( 1024,1024,4 );//load colour texture
	if (LoadRAWTexture("HEIGHT.raw",height)==0)
	{
		MessageBox(NULL,"Height.RAW could not load for some reason","Height map issue",MB_OK | MB_ICONINFORMATION);
		return FALSE;
	}

If anyone knows why it is tiling instead of appearing correctly mapped (like the normal one does) can you please help.

Thanks in advance.
 
Thanks for the reply.

I thought it may be that too since if the colour is loading fine, i can't see why the height isn't.

The details in photoshop show 8bit grayscale for the height map.
I've tried converting it to bmp and loading it in the same mechanism but still i get the same tiling issue.

I've tried changing the:
"AllocateTextureBuffer( width,height,pixel_depth )"
from 1024 to all sorts of numbers.
Strangely, when the height is set to 341.4 (1/3 of the original value) it seems to fit correctly on the y-axis but any changes to width parameter causes the image to stretch and skew.

This is the code i'm using to draw the faces.
Code:
glBegin( GL_QUADS );// Front Face
		glNormal3f(0.0,0.0,1.0);
		glTexCoord2f( 0.0f, 0.0f ); glVertex3f( -1.0f, -1.0f,  1.0f );
		glTexCoord2f( texmax, 0.0f ); glVertex3f(  1.0f, -1.0f,  1.0f );
		glTexCoord2f( texmax, texmax ); glVertex3f(  1.0f,  1.0f,  1.0f );
glTexCoord2f( 0.0f, texmax ); glVertex3f( -1.0f,  1.0f,  1.0f );
	glEnd();

texmax is just set to 1.0.

I really hope someone can help, i've been spending way too long trying to figure this out and its making me want to pull my hair out!
 
Lol yeah the lion. This work seems harder than it really should be!!

:D Changing the colour scale from grayscale to RGB seemed to have fixed the mapping issue :)

Thanks pho!

Just a few concerns about changing the height map data, will using RGB format cause any issues with using the height map in relation to bump mapping?

There just doesnt seem to be a lot of information on the net and the nehe tutorials are slightly out of date!

Once again, thanks for the help!
 
Back
Top Bottom