This topic is now archived and is closed to further replies.


what is causing this texture problem?

Recommended Posts

What is causing this texture problem? does anyone know? here is my texture loading function...
bool CreateTexture(UINT &texture, LPSTR strFileName)
	AUX_RGBImageRec *pImage = NULL;
	FILE *pFile = NULL;

		return false;

	// Open a file pointer to the BMP file and check if it was found and opened 
	if((pFile = fopen(strFileName, "rb")) == NULL) 
		// Display an error message saying the file was not found, then return NULL
		MessageBox(g_hWnd, "Unable to load BMP File!", "Error", MB_OK);
		return NULL;

	// Load the bitmap using the aux function stored in glaux.lib
	pImage = auxDIBImageLoad(strFileName);				

	// Make sure valid image data was given to pImage, otherwise return false
	if(pImage == NULL)								
		return false;

	// Generate a texture with the associative texture ID stored in the array
	glGenTextures(1, &texture);

	// This sets the alignment requirements for the start of each pixel row in memory.
	glPixelStorei (GL_UNPACK_ALIGNMENT, 1);

	// Bind the texture to the texture arrays index and init the texture
	glBindTexture(GL_TEXTURE_2D, texture);
	// Build Mipmaps (builds different versions of the picture for distances - looks better)
	gluBuild2DMipmaps(GL_TEXTURE_2D, 3, pImage->sizeX, 
					  pImage->sizeY, GL_RGB, GL_UNSIGNED_BYTE, pImage->data);

	//Assign the mip map levels and texture info

	// Now we need to free the image data that we loaded since openGL stored it as a texture

	if (pImage)										// If we loaded the image
		if (pImage->data)							// If there is texture data
			free(pImage->data);						// Free the texture data, we don''t need it anymore

		free(pImage);								// Free the image structure

	// Return a success
	return true;
also take a look at this area... now i can tell you whats happening... the bottom edge of the texture is kind of blending to the top edge of the texture, like a wrap around, but i dont see any part of my code that causes that... please help? thanks.

Share this post

Link to post
Share on other sites
Add the following lines:

By default, the wrapping mode is GL_REPEAT, which causes the behaviour you're seeing.

You may need to define GL_CLAMP_TO_EDGE, since it wasn't defined in OpenGL 1.1. It's 0x812F anyway.

[edit: added semicolons ]

[edited by - benjamin bunny on October 22, 2003 9:13:00 PM]

Share this post

Link to post
Share on other sites
well im also mutlitexturing, and if i do this, my set texture coord function no longer works correctly...

void SetTextureCoord(float x, float z)
// Find the (u, v) coordinate for the current vertex
float u = x / (float)MAP_SIZE;
float v = -z / (float)MAP_SIZE;
// Instead of using the normal API for assigning the current texture
// coordinate, we want to use the glMultiTexCoord2fARB() function.
// This will allow us to choose the (u, v) coordinate for every texture
// map, since we are using multitexturing. Due to the fact that we
// are going to be using the texture matrix to set the tiling of our
// detail texture, we just assign the same (u, v) coordinate for both
// textures.
// Give OpenGL the current terrain texture coordinate for our height map
glMultiTexCoord2fARB(GL_TEXTURE0_ARB, u, v);
// Give OpenGL the current detail texture coordinate for our height map
glMultiTexCoord2fARB(GL_TEXTURE1_ARB, u, v);

if i change -z to z, then the terrain will be textured just fine, but detail textures go out of wack!

screen shot

thanks by the way, you''ve been a big help

Share this post

Link to post
Share on other sites
ok great, i hacked it together unforunately , but... i spoke too soon on the other textures, its rendered upside down for each block... if i do negative numbers for the uv, the entire thing is a buntch of long green lines (clamping effect)...

any ideas?

thank you so much for sticking with me man

Share this post

Link to post
Share on other sites