Skip to content

Commit

Permalink
2.0 devFixing putpixel and put image overlapping incorrectly after a …
Browse files Browse the repository at this point in the history
…mlx_clear_window() call (#96)

Fixed m_draw_layer incrementation when TexturePut is called
  • Loading branch information
Kbz-8 authored Oct 25, 2024
2 parents da85343 + 185a2b7 commit ef61b79
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
1 change: 1 addition & 0 deletions runtime/Includes/Core/Graphics.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ namespace mlx
int m_id;

bool m_has_window;
bool m_pixelput_called = false;
};
}

Expand Down
13 changes: 11 additions & 2 deletions runtime/Includes/Core/Graphics.inl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace mlx
p_scene->ResetSprites();
m_put_pixel_manager.ResetRenderData();
m_draw_layer = 0;
PixelPut(0, 0, 0x00000000); // bozoman solution FIXME WTF
m_pixelput_called = false;
}

void GraphicsSupport::PixelPut(int x, int y, std::uint32_t color) noexcept
Expand All @@ -18,6 +18,7 @@ namespace mlx
NonOwningPtr<Texture> texture = m_put_pixel_manager.DrawPixel(x, y, m_draw_layer, color);
if(texture)
{
m_pixelput_called = true;
Sprite& new_sprite = p_scene->CreateSprite(texture);
new_sprite.SetPosition(Vec2f{ 0.0f, 0.0f });
}
Expand All @@ -38,12 +39,20 @@ namespace mlx
NonOwningPtr<Sprite> sprite = p_scene->GetSpriteFromTextureAndPosition(texture, Vec2f{ static_cast<float>(x), static_cast<float>(y) });
if(!sprite)
{

Sprite& new_sprite = p_scene->CreateSprite(texture);
new_sprite.SetPosition(Vec2f{ static_cast<float>(x), static_cast<float>(y) });
m_draw_layer++;
if(m_pixelput_called)
{
m_draw_layer++;
m_pixelput_called = false;
}
}
else if(!p_scene->IsTextureAtGivenDrawLayer(texture, m_draw_layer))
{
p_scene->BringToFront(std::move(sprite));
m_draw_layer++;
}
}

void GraphicsSupport::TryEraseSpritesInScene(NonOwningPtr<Texture> texture) noexcept
Expand Down

0 comments on commit ef61b79

Please sign in to comment.