Pixel-perfect texturing with GL_NEAREST

This topic contains 1 reply, has 2 voices, and was last updated by  Arron 6 years ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #30654

    poslundc
    Member

    Hi,

    I’m trying to represent a sprite from a texture atlas using a quad with a 1:1 texel-to-pixel mapping, using GL_NEAREST as the filter. I’m getting occasional artifacts depending on where the sprites are being positioned (I am only using integer coordinates).

    I’ve found all kinds of contradictory advice online, ranging from having to offset the vertices being drawn by 0.5, to having to offset and/or scale the texels being drawn by various amounts. Nothing seems to produce consistently accurate results.

    What is the correct method in OpenGL ES to get a 1:1 texel-to-pixel mapping of a sub-rectangle of a texture onto a quad of matching dimensions, when using GL_NEAREST?

    Thanks,

    Dan.

    #35158

    Arron
    Member

    Hi Dan.

    What artefacts are you getting exactly? I assume you mean that you’re getting sub-pixel results? Or are you getting borders around the sprites?

    I also assume that your orthographic projection matrix matches the dimensions of your viewport?

    If you have a screenshot of the artefact it may help us diagnose the issue.

Viewing 2 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic.