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

Author Topic: [SOLVED]RenderWindow.SetSize(width, height) and font problem  (Read 5954 times)

0 Members and 1 Guest are viewing this topic.

amdlintuxos

  • Newbie
  • *
  • Posts: 17
    • View Profile
[SOLVED]RenderWindow.SetSize(width, height) and font problem
« on: March 20, 2012, 04:45:53 pm »
Greetings all.

I have got a small project:
1) mostly everything is rendered in plain opengl
2) sfml render only the texts

Have got a problem when i do re-sizing render window.
case 1 (works OK):
1)
Code: [Select]

int SCREEN_WIDTH_MIN = 800[b]*2[/b];
int SCREEN_HEIGHT_MIN = 600;
sf::RenderWindow g_APP(sf::VideoMode(SCREEN_WIDTH_MIN, SCREEN_HEIGHT_MIN, g_BPP), "app");

2)
Code: [Select]

g_APP.SetSize(SCREEN_WIDTH_MIN, SCREEN_HEIGHT_MIN );
resizeGl(SCREEN_WIDTH_MIN, SCREEN_HEIGHT_MIN);


picture is drawn OK(make notice that text is drawn within border)


case 2(not OK):
1)
Code: [Select]

int SCREEN_WIDTH_MIN = 800;
int SCREEN_HEIGHT_MIN = 600;
sf::RenderWindow g_APP(sf::VideoMode(SCREEN_WIDTH_MIN, SCREEN_HEIGHT_MIN, g_BPP), "app");

2)
Code: [Select]
g_APP.SetSize(SCREEN_WIDTH_MIN[b]*2[/b], SCREEN_HEIGHT_MIN );
resizeGl(SCREEN_WIDTH_MIN[b]*2[/b], SCREEN_HEIGHT_MIN);


picture is drawn not OK, the text(which is drawn by SFML) is wider and in some reson it is drawn below the opengl border (on first picture the text draw call overrides drawing the border)


How could i fix the screen width/height re-sizing to get all objects fitted? or suggestions where i am doing wrong? Thanks in advance.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
[SOLVED]RenderWindow.SetSize(width, height) and font problem
« Reply #1 on: March 20, 2012, 05:02:37 pm »
You must resize the SFML view which is used to draw the text. By default, it always shows the same area of the world, so when the window is resized, what you see is stretched to fit the new size; what you want instead is that the view shows a bigger area.
Laurent Gomila - SFML developer

amdlintuxos

  • Newbie
  • *
  • Posts: 17
    • View Profile
[SOLVED]RenderWindow.SetSize(width, height) and font problem
« Reply #2 on: March 20, 2012, 09:07:36 pm »
Laurent
Hi, thanks for clarification.
But still no luck.

I have been added in my_resize function
Code: [Select]

g_APP.SetSize(width, height);
sf::View view(sf::FloatRect(0, 0, width, height));
g_APP.SetView(view);


The text becomes invisible, so i guess i made something worse with view.
By the way if i re-created window in my_resize function
Code: [Select]

g_APP.Create(sf::VideoMode(width, height, g_BPP), "SFML Window");

the text fitted OK, but something bad with my textures (they becomes like a crap).

Is it something else i could try to solve it? Or maybe my resize view method is not Ok?
Or i need to recreated window and re-load all game graphic resource afterwards? Not sure if it will work, but i was hoping to get easier solution without reloading opengl textures.

Bytheway i forgot to mention, i am using sfml1.6, window mode

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
[SOLVED]RenderWindow.SetSize(width, height) and font problem
« Reply #3 on: March 21, 2012, 08:00:52 am »
The window keeps a pointer to the view, so the instance that you pass to SetView must remain alive as long as it's used. Yours seems to be local to the function, and therefore destroyed immediately.
Laurent Gomila - SFML developer

amdlintuxos

  • Newbie
  • *
  • Posts: 17
    • View Profile
[SOLVED]RenderWindow.SetSize(width, height) and font problem
« Reply #4 on: March 21, 2012, 06:10:23 pm »
Hi Laurent, you are right.
I guess my knowledge around C++ still not perfect. Now i knows exact difference between "pass by reference" and "pass by copy".  You advice solved the problem! Thanks for pointing!

 

anything