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

Pages: [1] 2 3 4
1
Thank you alot, that greatly helped :)

2
hi, that is indeed doing what its supposed to do haha thank you so much :)

now my question: why does it work?^^

from what i undestood its like this:
the ratio of the view and renderwindow's dimensions determines whether the drawings are distorted or not.
e.g. if i setup a view with a width of 300 and the renderwindows own width is 100 pixels and the viewport is the whole renderwindow all drawings are shrunk by a factor of 3 (in x direction).
same goes for the other dimension.

now when i set a new viewport that is smaller than the renderwindow, this should stay the same just with local viewport coordinates? I.e. when i got my 100 pixel wide renderwindow and setup a viewport that fills up 1/4 of that area (so half height, width) and the center of my 300 pixel view is set to (150.f,150.f) my drawings will be shrunk by a factor of 6 in each direction (assuming a 300 x 300 view) without displacement of any sorts relative to the top left corner of my viewport?

small additional question:
in your second option you set the first two parameters to 0, opposed to the 320 you chose in the first version. Is the second one setting the top left corner?

3
I see, Thank you so much :) Both of you of course :)

edit: it still does not do what i want.
i initialized it with my desired center and size and then changed its viewport, yet it still gets displaced.
Furthermore arent all tiles shown which i thought to be the case when i adjust the size of the view accordingly (in the initialization).



what i changed:
        sf::View mapview(app_window.getDefaultView());
        sf::View minimap(sf::Vector2f(80.f, 320.f * 0.875) , sf::Vector2f(20 * 32.f, 20 * 32.f));
        //sf::View menu(app_window.getDefaultView());

        mapview.setViewport(sf::FloatRect(0.f,0.f,1.f,0.75f));
        minimap.setViewport(sf::FloatRect(0.f, 0.75, 0.5, 0.25));
 


4
So am i doing it right and my graphics card just sucks ass in regards to sfml?

5
Hi, this is basically just a compressed version of this thread: http://en.sfml-dev.org/forums/index.php?topic=15414.0

i figured that this is better suited in this section of the forum.

So in short:
Quote
i want to split my window in three (well known) parts basically:

1) game region where the game itself is drawn e.g. the map, units and everything else
2) minimap in the typical left bottom corner
3) unitmenu in the bottom right part of the screen for the player to give commands to the units

i ignored the third point for now, so im messing around with sf::View to get what i want.

i was told that to have the minimap display the whole map i just need to set its view to the respective size of the whole map in pixel. This is what i did, but the map gets displaced that way, which i do not want to happen.

see for yourself:

Quote
when i do this i get this:


the view is shifted by some offset when i set the size of it to the size of the whole tilemap.

all i did was to add one line, which does what you told me:
        sf::View mapview(app_window.getDefaultView());
        sf::View minimap(app_window.getDefaultView());
        //sf::View menu(app_window.getDefaultView());

        mapview.setViewport(sf::FloatRect(0.f,0.f,1.f,0.75f));
        minimap.setViewport(sf::FloatRect(0.f, 0.75, 0.5, 0.25));
        minimap.setSize(20*32,20*32); // my tilemap is 20 x 20 with each tile having the size of 32 x 32 pixel
 

but i don't want this behaviour, i want the minimap to be drawn at the position specified in "setViewport" (well to be precise i want the map to be drawn at the top left corner of that viewport)

what i want is this (note: minimap does not show the whole map so it is not what im trying to achieve):


my code is the following:
#include <SFML/Graphics.hpp>
#include <iostream>

sf::Texture m_tileset;
sf::VertexArray m_vertices;
void setTilemap()
{
    m_tileset.loadFromFile("Tileset.png");
    m_vertices.setPrimitiveType(sf::Quads);
    m_vertices.resize(20*20*4); // we use some dummy numbers to get a mapwidth > renderwindow_width

    for (unsigned int i = 0; i < 20; ++i)
    {
        for (unsigned int j = 0; j < 20; ++j)
        {
            //get the current tile number
            int tileNumber = 34;

            // find its position in the tileset texture
            int tu = tileNumber % (m_tileset.getSize().x / 32);
            int tv = tileNumber / (m_tileset.getSize().x / 32);

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

            // define its 4 corners
            quad[0].position = sf::Vector2f(i * 32, j * 32);
            quad[1].position = sf::Vector2f((i + 1) * 32, j * 32);
            quad[2].position = sf::Vector2f((i + 1) * 32, (j + 1) * 32);
            quad[3].position = sf::Vector2f(i * 32, (j + 1) * 32);

            // define its 4 texture coordinates
            quad[0].texCoords = sf::Vector2f(tu * 32, tv * 32);
            quad[1].texCoords = sf::Vector2f((tu + 1) * 32, tv * 32);
            quad[2].texCoords = sf::Vector2f((tu + 1) * 32, (tv + 1) * 32);
            quad[3].texCoords = sf::Vector2f(tu * 32, (tv + 1) * 32);
        }
    }
}



int main() {
    // Create the main SFML window
    float width = 320.f;
    float height = 420.f;
    sf::RenderWindow app_window( sf::VideoMode(width,height), "SFGUI Canvas Example", sf::Style::Titlebar | sf::Style::Close );

    // Start the game loop
    app_window.setFramerateLimit(20);
    setTilemap();
    sf::RenderStates states;
    states = &m_tileset;

    sf::View mapview(app_window.getDefaultView());
    sf::View minimap(app_window.getDefaultView());
    //sf::View menu(app_window.getDefaultView());

    mapview.setViewport(sf::FloatRect(0.f,0.f,1.f,0.75f));
    minimap.setViewport(sf::FloatRect(0.f, 0.75, 0.5, 0.25));
    minimap.setSize(20*32,20*32);




    while ( app_window.isOpen() ) {
        sf::Event event;

        while ( app_window.pollEvent( event ) ) {

            // Close window : exit
            if ( event.type == sf::Event::Closed ) {
                app_window.close();
            }
        }

        app_window.clear();
        app_window.setView(mapview);
        app_window.draw(m_vertices,states);

        app_window.setView(minimap);
        app_window.draw(m_vertices,states);


        app_window.display();
    }
    return EXIT_SUCCESS;
}

the used tileset can be found in the attachment.

why is the minimap displaced when i set its size to the mapsize? i expected (and observed) this behaviour when calling sf::View::zoom(), but not for sf::View::setSize().

Advice is greatly appreciated.

6
General / Re: Advice on window seperation needed
« on: June 09, 2014, 12:41:50 am »
im still wondering why this happens :/

7
General / Re: Advice on window seperation needed
« on: June 06, 2014, 10:24:03 pm »
There's probably a simple bug in your code then.  For instance, are you sure that your tilemap actually starts at 0,0?

If you could provide a complete and minimal example that has this problem then we might be able to help you find the bug.

Here is my complete code (note: was randomly changing some example stuff from sfGUI thats why the code is so ugly):

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

sf::Texture m_tileset;
sf::VertexArray m_vertices;
void setTilemap()
{
    m_tileset.loadFromFile("Tileset.png");
    m_vertices.setPrimitiveType(sf::Quads);
    m_vertices.resize(20*20*4); // we use some dummy numbers to get a mapwidth > renderwindow_width

    for (unsigned int i = 0; i < 20; ++i)
    {
        for (unsigned int j = 0; j < 20; ++j)
        {
            //get the current tile number
            int tileNumber = 34;

            // find its position in the tileset texture
            int tu = tileNumber % (m_tileset.getSize().x / 32);
            int tv = tileNumber / (m_tileset.getSize().x / 32);

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

            // define its 4 corners
            quad[0].position = sf::Vector2f(i * 32, j * 32);
            quad[1].position = sf::Vector2f((i + 1) * 32, j * 32);
            quad[2].position = sf::Vector2f((i + 1) * 32, (j + 1) * 32);
            quad[3].position = sf::Vector2f(i * 32, (j + 1) * 32);

            // define its 4 texture coordinates
            quad[0].texCoords = sf::Vector2f(tu * 32, tv * 32);
            quad[1].texCoords = sf::Vector2f((tu + 1) * 32, tv * 32);
            quad[2].texCoords = sf::Vector2f((tu + 1) * 32, (tv + 1) * 32);
            quad[3].texCoords = sf::Vector2f(tu * 32, (tv + 1) * 32);
        }
    }
}



int main() {
        // Create the main SFML window
        float width = 320.f;
        float height = 420.f;
        sf::RenderWindow app_window( sf::VideoMode(width,height), "SFGUI Canvas Example", sf::Style::Titlebar | sf::Style::Close );

        // Start the game loop
        app_window.setFramerateLimit(20);
        setTilemap();
        sf::RenderStates states;
        states = &m_tileset;

        sf::View mapview(app_window.getDefaultView());
        sf::View minimap(app_window.getDefaultView());
        //sf::View menu(app_window.getDefaultView());

        mapview.setViewport(sf::FloatRect(0.f,0.f,1.f,0.75f));
        minimap.setViewport(sf::FloatRect(0.f, 0.75, 0.5, 0.25));
        minimap.setSize(20*32,20*32);




        while ( app_window.isOpen() ) {
                sf::Event event;

                while ( app_window.pollEvent( event ) ) {

                        // Close window : exit
                        if ( event.type == sf::Event::Closed ) {
                                app_window.close();
                        }
                }

                app_window.clear();
        app_window.setView(mapview);
                app_window.draw(m_vertices,states);

        app_window.setView(minimap);
                app_window.draw(m_vertices,states);


                app_window.display();
        }
        return EXIT_SUCCESS;
}
 

the used tileset can be found in the attachment.

the map should start at (0,0), thats what you get for the quads position if i and j are both zero.


8
General / Re: Advice on window seperation needed
« on: June 06, 2014, 07:02:07 pm »
hi,

sadly that is not entirely true.

when i do this i get this:


the view is shifted by some offset when i set the size of it to the size of the whole tilemap.

all i did was to add one line, which does what you told me:
        sf::View mapview(app_window.getDefaultView());
        sf::View minimap(app_window.getDefaultView());
        //sf::View menu(app_window.getDefaultView());

        mapview.setViewport(sf::FloatRect(0.f,0.f,1.f,0.75f));
        minimap.setViewport(sf::FloatRect(0.f, 0.75, 0.5, 0.25));
        minimap.setSize(20*32,20*32);
 

but i don't want this behaviour, i want the minimap to be drawn at the position specified in "setViewport" (well to be precise i want the map to be drawn at the top left corner of that viewport)

9
General / Re: Advice on window seperation needed
« on: June 06, 2014, 04:14:56 am »
im really interested in this as the tutorial is not helping much sadly.

10
General / Re: Advice on window seperation needed
« on: June 05, 2014, 03:34:23 am »
Thanks for your indepth answer :) (though the intention of the thread was to learn how to do what i talked about^^ :D).

So im trying to implement the minimap now which is supposed to show the whole "map".
For this i simply made a dummy tilemap which size is greater than the renderwindows one.

I use the following views to render both the gameview and the minimap:
        sf::View mapview(app_window.getDefaultView());
        sf::View minimap(app_window.getDefaultView());

        mapview.setViewport(sf::FloatRect(0.f,0.f,1.f,0.75f));
        minimap.setViewport(sf::FloatRect(0.f, 0.75, 0.5, 0.25));

// some more code to generate tilemap and draw it with respective views
 

i get the following:


Now for a real minimap i want it to show ALL tiles the map consists of (size is 20x20 with 32x32 pixels per tile), but zooming or resizing will somehow stretch the way its drawn in an undesired way (well i get that if you zoom it has to be contracted).
How would i set up a view for the minimap so that it will show all 20x20 tiles inside its viewport?



11
General / Re: Glew trouble when trying to run modern OpenGL
« on: June 04, 2014, 10:57:52 pm »
Quote
multiple definition of `__glewWindowPos2dARB'

this appears usually when you define a function in a header file and then include it in two other files, then the functions are loaded in different files and once everything is compiled and the linker builds your exe it realizes you have identical functionnames and it throws an error.

12
General / Re: Advice on window seperation needed
« on: June 02, 2014, 04:15:42 pm »
Thanks your answer.

I understood the tutorial so that sf::View is made for anything related to the rendering of the game world.
The menu is not part of that it is merely another layer drawn upon the game view. i dont see why a sf::view would be the way to go

13
General / Advice on window seperation needed
« on: June 02, 2014, 01:43:02 am »
hi,

i want to split my window in three (well known) parts basically:

1) game region where the game itself is drawn e.g. the map, units and everything else
2) minimap in the typical left bottom corner
3) unitmenu in the bottom right part of the screen for the player to give commands to the units

like this:

i want to use SfGUI for the menu.

How do i best implement this with sfml? if this was QT i would just use 3 widgets and 2 layouts to get the proper ordering and positions but in SFML and SFGUI im unsure how to do it.

Any advice is greatly appreciated :)

14
Graphics / Re: VertexArray is not drawn
« on: June 01, 2014, 09:16:29 pm »
Hi, important update:

i built the master branch just now and it works!  ;D ;D ;D haha, puh, im relieved.
Something was wrong apparently, sadly no idea what.

15
Graphics / Re: VertexArray is not drawn
« on: June 01, 2014, 06:38:19 pm »
Have you adapted the vertex order accordingly? What about triangle strips?

You could also try the latest SFML and Thor revisions (master branch), but I'm not aware of a vertex array problem that has recently been fixed.

tried both sf::Triangle and Trianglestrips, both show the same graphics as sf::Quad.
I think i will try an older graphic card driver first, i just tried out sfGUI and the rendering didnt work there as well as far as i could tell (first time using), only the text inside the widgets was shown but the widets themselves werent (saw black background instead).
This seriously sucks, i need both sf::VertexArray and sfGUI for my project :/

Pages: [1] 2 3 4
anything