DigiPen-Faculty / CProcessing

MIT License
27 stars 3 forks source link

Fixed the CP_Image_Screenshot function #10

Closed gabeGillette closed 2 years ago

gabeGillette commented 2 years ago

Made two changes to the CP_Image_ScreenShot function.

The issue with only the background being captured has been fixed. This seems to have been caused by what appears to be NanoVG storing the draw calls in a buffer and only drawing everything when nvgEndFrame is called. The nvgEndFrame function is only ever called by CProcessing at the end of the game state loop, during the CP_EndFrame function. ScreenShot relies on a raw OpenGL call (glReadPixels), not a NanoVG one, so basically what was happening was that glReadPixels was working as expected, there just wasn't anything actually drawn on screen at the time of the call because nvgEndFrame hadn't been called yet.

My fix is really simple. Call nvgEndFrame right before glReadPixels and nvgStartFrame immediately after. This allows nanoVG to do it's thing and gives glReadPixels something to capture. Calling nvgStartFrame afterwards allows the user to call additional drawing functions after the screenshot has been taken.

The other change to the function addresses the disconnect between CProcessing and OpenGL's coordinate systems. CProcessing has the screen origin at the top left, OpenGL has it at the bottom left. This inconsistency may cause some confusion, so a minor conversion has been made so now the function expects the same upper left origin coordinates as the rest of CProcessing's functions.