Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Recreating the projektion matrix onwindow rescale  (Read 13116 times)

0 Members and 1 Guest are viewing this topic.

tgm

  • Jr. Member
  • **
  • Posts: 69
    • View Profile
Recreating the projektion matrix onwindow rescale
« 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):
Code: [Select]


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^^

workmad3

  • Jr. Member
  • **
  • Posts: 71
    • View Profile
Recreating the projektion matrix onwindow rescale
« Reply #1 on: April 20, 2008, 08:14:37 pm »
Something along the lines of
Code: [Select]

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 :)

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Recreating the projektion matrix onwindow rescale
« Reply #2 on: April 21, 2008, 03:12:00 am »
Why don't you just use a custom view which you update on window resize ?
Laurent Gomila - SFML developer

workmad3

  • Jr. Member
  • **
  • Posts: 71
    • View Profile
Recreating the projektion matrix onwindow rescale
« Reply #3 on: April 21, 2008, 09:15:56 am »
Because I'm at heart an OGL programmer?  :oops:  :lol:

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Recreating the projektion matrix onwindow rescale
« Reply #4 on: April 21, 2008, 09:41:54 am »
Then just use sf::Window instead of sf::RenderWindow, you'll get more stuff to do yourself with OpenGL ;)
Laurent Gomila - SFML developer

workmad3

  • Jr. Member
  • **
  • Posts: 71
    • View Profile
Recreating the projektion matrix onwindow rescale
« Reply #5 on: April 21, 2008, 11:13:14 am »
: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 :)

tgm

  • Jr. Member
  • **
  • Posts: 69
    • View Profile
Recreating the projektion matrix onwindow rescale
« Reply #6 on: April 21, 2008, 07:10:18 pm »
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)

tgm

  • Jr. Member
  • **
  • Posts: 69
    • View Profile
Recreating the projektion matrix onwindow rescale
« Reply #7 on: April 26, 2008, 10:51:11 pm »
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:
 
Code: [Select]

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.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Recreating the projektion matrix onwindow rescale
« Reply #8 on: April 27, 2008, 06:11:50 am »
Your viewport shouldn't affect the SFML rendering. This should be fixed in the current version.
Laurent Gomila - SFML developer

tgm

  • Jr. Member
  • **
  • Posts: 69
    • View Profile
Recreating the projektion matrix onwindow rescale
« Reply #9 on: April 27, 2008, 12:22:42 pm »
great ;) thx

 

anything