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

Pages: [1]
1
Graphics / Re: sf::Triangles pixel accuracy
« on: July 28, 2013, 08:32:04 pm »
That is intentional, since, with the zero row and column, the triangle takes up that much space. In other words, if you open the texture up in a paint program, the bottom right pixel will be pixel 27, 32.

2
Graphics / sf::Triangles pixel accuracy
« on: July 28, 2013, 05:55:48 am »
I have found that drawing triangles is not accurate to the coordinates I specify. I am having issues with vertex pixels being cut off, as well as edges. I am experiencing this with different orientations of triangles. I am only using integers, so it is not a decimal issue.

Below is the code, texture, and screenshot. In the screenshot below, the leftmost vertex is cut off, as is the rightmost edge.

#include <SFML/Graphics.hpp>

int main()
{
    sf::RenderWindow window(sf::VideoMode(512, 256), "Triangle");

        sf::VertexArray triangle(sf::Triangles, 3);
    sf::Texture tex;
    if (!tex.loadFromFile("texture.png"))
                return -1;
       
        triangle[0].position = sf::Vector2f  ( 0, 16);
        triangle[1].position = sf::Vector2f  ( 27, 0);
        triangle[2].position = sf::Vector2f  ( 27, 32);
        triangle[0].texCoords = sf::Vector2f ( 0, 16);
        triangle[1].texCoords = sf::Vector2f ( 27, 0);
        triangle[2].texCoords = sf::Vector2f ( 27, 32);
       
    while (window.isOpen())
    {
        sf::Event event;
        while (window.pollEvent(event))
        {
            if(event.type == sf::Event::Closed)
                window.close();
        }
        window.clear();
        window.draw(triangle, &tex);
        window.display();
    }

    return 0;
}

3
Graphics / Re: Vertex arrays and diagonal lines
« on: July 27, 2013, 08:52:43 pm »
Hey, thanks. That seems like it should be a good solution, and not the type I was thinking of. Still, it seems there's something fundamental that I'm missing about how the graphics work, and I don't really want to move on without learning what that might be. In the end, I may use your solution either way, but I have to know what's going on with these hexagons.

4
Graphics / Vertex arrays and diagonal lines
« on: July 27, 2013, 08:05:20 am »
I wrote some code to make hexagons using sf::Triangles, but the texture is not displaying on the entity as I would expect. Along the top-left vectors, things are mostly fine, but along the others, especially the bottom-right, some peripheral pixels are cut off. An enlarged screenshot and the texture are attached. Below is the printout of the vertex coordinates. The data was the same for .position and .texCoords. According to the data and my texture, I can't find any reason why the image is not displaying properly.

I also have another question, which is related. If, using vertices, I define two lines that are mirror images of each other, such as the diagonal sides of a hexagon, will the set of pixels that make up both lines also be mirror images? Or, what if they are the same line (at different locations) but the order of the vertices is different, so that, in a sense, one line is drawn from left to right and the other from right to left. I know that the paint program I used to make my texture produced a different configuration for each line (using the line tool). If they're not the same, how do I approach that? For example, how would I make two diagonal lines flush with one another?

27              32
54              48
27              64

27              32
27              64
0               48

27              32
0               48
0               16

27              32
0               16
27              3.55271e-15

27              32
27              3.55271e-15
54              16

27              32
54              16
54              48

5
Graphics / Re: Triangle Fan Hex Map
« on: July 26, 2013, 10:55:22 pm »
Thanks very much Laurent. That totally makes sense. I guess the only practical way to get all the hexagons into one vertex array would be to use sf::Triangles (since I think sf::TriangleStrip would make indexing the hexes awkward once there's more than one row of them). At what number of hexes would drawing each hex separately become a significant demand on modern video cards?

6
Graphics / Triangle Fan Hex Map
« on: July 26, 2013, 10:10:59 pm »
I'm trying to program a hexagon tile map by adapting the tile map code from the vertex tutorial to use sf::TriangleFan hexes. Unfortunately, I'm getting some weird distortions of the tiles. I attached a screenshot. In the code I define the centre of the fan and then use trigonometry to define the corners of the hexagons. The math I used for that is from here.. The texture is 110 x 64 pixels, white on the left half, red on the right half.

If anyone has an idea what's going with this I would be grateful.

#include <SFML/Graphics.hpp>
#include <cmath>

const double PI  =3.141592653589793238462;

class TileMap : public sf::Drawable, public sf::Transformable
{
public:

    bool load(const std::string& tileset, int hex_size, const int* tiles,
        unsigned int map_width, unsigned int map_height, int relative_offset)
    {

                int offset = relative_offset * hex_size;
                float height = hex_size * 2;
                float width  = std::sqrt(3) * hex_size;


        // load the tileset texture
        if (!m_tileset.loadFromFile(tileset))
            return false;

        // resize the vertex array to fit the level size
        m_vertices.setPrimitiveType(sf::TrianglesFan);
        m_vertices.resize(map_width * map_height * 8);

        // populate the vertex array, with one fan per tile
        for (unsigned int i = 0; i < map_width; ++i)
            for (unsigned int j = 0; j < map_height; ++j)
            {
                // get the current tile number
                int tileNumber = tiles[i + j * map_width];

                // find its position in the tileset texture
                int tx = tileNumber % (m_tileset.getSize().x / (int) width);
                int ty = tileNumber / (m_tileset.getSize().x / width);

                // get a pointer to the current tile's hex
                sf::Vertex* hex = &m_vertices[(i + j * width) * 8];


                // define its  centre
                        hex[0].position= sf::Vector2f ( offset + i * width, offset + j * height);

                        //define its corners
                        for (int k = 1; k < 7; k++)
                        {
                                float angle = 2 * PI / 6 * (k + 0.5);
                                hex[k].position = sf::Vector2f (
                                    hex[0].position.x + hex_size * cos(angle),
                                    hex[0].position.y + hex_size * sin(angle) );
                        }
                        hex[7].position = hex[1].position;



                // define its texture centre
                hex[0].texCoords = sf::Vector2f(  
                    (width/2) + (tx * width),  hex_size + (ty * height)  ) ;
               
                //define its corners
                for (int k = 1; k < 7; k++)
                        {
                                float angle = 2 * PI / 6 * (k + 0.5);
                                hex[k].texCoords = sf::Vector2f (
                                    hex[0].texCoords.x + hex_size * cos(angle),
                                    hex[0].texCoords.y + hex_size * sin(angle) );
                        }
                hex[7].texCoords = hex[1].texCoords;

            }

        return true;
    }

private:

    virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const
    {
        // apply the transform
        states.transform *= getTransform();

        // apply the tileset texture
        states.texture = &m_tileset;

        // draw the vertex array
        target.draw(m_vertices, states);
    }

    sf::VertexArray m_vertices;
    sf::Texture m_tileset;
};



int main()
{
    // create the window
    sf::RenderWindow window(sf::VideoMode(512, 256), "Tilemap");

    // define the level with an array of tile indices
    const int level[] =
    {
        0, 0, 1//, 0//, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
    };

    // create the tilemap from the level definition
    TileMap map;
    if (!map.load("tileset.png", 32, level, 3, 1, 2))
        return -1;

    // run the main loop
    while (window.isOpen())
    {
        // handle events
        sf::Event event;
        while (window.pollEvent(event))
        {
            if(event.type == sf::Event::Closed)
                window.close();
        }

        // draw the map
        window.clear();
        window.draw(map);
        window.display();
    }

    return 0;
}

7
General / Re: GUI solutions for GUI-intensive games
« on: July 10, 2013, 09:36:10 am »
@cpolymeris
I also considered using GWEN and decided against it partly for the same reason. Also, its probably impractical to insist on maximum range of features, but I want to make sure that anything I need down the line will be available.


@eXpl0it3r
Quote
The fact is, that there doesn't exist an optimal GUI library.
Thanks for explicating this.

Quote
Since your game would be heavily based on the UI, i.e. the UI is the core element of your game, then it would make sense to implement it yourself.
This had occurred to me, and I think you're generally right, but it seems like a lot of challenging work that isn't my main interest. Since I'm not an experienced or gifted programmer, I want to avoid doing things myself as much as possible. So, I think I will probably just settle for flanking widgets and tabs for most of the UI. I'm thinking of using Qt for that. Then, for the stuff that I really want to do in the sf window, like tool-tips and whatever else, I will use something like SFGUI.

Quote
If you want a nice start point and want to contribute to the general public, then this would be a good starting point.
If I get my project to the point where it feels worthwhile to code custom UI widgets, it would be really nice to do it in a way that would contribute back to the community. However, at the moment, I dunno if I can get stoked on coding a GUI library.

8
General / Re: GUI solutions for GUI-intensive games
« on: July 09, 2013, 01:44:11 am »
Thanks, but those are among the category that lacks the breadth and depth of features I seek.

9
General / GUI solutions for GUI-intensive games
« on: July 08, 2013, 11:16:18 pm »
I want to program a 4X game somewhat like this, which is very GUI-intensive.

Having looked at the GUI libraries that integrate well with game engines like SFML (CEGUI, GWEN), I do not think that their features are sufficient for such an application. On the other hand, searching the web and forums suggests that solutions like GTK+ or Qt don't integrate well with SFML.

So, I'm just wondering if there is a solution that would allow me to integrate a more comprehensive GUI kit with SFML. Specifically, I would like to be able draw elements over the game window and not just flanking it.

Pages: [1]