aphadeon / OpenGame.exe

A custom Ruby-powered game engine that supports RPG Maker games.
24 stars 11 forks source link

Entire program is upsidown #25

Closed felixjones closed 7 years ago

felixjones commented 8 years ago

I started implementing snap_to_bitmap and the first thing I noticed was when downloading the frame-buffer it was actually upside-down.

I flipped all the view port textures to investigate and everything was upside-down, including the downloaded frame-buffer, which indicates that the entire program is upside-down.

All texture co-ordinates and Y co-ordinates need to be flipped.

Current state; current_flip

Corrected state (This is correct OpenGL rendering); all_flipped

Notice how the world is upside-down in both.

aphadeon commented 8 years ago

I flipped the entire renderer manually by setting up an upside-down projection, because I prefer higher Y coordinates meaning lower positions on the screen; not to mention that this is how RGSS works.

That said, it starts to get muddy when I'm having to render that to textures, which are then rendered to other textures, before getting to the screen. I'd bet the issue is in one of the framebuffer projections being set up as flipped and then being flipped again by the main projection. Sorry about that.

felixjones commented 8 years ago

Here's the Graphics::snap_to_bitmap method I made that shows this problem;

public static Bitmap snap_to_bitmap()
{
    Bitmap bmp = new Bitmap(Math.Max(1, width), Math.Max(1, height));

    GL.BindFramebuffer(FramebufferTarget.Framebuffer, 0);

    GL.ReadBuffer(ReadBufferMode.Front);
    GL.Enable(EnableCap.Texture2D);

    GL.BindTexture(TextureTarget.Texture2D, bmp.txid);
    GL.CopyTexSubImage2D(TextureTarget.Texture2D, 0, 0, 0, 0, 0, bmp.width(), bmp.height());
    GL.BindTexture(TextureTarget.Texture2D, 0);

    GL.Disable(EnableCap.Texture2D);
    GL.ReadBuffer(ReadBufferMode.None);

    return bmp;
}

Any bitmaps with that method will show the true orientation of the frame buffer in GPU memory.