Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Thorbadin

Bug in my 2d "engine" if anyone can help.

This topic is 5370 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

Hi, not sure if here is the best place to post but let''s try. So I have this game that is starting to actually work, it''s a zelda 1 type game, 2d sprites over a map using open gl boxes to display it''s tile. I actually got the "inspiration" from the old nehe zelda project (I did ripe graphics from there and started my code from some of it too). Anyway, so everything work fine until I started to do some global "offset" when the player move. Imagine there is an invisible box in the middle of the screen where the player can move. When the player move out of that box, the map move instead to simulate going farther (it''s not 1 map = 1 screen like old zelda but bigger maps). I used gl translate to move everything for that offset like this: glTranslatef(testplayer.OffSet_x, testplayer.OffSet_y, 0.0f); And use popmatrix for when it''s the player so the player stay at the same spot on the screen while everything move around him. glPushMatrix(); glLoadIdentity(); cTile::DrawXYZ(xPos, yPos, zPos, (*TileArray[CurrentAction])[CurrentTile].TileID, false); glPopMatrix(); It work fine on my pc (fx5200), but when a friend tried it, lines would appear often between the map tiles as if they are not getting a good alignement or something. On my work pc a gf2mx I see the lines, on a gf2 and on a gf4 something I also see the lines, but it work fine on my pc. Ring a bell to anyone? Some other codes that may be usefull (and I can post anything else if someone feel it can help). I load my textures with the Ilut image library with the following code or so. global_texture[iCurrent].glreference = ilutGLBindTexImage(); ilDeleteImages(1, &ImageName); glBindTexture(GL_TEXTURE_2D, global_texture[iCurrent].glreference); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,GL_NEAREST); And here is the quad code (a rip from one of the old zelda source or so thanks to whoever did this!): glBegin(GL_QUADS); glTexCoord2f( // Top Left cx + fBorder, 1.0f - cy - fBorder); glVertex3f(x, y, z); glTexCoord2f( // Top Right cx + 1.0f/SpritePerX - fBorder, 1.0f - cy - fBorder); glVertex3f(x + (m_fWidth * cGameState::World_Zoom), y, z); glTexCoord2f( // Bottom Right cx + 1.0f/SpritePerX - fBorder, 1.0f - (cy + 1.0f/SpritePerY) + fBorder); glVertex3f(x + (m_fWidth * cGameState::World_Zoom), y + (m_fHeight * cGameState::World_Zoom), z); glTexCoord2f( // Bottom Left cx + fBorder, 1.0f - (cy + 1.0f/SpritePerY) + fBorder); glVertex3f(x, y + (m_fHeight * cGameState::World_Zoom), z); glEnd(); Hopefully it will come out correctly in this. Thanks in advance and hopefully someone will find something. Thorb

Share this post


Link to post
Share on other sites
Advertisement
i had this problem before. i think it''s something about clamping the textures...

Share this post


Link to post
Share on other sites
I''m going to check into the float precision problem tomorrow.

I''m currently using orthoprojection. Sorry for not mentionning it.

And what exactly do you mean by "clamping the textures..."? I''m trying to picture this but it come out very wrong..

Thorb

Share this post


Link to post
Share on other sites
Think ctoa may mean this

// The default GL_TEXTURE_WRAP_S and ""_WRAP_T property is GL_REPEAT.
// We need to turn this to GL_CLAMP_TO_EDGE, otherwise it creates ugly seems
// in our sky box. GL_CLAMP_TO_EDGE does not repeat when bound to an object.
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

as in the crappy joins you get when you draw a skybox and use REPEAT

Share this post


Link to post
Share on other sites
Well, I guess it was the float thing, which I don''t exactly understand why, maybe OPENGL doesn''t do the rounding the same way all the time or something.

By using int after the coordinates are set the lines go away. At least on this crappy card it does.

I tried the GL_CLAMP thing, not sure exactly what it did but it wasn''t that.

Thanks!

Thorb

Share this post


Link to post
Share on other sites
one thing you wanna be careful about is this...
when you draw two poly''s next to each other...
DON''T DO THIS:
store their size or their vertices or whatever & translate to ones location, draw it, & then translate over to the other''s location & draw it... & you know they SHOULD match... cus you translated just right & their edges should touch. DON''T DO THAT.

instead... store a point in 3D space such as a corner used by more than one poly... so that when you need to draw the other polys, you call on that EXACT value... don''t be translating over here & there all the time... your edges won''t match up perfectly. so if you have a huge 2D board... with many squares... I''d imagine a huge array of vertices would work well for you.

Share this post


Link to post
Share on other sites

  • 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!