Another Day, Another Problem! Heh, but this one is truely confusing me, due to the fact i think it should be working. Basically I am trying to create textures based on the position of an object, so i have created a function seen below:
void DropFunc(void){
if (Drop == true)
{
glPushMatrix();
glBindTexture(GL_TEXTURE_2D, texture[2]);
glBegin(GL_QUADS);
glTexCoord2f(0.0f, 0.0f); glVertex3f(DropTileX + 0.0,0.1,DropTileZ + 5.0);
glTexCoord2f(1.0f, 0.0f); glVertex3f(DropTileX + 5.0,0.1,DropTileZ + 5.0);
glTexCoord2f(1.0f, 1.0f); glVertex3f(DropTileX + 5.0,0.1,DropTileZ + 0.0);
glTexCoord2f(0.0f, 1.0f); glVertex3f(DropTileX + 0.0,0.1,DropTileZ + 0.0);
glEnd();
glPopMatrix();
glutPostRedisplay();
Drop = false;
}
}
This is the formula for the x and z values:
int DropTileX = (Dropi * 5) - 5;
int DropTileZ = (Dropj * 5) - 5;
where Dropi and Dropj are constantly being updates by the moving object, so you press the right key and j increases by 1 etc. This function should basically (as far as i know) create a square with the desired vertex, and apply texture[2] to that object. I know this as it works elsewhere in my code (and basically forms the grid my objects move about). Except for this placement, I have increased the y co-ord by 0.1 so it sits above the main floor.
In my drop key i have:
case ‘X’: //drops bottom texture
case ‘x’: Drop = true;
glutIdleFunc(DropFunc);
glutPostRedisplay(); // Redisplay with dropped textures
break;
which as far as I know sets Drop to true, which should activate the function, then it should create the tile as described, then set drop to false so it doesnt loop.
If anyone can understand what i’m trying to do, can you help me?
Thanks,
EJD