Skip to content

Documentation for RenderTexture incomplete #2

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

Closed
wolfgang371 opened this issue Feb 16, 2021 · 11 comments · Fixed by #3
Closed

Documentation for RenderTexture incomplete #2

wolfgang371 opened this issue Feb 16, 2021 · 11 comments · Fixed by #3

Comments

@wolfgang371
Copy link

SFML seems to have a problem with RenderTextures in combination with Sprites. Typically, the sprites will get drawn upside down.

This also took me a while, but finally I came across https://stackoverflow.com/questions/22424124/sfml-rendertexture-flipped-output, which helped me solve the problem easily.

Maybe you want to update your code example accordingly in https://oprypin.github.io/crsfml/api/SF/RenderTexture.html.

frame = SF::Image.from_file("some.jpg")
texture = SF::RenderTexture.new(frame.size.x, frame.size.y)
texture.draw(SF::Sprite.new(SF::Texture.from_image(frame))) # this will get drawn flipped except...
rectangle = SF::RectangleShape.new
rectangle.size = SF.vector2f(100, 50)
rectangle.outline_color = SF::Color::Red
rectangle.outline_thickness = 5
rectangle.position = {300, 200}
texture.draw(rectangle)
texture.display
sprite = SF::Sprite.new(texture.texture.dup) # ... you use `.dup` here!

ImGui.image_button(sprite)
@oprypin
Copy link
Owner

oprypin commented Feb 17, 2021

Why is there ImGui here O_o
Is this about SFML or what?

@oprypin

This comment has been minimized.

@oprypin
Copy link
Owner

oprypin commented Feb 17, 2021

Code is this, and it does indeed reproduce. Only for the interaction with ImGui though.

require "crsfml"
require "imgui"
require "imgui-sfml"

window = SF::RenderWindow.new(SF::VideoMode.new(1280, 720), "ImGui + SFML = <3")
window.framerate_limit = 60
ImGui::SFML.init(window)

delta_clock = SF::Clock.new
while window.open?
  while (event = window.poll_event)
    ImGui::SFML.process_event(event)

    if event.is_a? SF::Event::Closed
      window.close
    end
  end

  ImGui::SFML.update(window, delta_clock.restart)

  frame = SF::Image.from_file("some.jpg")
  texture = SF::RenderTexture.new(frame.size.x, frame.size.y)
  texture.clear
  texture.draw(SF::Sprite.new(SF::Texture.from_image(frame)))
  texture.display()
  sprite = SF::Sprite.new(texture.texture)

  ImGui.image_button(sprite)

  window.clear
  window.draw sprite
  ImGui::SFML.render(window)
  window.display
end

ImGui::SFML.shutdown

@oprypin
Copy link
Owner

oprypin commented Feb 17, 2021

But the issue is with "imgui-sfml" (not even its Crystal binding).
SFML/imgui-sfml#35

If you were getting this effect without ImGui, then it'd be about not having called .display() - a general SFML issue
https://en.sfml-dev.org/forums/index.php?topic=10582.0
(But we're NOT in this situation)

Either way, this is not about CrSFML. Also I almost never add my own examples to https://oprypin.github.io/crsfml/api/, everything there is directly ported from SFML's own docs.

@oprypin oprypin transferred this issue from oprypin/crsfml Feb 17, 2021
@oprypin
Copy link
Owner

oprypin commented Feb 17, 2021

SFML/imgui-sfml#35 (comment) - it seems like they never ended up adding those overloads like they planned.
https://github.com/eliasdaler/imgui-sfml/search?q=RenderTexture&type=code
Maybe I can add it directly here though

@oprypin
Copy link
Owner

oprypin commented Feb 17, 2021

No, I'm not finding an appropriate way to implement this as part of imgui-sfml. They really just need to add that overload, then I'll do the same.

@oprypin oprypin closed this as completed Feb 17, 2021
@wolfgang371
Copy link
Author

I also saw those comments/promises about the overloads years ago; but obviously they didn't come. Nevertheless users have an issue with those RenderTextures. So I was searching for a workaround and the easiest I could find was the .dup one. But this is completely unintuitive, so I thought (for the next couple of years) users might be grateful for this hint.

@eliasdaler
Copy link

Hello, I'm sorry about the delay - the problem was pretty complex and I kinda procrastinated, yep.
Check out this comment which has some explanations about the possible overload.

If you check out "render-texture-fixes" branch and it'll work for you, then I'll merge it into master soon.

@oprypin
Copy link
Owner

oprypin commented Feb 22, 2021

Yes, that branch works well, thank you!

Then the example above just needs to be changed ImGui.image_button(sprite)ImGui.image_button(texture)

@wolfgang371
Copy link
Author

I can also confirm - thank you!

@eliasdaler
Copy link

The fix merged into master, here: SFML/imgui-sfml@ee41e16
Also added a note about sf::RenderTexture in README.

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 a pull request may close this issue.

3 participants