retrooper
retrooper

Reputation: 47

LWJGL 3 failing to render textures properly with slick-util compatible version with LWJGL 3

I have recently started rewriting my game in LWJGL 3, and it is so different. I tried looking for tutorials, and this person used this slick-util compatible with LWJGL version 3. I followed the tutorial and watched the 30 minute tutorial almost three times and couldn't figure out what was wrong, I checked it's github repository and still couldn't figure out why I couldn't get my texture loading properly.

Here is how my texture looks rendered with my code

Here is his github repository for the tutorial enter link description here

Here is the tutorial video enter link description here

Skip to timestamp: 32:02

I really need help I tried all day I can't get this working! Let me know if sharing code is necessary, because maybe one of you might have had this bug already and already know the solution. Thank you

Upvotes: 1

Views: 163

Answers (1)

Rabbid76
Rabbid76

Reputation: 210946

The vertex specification does not match the the attribute indices of the shader program:

pbo = storeData(positionBuffer, 0, 3);
// [...]
cbo = storeData(colorBuffer, 1, 3);
// [...]
tbo = storeData(textureBuffer, 2, 2);

Your vertex shader:

#version 460 core

in vec3 position;
in vec3 color;
in vec2 textureCoord;

out vec3 passColor;
out vec2 passTextureCoord;

void main() {
  gl_Position = vec4(position, 1.0);
  passColor = color;
  passTextureCoord = textureCoord;
}

Your fragment shader

#version 330 core

in vec3 passColor;
in vec2 passTextureCoord;

out vec4 outColor;

uniform sampler2D tex;

void main() {
  outColor = texture(tex, passTextureCoord);
}

The attribute indices are not automatically enumerated (0, 1, 2, ...). The attribute color doesn't even get an attribute index, because it is not an active program resource. color is set to the interface variable passColor, but that variable is not used in the fragment shader. Hence this shader program has only 2 active attributes and the attribute indices of this attributes are not specified. Possibly the indices are 0 for position and 1 for textureCoord (that is what most hardware drivers will do), but you cannot be sure about that.

Use Layout Qualifier (GLSL) for the Vertex shader attribute indeices:

#version 460 core

layout(location = 0) in vec3 position;
layout(location = 1) in vec3 color;
layout(location = 2) in vec2 textureCoord;

// [...]

Upvotes: 1

Related Questions