Jump to content
  • Advertisement
Sign in to follow this  
polpoint

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

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

If you intended to correct an error in the post then please contact us.

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);
}




    glBegin(GL_QUADS);

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 this post


Link to post
Share on other sites
Advertisement
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.


Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!