pixel perfect aspect2d / different pixel centers opengl / DX

Hi,

I’m working on 2D gui system and am running into text rendering problems as discussed in this thread:

https://discourse.panda3d.org/viewtopic.php?t=2304&highlight=pixel+center+centre

so namely, I’m also hitting the problem that a very low res font, which I render with nearest (= no) filtering has it’s baseline not aligned.
I also changed the position by 0.5/0.5 and that works.

However, now I’m bit by the fact that openGL and directX have different pixel centers. DX is off by 0.5/0.5 from OpenGL.

Does panda have a built-in way to compensate for that?
One could solve this by offsetting the view matrix or the aspect2d by half a pixel, depending on the graphics API. I could do this in user (python) code, but that feels wrong.

Any ideas?

Cheers,

Erik

What! Really? How did I never notice that?

David

I think i have seen this too. I attributed to bad dx drawing of fonts implementation. But yeah if they where shifted .5,.5 pixels that would explain dx blurriness.

I am also working on a pixel perfect gui system for panda3d. Search treeGUI on the forums.

I’ve confirmed this: yes, it’s true, DirectX and OpenGL use a different texel center for applying textures. Curse Microsoft and their anything-different-from-OpenGL philosophy.

It’s not obvious to me what the best solution is at the low level. We could introduce code within Panda to compensate automatically, but this would require universally imposing a texture offset, or hand-munging the texture coordinates, on either DirectX or OpenGL–and this would introduce a small but nonzero runtime overhead. Seems like overkill for most applications.

So maybe a better solution would be to have a special render attrib, maybe a variant on TexMatrixAttrib, that means “shift the texture coords by the appropriate amount to put the texel in the middle of the pixel, like OpenGL does it.” Then you would apply this attrib only where you really do care about pixel accuracy.

In the meantime, you might as well continue to make the determination at the Python level. One reliable way would be something like:

if base.win.getPipe().getInterfaceName().startswith('DirectX'):

David

I will compensate for this on the Python side.

But I was wondering: wouldn’t it be possible for panda3d to offset aspect2d and render2d by half a pixel, instead of doing this on a node per node basis via the texture offset?
That way, everything parented to aspect2d would automatically do the shift

This is how I’ll compensate on our end. I’ll let you know how it works out…

Cheers,

Erik