Graphical Elements Flickering on W10 / NG / OpenGL

Started by sonic, June 04, 2020, 20:33:31

Previous topic - Next topic

Derron

Do not rely on what DesktopWidth() tells - maybe in Ogl it reports something different. "GraphicsWidth()" and "GraphicsHeight()" will return the size of the used graphics context.


bye
Ron

sonic

it seems to line up now anyway now that i switched to monitor scaling. fullscreen mode does seem to change the desktop res to be the same as the Bmax app res as far as i can tell (i know Unity and the like have deprecated that behaviour in favour of a stretched window.)

i'm going to try this SDL conversion. i will let you know how it goes.

sonic

hey there. so i got it up and running with SDL after a while messing with some of my modules. unfortunately i'm still seeing the issue in both SDL drivers. in the SDL2 driver, there seem to be individual text characters missing in the glitches, so it's less obvious at first, which is why i probably missed it in my test program. however this driver breaks my FBO support. in SDL one the performance is similar to BMax driver, with whole DrawText calls occasionally flashing black white or red. sometimes a whole group of drawn items will glitch - for example a rectangle, a couple of lines and the text on top of it that make up a button in my home-made UI framework. also it seems i wasn't able to get fullHD, 900p or other resolutions than native working in fullscreen mode with any driver. windowed mode works quite well, although feels a touch laggier (this app included pixel art creation so i hope for it to be responsive.) as it stands i don't think i'd be able to support fullscreen mode, but windowed mode still displays these issues anyway.

edit: i'm not sure what to try next, beyond moving to dx9 and getting some solid render texture alternative to replace the heart of my code. if anyone has time to check out the first test program i made and see if they see any issues, that would be really helpful. they often don't show up for a minute but then come quite frequently for a short while.

sonic

hmmm it's definitely a problem with DrawText - when i ran another old game project it ran perfectly until text was displayed and then random background tiles in the tilemap started flashing...

Derron

#19
DrawText renders individual textures ... so
"HELLO" draws
H ...
E ...
L ...
L ...
O

As L's are two times there next to each other, you have 4 texture switches alone with this simple DrawText.


To avoid this, I created my bitmapfont class... you could copy ideas from it (simply copying wont work as I utilize my TSprite class and other stuff):
https://github.com/GWRon/Dig/blob/master/base.gfx.bitmapfont.bmx

The idea is to have all the glyphs ("characters") of a font in a sprite atlas (single image). When now rendering text, it renders with the same texture ("sub images").
To emulate that ... you could simply create a "text image" for each text you display. Then DrawImage() them - I assume none of them is flickering.
My code copies all the glyphs loaded from a TTF into such a sprite atlas. When requesting a different font size, it automatically creates new bitmap fonts from it. You could even attach image manipulation (so you could add gradients, drop shadows ...).


So of course "DrawText" might somehow create other issues (dunno which ones). Do you rotate stuff? Scale stuff ? ...maybe it somehow borks up the "matrix" (rotation, scale ... of textures).



@ Fullscreen
I do not have issues here and others too ... so maybe it would be good to check this out in a simple "base example" ... Create a programme which renders an arrow (vertical + horizontal line) in all corners. Print the res in the center ... and done. Now check with various resolutions and brl/sdl drivers.


@ DX 9
My Pull Request for NG contains render2texture support for OpenGL, DX9 ... in brl and sdl fashion.


Edit: did you create an apitrace as I suggested? So we could see if the "commands " stay the same (driver issue) or if something is done which you did not do on purpose (modules or application bug).

bye
Ron

sonic

thanks Ron. that text renderer rewrite is looking like my only option... i'd presumably have to prebake it too to ensure that no glyphs were glitched on the way in. it's really not ideal - this is a text focussed editor, with a built-in IDE and scripting language and makes heavy use of DrawText. it's been fast enough since i first wrote it on my mac in 2006, so performance has never been an issue. i want to support other languages and so on so that means the things would need to be robust and extensible and quite an undertaking. there are also at least 5-6 fonts used in varying sizes.

the resolution one really has me stumped - i literally copied the test program to another tab in MaxIDE, and one ran perfectly in 1080p, while the other refused to select that res and went to the weird, blurry offcentre 2560x1600 no matter what i removed from the program. i could get the issue to show with two identical programs which did nothing but set the res and then attempt to read the desktop res back. one worked, the other always failed. the code was just a few lines and identical.

i will try this api trace at some point, but i had hoped not to need to debug the engine itself, that maybe there was a fix that someone might already to be able to suggest.

Derron

You are the first person reporting this (at least of what I got aware of).

Chances exist, that it is not an engine thing but a "Windows+driver+your individual config" thing.


@ GUI driven
Render the buttons into textures and draw them ... saves GPU/cpu cycles. You could even do that via "software rendering" if only done here and there. Check out my Dig-framework's "imagehelper" on how to do this - and my bitmapfont class renders onto TPixmap too (which you can then loadimage() etc).



bye
Ron


sonic

it's just a shame my code works perfectly in 1.51 and refuses to in NG, even on the simplest use case (my demo prog.)

both the resolution issue and the flickering elements issue is not present in 1.51 with the same codebase. other commercial games i've tested seem to play fine with non-native resolutions, as do ones i've made in Unity.

you may be right and it's my individual config but that's not going to help me or any potential customers. it's a clean install of a new system, all highest grade parts, with the latest drivers and everything else runs great, including the same apps built in 1.51.

i really appreciate all your help with this but i think i'm going to go back to 1.51, and then be prepared to not release it and only use it for personal use if it looks like Windows is likely to drop 32bit support. obviously a mac version can't be done anymore (although i am still on High Sierra, i wouldn't release a new Mac app in 32bit now that Catalina is here.)

sonic

ah i'm sorry i spoke too soon - the issue is also present in original Blitzmax. this is worrying as i'm going to be unable to use my toolset on my main dev machine - i'll have to continue using my mac for that.

i'm unable to find any other games which display this, but i'll see if i can find any with an opengl renderer (hard to find these days!)

may just be a case of nvidia not really caring about their modern ogl drivers for the 20x0 series of cards... may even be fixed in a future update. i did a clean install of the latest driver but saw no improvement. i'm hesitant to say there's a problem with my card as i don't see any other issues in games.

i think i am too deep in to rewrite the code for use with a new render to texture module - my pixel software is heavily optimised around layers created with the FBO mod created by beanage.

edit2 - well it seems one opengl game i could test also have an issue with lower than native resolution, Deus Ex. everything is completely broken (with borders and the OS behind in low res) unless running in 4k. but it's hardly a conclusive test because it's a very old game with some known issues. it only works in 4k with the help of a launcher someone made. i will keep looking to see if i can find any more modern examples in my library. it doesn't display any flickering, but i'm really leaning towards that being an issue specific to DrawText or Freetype with my OpenGL driver. i honestly feel like it's the driver at this point. modern DX games such as many Capcom ones in my Steam library happily switch into any standard res without any faff, or weird borders...

sonic

amazing - the 'Power management mode' setting in my Nvidia Control panel was the cause of the flicker. setting it to 'Prefer Maximum Performance' has fixed the issue.

now i can at least use the tool myself. and possibly release it too... i'd really want to be able to scale to different resolutions for development ideally though. if i can get a fix to that, all would be well... (my hope is this is just a problem with current openGL drivers)

Derron

Regarding the fullscreen issue ...

We should tackle this individually...


so as said - simple app which draws corner markers (so you see "offsets") ... then check against 16, 32 ... bit depth etc.

With SDL you at least should not see multi monitor setups displaying the same fullscreen app (only main app does then)


bye
ron

sonic

ah i've finally got to the bottom of the resolution issue - Windows scaling. although the results made no sense to me (i mean, how hard can it be to scale up 1080p exactly by 2.0 in each dimension, and not get 1600p?), it seems legacy code using the 'GDI' interface can end up with some bizarro scaling:

https://blogs.windows.com/windowsdeveloper/2017/05/19/improving-high-dpi-experience-gdi-based-desktop-apps/

i assume this is what Blitz uses for fullscreen mode?

either way, by bringing up the app and enabling compatability mode to override high-DPI scaling i was able to get non-native res legacy code to work, both Deus Ex and my BMax / NG codebases. it seems i'm going to have to do this on a case by case basis and i guess is just part of Microsoft's chosen method of dealing with this. it's definitely something the mac does nicely compared to Windows. otoh, recent macs have had loads of connection / heat issues with external monitors so swings and roundabouts.