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

Pages: 1 ... 222 223 [224]
3346
Graphics / Re: image deformation (skewing/perspective)
« on: February 07, 2014, 07:40:33 pm »
I didn't know I could have multiple quads in a vertex array.
This also reduces the number of times you need to call draw() which is good for performance ;)
Remember that you can only use one texture per vertexarray though, so either use multiple vertexarrays or use multiple parts of one texture (like spritesheets/tilemaps, for example).

3347
Graphics / Re: image deformation (skewing/perspective)
« on: February 07, 2014, 07:30:14 pm »
Here's some code that should clarify.

  • This creates two quads. One that is double size of the original texture and one that is manipulated. There are eight vertices in "quads" because there are four per quad.
  • The image in this example was 48x48 and the texture positions were hard-coded. Sorry :p
  • If you try to use this code, you should change the texture filename too ;)

#include <SFML/Graphics.hpp>

int main()
{
        sf::RenderWindow window(sf::VideoMode(800, 600), "Skew Image", sf::Style::Default);

        sf::Texture texture;
        if (!texture.loadFromFile("image (48x48).png"))
        {
                return EXIT_FAILURE;
        }

        // vertexarray with 8 vertices (4 per quad)
        sf::VertexArray quads(sf::Quads, 8);

        // first quad (vertices 0 - 3)
        quads[0].position = sf::Vector2f(100, 100);
        quads[1].position = sf::Vector2f(196, 100);
        quads[2].position = sf::Vector2f(196, 196);
        quads[3].position = sf::Vector2f(100, 196);
        quads[0].texCoords = sf::Vector2f(0, 0);
        quads[1].texCoords = sf::Vector2f(47, 0);
        quads[2].texCoords = sf::Vector2f(47, 47);
        quads[3].texCoords = sf::Vector2f(0, 47);

        // second quad (vertices 4 - 7)
        quads[4].position = sf::Vector2f(210, 160);
        quads[5].position = sf::Vector2f(320, 100);
        quads[6].position = sf::Vector2f(292, 250);
        quads[7].position = sf::Vector2f(180, 240);
        quads[4].texCoords = sf::Vector2f(0, 0);
        quads[5].texCoords = sf::Vector2f(47, 0);
        quads[6].texCoords = sf::Vector2f(47, 47);
        quads[7].texCoords = sf::Vector2f(0, 47);

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

                // draw both quads using the texture
                window.draw(quads, &texture);

                window.display();
        }
        return EXIT_SUCCESS;
}

3348
Graphics / Re: Help with texture coordinates on a vertex array
« on: February 07, 2014, 07:23:24 pm »
They are positions of the final pixel in the texture, not sizes of the rectangle. If the first coord is at (1, 1), the last pixel is (size.x, size.y). Since the first coord is at (0, 0), the last pixel would be at (size.x - 1, size.y - 1).

And, you're welcome :)

3349
Graphics / Re: AW: Re: image deformation (skewing/perspective)
« on: February 07, 2014, 07:18:16 pm »
To skew an image, you can use VertexArrays with quads and manipulate the coords of its corners.
Unfortunately that won't work, since a quad is just two triangles set next to each other. Thus if you move a corner that doesn't connect the two triangles only parts of one triangle will get scewed, the rest stays the same.
A skewed quad is drawn as two triangles but it is stored as only four vertices so when one vertex is moved, any triangles that use that vertex use the updated position.

3350
Graphics / Re: Help with texture coordinates on a vertex array
« on: February 07, 2014, 07:07:51 pm »
Ah, I see you found the VertexArrays yourself :)

The texture coordinates should follow the perimeter of the texture:
(0, 0)
(size.x - 1, 0)
(size.x - 1, size.y - 1)
(0, size.y - 1)

You're currently only mapping the top-right quarter ;)

Also, n should not all be zero in "lines[n]"

Try this:
lines[0].texCoords = sf::Vector2f(0, 0);
lines[1].texCoords = sf::Vector2f(0, size.y - 1);
lines[2].texCoords = sf::Vector2f(size.x - 1,size.y - 1);
lines[3].texCoords = sf::Vector2f(size.x - 1, 0);

EDIT: Just noticed that your coordinates are in the opposite direction so I've edited the code.

3351
Graphics / Re: image deformation (skewing/perspective)
« on: February 07, 2014, 07:02:03 pm »
To skew an image, you can use VertexArrays with quads and manipulate the coords of its corners.

3352
Graphics / Re: RenderWindow doesn't clear
« on: February 07, 2014, 01:54:50 pm »
If you're not going to manage game states as eXpl0it3r suggested (you should) then you should at least take the showLogo() and sleep functions out of the main loop ;)

3353
Graphics / Re: Does anyone use the built in sf move function?
« on: February 07, 2014, 01:47:33 pm »
move() irks me. what's it doing there..? a little blemish on an otherwise perfect library. ;D
It makes more sense to use:
object.move(offset);
than:
object.setPosition(object.getPosition() + offset);

3354
Graphics / Re: Does anyone use the built in sf move function?
« on: February 07, 2014, 01:21:52 am »
I use the move function for a simple drop-down shadow function.

3355
Graphics / Re: Circular movement
« on: February 07, 2014, 01:15:36 am »
st would be the speed of rotation, not the speed of movement.
If it's turning too quickly, divide st by n or - as Azaral suggested - convert to radians.
If it's moving (changing position) too quickly, you'll need to divide sx and sy by n.

n, in this case, is dependent on your computer's speed. It would be trial and error. If you wanted to be able to multiply by a speed variable, you'd need to divide by a higher number.

3356
Window / Re: Window does not activate if you click inside it
« on: February 02, 2014, 09:14:32 pm »
But not in the current release?
I'm new and I've been using C++ and SFML for only a few days after I had to build it from the source code myself. I found that this workaround temporarily fixes the problem until the latest version has the proper fix.

That said, I have no idea what github is.

3357
Window / Re: Window does not activate if you click inside it
« on: February 02, 2014, 08:19:37 pm »
I'm sorry for resurrecting an old thread; I believe it's still relevant, however, as the problem still exists. (I'm aware that this is being fixed in the library)

I ended up on this thread because I was having this problem too. I came back because I found a simple workaround. It may be bad practice but it seems to work until the fix is applied.

This is for Windows only. You'll also need to
#include <Windows.h>

If, in your main loop, you put the code:
SetForegroundWindow(renderWindow.getSystemHandle());
with "renderWindow" being your RenderWindow object, it should allow you to click the client area to refocus the window. Oddly, it doesn't actually set the focus of the window or activate it by itself as it is supposed to.

I hope this helps for now. I'm looking forward to the new version of SFML (hopefully with a VS2013 build as my build seemed to fail at creating debug libraries :( )

Pages: 1 ... 222 223 [224]