1.35 readpixel not accurate in fullscreen

Archives Forums/BlitzMax Bug Reports/1.35 readpixel not accurate in fullscreen

DjBigWorm(Posted 2009) [#1]
Hi,

Hope I can explain this one well enough for someone to confirm and explain what i might of been doing wrong:)

I was excited to see the 1.35 was up and now uses dx9 wow.
I am working on a game the uses a bottom layer with solid colored blocks and use the following lines of code to get the pixel color
the player is on.

Function Getpixelcolor:Int(X:Int, Y:Int)
Local mypix:TPixmap = GrabPixmap(X, Y, 1, 1)
'------------amazing fix----------------
DrawPixmap(mypix, 1, 1)
'line above makes the readpixel commad work again
Return ReadPixel(mypix, 0, 0)
End Function

funny thing though 1.34 and before would work fine.
i draw a layer of what the stage looks like if it were solid
colored areas, read the color the player is on then make various things happen to the player. everything works fine on my desktop.

Then played it on my laptop and my player went erratic as if it didn't know what color it was on. The same game worked perfect in windowed mode, but in fullscreen mode it acts up. I uninstalled and tried it with blitzmax 1.34 and played perfect. Me being curious just tried diffent things to see if I can bypass this or come up with a different way to do it. answer was if I add the "DrawPixmap" command the function works a treat again?!?! Is there a reason this might have made it work? or is it an unknown bug. Thanks in advance! Keep up the good work.

Laptop specs that failed xp sp3 - 3 gig ram - video card ATI Mobility Radeon x1400. I tried latest drivers available on ms update site.


marksibly(Posted 2009) [#2]
Hi,

Runnable example please!

Note that there's an issue with the current d3d9 driver where GrabPixmap isn't setting alpha to '255' as it should be - could this be related?


_Skully(Posted 2009) [#3]
Are you using the new Virtual Resolution commands?


DjBigWorm(Posted 2009) [#4]
no not using virtual resolutions. i will put together a working example for you guys to try and see what happens. will try after i get out of work this evening.


DjBigWorm(Posted 2009) [#5]
Ok, haven't had much of a chance to put together a working exe to test.
From what i could figure out, the grabpix command under dx9 is getting the front buffer and not the backbuffer as expected. same problem shows up in rc5. You changed so grabpixmap would set alpha to 255. This didn't seem to help the problem.


Beaker(Posted 2009) [#6]
I suspect Mark wants some runnable code, not an exe.


DjBigWorm(Posted 2009) [#7]
i see, i can try to send some to him shortly


DjBigWorm(Posted 2009) [#8]
Ok,

Here Is some code I put together to demonstrate the problem that
shows up on my laptop.
'-----------------------------------------------
SetGraphicsDriver(D3D9Max2DDriver())
'SetGraphicsDriver(D3D7Max2DDriver())
'SetGraphicsDriver(GLMax2DDriver())
Graphics (640, 480, 32, 60, GRAPHICS_ALPHABUFFER)
Global RED:Int, green:Int, blue:Int
Global mx:Int, my:Int
Repeat
   Cls ' clear screen
   mx = MouseX()
   my = MouseY()
   SetColor (255, 0, 0)
   DrawRect (0, 40, 50, 50)
   PCOLOR = Getpixelcolor (mx, my) ' find out the Color of the pixel under mouse
   GetRGB (PCOLOR)
   SetColor(255, 255, 255)
   DrawOval(mx - 3, my - 3, 6, 6)
   DrawText (RED + "," + green + "," + blue, 0, 0)
   Flip True

Until KeyHit(KEY_ESCAPE)

Function Getpixelcolor:Int(X:Int, Y:Int)
	'grabs a pixmap from x and y location
	Local mypix:TPixmap = GrabPixmap(X, Y, 1, 1)
	'readpixel and return the value
	Return ReadPixel(mypix, 0, 0)
End Function

Function GetRGB(pixelValue:Int)
	'this function breaks down the colors to individual rbg values
	'	Alpha = (argb Shr 24) & $ff
	'	RED = (argb Shr 16) & $ff
	'	green = (argb Shr 8) & $ff
	'	blue = (argb) & $ff

	pixelValue = ($00ffffff & pixelvalue) 'gets rid of the alpha bits making the number make sense
	RED = pixelvalue / $10000
	pixelValue = ($00ffff & pixelvalue) 'removes the r value
	'Print r
	green = pixelvalue / $100
	'Print g
	pixelValue = ($00ff & pixelvalue) 'removes the g value leaving only b
	blue = pixelvalue
	'Print b
	
End Function
'--------------------------------------------------


In fullscreen mode it seems to read the white color under the mouse, in
windowed mode it works as expected and the white circle under the mouse
doesn't show the value. Seems to be grabpixmap grabs the front buffer and not the backbuffer as expected.

Can anyone else get the same problem or am I understanding the code wrong.
Thanks for any insight:)