im new to textures. im having some trouble mapping textures onto a rendered terrain. im trying to map it onto a rendered terrain the code for which i found online.
The left one is the output. The right one is my texture. i just wanted to map it onto it. The texture is a 256x256 bmp image.
im using this for mapping texture:
for(int z = 0; z < _terrain->length() - 1; z++) {
glBegin(GL_QUAD_STRIP);
for(int x = 0; x < _terrain->width(); x++) {
/* set normal and set vertex */
glTexCoord2d((double)x / _terrain->width(), (double)z / _terrain->length());
// Two
/* set normal and set vertex */
glTexCoord2d((double)x / _terrain->width(), (double)z + 1 / _terrain->length());
}
}
But im not able to map the texture. im using a 50x50 height map for the terrain. Can anyone please correct me?
i agree. You are calling glBegin recursively, but never ending the process. remember, openGL is a state machine, once something like this is initiated, it must be terminated.
Thanks for the replies. Sorry missed out on the glEnd(). Here is the code. Not sure why the texture is not mapped.
for(int z = 0; z < _terrain->length() - 1; z++) {
glBegin(GL_QUAD_STRIP);
for(int x = 0; x < _terrain->width(); x++) {
/* set normal and set vertex */
glTexCoord2d((double)x / _terrain->width(), (double)z / _terrain->length());
// Two
/* set normal and set vertex */
glTexCoord2d((double)x / _terrain->width(), (double)z + 1 / _terrain->length());
}
glEnd();
}
//a glutSwapBuffers() here.
for(int z = 0; z < _terrain->length() - 1; z++, count1++) {
glBegin(GL_QUAD_STRIP);
for(int x = 0; x < _terrain->width(); x++, count2++) {
// Set Normal and vertex
..
glTexCoord2d(x / 50.0, z / 50.0);
// Set normal and vertex
..
glTexCoord2d(x/ 50.0, (z + 1) / 50.0);
}
glEnd();
}
glutSwapBuffers();
z != _terrain->length - 1, so it is max _terrain->length-2, if you add 1 to this you get _terrain->length-1 and divide by 50, you don’t get exactly 1. Maybe try to divide by 49.