0
\$\begingroup\$

Hi i have newbe question. I am sending to gpu textures unit and they dont display. This is simple version of my fragment and vertexshader. (More complicated version also dont work with other textures than DDS but maybe simpler version will tell you what newbe mistake i made)

for (unsigned int i = 0; i < textures.size(); i++){
    glActiveTexture(GL_TEXTURE0+i);
    glBindTexture(GL_TEXTURE_2D, Textures[i]);
    // Set our "myTextureSampler" sampler to user Texture Unit 0
    glUniform1i(TextureID, i);
}

This is my simple fragmentshader

#version 330 core

// Interpolated values from the vertex shaders
in vec2 UV;

// Ouput data
out vec3 color;

// Values that stay constant for the whole mesh.
uniform sampler2D myTextureSampler;

void main(){

    // Output color = color of the texture at the specified UV
    color = texture2D( myTextureSampler, UV ).rgb;
}

This is my simple vertexshader

#version 330 core

// Input vertex data, different for all executions of this shader.
layout(location = 0) in vec3 vertexPosition_modelspace;
layout(location = 1) in vec2 vertexUV;

// Output data ; will be interpolated for each fragment.
out vec2 UV;

// Values that stay constant for the whole mesh.
uniform mat4 MVP;

void main(){

    // Output position of the vertex, in clip space : MVP * position
    gl_Position =  MVP * vec4(vertexPosition_modelspace,1);

    // UV of the vertex. No special space for this one.
    UV = vertexUV;
}

EDIT this corrected version but still something dont work. If i had DDS everything was working OK but jpg textures all time i have problems.

EDIT i have correct number of textures but they looks diffrent than originalenter image description here

correct texture

\$\endgroup\$
  • \$\begingroup\$ If it works with DDS-loaded textures but not JPEG loaded textures then your problem is almost certainly in your image loading code, not the shaders or texture binding. \$\endgroup\$ – bcrist Feb 2 '14 at 19:18
  • \$\begingroup\$ Download gDEBugger and see if the textures are actually being uploaded \$\endgroup\$ – bcrist Feb 2 '14 at 19:20
  • \$\begingroup\$ ok. I will try thx \$\endgroup\$ – Luffy Feb 2 '14 at 19:30
  • \$\begingroup\$ They are uploaded and they have correct sizes. But they show dont show textures corectly. Texture in DDS looks perfect. \$\endgroup\$ – Luffy Feb 2 '14 at 19:39
  • \$\begingroup\$ You should probably start a new question, since your problem has nothing to do with the first question. You should provide your image loading code, so that we can see what internal format and pixel transfer formats you're using. Something is definitely wrong with the image data being uploaded \$\endgroup\$ – bcrist Feb 2 '14 at 20:05
0
\$\begingroup\$

You are using sampler 0 for every single texture, you should fix this call glActiveTexture(GL_TEXTURE0); so that it looks more like:

for (unsigned int i = 0; i < textures.size(); i++){
    glActiveTexture(GL_TEXTURE0 + i);
    glBindTexture(GL_TEXTURE_2D, Textures[i]);
    // Set our "myTextureSampler" sampler to user Texture Unit 0
    glUniform1i(TextureID, i);
}
\$\endgroup\$
  • \$\begingroup\$ Thx i didnt knew that i should add +i \$\endgroup\$ – Luffy Feb 2 '14 at 18:46
  • \$\begingroup\$ but it still doesnt work :/ If i had enough points i would upvote. Atm i am still trying to figure why it doesn't work. \$\endgroup\$ – Luffy Feb 2 '14 at 18:47
  • \$\begingroup\$ Honestly, I didn't expect that it was the only problem, if you're asking this question then your texture code almost is guaranteed to be packed full of errors, and DDS vs JPEG issue is definitely nowhere in the code you posted. Read the manual. \$\endgroup\$ – MickLH Feb 2 '14 at 19:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.