It's possible I am over-complicating it, I'm not an expert so I may be missing something obvious! If you don't mind looking, here is a quick snippet of my canvas (offscreen texture) code I use to achieve the desired results. You say it's just an extra sprite to draw, but I thought it was a lot more?
//Clear the canvas
canvas.clear(Color::Black); //equivalent to drawing an entire window of pixels?
//Here I would draw all my things - normally to the window but needs to be the canvas now. No change between techniques.
canvas.draw(stuff);
//Display the canvas
canvas.display(); //seems to be taxing to the framerate?
//Window clear, draw canvas sprite, and display
window.clear(Color::Black); //equivalent to drawing an entire window of pixels?
window.draw(canvas_sprite); //draws an entire window of pixels
window.display(); //as above
In a normal renderwindow-only setup, I just have the last 3 lines (except drawing objects instead of the canvas sprite), achieving ~500fps. With the canvas code it drops to 250fps, even with no object drawing (only 2 tiny objects so I'm not surprised). So is the canvas process alone adding 3 extra full window pixel fills for the gpu, I think? I was expecting some performance hit, but not this much.
I'm not particularly upset with the outcome, I'm mainly curious if I missed something obvious?
The trick is.
If your window is smaller than your view's size: Things affected by the view will seems to be smaller. (zoom out)
If your window is bigger than your view's size: Things affected by the view will seems to be bigger. (zoom in)
If your window is the same size than your view's size: no zoom.
If you want to zoom in the view, without change the view size.
Use the zoom method:
float zoom = 2.0f ;
view.zoom( 1.0f / zoom ) // Zoom in.
view.zoom( zoom ) // Zoom out.
Anothers views methods here (http://www.sfml-dev.org/documentation/2.3/classsf_1_1View.php#ac95b636eafab3922b7e8304fb6c00d7d).
Jesper, yes in my original post I described that my current solution is to use a RenderTexture. Visually it's perfect but I was concerned about the performance hit, I think it's not a big issue now :)
DarkRoku I have experimented with zooming but I wasn't able to find a solution that solves my issue :( Thank you for your help I really appreciate it!
If anyone is curious I thought I would share my very small basic example to illustrate my problem. Hit Q to switch between window only and rendertexture. If anyone if bored enough to check it out I'm always open for feedback. Thanks everyone!
//in main.cpp
#include <SFML/Graphics.hpp>
//program entry point and loops
int main(int argc, char* args[]){
//view setup
sf::Vector2f native_res={800,600};
sf::View view;
view.setSize(native_res);
view.setCenter(native_res.x/2,native_res.y/2);
//window setup
sf::Vector2f user_res={640,480};
sf::RenderWindow window(sf::VideoMode(user_res.x, user_res.y),"View testing",sf::Style::Titlebar|sf::Style::Close);
//apply view with zoom here??
//float zoom=native_res.x/user_res.x; //assumes matching ratios
//view.zoom(zoom);
//apply view
window.setView(view);
//textures
sf::Texture walltex;
sf::Texture backingtex;
walltex.loadFromFile("wall.png");
backingtex.loadFromFile("backing.png");
walltex.setSmooth(true);
backingtex.setSmooth(true);
//sprites
sf::Sprite backing(backingtex);
sf::Sprite wall1(walltex);
sf::Sprite wall2(walltex);
wall1.setPosition(100,100);
wall2.setPosition(132,116);
//off-screen canvas via rendertexture
sf::RenderTexture canvas;
canvas.create(native_res.x,native_res.y);
canvas.setSmooth(true);
sf::Sprite canvas_sprite(canvas.getTexture());
//loop
bool drawcanvas=true;
while(window.isOpen()){
//sole event check for closing window
sf::Event event;
while(window.pollEvent(event)){
if(event.type==sf::Event::Closed){
window.close();
}
if(event.type==sf::Event::KeyPressed){
if(event.key.code==sf::Keyboard::Q){
drawcanvas=!drawcanvas;
}
}
}
if(drawcanvas==true){
//WINDOW ONLY DRAWS
window.clear(sf::Color::Black);
window.draw(backing);
window.draw(wall1);
window.draw(wall2);
window.display();
} else {
canvas.clear(sf::Color::Black);
canvas.draw(backing);
canvas.draw(wall1);
canvas.draw(wall2);
canvas.display();
window.clear(sf::Color::Black);
window.draw(canvas_sprite);
window.display();
}
}
return 0;
}