【发布时间】:2015-08-20 22:45:04
【问题描述】:
我正在用 OpenGL 开发一个程序。我当前的设置只包括一个四边形和一个我想在其上渲染的纹理。问题是纹理没有渲染到四边形上。如果我更改片段着色器以呈现它正确呈现的颜色。
这里是渲染代码:
glfwSwapBuffers(window);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glUseProgram(programID);
glBindVertexArray(vaoID);
glEnableVertexAttribArray(0);
glEnableVertexAttribArray(1);
GL13.glActiveTexture(GL13.GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, textureID);
glDrawElements(GL_TRIANGLES, indicies.length, GL_UNSIGNED_INT, 0);
glDisableVertexAttribArray(0);
glDisableVertexAttribArray(1);
glBindVertexArray(0);
glUseProgram(0);
顶点着色器:
#version 400 core
layout(location = 0) in vec3 position;
layout(location = 1) in vec2 textureCoords;
out vec2 pass_TextureCoords;
void main() {
gl_Position = vec4(position, 1.0);
pass_TextureCoords = textureCoords;
}
片段着色器:
#version 400 core
in vec2 pass_textureCoords;
out vec4 out_Color;
uniform sampler2D textureSampler;
void main() {
out_Color = texture(textureSampler, pass_textureCoords);
}
【问题讨论】:
-
设置顶点缓冲区的代码在哪里?