Hello. I did a search for a similar topic and couldn't find one, so I apologize in advance if one does indeed exist elsewhere.
I've been programming a game in Visual Basic 6 using the DirectX 8 Graphics interface, but I've run into a bit of trouble in my attempts to correctly read the color value from a single pixel from the front buffer that I've already locked with LockRect. Just so I'm not misunderstood, though, I'm not having trouble with the functionality. I've already successfully locked the front buffer, read from it, and unlocked it. My problem is figuring out the correct math for reading the appropriate color data from the pixels. (That being said, I hope I've started this thread in the right place and I apologize if I haven't.)
This is the helper function that I have going to make the job easier...
Function GrabPixel(XPos As Long, YPos As Long) As Long
Dim TempColor As Long
' LockedRect is the front buffer surface (D3DLOCKED_RECT) I've locked with Direct3DSurface.LockRect, and according to the docs it ought to be 32-bit automatically.
' X_RES& is the width of the game's current screen mode.
' Y_RES& is the height of the game's current screen mode.
With LockedRect
TempColor = (.pBits + ((Y_RES& - 1 - YPos) * .Pitch) + (XPos * 4))
End With
' Anything else I need to do here to manipulate the color value I get before it's usable?
GrabPixel = TempColor
End Function
If anyone can figure out where I'm going wrong with my math, I'd greatly appreciate it. Thank you in advance to anyone who posts with help and advice.