我想以这样的方式修改下面的代码片段,我想使用for循环生成具有特定纹理的几何体。我想输入顶点坐标和顶点数量,然后使用glVertex3f生成纹理平面。这可能吗?
编辑:为了澄清,我希望能够提供
中包含的信息 glTexCoord2f(0.f, 0.f); glVertex3f(-1, -1, -1);
glTexCoord2f(rep, 0.f); glVertex3f(-1, 1, -1);
glTexCoord2f(rep, rep); glVertex3f(-1, 1, 1);
glTexCoord2f(0.f, rep); glVertex3f(-1, -1, 1);
使用for循环进行分段。这就像我想要一个glVertex3f [n]数组,其中包含用户给出的坐标。
// Obstacle texture
// draw with different ppm file
obstProg->enable();
obstProg->bindTexture("tex", obstTex, GL_TEXTURE_2D, 0);
obstProg->bindTexture("shadowTex", renderer->getShadowTexture(), GL_TEXTURE_2D, 1);
obstProg->setUniformfv("lightPosEye", renderer->getLightPositionEyeSpace(), 3);
obstProg->setUniformfv("lightColor", lightColor, 3);
// set shadow matrix as texture matrix
matrix4f shadowMatrix3 = renderer->getShadowMatrix();
glActiveTexture(GL_TEXTURE0);
glMatrixMode(GL_TEXTURE);
glLoadMatrixf((GLfloat *) shadowMatrix3.get_value());
glColor3f(1.0, 1.0, 1.0);
glNormal3f(0.0, 1.0, 0.0);
glBegin(GL_QUADS);
{
float rep = 10.f;
glTexCoord2f(0.f, 0.f); glVertex3f(-1, -1, -1);
glTexCoord2f(rep, 0.f); glVertex3f(-1, 1, -1);
glTexCoord2f(rep, rep); glVertex3f(-1, 1, 1);
glTexCoord2f(0.f, rep); glVertex3f(-1, -1, 1);
glTexCoord2f(0.f, 0.f); glVertex3f(1, -1, -1);
glTexCoord2f(rep, 0.f); glVertex3f(1, 1, -1);
glTexCoord2f(rep, rep); glVertex3f(1, 1, 1);
glTexCoord2f(0.f, rep); glVertex3f(1, -1, 1);
glTexCoord2f(0.f, 0.f); glVertex3f(-1, -1, 1);
glTexCoord2f(rep, 0.f); glVertex3f(-1, 1, 1);
glTexCoord2f(rep, rep); glVertex3f(1, 1, 1);
glTexCoord2f(0.f, rep); glVertex3f(1, -1, 1);
glTexCoord2f(0.f, 0.f); glVertex3f(-1, -1, -1);
glTexCoord2f(rep, 0.f); glVertex3f(-1, 1, -1);
glTexCoord2f(rep, rep); glVertex3f(1, 1, -1);
glTexCoord2f(0.f, rep); glVertex3f(1, -1, -1);
glTexCoord2f(0.f, 0.f); glVertex3f(-1, 1, -1);
glTexCoord2f(rep, 0.f); glVertex3f(1, 1, -1);
glTexCoord2f(rep, rep); glVertex3f(1, 1, 1);
glTexCoord2f(0.f, rep); glVertex3f(-1, 1, 1);
}
glEnd();
obstProg->disable();
答案 0 :(得分:1)
由于您已经在数组中拥有顶点数据,因此直接将它们发送到OpenGL是有意义的,而不是手动循环它们并调用立即模式函数。谷歌的“顶点阵列”