July 16, 2019, 06:10:35 AM

Author Topic: Texture bleeding - Blitzmax bug with virtual resolution  (Read 6476 times)

Offline Derron

  • Hero Member
  • *****
  • Posts: 2199
Re: Texture bleeding - Blitzmax bug with virtual resolution
« Reply #60 on: October 19, 2017, 10:17:46 PM »
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

Offline col

  • Sr. Member
  • ****
  • Posts: 422
Re: Texture bleeding - Blitzmax bug with virtual resolution
« Reply #61 on: October 19, 2017, 10:29:22 PM »
Quote
I hoped for a more enthusiastic reply :p
I edited my last reply a tiny bit.

Quote
Aren't we coders? Coders to solve problems
Haha, and rendering to a texture does exactly that yes?  :P
To be is to be perceived.

https://github.com/davecamp

Offline col

  • Sr. Member
  • ****
  • Posts: 422
Re: Texture bleeding - Blitzmax bug with virtual resolution
« Reply #62 on: October 19, 2017, 10:36:26 PM »
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
To be is to be perceived.

https://github.com/davecamp

Offline Derron

  • Hero Member
  • *****
  • Posts: 2199
Re: Texture bleeding - Blitzmax bug with virtual resolution
« Reply #63 on: October 19, 2017, 10:40:35 PM »
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
  1.    Method ResetGLContext( g:TGraphics )
  2.       Local gw,gh,gd,gr,gf
  3.       g.GetSettings gw,gh,gd,gr,gf
  4.      
  5.       state_blend=0
  6.       state_boundtex=0
  7.       state_texenabled=0
  8.       glDisable GL_TEXTURE_2D
  9.       glMatrixMode GL_PROJECTION
  10.       glLoadIdentity
  11.       glOrtho 0,gw,gh,0,-1,1
  12.       glMatrixMode GL_MODELVIEW
  13.       glLoadIdentity
  14.       'make sure that primitives on x=49.99 do land on x=50
  15.       glTranslatef(0.01, 0.01, 0)
  16.       glViewport 0,0,gw,gh
  17.    End Method
  18.  

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

Offline col

  • Sr. Member
  • ****
  • Posts: 422
Re: Texture bleeding - Blitzmax bug with virtual resolution
« Reply #64 on: October 19, 2017, 10:50:02 PM »
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.
To be is to be perceived.

https://github.com/davecamp

Offline Derron

  • Hero Member
  • *****
  • Posts: 2199
Re: Texture bleeding - Blitzmax bug with virtual resolution
« Reply #65 on: October 19, 2017, 11:18:55 PM »
Isn't linear only used when "FILTEREDIMAGE" is used?

Code: BlitzMax
  1.    If flags & FILTEREDIMAGE
  2.       glTexParameteri GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR
  3.       If flags & MIPMAPPEDIMAGE
  4.          glTexParameteri GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_LINEAR
  5.       Else
  6.          glTexParameteri GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR
  7.       EndIf
  8.    Else
  9.       glTexParameteri GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST
  10.       If flags & MIPMAPPEDIMAGE
  11.          glTexParameteri GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST_MIPMAP_NEAREST
  12.       Else
  13.          glTexParameteri GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST
  14.       EndIf
  15.    EndIf
  16.  

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