Texture Loading Question

Started by
0 comments, last by karwosts 13 years, 2 months ago


struct TEXTURE2D
{
GLuint m_ID;
int m_Width;
int m_Height;
int m_Comp;
};


bool LoadTexture2D(const char* filename,TEXTURE2D* m_Tex)
{
TEXTURE2D Temp;
ZeroMemory(&Temp,sizeof(Temp));

unsigned char* pData = 0;
pData = stbi_load(filename,&Temp.m_Width,&Temp.m_Height,&Temp.m_Comp,0);
if(pData == 0)
return false;

glGenTextures(1,&Temp.m_ID);
glBindTexture(GL_RGBA,Temp.m_ID);

glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR_MIPMAP_LINEAR);

glPixelStorei(GL_UNPACK_ALIGNMENT,1);

GLint Format = 0;
switch(Temp.m_Comp)
{
case 1:
Format = GL_ALPHA;
break;
case 3:
Format = GL_RGB;
break;
case 4:0
Format = GL_RGBA;
break;
default:
break;
}

//Set Texture OpenGL
glTexImage2D(GL_TEXTURE_2D,0,Temp.m_Comp,Temp.m_Width,Temp.m_Height,0,GL_RGBA,GL_UNSIGNED_BYTE,pData);
stbi_image_free(pData);

if( glIsTexture(Temp.m_ID))
{
if(glIsTexture(m_Tex->m_ID))
{
glDeleteTextures(1,&m_Tex->m_ID);
ZeroMemory(m_Tex,sizeof(*m_Tex));
}
memcpy(m_Tex,&Temp,sizeof(Temp));
return true;
}

return false;
}


Alright I started using a new library to load images. It loads them all fine. However, I'm having an issue getting them into the OpenGL pipeline. Problem is glIsTexture() returns false after I've generated and binded the id. What could be the reason the glIsTexture() returns false?
Advertisement

glBindTexture(GL_RGBA,Temp.m_ID);
[/quote]

GL_RGBA is not a legal target for glBindTexture.

You need to familiarize yourself with using glGetError, it will help you resolve these kinds of problems.

The opengl online docs are a good source of information to understand these functions.

http://www.opengl.org/sdk/docs/man/xhtml/glBindTexture.xml
[size=2]My Projects:
[size=2]Portfolio Map for Android - Free Visual Portfolio Tracker
[size=2]Electron Flux for Android - Free Puzzle/Logic Game

This topic is closed to new replies.

Advertisement