Jump to content
  • Advertisement
Sign in to follow this  
zerorepent

OpenGL Setting and loading texture2d

This topic is 2665 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

Hi!
I'm trying to load and render a model with texture, everything looks correct except the texture part, being completely black. I'm using DeviL as a textureloader and it seems to work correctly (at the very least not giving any errors). I've tried to only paste the relevant code concerning textures.

In the constructor of the class handling textures I do

ilInit();
iluInit();
ilutInit();
ilutRenderer(ILUT_OPENGL);

The 2D-texture loading function where Textures is a std::map

Texture2D GLRenderer::LoadTexture2DFromFile( const char *_FileName )
Texture2D texture = 0;
texture = m_Textures[_FileName ];
if(texture!= 0)
{
return texture;
}

char* temp = const_cast<char*>(_FileName);
GLuint temp2 = ilutGLLoadImage(temp);
m_Textures[_FileName ] = temp2;
return temp2;
}



Fragmentshader code

#version 130

precision highp float;

uniform sampler2D ColorMapSampler;

in vec3 VertexPos;
in vec3 Normal;
in vec2 TexCoord;

out vec4 FragColor;

void main()
{
vec4 texel = texture2D(ColorMapSampler,TexCoord);
FragColor =texel; //vec4(TexCoord.x, TexCoord.y,0,1);//texel;//vec4(Normal.x,Normal.y,Normal.z,1.0);//vec4(1.0,0.5,0.5,1.0);
}


In my code I do for the sampler

glUseProgram(m_ShaderProgram);
glUniform1i(glGetUniformLocation(m_ShaderProgram, "ColorMapSampler"),0);



and setting the texture

glActiveTexture(GL_TEXTURE0);
GLuint text = textureData->GetTexture(0);
glBindTexture(GL_TEXTURE_2D, text);
glBindVertexArray(geo->m_VertexArrayObject);
glDrawArrays(GL_TRIANGLES,0,geo->m_NumVertices);
glBindVertexArray(0);
glBindTexture(GL_TEXTURE_2D, 0);
glUseProgram(0);


I get no glErrors and no errors from Devil, and I have no clue about what I'm doing wrong, I've tried several different image-formats but none worked. I think it is the setting of textures to shader that isn't working correctly bacause I've tried a few other textureloading functions from different sites. So please help if you have any idea of what could be wrong!

Share this post


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

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!