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

Pages: [1] 2 3 4
1
Graphics / Re: RenderTexture question
« on: October 25, 2012, 12:50:46 pm »
Oh man, sorry. The problem disappears O_o. Sorry for disturbing you.

2
Graphics / Re: RenderTexture question
« on: October 25, 2012, 12:38:17 pm »
And a small another problem: camera movement works fine but scaling doesn't :(. Maybe I have to look at something when I transform my points using camera?

3
Graphics / Re: RenderTexture question
« on: October 25, 2012, 09:42:48 am »
>And, most important: who's that girl?
I wish her to be my wife.:D But it's just a nice wallpaper :(

So, the bug has been destroyed! The problem was in sf::IntRect and and rightBottom width/global coords conversion.

Thanks!

4
Graphics / Re: RenderTexture question
« on: October 24, 2012, 04:47:23 pm »
Thanks ;) Maybe you are going to add some another function inverse to convertCoords before sfml 2.0 release?

The new code is:

        sf::View *cam = prmDisplayManager->getCamera();
        sf::Vector2f size = cam->getSize();

        leftTop     = cam->getTransform().transformPoint(leftTop);
        rightBottom = cam->getTransform().transformPoint(rightBottom);

        leftTop.x = (leftTop.x + 1) * size.x / 2;
        leftTop.y = (leftTop.y + 1) * size.y / 2;
        leftTop.y = size.y - leftTop.y;

        rightBottom.x = (rightBottom.x + 1) * size.x / 2;
        rightBottom.y = (rightBottom.y + 1) * size.y / 2;
        rightBottom.y = size.y - rightBottom.y;

        std::cout << leftTop.x << "; " << leftTop.y << std::endl;

        sf::IntRect rect = sf::IntRect(leftTop.x, leftTop.y, rightBottom.x, rightBottom.y);

It almost works! Especially leftTop. But something seems to be wrong with rightBottom. Look at the video (I hope it won't be hard for you to look video taken from 2 monitors). In console you can see the std::cout I wrote in code (leftTop coords).


5
Graphics / Re: RenderTexture question
« on: October 24, 2012, 03:53:21 pm »
Thanks for the great reply!

I think, today I gonna suspend coding and learn more about coordinates, matricies, etc. :)
The only thing, transformPoint returns me coordinates like: (-0.68; 0.4), (-0.685, 0.477). I think they are in [-1;-1].

6
Graphics / Re: RenderTexture question
« on: October 24, 2012, 03:29:48 pm »
Okay, I need a few time to reproduce small example. A few tests:

Here is a few attachments. Blue circle is rendered in (0, 0). Magenta circle is rendered in leftTop

leftTop = mRenderTarget->convertCoords(sf::Vector2i(leftTop.x, leftTop.y), *mCamera);

The value of leftTop is in attachment names (x;y) (forum has renamed them and now they are: x?y

[attachment deleted by admin]

7
Graphics / Re: RenderTexture question
« on: October 24, 2012, 02:56:20 pm »
Now I don't know what to do :(

Everything is rendered into sf::RenderTexture. Before water rendering I call:

mRenderTarget->setView(myCamera);
// Calculate polygon

sf::IntRect rect = sf::IntRect(leftTop.x, leftTop.y, rightBottom.x, rightBottom.y);
polygon.setTexture(&map);
polygon.setTextureRect(rect);

When I show up leftTop and rightBottom they are always the same (of course). Before camera moves everything is fine and texture coordinates are okay. Now I try to move camera somewhere else:

myCamera->move(-4, 0);
mRenderTarget->setView(myCamera);

Sure, now leftTop and rightBottom becomes invalid (I don't convert their coordinates refer to view perspective).

So, the first try is:
leftTop = mRenderTarget->convertCoords(sf::Vector2i(leftTop.x, leftTop.y), *myCamera);
rightBottom = mRenderTarget->convertCoords(sf::Vector2i(rightBottom.x, rightBottom.y), *myCamera);

Now they are changing when camera moves but the coordinates are incorrect and I see same troubles as in video I've uploaded before.

At the end of render cycle I do:

// mApp is sf::RenderWindow
mRenderTarget->display();
mApp->draw(sf::Sprite(mRenderTarget->getTexture()));
mApp->display();

8
Graphics / Re: RenderTexture question
« on: October 23, 2012, 07:07:32 pm »
I have a view inside my display manager and all changes are applied to it.

The problem is that blues rectangle coordinates doesn't change. They are always the same even when camera is moving.

9
Graphics / Re: RenderTexture question
« on: October 23, 2012, 05:38:42 pm »
    b2Vec2 leftTopB     = prmLiquid->mFieldAABB.lowerBound;
    b2Vec2 rightBottomB = prmLiquid->mFieldAABB.upperBound;

    float yMax = some_float_value;

    // Key points for the subrect of the water (Full bounding box including surface deformation)
    sf::Vector2f leftTop     = prmDisplayManager->ConvertMetersCoords(leftTopB.x, yMax);
    sf::Vector2f rightBottom = prmDisplayManager->ConvertMetersCoords(rightBottomB.x, rightBottomB.y);
    rightBottom -= sf::Vector2f(leftTop.x, leftTop.y);

            inline sf::Vector2f ConvertMetersCoords(double x, double y)
            {
                sf::Vector2i pos(static_cast<int>(Meters2Pixels(x)), static_cast<int>(Meters2Pixels(y)));
                return renderTarget()->convertCoords(pos);
            }

leftTopB, rightBottomB are physical coordinates taken from box2d. They are in meters, not pixels.
yMax is the highest rectangle Y-points. There is some value in meters too.

leftTop, rightBottom: you saw them in my previous post, the blue rectangle is rendered using this variables.

ConvertMetersCoords takes coordinates in meters, converts them into pixels (using some float-coefficient).
renderTarget() is an object of sf::RenderTexture.

10
Graphics / Re: RenderTexture question
« on: October 23, 2012, 03:46:48 pm »
Okay, the video:

You can see that without camera movement texture taken for the water is fine. But it becomes invalid when camera moves.

A few code:

    sf::RectangleShape rectangle;
    rectangle.setOutlineColor(sf::Color::Blue);
    rectangle.setOutlineThickness(2);
    rectangle.setFillColor(sf::Color::Transparent);
    rectangle.setPosition(leftTop);
    rectangle.setSize(rightBottom);
    mTarget->draw(rectangle);

This is the code for blue rectangle you see in the video. It's calculated right (because it also moves with camera).

leftTop and rightBottom - magic coordinates I'm calculate using convertCoords from window.

        sf::IntRect rect = sf::IntRect(leftTop.x, leftTop.y, rightBottom.x, rightBottom.y);
        sf::Texture map(mTarget->getTexture());

        // Apply texture to polygon
        polygon.setTexture(&map);
        polygon.setTextureRect(rect);

mTarget - sf::RenderTexture, everything is drawn there. polygon - convex shape of the blue water you can see in video. I'm trying to set the texture coords I want to apply for the polygon. And they are wrong :( I can't understand why, because blue rectangle draws fine and texture coordinates which uses same leftTop/rightBottom.

Any ideas?

11
Graphics / Re: RenderTexture question
« on: October 23, 2012, 12:31:36 am »
I know about this but, probably, the main question is how to process convertCoords during drawing (before display call) if my texture has another coords and that function returns vector from another origin?

12
Graphics / RenderTexture question
« on: October 23, 2012, 12:23:40 am »
Hello, I have a render texture and now I found that it's turned with 2Pi radians. Now when I want to convert some coords with renderTarget()->convertCoords(x, y) I get them but refer to bottom&right, not left&top.

When I call renderTarget.display() the texture becomes "normal". That's a feature? :)

13
Graphics / Re: sf::View and render target
« on: October 20, 2012, 06:31:14 pm »
Wow, the tutorial is great! Thanks ;)

14
Graphics / sf::View and render target
« on: October 20, 2012, 01:23:02 am »
Hello, I have a few questions about how views are working.

    sf::RenderWindow *mApp;
    sf::View *mCamera;
    sf::RenderTexture *mRenderTarget;

So first, everything is rendered into mRenderTarget and at the end of the game cycle I draw final image to mApp.

Here is the function which initializes camera and reinitializes it when window is resized:

void DisplayManager::InitializeCamera(const sf::FloatRect &rect)
{
    // This is automatically called when window is resized
    mCamera->reset(rect);
    mApp->setView(*mCamera);

    mRenderTarget->create(rect.width, rect.height);
    mRenderTarget->setView(*mCamera);
}
 
And it looks like:
    mRenderTarget->display();
    mApp->draw(sf::Sprite(mRenderTarget->getTexture()));
    mApp->display();

The questions:
Is that code right?
How does views work? When I change some parameters of it I have to reinitialize render target and/or window with same view:

         mCamera->zoom(0.96);
        //mApp>setView(*mCamera);  // Required?
        mRenerTarget->setView(*mCamera);

Should I set view to render target only (everything is drawn onto it first)? And why should I setView again and again after any change to the view object? If sf::Window (abstract) takes in arguments address of the view why doesn't it track the changes inside the object?

And the last: when I want to use sf::Window::convertCoords, should I call it from renderTarget (sf::RenderTextuer) or mApp (sf::RenderWindow)?

Thanks ;)

15
Graphics / Re: Polygon to shader
« on: October 18, 2012, 09:28:38 am »
You were right, thanks! The theme is closed now.

Pages: [1] 2 3 4
anything