Original Post
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: 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
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 );
}