Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix erroneous flipping of renderers #169

Merged
merged 2 commits into from
Apr 9, 2024

Conversation

WhyPenguins
Copy link
Contributor

PR duplicated from thoth-tech#39
Commits were rebased.

Description

There were occasions when saving bitmaps, and restoring bitmaps (when all windows are destroyed then recreated) would cause them to be flipped vertically.

An sk_drawing_surface can have its internal bitmap stored either in textures or a surface, depending on if its 'drawable'. The code that handled reading from textures/renderers had a special case for Windows, that flipped the texture (or the coordinates being read) vertically. This was likely a workaround for a bug that used to be in SDL, but was fixed a while ago, so this PR simply removes those special cases.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • Breaking change (fix or feature that would cause existing functionality to not work as
    expected) - if any people using SplashKit relied on the textures being flipped (or worked around it), they will experience different behavior.

How Has This Been Tested?

Tested using the following sample, on Windows:

open_window("Test", 256, 256);
bitmap bmp = create_bitmap("test bitmap",256,256);

clear_bitmap(bmp, COLOR_WHITE);

// draw a square in the corner
draw_rectangle_on_bitmap(bmp, COLOR_RED, {0,0,32,32});

// write out some pixels read from the bitmap in lines
draw_pixel_on_bitmap(bmp, COLOR_BLACK, {199,0});
draw_pixel_on_bitmap(bmp, get_pixel(bmp, 0,0), {200,0}); // expected: red
draw_pixel_on_bitmap(bmp, get_pixel(bmp, 1,0), {201,0}); // expected: red
draw_pixel_on_bitmap(bmp, get_pixel(bmp, 1,1), {202,0}); // expected: white

draw_pixel_on_bitmap(bmp, COLOR_BLACK, {199,1});
draw_pixel_on_bitmap(bmp, get_pixel(bmp, 0,1), {200,1}); // expected: red
draw_pixel_on_bitmap(bmp, get_pixel(bmp, 1,1), {201,1}); // expected: white
draw_pixel_on_bitmap(bmp, get_pixel(bmp, 1,1), {202,1}); // expected: white

draw_pixel_on_bitmap(bmp, COLOR_BLACK, {199,2});
draw_pixel_on_bitmap(bmp, get_pixel(bmp, 0,255), {200,2}); // expected: white
draw_pixel_on_bitmap(bmp, get_pixel(bmp, 1,255), {201,2}); // expected: white
draw_pixel_on_bitmap(bmp, get_pixel(bmp, 1,254), {202,2}); // expected: white

// without commit, the saved bitmap is flipped vertically
save_bitmap(bmp, "is_it_flipped");

// the bitmap drawn here is the correct way around
draw_bitmap(bmp,0,0);
refresh_screen();
delay(2000);

close_window("Test");
//------------------------------------
open_window("Test", 256, 256);

// The bitmap drawn here is now vertically flipped before the commit
draw_bitmap(bmp,0,0);
refresh_screen();
delay(2000);

close_window("Test");

Without the commits, the get_pixels are all white (reading is flipped vertically), the save_bitmap saves a flipped bitmap, and the bitmap bmp is flipped once the window is closed then re-opened. All works correctly with the commits.

Testing Checklist

  • Tested with sktest
  • Tested with skunit_tests

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • My changes generate no new warnings
  • I have requested a review from ... on the Pull Request

@macite macite merged commit cfd9cca into splashkit:develop Apr 9, 2024
2 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants