Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: [SOLVED] Problem with precisely applying textures  (Read 1078 times)

0 Members and 1 Guest are viewing this topic.

rallion

  • Newbie
  • *
  • Posts: 1
    • View Profile
[SOLVED] Problem with precisely applying textures
« on: April 02, 2012, 12:07:14 am »
I don't know if there's really a good solution to this, but I thought I would ask.

I'm using a Vertex array to draw a grid of tiles to the screen. I have a big array of vertices that define 1x1-sized quads.

The texture I'm using is just a small 64x64px image, with four tile textures in it, so I set the texcoords for each quad to what I believe are the appropriate pixel values: the top left tile, for example, goes from (0.0) to (32,32), and the bottom right goes from (32,32) to (64,64).

When it's time to draw, I create a view that scales the 1x1 quads to the size that I want. This allows me to very easily zoom in and out. It also allows me to maintain the scale when the window is resized, and show more tiles instead of making them bigger.

For the most part, this works fine. I believe that there is a chance that I won't always get perfectly uniform tiles, because of things like rounding errors, and I'm okay with it if one tile ends up being 32px wide and another is 33px. The problem that I have is that it seems like I'm running into errors with the precise areas of the textures that are applied to the tiles, and that creates a much more problematic effect.

It's supposed to, and usually does, look like this (ignore my terrible random map):


However, with certain view sizes, it looks like this:


The floor tiles are the upper-left quadrant of the texture I'm using, and the doors are the bottom-left.

To make it clear what's happening, the floor tiles all include the row of pixels BELOW the specified texcoords -- specifically, the top row of the door tile texture. The door tiles are also wrong. On some, they're missing that same row, and on others the textures are slightly twisted.

The actual tile sizes are correct, they're all 32px in each image. It's just the textures that are wrong. This actually only happens "vertically." There is no corresponding effect where textures get messed up in the X direction.

Like I said, I'm not sure whether there is good solution to this, but I thought it couldn't hurt to ask.

[SOLVED] Seems like this only happens when the view size and center result in a view rectangle where the top ends up as a non-integer after the transform. Added some extra checks to shift the view a little bit if this happens, and I don't get the lines anymore.
« Last Edit: April 02, 2012, 02:23:39 am by rallion »

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: [SOLVED] Problem with precisely applying textures
« Reply #1 on: April 04, 2012, 10:14:47 am »
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development: