• Advertisement
Sign in to follow this  

Tile Drawing not looking right..

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

That's a screen shot. As you can see, you can clearly tell where the tiles are due to that annoying lines separating them... That only happens when i have the whole map move, but when it's stationary it's fine... is there a reason for this?? maybe a setting i can set??

Share this post


Link to post
Share on other sites
Advertisement
Can you provide a little more information(maybe a snippet of code) as to how you are loading/drawing your texture? Are your tiles extracted from a tileset image? Are each tiles from the set separated by a 1 pixel border?


Are you developing your game using C++ or C#?

Share this post


Link to post
Share on other sites
here's the draw routine


for (unsigned long i=0 ; i<m_lLayerRow ; i++)
{
for (unsigned long j=0 ; j<m_lLayerCol ; j++)
{
// Top-right
glTexCoord2d(((m_TileData[j] % m_lTexCol + 1) * m_lFrameWidth * 1.0f) / texwidth,
((m_TileData[j] / m_lTexCol) * m_lFrameHeight * 1.0f) / texheight);
glVertex3f(((float)j + 1.0f) * width, -(float)i * height, 0.0f);

// Top-left
glTexCoord2d(((m_TileData[j] % m_lTexCol) * m_lFrameWidth * 1.0f) / texwidth,
((m_TileData[j] / m_lTexCol) * m_lFrameHeight * 1.0f) / texheight);
glVertex3f((float)j * width, -(float)i* height, 0.0f);

// Bottom-left
glTexCoord2d(((m_TileData[j] % m_lTexCol) * m_lFrameWidth * 1.0f) / texwidth,
((m_TileData[j] / m_lTexCol + 1) * m_lFrameHeight * 1.0f) / texheight);
glVertex3f((float)j * width, -((float)i + 1.0f) * height, 0.0f);

// Bottom-right
glTexCoord2d(((m_TileData[j] % m_lTexCol + 1) * m_lFrameWidth * 1.0f) / texwidth,
((m_TileData[j] / m_lTexCol + 1) * m_lFrameHeight * 1.0f) / texheight);
glVertex3f(((float)j + 1.0f) * width, -((float)i + 1.0f) * height, 0.0f);
}
}



i'm extracting each tile from a tileset image loaded and the data for each tile is in the 2d variable m_TileData[][]

Share this post


Link to post
Share on other sites
If you have texture filtering turned on it uses texels outside the tile, I had same fragments in lightmap. Try to "correct" UV coordinates.

original coords:
U[x1, x2]
V[y1, y2]

correction:

correct_value = 0.01f
U[x1+correct_value, x2-correct_value]
V[y1+correct_value, y2-correct_value]

experiment with correct_value, to get best result.

I hope that will help.

Share this post


Link to post
Share on other sites
there has to be some way of fixing it with a specific thing, i don't want to have to estimate.. i want something exact..

Share this post


Link to post
Share on other sites
While ladik-BigBoss's explaination is about right, the actual implementation leaves something to be desired.

What you need to do is pull the texture coords 'inwards' towards the center of the tile by half a texel, so that the filtering doesn't interpolate to values outside of the actual tile.

The size of a texel for any given texture is:
texelWidth = 1f / textureWidth;
texelHeight = 1f / textureHeight;

Share this post


Link to post
Share on other sites
You can't use texture clamping if you're storing multiple tiles in a single texture atlas. Texture clamping only applies to the outside edge of a texture.

Share this post


Link to post
Share on other sites
Quote:
Original post by OrangyTang
You can't use texture clamping if you're storing multiple tiles in a single texture atlas. Texture clamping only applies to the outside edge of a texture.


Oh sorry. Didn't see that.

Share this post


Link to post
Share on other sites
alright, that makes sense. How would i do that though? moving the UV coordinates of the texture, i've never messed with that before in OGL.

Share this post


Link to post
Share on other sites
instead of messing with the UV coordinate, because i don't know how, i tried moving the verticies inward, here's my code


float width = m_lFrameWidth * 1.0f;
float height = m_lFrameHeight * 1.0f;
long texwidth = m_pTexture->GetWidth();
long texheight = m_pTexture->GetHeight();
float texelx = 1.0f / (texwidth * 2.0f);
float texely = 1.0f / (texheight * 2.0f);

// ...

for (unsigned long i=0 ; i<m_lLayerRow ; i++)
{
for (unsigned long j=0 ; j<m_lLayerCol ; j++)
{
// Top-right
glTexCoord2d(((m_TileData[j] % m_lTexCol + 1) * m_lFrameWidth * 1.0f) / texwidth,
((m_TileData[j] / m_lTexCol) * m_lFrameHeight * 1.0f) / texheight);
glVertex3f(((float)j + 1.0f) * width - texelx, -(float)i * height - texely, 0.0f);

// Top-left
glTexCoord2d(((m_TileData[j] % m_lTexCol) * m_lFrameWidth * 1.0f) / texwidth,
((m_TileData[j] / m_lTexCol) * m_lFrameHeight * 1.0f) / texheight);
glVertex3f((float)j * width + texelx, -(float)i* height - texely, 0.0f);

// Bottom-left
glTexCoord2d(((m_TileData[j] % m_lTexCol) * m_lFrameWidth * 1.0f) / texwidth,
((m_TileData[j] / m_lTexCol + 1) * m_lFrameHeight * 1.0f) / texheight);
glVertex3f((float)j * width + texelx, -((float)i + 1.0f) * height + texely, 0.0f);

// Bottom-right
glTexCoord2d(((m_TileData[j] % m_lTexCol + 1) * m_lFrameWidth * 1.0f) / texwidth,
((m_TileData[j] / m_lTexCol + 1) * m_lFrameHeight * 1.0f) / texheight);
glVertex3f(((float)j + 1.0f) * width - texelx, -((float)i + 1.0f) * height + texely, 0.0f);
}
}



BUT it's still not working... I even tried to make the texels bigger but then i start to see the clear color that's behind the actual map (the blackness)

how do i move them correctly so it will look right?

Share this post


Link to post
Share on other sites

Moving the vertices will definetely create gaps between the tiles.

You are feeding the UV coordinates with glTexCoord2d command, so you'll need to manipulate them instead of the location.

Share this post


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

  • Advertisement