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

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - JoshuaBehrens

Pages: [1] 2 3
1
Window / Re: Change viewport to keep aspect ratio of scene
« on: August 02, 2014, 01:19:22 am »
@Hapax: Well then I know why we miscommunicate as you see percentage in a range of 0..100(which is absolutely right) and I just called it percentage as it should not be larger than 100% = 1.0.
I can understand your misinterpretation of the doubled usage of the floatrects properties width/height on the one hand in pixels and on the one hand in ratios.
The code from the others works, but I found an other error(continue reading).

@mely: I just tested your example and it worked perfectly. I put it into my application and it was working. Then I changed the code from relying on window.getSize( ) on my variables windoww and windowh. Then it was not working and stretching wrong. Then I found a typo in my resize-event where I asign the new width and height to windoww but windowh is not affected. So I guess even my code should have worked without the typo (not tested).

Thank you for your patience and pointing me (unintentionally) to an error (I should have been aware of).

2
Window / Re: Change viewport to keep aspect ratio of scene
« on: August 01, 2014, 07:14:00 am »
I want to always see the whole scene so if my scene has an aspect ratio of 1:1 and the width is greater than the height of the window I need black panels on the upper and lower part of the window (vice versa for height > width). And I try to achieve this with using glViewport as used with the viewport from sf::View.

3
Window / Re: Change viewport to keep aspect ratio of scene
« on: August 01, 2014, 05:26:28 am »
I get your dirty trick behind it as you limit the window size. I don't really like it as I cannot freely do with the window what I want (as a player).
I tried your code with currentAspectWidth and currentAspectHeight as floats. After resizing once the window shrunk:
(click to show/hide)
I also tried to change the floats to ints(just currentAspect***) and the same phenomenom:
(click to show/hide)

4
Window / Re: Change viewport to keep aspect ratio of scene
« on: July 31, 2014, 07:55:22 pm »
I tried yours maly and it ends up the same as my implementation.
        float screenwidth =  static_cast<float>(basicSettings.windoww) / static_cast<float>(basicSettings.screenw);
        float screenheight = static_cast<float>(basicSettings.windowh) / static_cast<float>(basicSettings.screenh);

        sf::FloatRect viewport;
        viewport.width = 1.f;
        viewport.height = 1.f;

        if( screenwidth > screenheight )
        {
                viewport.width = screenheight / screenwidth;
                viewport.left = (1.f - viewport.width) / 2.f;
        }
        else if(screenwidth < screenheight)
        {
                viewport.height = screenwidth / screenheight;
                viewport.top = (1.f - viewport.height) / 2.f;
        }

        sf::View v( sf::FloatRect( sf::Vector2f( basicSettings.screenx, basicSettings.screeny ), \
                                                           sf::Vector2f( basicSettings.screenw, basicSettings.screenh ) ) );
        v.setViewport(viewport);

        basicSettings.window.setView( v );
I guess I make some screenshots:
(click to show/hide)

5
Window / Re: Change viewport to keep aspect ratio of scene
« on: July 31, 2014, 08:16:39 am »
Well percentages and ratios both are usually used with values between 0..1 and as I am not a native English speaker I might tend to use wrong words.

Ok, I got the reason why ratios are used. Why do you stick to the thought that the units were/are wrong and not the values? Check the code, I convert from pixel to ratio with this:
    viewport.width  = viewport.width  / W.x;
    viewport.height = viewport.height / W.y;
And all before this is pixel and all after this is in ratio units.

Can't you write something more helpful? If you already had the same problem why can't you give a hint, where I should rethink my code or give (pseudo-)code.

6
Window / Re: Change viewport to keep aspect ratio of scene
« on: July 30, 2014, 04:49:46 pm »
I got your point, but the units are fine(and they were the right units all the time). I was testing an other way, but here is the same issue that it is scaling weird. I looks like this generates no panels when the window is like a square and scales wrong if it is rectangular.
        // not edited
        sf::View v( sf::FloatRect( sf::Vector2f( basicSettings.screenx, basicSettings.screeny ), \
                                                           sf::Vector2f( basicSettings.screenw, basicSettings.screenh ) ) );

        sf::Vector2f S( basicSettings.screenw, basicSettings.screenh );
        sf::Vector2f W( basicSettings.windoww, basicSettings.windowh );

        float scalor( std::min( W.x / S.x, W.y / S.y ) ); // squared window preference?!
        sf::Vector2f scaled( S );
        scaled *= scalor;
        printf( "scaled: %f %f\n", scaled.x, scaled.y );

        sf::FloatRect viewport( sf::Vector2f( 0, 0 ), scaled );
        viewport.width  = viewport.width  / W.x;
        viewport.height = viewport.height / W.y;
        viewport.left = ( 1.0 - viewport.width  ) * 0.5;
        viewport.top  = ( 1.0 - viewport.height ) * 0.5;
        v.setViewport( viewport ); // in the end still not the same ratio as the scene
        basicSettings.window.setView( v );

Why did anyone chose to set the viewport in percent units? Why not in pixels as the glViewport does? It was easier with pixel values to check the problem :/ as you always had to deal with pixels when changing the viewport.

7
Window / Re: Change viewport to keep aspect ratio of scene
« on: July 16, 2014, 05:42:20 am »
That is why I scale the size values by dividing by their maximum pixel units (window size). The position is just position in the center.

8
Window / Re: Change viewport to keep aspect ratio of scene
« on: July 16, 2014, 12:30:51 am »
As scenew, sceneh, windoww and windowh contain values in pixel unit scaleToFit returns unit pixel. So viewport.width/.height contain pixel values.

9
Window / Re: Change viewport to keep aspect ratio of scene
« on: July 15, 2014, 06:11:20 pm »
Yeah that is just a typo. As I compared it to a scene I renamed the variables in the code (except these two). So this is not a real "error".
Letterboxed ... that was the word ... Well at the right window ratio there are no letterboxes(obvious) but yes I want the letterboxes.

10
Window / [Solved] Change viewport to keep aspect ratio of scene
« on: July 14, 2014, 02:16:22 pm »
Hey guys,

I am stuck with certain problem: I manage stuff inside of sth you can call a scene and I want to keep the aspect ratio of the scene when the window is resized. I want to do this by changing the viewport. I am used to the fact that the viewport is given in pixels as sf::View seems to use percentage values of the window size I scale my calculated viewport down with these lines:

// down scale to % units ; windoww/h are from the resize event
viewport.width  = viewport.width  / windoww;
viewport.height = viewport.height / windowh;
// center
viewport.left = ( 1.0 - viewport.width  ) * 0.5;
viewport.top  = ( 1.0 - viewport.height ) * 0.5;

But it seems that my calculations are always wrong :/ and I guess I am stuck in my head so I can't see the problem. I tried this way to get the right upscaled/cropped size:
 // in = ( scenew, sceneh ); clip = ( windoww, windowh )
sf::Vector2f scaleToFit( const sf::Vector2f& in, const sf::Vector2f& clip )
{
        sf::Vector2f ret( in );
        if ( ( clip.y * in.x ) / in.y >= clip.x )
        {
                ret.y = ( clip.x * in.y ) / in.x;
                ret.x = clip.x;
        }
        else if ( ( clip.x * in.y ) / in.x >= clip.y )
        {
                ret.x = ( clip.y * in.x ) / in.y;
                ret.y = clip.y;
        }
        else
                ret = clip;
        return ret;
}
 
All I get is strange resizing. The scene keeps in the center but if I extend the width of the window (there should be black panels on the left and right) the black panels get very big so the scene does not keep its ratio and I don't know why. I hope I can get some help here.

Just for your information: This is what all happens on the resize event but I don't expect an error there:
sf::View v( sf::FloatRect( 0, 0, scenew, sceneh ) );
sf::FloatRect viewport( sf::Vector2f( 0, 0 ), scaleToFit( sf::Vector2f( screenw, screenh ), sf::Vector2f( windoww, windowh ) ) );
viewport.width  = viewport.width  / basicSettings.windoww;
viewport.height = viewport.height / basicSettings.windowh;
viewport.left = ( 1.0 - viewport.width  ) * 0.5;
viewport.top  = ( 1.0 - viewport.height ) * 0.5;
v.setViewport( viewport );
window.setView( v );
 

11
General / Re: Weird horizontal lines
« on: July 14, 2013, 03:58:35 pm »
You can see a two dimensional field. Every quad, displayed with two triangles, have the coordinates 0..1,0..1 + an offset that depends on time. So it moves all the time. This offset is between 0 and 1 so if I just use integer I wouldnt have any movement, would I?

12
General / Re: Weird horizontal lines
« on: July 14, 2013, 03:29:58 pm »
One of my friend just said he uses a desktop pc for testing it. So when I use glm to modify the matrix and the pointer for the vertex I should change all of this to int/short? So like multiplying everything by 100 because the current values depend on decimals?

13
General / Re: Weird horizontal lines
« on: July 14, 2013, 02:45:06 pm »
_wayvertex and _waytexvertex are both double* and the textures arent set to GL_NEAREST, but they seems to be set to GL_NEAREST by default. I load them with SOIL.

14
General / Re: Weird horizontal lines
« on: July 14, 2013, 02:14:15 pm »
Lol I didnt know I can draw with DirectX in SFML :P so sure I use GL. I didnt wanted to tell you, what I dont use I just wanted to verify why I'm posting here ;)
So I initialize with this:
glClearColor( 0, 0, 0, 1 );

glEnable( GL_ALPHA_TEST );
glAlphaFunc( GL_GREATER , 0.1 );

glEnable( GL_BLEND );
glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
And draw like that
glBindTexture( GL_TEXTURE_2D, _idtiles );

glEnableClientState( GL_VERTEX_ARRAY );
glVertexPointer( 2, GL_DOUBLE, 0, &_wayvertex[ 0 ] );

glEnableClientState( GL_TEXTURE_COORD_ARRAY );
glTexCoordPointer( 2, GL_DOUBLE, 0, &_waytexvertex[ 0 ] );

glDrawArrays( GL_TRIANGLES, 0, _wayvertex_size );

glDisableClientState( GL_TEXTURE_COORD_ARRAY );
glDisableClientState( GL_VERTEX_ARRAY );
 
I also buffered the coins you can see, but they are drawn the same way.

15
General / Weird horizontal lines
« on: July 14, 2013, 01:36:05 pm »
I do not use the sfml-graphics-package for this, so I m posting this in the General-Subforum.

I draw some triangles. My friends see these lines, me not. I tried VSync and Framelimit. Both didnt helped it. How do I fix this, and what do I need to tell you to investigate this?

Pages: [1] 2 3