greenboxal
greenboxal

Reputation: 469

GLSL Texture Won't Work

Consider the following:

virtual void Draw()
{
    _texture->Bind(0);

    _shader->Begin();
    _shader->SetUniform("WVPMatrix", _mvp);
    _shader->SetUniform("InColor", _color);
    _shader->SetUniformImm("InTexture", 0);
    _vbo.GetDeclaration().Activate();
    _vbo.Render(GL_QUADS, _ibo, 4);
    _shader->End();
}

void Texture2D::Bind(int index)
{
    if (index != -1)
    {
        glActiveTexture(GL_TEXTURE0 + index);
    }

    glBindTexture(GL_TEXTURE_2D, _textureID);
}

Where the calls for _shader->Begin(), _shader->SetUniform, _shader->SetUniformImm, _vbo.GetDeclaration().Activate and _vbo.Render works as if I set the fragment shader to render a static color(or even a color through the uniforms) it renders fine.

Now I'm trying to render a texture2d(it was loaded fine, I tested with immediate mode) and I get a black screen, why?

Vertex:

#version 330

layout(location = 0) in vec3 VertexPosition;
layout(location = 1) in vec2 VertexTexCoord;

uniform mat4 WVPMatrix;

out vec2 TexCoord0;

void main()
{
    TexCoord0 = VertexTexCoord;

    gl_Position = WVPMatrix * vec4(VertexPosition, 1);
}

Fragment:

#version 330

in vec2 TexCoord0;

uniform sampler2D InTexture;
uniform vec4 InColor;

out vec4 OutFragColor;

void main()
{
    OutFragColor = texture(InTexture, TexCoord0) * InColor;
}

PS: InColor is white, so it doesn't mess with texture color and TexCoord0 is valid as I already set R and B on OutFragColor as TexCoord0's S and T to debug it values.

Upvotes: 0

Views: 1934

Answers (1)

Tim
Tim

Reputation: 35933

(Posting answer for bookkeeping)

Question asker forgot to set minification filter for his texture, and as such the texture was not complete and does not display.

Need to call glTexParameteri(GL_TEXTURE_2D, GL_MIN_FILTER, GL_LINEAR); (or GL_NEAREST)

Upvotes: 5

Related Questions