SFML community forums
General => Feature requests => Topic started by: tgm on April 20, 2008, 06:35:58 pm
-
I would be interested if there would be a way to proper recreate the projektion matrix on rescaling of the window.. (or this being done automaticly)
So Sprites wouldn't be distorted after rescaling the window, but instead some part of the world simply lay outside the screen.
something like(from :http://www.lighthouse3d.com/opengl/glut/index.php?3):
void changeSize(int w, int h) {
// Prevent a divide by zero, when window is too short
// (you cant make a window of zero width).
if(h == 0)
h = 1;
float ratio = 1.0* w / h;
// Reset the coordinate system before modifying
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
// Set the viewport to be the entire window
glViewport(0, 0, w, h);
// Set the correct perspective.
gluPerspective(45,ratio,1,1000);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(0.0,0.0,5.0,
0.0,0.0,-1.0,
0.0f,1.0f,0.0f);
}
Well, of course you don't use glut, do you? Gonna have a look in the source.. Well, doesn't seems like you do ;) But I guess this code shows pretty well, what I want to say^^
-
Something along the lines of
sf::Window app(/*some options in here*/);
sf::Event e;
while (app.GetEvent(e))
{
// Resize event
if (e.Type == sf::Event::Resized)
{
// go to projection matrix
glMatrixMode(GL_PROJECTION);
// reset
glLoadIdentity();
// set the viewport to the new size
glViewPort(0, 0, e.Size.Width, e.Size.Height);
// setup the projection matrix using glu
gluPerspective(45, static_cast<float>(e.Size.Width) / static_cast<float)(e.size.Height));
// switch to the modelview matrix
glMatrixMode(GL_MODELVIEW);
}
}
should be what you are thinking of :)
-
Why don't you just use a custom view which you update on window resize ?
-
Because I'm at heart an OGL programmer? :oops: :lol:
-
Then just use sf::Window instead of sf::RenderWindow, you'll get more stuff to do yourself with OpenGL ;)
-
:lol: Did you look at my example code? :P
I'm in the middle of architecture type coding at the moment though, so choice of window type is sort of moot (currently in the middle of encapsulating joystick buttons into input objects that I can then check through names loaded in from a file... good fun :)
-
Actually I was quite aware, that there is a way doing this (though I thought, I would have to digg deeper since SFML manages OGL quite well, and thus Imhot a "Simple" library should be able to manage that.. (just my 2 cent)
-
Well actually this ain't working out the way I thought..
The code Posted above doesn't work at all.. everything is distorted as always.. However, if I exchange the Viewport recreation with something like:
glViewport(0, 0, 512, 512);
(constant size) the OGL cube is rendert properly, but sf::Sprites Strings etc aren't rendert correct.. :? any Idea hjow to fix this?
thx in advance.
-
Your viewport shouldn't affect the SFML rendering. This should be fixed in the current version.
-
great ;) thx