Jump to content
  • Advertisement
Sign in to follow this  
ChaseRLewis

OpenGL Texture Loading Question

This topic is 2679 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts



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?

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!