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

How to change Renderer target? #545

Closed
dpc opened this issue Oct 16, 2016 · 3 comments
Closed

How to change Renderer target? #545

dpc opened this issue Oct 16, 2016 · 3 comments
Labels

Comments

@dpc
Copy link
Contributor

dpc commented Oct 16, 2016

Is it possible to change current rendering target of a given Renderer?

Also when doing:

let prescaled_surface_ref = prescaled.surface().unwrap();
let prescaled_texture = screen.create_texture_from_surface(prescaled_surface_ref).unwrap();

where prescaled is a Renderer https://docs.rs/sdl2/0.24.0/sdl2/render/struct.Renderer.html

I get:

src/main.rs:47:36: 47:63 error: the trait bound `sdl2::surface::SurfaceRef: std::convert::AsRef<sdl2::surface::SurfaceRef>` is not satisfied 

I'm puzzled if what I'm trying to do is allowed or not. (I've switched to Renderer::into_surface, but I don't want to recreate the Renderer if I don't have to).

@dpc
Copy link
Contributor Author

dpc commented Oct 23, 2016

The later part is fixed in #547

@Cobrand
Copy link
Member

Cobrand commented Nov 22, 2016

Currently is is pretty non-Rust-y but a Renderer has an inner target called RendererTarget that you can change without having to create another Renderer.

See here.

Basically you have to query the RenderTarget from your Renderer, and then "set" the target of your RendererTarget, do your stuff, and then switch back to the initial RenderTarget (I assume your window) with reset.

Also note that switching RenderTarget is pretty slow compared to other methods (few µs instead of ns), so you should avoid doing it every single frame.

@Cobrand
Copy link
Member

Cobrand commented May 3, 2017

PR 639 closed this, we changed how to change a target globally and added examples on that side as well.

@Cobrand Cobrand closed this as completed May 3, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants