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

Pages: 1 ... 5 6 [7] 8 9 10
91
Graphics / sf::View, Viewports and scaling - Default behavior
« on: November 22, 2012, 06:51:05 am »
I have been doing a little experimenting with sf::View.  I'd wanted to use 2 sf::Views in combination with their viewports to map some content to different areas of the screen.  One area of the screen would be for the 'action' and one area would be for information related to what was occurring on the 'action' portion in a 75% - 25% split.  Because I don't need nearly the same size to render the action area and the information area, I defined the view for the information area to be much smaller than the view for the action area.

The following code/picture should illustrate the result I achieved.  The only difference in the code here and the code I used is that the background tiles I used to differentiate the two areas has been removed for brevity.  The text and the rectangle shape should be faithfully reproduced, although you'll have to supply your own font!

#include <SFML/Graphics.hpp>

const sf::Vector2f leftSize(1440.0f, 1080.0f) ;
const sf::Vector2f rightSize(480.0f, 1080.0f) ;
const sf::Vector2f origin(0.0f, 0.0f) ;

int main()
{
    sf::RenderWindow window(sf::VideoMode(1280, 720), "Text & View" ) ;

    sf::View leftView( sf::FloatRect(origin, leftSize) ) ;
    leftView.setViewport(sf::FloatRect(0.0f, 0.0f, 0.75f, 1.0f)) ;

    sf::View rightView( sf::FloatRect(origin, rightSize) ) ;
    rightView.setViewport(sf::FloatRect(0.75f, 0.0f, 1.0f, 1.0f)) ;

    sf::RectangleShape rect(sf::Vector2f(120.0f, 50.0f)) ;
    rect.setPosition(10, 15) ;
    rect.setFillColor(sf::Color(0,0,127)) ;

    sf::Font font ;
    font.loadFromFile("SketchFlow.ttf") ;

    sf::Text text("Word!", font);
    text.setColor(sf::Color(127, 255, 63, 255)) ;
    text.setPosition(20.0, 20.0) ;

    while ( window.isOpen() )
    {
        sf::Event event ;
        while ( window.pollEvent(event) )
        {
            if ( event.type == sf::Event::Closed )
                window.close() ;
        }

        window.clear() ;
       
        window.setView(leftView) ;
        window.draw(rect) ;
        window.draw(text) ;

        window.setView(rightView) ;
        window.draw(rect) ;
        window.draw(text) ;

        window.display() ;
    }
}

The result:


Someone correct me if I'm wrong:  the content in the sf::views that represent the right and left seems to be scaled from the view's respective sizes to the view's initial viewport size (in this case, 1280x720.)  This seems a little counter-intuitive to me.  I would've expected the content to be scaled from the size of the view to the size of the current viewport size.  I haven't yet been mucking about in the internals of SFML, so I don't know if this expectation is reasonable given the implementation.

I did try to implement a few solutions.  Unfortunately, the zoom can't be used to adjust the scaling factor, because the height to width ratio isn't the same, in other words I can't just zoom out from the x-axis without also zooming out from the y-axis.  Adjusting the size of the right view so the height/width ratio is correct and then using zoom to adjust the scaling factor does seem to work, although it feels very hackish.  The easiest solution I found was just to give the right view the same size as the left view, so that they both scaled the same.  Again, that still feels a little hackish.

So, I guess my question is whether or not this behavior is right?  The documentation states:

Quote
If the source rectangle has not the same size as the viewport, its contents will be stretched to fit in.

which seems to fit what my expectations were.

Any insights?  Is there something I'm missing?

93
Graphics / Re: Font .loadFromFile throwing a access violation.
« on: November 19, 2012, 09:00:32 pm »
  CurserPosText.setPosition(0,0);

Have you tried a different position?

94
It's fairly trivial to roll up your own sprite/texture type that behave the way you think is more natural from the existing system.  On the other hand, it's nearly impossible to do the reverse from a system where the behavior you prefer is enforced. 

The existing approach is quite flexible, which is something I value in a library.  It doesn't hurt that it doesn't impose overhead for something that I really don't need (and that certainly follows in the grand tradition of C++.)

95
fyi, I've been using C++ since before a standard *existed*.

So, even though the constructor for sprite takes a *reference*, it's assumed that reference is to heap memory, or the sprite is not going to last past the current scope?

The question after the claim just boggles my mind.

97
General / Re: Storing a list of resolutions as an array?
« on: November 15, 2012, 08:18:36 pm »

isValid() is telling me that all of my video modes in my vector are invalid...

        //Iterate through the vector removing incompatable resolutions.
        std::vector<sf::VideoMode>::iterator it;
        for(it=reslist.begin(); it != reslist.end(); it++)
        {
                if(!(*it).isValid())
                {
                        it = reslist.erase(it);
                }
        }
 

If all of your video modes were invalid, this loop would only be capable of removing half of them.  An element is skipped for every one removed, with the exception of the last element if it happens to be removed -- undefined behavior is invoked in that case.


98
i tried to do it like in your code suggestion. The problem is that it doesn't process expose events.

You could keep track of the time since the last time you drew the window and update/redraw periodically if the time is excessive.  Or you could implement an OS-specific solution.

 
   const sf::Time maxTimeNotDisplayed = sf::seconds(1.0/20.0f) ;

    window.display() ;
    sf::Clock lastDisplay ;
    while ( window.isOpen() )
    {
        bool eventsProcessed = false ;
        sf::Event event ;
        while ( window.pollEvent(event) )
        {
            eventsProcessed = true ;
            // process events
        }

        if ( eventsProcessed || lastDisplay.getElapsedTime() > maxTimeNotDisplayed )
        {
            window.clear() ;
            //  stuff ...
            window.display() ;
            lastDisplay.restart() ;
        }
        else
        {
            // ...
        }
    }

99

Unfortunately, solving the CPU hogging with an artificial frame rate limitation would hurt me when i actually need the full frame rate (e.g. when dragging stuff around or in widget change animations).

I'm not sure I see the problem.  When you don't want the limit, don't set the limit.  It's not like you need to make a choice now and it's set in stone for every application you generate from here on out (or even within a single application.) Also if you don't want to update/render when there are no events processed, don't.

while ( window.isOpen() )
{
    bool eventsProcessed = false ;
    sf::Event event ;
    while ( window.pollEvent(event) )
    {
        eventsProcessed = true ;
        // process events
    }

    if ( eventsProcessed )
   {
       window.clear() ;
       //  stuff ...
       window.display() ;
   }
   else
   {
       // ...
   }
}

100
Window / Re: RenderWindow not appearing?
« on: November 12, 2012, 01:47:53 am »
Quote
but I haven't seen any specific references to my issue in regards to ATI.

http://en.sfml-dev.org/forums/index.php?topic=9127.0
http://en.sfml-dev.org/forums/index.php?topic=7288.0
http://en.sfml-dev.org/forums/index.php?topic=9145.0

Definitely nothing about that on these forums.

101
Audio / Re: sf::Music trying to solve non-copy problem with "move"
« on: November 10, 2012, 01:57:22 am »
std::move on an object that doesn't implement a move constructor or move assignment operator (like sf::Music) simply has no effect.

102
Graphics / Re: Shader Lighting? Newbie here.
« on: November 09, 2012, 03:59:38 pm »
Try this:

#include <SFML/Graphics.hpp>

int main()
{
    sf::RenderWindow window(sf::VideoMode(800, 600), "myshader") ;

    sf::Shader shader ;
    if ( shader.loadFromFile("light.frag", sf::Shader::Fragment) )
    {
        shader.setParameter("texture", sf::Shader::CurrentTexture) ;
        shader.setParameter("lcolor", sf::Color(255, 255, 255)) ;
   
        while ( window.isOpen() )
        {
            sf::Event event ;
            while ( window.pollEvent(event))
            {
                switch(event.type)
                {
                case sf::Event::Closed:
                    window.close() ;
                    break ;
                }
            }

            sf::Vector2i mpos = sf::Mouse::getPosition(window) ;
            shader.setParameter("light", sf::Vector3f(mpos.x,600-mpos.y,100)) ;

            window.clear() ;

            sf::RectangleShape rect(sf::Vector2f(800,600)) ;
     
            window.draw(rect, &shader) ;
            window.display() ;
        }
    }
}

light.frag:
uniform sampler2D texture ;
uniform vec3 light;
uniform vec4 lcolor;

void main() {
    float distance = sqrt(pow(gl_FragCoord.x - light.x, 2) + pow(gl_FragCoord.y - light.y, 2));

    if (floor(light.x) == floor(gl_FragCoord.x) && floor(light.y) == floor (gl_FragCoord.y))
        distance = 0.1;

    if (distance > light.z)
        distance = light.z;

    vec2 pos = gl_TexCoord[0].xy ;
    gl_FragColor = mix(texture2D(texture,pos), lcolor, 1.0-(distance/light.z));

}

[Edit:  Simplified main - you don't actually need the texture reference in the fragment shader for a thing like a sf::RectangleShape, but you do need it if you're shading something with a texture, such as an sf::Sprite.]

103
Graphics / Re: Shader Lighting? Newbie here.
« on: November 09, 2012, 01:32:58 am »
Quote
In fact, if I create other program and throw this code in it, I get

Something nonsensical now that I look at it a little more closely!

But, yes, mix should do the interpolation for you.

Is lcolor normalized?



104
Graphics / Re: Shader Lighting? Newbie here.
« on: November 09, 2012, 12:54:05 am »
inter.r = (color1.r * p + color2.r * (1.0 - p));

x * p + x * (1-p ) ->
x*(p + 1 - p) ->
x *(1) ->
x

You may want to reference: http://www.opengl.org/sdk/docs/manglsl/xhtml/mix.xml

105
It occurred with 12.9 too.  Wasn't quite up-to-date the first time I tried it.  Driver updates have been pretty frequent lately, though.  I wouldn't be surprised if it was something that got borked up recently.

Pages: 1 ... 5 6 [7] 8 9 10