Greetings,
I have a small issue with OpenGL texturing, which is not related to any GPU in particular. I've reproduced this problem with Radeon GPU and Mali GPU, so it's just a "I don't understand OpenGL" problem. However, I'm putting this in the ARM Mali graphics section, as it seems to be the most adequate section by elimination, and I'd like to know how this problem is called in OpenGL terms.
My problem is that when I use a texture atlas and apply a part of the texture atlas to a quad, it sometimes picks one more pixel from contiguous parts of the texture atlas.
The same quad displayed at different zones of the screen will glitch differently.
The problem tends to disappear when I use GL_NEAREST with GL_TEXTURE_???_FILTER, instead of GL_LINEAR. However, the texture become awfully pixelated then.
Here's an example of the code used :
psychic-octo-waffle/myy.c at master · Miouyouyou/psychic-octo-waffle · GitHub
The code basically generates two cards, divided in one opaque and two transparent parts, at two different parts of the screen (-0.02, 0 and 0.24, 0).
The non-converted atlas can be seen here. It's a set of 13x4 playings cards, 4 suits symbol, 4 turned cards and 4 backgrounds.
So, the normalised dimensions of each card part of the texture atlas are :
I really doubt that these dimensions can generate rounding errors.
When executed, the code produces a window with two turned-around cards on the screen. Each one glitching slightly differently.
Here's the result :
So my questions are :
Alright, I still wanted to use my atlas 'as-is' and applying the +(1/(2*tex_width)),-(1/(2*tex_height)) offset solved the problem.
The texture looks nice with GL_LINEAR filtering and with GL_NEAREST filtering too, and gets better with GL_LINEAR + SAMPLE_BUFFERS which is good news.
I updated my code in the example Github repository, so that future readers understand the trick.
I glanced over the OpenGL ES 2.x specification and saw this at chapter 3.5.2:
Denote a datum at pa, pb, or pc as fa, fb, or fc, respectively. Then the value f of a datum at a fragment produced by rasterizing a triangle is given byf = (a*fa/wa + b*fb/wb + c*fc/wc) / (a/wa + b/wb + c/wc)(3.5)where wa, wb and wc are the clip w coordinates of pa, pb, and pc, respectively.a, b, and c are the barycentric coordinates of the fragment for which the data areproduced. a, b, and c must correspond precisely to the exact coordinates of thecenter of the fragment. Another way of saying this is that the data associated witha fragment must be sampled at the fragment’s center.
Denote a datum at pa, pb, or pc as fa, fb, or fc, respectively. Then the value f
of a datum at a fragment produced by rasterizing a triangle is given by
f = (a*fa/wa + b*fb/wb + c*fc/wc) / (a/wa + b/wb + c/wc)
(3.5)
where wa, wb and wc are the clip w coordinates of pa, pb, and pc, respectively.
a, b, and c are the barycentric coordinates of the fragment for which the data are
produced. a, b, and c must correspond precisely to the exact coordinates of the
center of the fragment. Another way of saying this is that the data associated with
a fragment must be sampled at the fragment’s center.
Is it what you were referring to ?
Great, glad you got it sorted.
> Is it what you were referring to ?
That's part of it. There are similar comments related to the texture coordinates and filtering too.