Draw the 2d tile image using openGL and C++
void drawGLTexture(GLuint *texture, int x, int y, int width, int height, int tileIndex, int column, int row) { float cOffset = (float)1.0 / (float)column; float rOffset = (float)1.0 / (float)row; float tileRowPos = (float)(tileIndex / column) * rOffset; float tileColumnPos = (float)(tileIndex % column) * cOffset; float x2 = (float)x + width; float y2 = (float)y + height; // Bind the texture to which subsequent calls refer to glBindTexture( GL_TEXTURE_2D, *texture ); glBegin( GL_QUADS ); //Top-left vertex (corner) glTexCoord2f((float)tileColumnPos, (float)tileRowPos ); //glTexCoord2f(0.0f, 0.0f ); glVertex3f((float)x, (float)y, 0.0f ); //Bottom-left vertex (corner) glTexCoord2f( (float)tileColumnPos + cOffset, (float)tileRowPos ); glVertex3f((float)x2, (float)y, 0 ); //Bottom-right vertex (corner) glTexCoord2f( (float)tileColumnPos + cOffset, (float)tileRowPos + rOffset ); glVertex3f((float)x2, (float)y2, 0 ); //Top-right vertex (corner) glTexCoord2f( (float)tileColumnPos, (float)tileRowPos + rOffset ); glVertex3f((float)x, (float)y2, 0 ); glEnd(); }
Log in to answer.
leothenerd 2:59 am on December 3, 2009