0
我一直在試圖讓這段代碼工作一段時間,現在仍然無法弄清楚我做錯了什麼。 (LWJGL - Java)LWJGL - Quad未呈現
我試圖檢查網絡上的其他人的代碼,但我找不到任何主要區別。我實際上學會了使用OpenGL和C++,所以我的思想可能會停留在它上面,這可能是我找不到我的錯誤的原因。
這裏是init(稱爲一次)
FloatBuffer vertices = BufferUtils.createFloatBuffer(4 * 5);
vertices.put(new float[]{
// pos // Color
0.5f, 0.5f, 0.5f, 0.0f, 0.5f,
0.5f, -0.5f, 0.5f, 0.0f, 0.75f,
-0.5f, -0.5f, 0.0f, 1.0f, 0.0f,
-0.5f, 0.5f, 0.5f, 0.5f, 1.0f
});
vertices.flip();
ByteBuffer indices = BufferUtils.createByteBuffer(2 * 3);
indices.put(new byte[]{
0, 1, 3,
1, 2, 3
});
indices.flip();
// VAO
VAO = GL30.glGenVertexArrays();
GL30.glBindVertexArray(VAO);
// VBO
VBO = glGenBuffers();
glBindBuffer(GL_ARRAY_BUFFER, VBO);
glBufferData(GL_ARRAY_BUFFER, vertices, GL_STATIC_DRAW);
// EBO
EBO = glGenBuffers();
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, indices, GL_STATIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, VBO);
glEnableVertexAttribArray(0);
// v - position in layout (see shader)
// v - Nb of component per vertex (2 for 2D (x, y))
// v - Normalized ? (between 0 - 1)
// v - Offset between things (size of a line)
// v - Where to start ?
glVertexAttribPointer(0, 2, GL11.GL_FLOAT, false, 5 * Float.SIZE , 0);
glEnableVertexAttribArray(1);
glVertexAttribPointer(1, 3, GL11.GL_FLOAT, false, 5 * Float.SIZE , 2 * Float.SIZE);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO);
// Unbinds the VAO
GL30.glBindVertexArray(0);
glDisableVertexAttribArray(0);
glDisableVertexAttribArray(1);
,這裏是渲染功能:
shaderProgram.bind();
GL30.glBindVertexArray(VAO);
GL11.glDrawElements(GL11.GL_TRIANGLES, 6, GL11.GL_BYTE, 0);
GL30.glBindVertexArray(0);
glBindBuffer(GL_ARRAY_BUFFER, 0);
着色器:
頂點:
#version 330 core
layout(location = 0) in vec2 position;
layout(location = 1) in vec3 color;
out vec4 Color;
void main()
{
gl_Position = vec4(position, 0.0, 1.0);
Color = vec4(color, 1.0);
}
Framgent:
#version 330 core
in vec4 Color;
out vec4 color;
void main()
{
color = Color;
}
似乎沒有做任何事情。由於無法訪問屬性,因此調試相當困難 – Gaktan 2014-11-14 21:08:36