Skip to main content
GameDev.net gamedev.net
🔒 Locked

Texture Loading/Rendering Problem

Started by dave Mar 30, 2007 at 1:04 AM 3 replies 1.2k views
Original Post
dave
dave
Hi, Time has come to write the OpenGL renderer for my GUI library. Now, for a bit of background information, i should tell you that because the gui is going to be cross-platform (OpenGL on Linux and D3D/OpenGL on windows) i have abstracted all the texture loading into memory away from the renderers. I have done this by adding a layer underneath the renderer that stores all the textures in system memory and then when the renderer is initialising it copies the texture data into whatever memory it pleases. Now to load the texture i do this:

	void GUIOGLRenderer::LoadSingleTexture(GUITextureBufferMapIter& iter)
	{
		GLuint id;

		GLsizei x = iter->second.width;
		GLsizei y = iter->second.width;

		glEnable(GL_TEXTURE_2D);
		glGenTextures(1, &id);
		glBindTexture(GL_TEXTURE_2D, id);
		glGetError();

		if ( iter->second.format == GTF_RGB )
		{
			glTexImage2D(GL_TEXTURE_2D, 
						 0, 
						 GL_RGBA, 
						 (GLsizei)iter->second.width, 
						 (GLsizei)iter->second.height, 
						 0, 
						 GL_RGB, 
						 GL_UNSIGNED_BYTE, 
						 iter->second.pData);
		}
		else if ( iter->second.format == GTF_RGBA )
		{
			glTexImage2D(GL_TEXTURE_2D, 
						 0, 
						 GL_RGBA, 
						 (GLsizei)iter->second.width, 
						 (GLsizei)iter->second.height, 
						 0, 
						 GL_RGBA, 
						 GL_UNSIGNED_BYTE, 
						 iter->second.pData);
		}
		glGetError();

		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);

		glBindTexture(GL_TEXTURE_2D,0);
		glDisable(GL_TEXTURE_2D);

		iter->second.apiVal = reinterpret_cast<void*>( id );
	}

Ok so this function gets passed an iterator that points to a struct that has information about the texture held in system memory. I know that this is all pretty solid because it all works perfectly in Direct3D. However the problem is that in opengl all textures load except 1. Well, it does load but it renders black when it is actually a font sheet with a white background and black text. All other textures work. The texture that doesn't load looks fine in memory (i have checked manually) and all the properties of the struct are set as usual. I expected this as it works for d3d as i mentioned a second ago. Now to debug this i have been rendering 1 large quad, loading all the 5 textures into memory each time and manually hardcoding in which texture number to use and build. glGetError() doesn't return anything after any of the calls in the code above. Now it was suggested that i use glIntercept to capture the images and save them to file to see if the image is being loaded ok. So i did and the images all saved fine and you can see the font texture sheet working ok here. Stranger still, in a later run, i textured the quad with the font sheet texture that glIntercept had saved and that rendered black as well. Also to prove that that in turn loaded in glIntercept resaved it to the same location. Well, i am completely lost on this one. Any thoughts on how i should proceed? Dave
Hodgman
Hodgman
All I can think of is that (iter->second.format != GTF_RGB && iter->second.format != GTF_RGBA)

perhaps you need another 'else' on the end to catch unsupported texture formats:
	if ( iter->second.format == GTF_RGB )	{...}	else if ( iter->second.format == GTF_RGBA )	{...}	else		printf/MessageBox/etc...
dave
dave
It's not that because, in the case of the texture that isn't rendering properly, i am creating the texture data myself and i know that it is RGBA.

Dave
Kalidor
Kalidor
Hmm... are the dimensions of the font texture a power of two or does your card support the GL_ARB_texture_non_power_of_two extension? Could you post your rendering code and any relevant state setup such as texture environment or blending modes?
dave
dave
Hi, i have fixed the problem.

It was simply the blending value i was setting. Moreover i didn't know that the blending value i WAS setting would show nothing. Yeah my library builds all textures to power-or-2.

Thanks,

Dave

Topic Locked

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

Sign in to reply to this topic.