我正在学习OpenGL SuperBible一书中的OpenGL。我想渲染使用函数gltMakeSphere()创建的球体。我绑定一个纹理并运行useProgram()。着色器使用GLBatch处理三角形,但球体只有绿色。试图在OpenGL中使用着色器纹理球体
下面是代码:
void RenderScene(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
modelViewMatrix.PushMatrix();
modelViewMatrix.Translate(0,0,-5.0f);
GLint locMVP = glGetUniformLocation(testShader, "mvpMatrix");
glBindTexture(GL_TEXTURE_2D, texture1ID);
glUniformMatrix4fv(locMVP, 1, GL_FALSE,
transformPipeline.GetModelViewProjectionMatrix());
glUseProgram(testShader);
testBatch.Draw();
sphereObject.Draw();
glutSwapBuffers();
glutPostRedisplay();
modelViewMatrix.PopMatrix();
}
的Vertex Shader
#version 130
in vec4 vVertex;
in vec2 vTexCoords;
smooth out vec2 vVaryingTexCoords;
void main(void)
{
vVaryingTexCoords = vTexCoords;
gl_Position = vVertex;
}
片段着色器
#version 130
uniform sampler2D colorMap;
out vec4 vFragColor;
smooth in vec2 vVaryingTexCoords;
void main(void)
{
vFragColor = texture(colorMap, vVaryingTexCoords.st);
}
Draw()函数内置于GLTriangleBatch类中,不是由我创建的。 – Ioncannon 2011-06-06 22:11:31