我想用 GLSL 做纹理映射。但我想我的代码不使用着色器。这是我的代码:
顶点.vert
#version 330
out vec2 texcoord;
void main()
{
gl_Position=gl_ModelViewProjectionMatrix*gl_Vertex;
texcoord=gl_MultiTexCoord0.xy;
}
片段.frag
#version 330
uniform sampler2D img;
in vec2 texcoord;
void main()
{
vec4 texcolor = texture2D(img,texcoord);
gl_FragColor=texcolor;
}
main中的纹理映射部分
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, _textureId[0]);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glUniform1i(glGetUniformLocation(shader.ShaderProgram,"img"),0);
glBegin(GL_QUADS);
glTexCoord2f(0.0f, 0.0f);
glVertex3f(-2.5f, -2.5f, 2.5f);
glTexCoord2f(1.0f, 0.0f);
glVertex3f(2.5f, -2.5f, 2.5f);
glTexCoord2f(1.0f, 1.0f);
glVertex3f(2.5f, -2.5f, -2.5f);
glTexCoord2f(0.0f, 1.0f);
glVertex3f(-2.5f, -2.5f, -2.5f);
glEnd();
我的代码有什么问题?完整代码: