Possible bug with OpenGL Screenshots

BlitzMax Forums/BlitzMax Programming/Possible bug with OpenGL Screenshots

Grey Alien(Posted 2008) [#1]
Hi all, I often take screenshots of my game to send to the artists and today I noticed something weird...

Previously I've been using DX and the screenshots were fine, like this one of a dialog with an alpha shadow over a background:



But recently I started using OpenGL instead (long story) and I noticed that the alpha shadow is not being captured properly in the screenshot (it looks fine on-screen). If you download this png and view it in a paint program you'll see that the shadow is actually partially transparent i.e. you can see the checkered background in the paint package which you should not be able to because the background image is solid!



Here's my code that saves screenshots:

		Local gfxGrab:TPixmap
		gfxGrab = GrabPixmap(0,0,ScreenWidth, ScreenHeight) 
		SavePixmapPNG(gfxGrab, filename, 9)



Note that it's possible it's a problem with my new graphics card, but I wondered if anyone has noticed this before or has an app/game with an alpha shadow that they can run in OpenGL and take a screenshot of with the above code. (Grey Alien Framework users simply press G to run your game in OpenGL mode then press F12 to take a screenshot which will be saved in your dynamic data folder).

[edit]The problem occurs in full-screen and windowed mode.

Thanks for any feedback. If this is a BMax bug then I'll post it in the bug forum after more investigation.


ImaginaryHuman(Posted 2008) [#2]
I guess it's possible that with your OpenGL driver the alpha values of the graphics you draw to the backbuffer are getting stored in the backbuffer's alpha channel, and then your screen grab is getting alpha channel data rather than all empty alpha data? That wouldn't really be a bug, if it's what's happening, it may be just the way your driver grabs screenshots, or how GL works?


Grey Alien(Posted 2008) [#3]
Yeah I just need someone else to try out a similar thing on their PC to verify if it's a bug or not (or I could try a new video card but that's a hassle).


Hotcakes(Posted 2008) [#4]
I'm not sure if this is an adequate test, but I took two screenshots showing the debug dialog which has that alphashaded area and the images screenshotted identically.

I use an nVidia 9600 and my image quality settings in the control panel are all set to highest possible quality, so this is the behaviour I would expect to see.

You use ATI which is not known for its OpenGL functionality, so I'd say this is not a Max thing, rather a drivers thing. I'm sure it is cheaper for the hardware to only touch every second pixel than it is to alter every pixel where the alphablend is necessary, although if you say it only happens in screenshots then that is a bit strange.


Grey Alien(Posted 2008) [#5]
So did you take the screenshot with code or just the PrtScn key (I haven't tried that key with this card in OGL, will do now...)

OK the Print Screen key DOES take screenshots in OGL CORRECTLY. This then may suggest an issue with Bmax. Correct?

I suppose I need a test app, but I thought someone might have something setup already they could quickly test...


jamesmintram(Posted 2008) [#6]
Hmm, not entirely sure if this is even a valid answer but it seems logical to me.

In glMax2D you have this at line 461 - you could experiment by changing the PF_RGBA8888 to PF_RGB888 and GL_RGBA to GL_RGB and seeing if that works. If the problem is solved then it looks like you will either have to use a modified Module or write your own GrabPixmap function for use with OpenGL.

Local p:TPixmap=CreatePixmap( w,h,PF_RGBA8888 )

glReadPixels ,GraphicsHeight()-h-,w,h,GL_RGBA,GL_UNSIGNED_BYTE,p.pixels


Volker(Posted 2008) [#7]
@hotcake
Just to inform you; maybe a false alert:
clicking on the link in your sig
http://ff-fan.com/
my virusprotection (Avira Antivir Personal)
gives me a trojan warning:
Name: HTML/Infected.WebPage.Gen


MGE(Posted 2008) [#8]
hmm.. I did tests a while back for screenshots in both ogl and dx modes and I didn't notice anything. I'll test an exe on 3 machines if someone wants to write it. ;)


Hotcakes(Posted 2008) [#9]
OK the Print Screen key DOES take screenshots in OGL CORRECTLY. This then may suggest an issue with Bmax. Correct?

I used F12 fyi and you may be right.


Grey Alien(Posted 2008) [#10]
@jamesmintram: OK thanks for that, now to find the time to test it...

@MGE: I could make a test exe but it's not a big issue for me personally at all, more for BMax (if the problem is with Bmax and not my video card). I'm going to change to another video card later this week and if the problem is still there then I'll post it as an official bug.

@Hotcakes: OK thx for the info.


Yan(Posted 2008) [#11]
Just convert the pixmap to a non alpha format, which is what the DX Max2D driver spits out BTW, and get on with it...
SavePixmapPNG(gfxGrab.Convert(PF_RGB888), filename, 9)
;op

[edit]
Err...Which is what James already said...Sorta... ;o)
[/edit]


Grey Alien(Posted 2008) [#12]
@Yan: That totally works thx. So should I report it as a bug that the GL driver doesn't output the same format as the DX driver?


Yan(Posted 2008) [#13]
It's probably worth pointing out as it *is* inconsistent, at the very least.

I'm just not sure which driver is as intended. ;o)

I have to agree that the way the alpha is handled in your case is just weird. I haven't been able to reproduce it here.


Grey Alien(Posted 2008) [#14]
weird that you haven't been able to duplicate it.

Anyway posted as a bug:

http://www.blitzbasic.com/Community/posts.php?topic=80611