# OpenGL openGL- one big texture to 32x32 sprites math problem

This topic is 4443 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

ok. I finally got my larger tile map to the correct format and my program is loading the individual tiles. Buuutt I don't think I even had the algorithm correct before. I am using a 1024x1024 pixel image with 32x32 pixel tiles. here is my code snppt
[/source

int iNer=0;
int oNer=0;

glBindTexture(GL_TEXTURE_2D, textureNumb[0]);

for(int yEr=2;yEr<44;yEr++)
{
for(int xEr=0;xEr<56 ;xEr++)
{

iNer=xEr;  //iNer and oNer are the coordinates of the individual
oNer=yEr;  //tiles 0-31 x 0-31

if(iNer>=32)
{
iNer=(iNer-32);
}
if(oNer>=32)
{
oNer=(oNer-32);
}

float cx=float(iNer%32)/32.0f;
float cy=float(oNer%32)/32.0f;

glTexCoord2f (0		+(cx)	,		0+(cy));
glVertex3f (-55.0+(xEr*2.5), -41.0+(yEr*2.5), 0.0);

glTexCoord2f (.03125	+(cx)	,		0+(cy));
glVertex3f (-52.5+(xEr*2.5), -41.0+(yEr*2.5), 0.0);

glTexCoord2f (.03125	+(cx)	,		.03125+(cy));
glVertex3f (-52.5+(xEr*2.5), -38.5+(yEr*2.5), 0.0);

glTexCoord2f (0		+(cx)	,		.03125+(cy));
glVertex3f (-55.0+(xEr*2.5), -38.5+(yEr*2.5), 0.0);

]



##### Share on other sites
What, exactly, is the problem? That'll make it easier to spot what's wrong.

##### Share on other sites
your right, I guess there was nothing wrong. I just did not think about the 2 that I started my yEr variable at in my x & y for loops.

1. 1
Rutin
47
2. 2
3. 3
4. 4
5. 5

• 10
• 27
• 20
• 9
• 20
• ### Forum Statistics

• Total Topics
633405
• Total Posts
3011683
• ### Who's Online (See full list)

There are no registered users currently online

×