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.


Topics - schizo-boy

Pages: [1]
1
General / [SOLVED]Vertex Array issue
« on: July 08, 2013, 12:53:37 pm »
Hello,

I am having trouble playing around with tile sets and vertex array.

I followed the tutorial:
http://www.sfml-dev.org/tutorials/2.0/graphics-vertex-array.php

And tried using the tile map example in my code but I can only see 3 tiles being drawn.

I believe that my problem comes from this part of the code:

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

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

In my code I only create the map randomly like so:

void           GameWindow::designMap(int width, int height)
{
    int         levelMap[width * height];

    for (int i  = 0; i < width * height ; i++)
        levelMap[i] = rand() % 3 + 1;

    if (!map.load("ressources/tileset4.png", sf::Vector2u(blockWidth, blockHeight), levelMap, width, height))
        throw GlobExcep("Cannot load tile image!");
}

with map being an attribute of type TileMap in my class.

But when I draw the map I can only see 3 different tiles being drawn. Here is the tile set I used ( with tiles being 32*32 like in the example):



and here is the result I get from drawing in map of 20 * 20.



I first thought that it was the format of the tileset I was using that was causing this issue so I changed it to a tileset like so:



but I would still get the same output and never get to see tile 1 drawn even if I create a map of 100 000 * 100 000

So I believe that I'm misunderstanding something about how to split tileset into quads.

So if somebody could help me understanding what I am doing wrong or what do I need to do to adapt this code:
  for (unsigned int i = 0; i < width; ++i)
            for (unsigned int j = 0; j < height; ++j)
            {
                // get the current tile number
                int tileNumber = tiles[i + j * width];

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

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

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

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

 to any other tileset format that would be great!

2
General / [SOLVED]Listenning event within a thread
« on: July 06, 2013, 02:52:18 pm »
Hello,

My colleague and I are developing an network based application but we did not manage to put the keyboard listening event into an SFML thread.

We would like the listening events to be non blocking:

Our application must have 2 infinite loops allowing us to :
1. Listen to the network requests. ( synchronized sockets)
2. Listen to the keyboard events.

All we've manage to do so fare when putting the listening events in a thread is either a segmentation fault or the application would simply ignore those events.

So our question is :

How can we create a non blocking keyboard listening event?

An other thing would be how could we avoid being in the pollEvent loop all the time :
while (renderWindow.isOpen())
    {
        sf::Event event;
        while (renderWindow.pollEvent(event))
        {
           //handle events
        }
    }
 

when we are trying to actions which are not related to events?

Thanks

PS: If a solution existe using the SFML network module we are not allowed to use it and we have to use the Posix sockets.

3
Window / [SOLVED]Zoom on view using too much ressources
« on: July 06, 2013, 02:32:21 pm »
Hello,
My colleague and I ran into an issue with views.
The following method

void    GameWindow::redrawMap(const int width, const int height, const bool recreateMap)
{
    sf::View view, view2;
    sf::RectangleShape rect;
    int altColor = 0;
    int posX = 0, posY = 0;
    int caseWidth = 32, caseHeight = 32;
    int sidePanelWidth = 200;
    sf::Sprite sidepanelImage;

    sidepanelImage.setTexture(sidePanel);
    screenWidth = caseWidth * 20 + sidePanelWidth;
    screenHeight = caseHeight * 20;
    if (recreateMap)
        renderWindow.create(sf::VideoMode(screenWidth, screenHeight), "UI", sf::Style::Titlebar | sf::Style::Close);
    renderWindow.clear(sf::Color(139, 115, 85));
    rect.setSize(sf::Vector2f(caseWidth, caseHeight));
    rect.setOutlineColor(sf::Color::Yellow);
    rect.setOutlineThickness(1);
    sidepanelImage.setPosition(screenWidth - sidePanelWidth, 0);
    rect.setPosition(posX, posY);
    view.reset(sf::FloatRect(0, 0, screenWidth, screenHeight));
    view.setViewport(sf::FloatRect(0, 0, 1.0f, 1.0f));
    view.zoom(curZoom);
    renderWindow.setView(view);
    while (posY <= caseHeight * height)
    {
        while (posX < caseWidth * width)
        {
            renderWindow.draw(rect);
            rect.setPosition(posX, posY);
            posX += caseWidth;
            rect.setFillColor(sf::Color(0, 123, 12));
            altColor++;
        }
        posX = 0;
        posY += caseHeight;
    }
    view2.reset(sf::FloatRect(0, 0, screenWidth, screenHeight));
    view2.setViewport(sf::FloatRect(0, 0, 1.0f, 1.0f));
    renderWindow.setView(view2);
    renderWindow.draw(sidepanelImage);
    renderWindow.display();
}
 

Allow us to redraw the content of the window each time we want to zoom in or zoom out on this view by modifying the curZoom variable before entering this method.

The problem is that we have to redraw the whole content of the window each time we want to modify the view.

Our window look like this:


The green squares are all we want to zoom into.

The problem we are facing is that because the views are passed by copy into our renderWindow we can not find a way to access it later or to keep a reference on it. So we are just redrawing the squares as well as the other view on the right ( the grey "box").

If there was a way to do it in a "cleaner" way or any help idea or solution on that problem would be greatly appreciated.

Thanks

Pages: [1]