I want to modify the code snippet below in such a way, that I want to generate the geometry with a particular texture using for-loops. I want to input the vertex coordinates, and the amount of vertices and then generate texture planes using glVertex3f. Is this possible?
Edit: To clarify, I want to be able to give the information contained in
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);
segment using a for-loop. It’s like I’d like to have a glVertex3f[n] array with the coordinates given by the user.
// 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();
Since you already have the vertex data in a array it makes sense to send them to OpenGL directly, instead of manually looping over them and call immediate mode functions. Google for “Vertex Arrays”