Texture bleeding - Blitzmax bug with virtual resolution

Started by Derron, October 13, 2017, 21:59:44

Previous topic - Next topic

Derron

I hoped for a more enthusiastic reply :p


Think the "glTranslatef()"-thing creates other problems as "0,0" will no longer be 0,0 then. So I am not sure if that is the right direction for a fix.


Rendering to an image (to avoid that lines?) smells a bit like "avoidance". Aren't we coders? Coders to solve problems, not to avoid them (I know... time is money...).




bye
Ron

col

QuoteI hoped for a more enthusiastic reply :p
I edited my last reply a tiny bit.

QuoteAren't we coders? Coders to solve problems
Haha, and rendering to a texture does exactly that yes?  :P
https://github.com/davecamp

"When you observe the world through social media, you lose your faith in it."

col

As for solving a problem... hmm the problem was/is/maybe caused by so many scalings going on that it would quite difficult to get them 100% correct using the limited precision of floating point math. To solve that would be to remove it from the equation and start again. Kind of where I was heading with my suggestion of writing your own DrawSubImageRect, but it may even need to go further - as you've discovered.

I'm all in for high quality and striving for high standards, but working with heavy chains ( scales on scales etc ) is difficult for me to find attractive :P
https://github.com/davecamp

"When you observe the world through social media, you lose your faith in it."

Derron

Hmm, rendering to a texture is less "cross platform" for now (SDL and NG) while this is an OGL-specific thing.
(as said on github: once r2t works properly I would be glad to use it in many situations as it speeds up rendering and eases a lot of pain).


@ scaling of scaling of ...
Yes it is a bit annoying, which is why I tend to accept my "whacky hacky fix" below to make it work. One might consider adding a "EnableGLCorrection()" function so one could enable that only when using scales/VirtualResolution<>RealResolution.
(On the other hand: the coordinates in the apitrace seem to look ok, so doesn't this say that there might be issues with the orthoview, matrix, viewports, ...whatever?)


For now I adjusted my code in glmax2d.bmx to this:
Code (blitzmax) Select

   Method ResetGLContext( g:TGraphics )
      Local gw,gh,gd,gr,gf
      g.GetSettings gw,gh,gd,gr,gf
     
      state_blend=0
      state_boundtex=0
      state_texenabled=0
      glDisable GL_TEXTURE_2D
      glMatrixMode GL_PROJECTION
      glLoadIdentity
      glOrtho 0,gw,gh,0,-1,1
      glMatrixMode GL_MODELVIEW
      glLoadIdentity
      'make sure that primitives on x=49.99 do land on x=50
      glTranslatef(0.01, 0.01, 0)
      glViewport 0,0,gw,gh
   End Method


As this seems to solve issues here this seems there is an rounding issue happening within my gpu-driver-ogl-combination. That "0.01" is so small that the "blurriness" of my sprites is neglictable (alpha-mixed colors vary by less than 1 percent). It's not the best thing but at least it "seems to do the job" (dunno if that is true on other computers too).


bye
Ron

col

I think you'll remove the blurriness by changing the pixel sampling mode from LINEAR to NEAREST. I'm not sure the final image would look though.
https://github.com/davecamp

"When you observe the world through social media, you lose your faith in it."

Derron

Isn't linear only used when "FILTEREDIMAGE" is used?

Code (blitzmax) Select

   If flags & FILTEREDIMAGE
      glTexParameteri GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR
      If flags & MIPMAPPEDIMAGE
         glTexParameteri GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_LINEAR
      Else
         glTexParameteri GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR
      EndIf
   Else
      glTexParameteri GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST
      If flags & MIPMAPPEDIMAGE
         glTexParameteri GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST_MIPMAP_NEAREST
      Else
         glTexParameteri GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST
      EndIf
   EndIf


So in my (test-)case it should always be correct except for certain fonts. I tried to see differences (removing the corresponding image flags) but it did not change something "visually". I then replaced the _LINEAR parts above with nearest (so ignoring image flags at all...) and text looked crisp again. This then made me find another little "bug" (= relying on default flags) - I create my bitmapfont-"all glyphs"-image without a given flag ("loadimage(pixmap)") which means it loads it with default flags. Passing a ", 0" lead to crisp fonts without the "_LINEAR" replacement in glmax2d.bmx.
BUT ... after doing so, the texts wont look good when scaled (...of course!) and this means they do not look nice when using virtual resolution. So that is no solution at all.


bye
Ron