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

Pages: [1]
1
Graphics / Re: Vertex Array 2.0
« on: February 25, 2021, 10:41:17 am »
I clearly misinterpreted the previous advice! I have fixed the memory issue and the texCoords issue. Turns out I didn't need to create a new quad[n+1].texCoord for each new tile from the tileset, I was also missing 2 tiles at the end of the first and last row in the array.

2
Graphics / Re: Vertex Array 2.0
« on: February 25, 2021, 09:10:02 am »
Thank you for replying Laurent. I was trying my best to follow the vertex array tutorial that you designed and in my previously raised issue I was advised to expand on the texCoords if I wanted to use more than the 4 tiles that you used in the tutorial. Other than following both of these I am sure I haven't added much else. Perhaps I took the previous advice too literally? Either way could you please help me? So far I have reached the conclusion that I have a memory and storage problem, but I'm not sure how to fix it..

3
Graphics / [Solved] Vertex Array 2.0
« on: February 24, 2021, 09:38:43 pm »
I'm back. I've made an amount of progress with my game, and the help that I previously recieved was awesome. I now have a new issue though. I have followed the structure of the vertex array tutorail to the 'T', and also tried to follow the advice given in my previous post. The map that I am drawing from (the [] itself) isn't 100% truly rendered as it was described in the code. Some tile aren't spawning where they are supposed to be, and tiles are replacing other tiles in random areas.

Most of this is directly from the tutorial and has been adapted to suit my classes.

Nothing looks amiss when compared to the tutorial so I'm stumped.


bool TileMap::load(const std::string& tileset, sf::Vector2u tileSize, const int* tiles, unsigned int width, unsigned int height)
{
    // load the tileset texture
    if (!m_tileset.loadFromFile(tileset))
        return false;

    // resize the vertex array to fit the level size
    m_vertices.setPrimitiveType(sf::Quads);
    m_vertices.resize(width * height * 5);

    // populate the vertex array, with one quad per tile
    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); //grass
            quad[1].texCoords = sf::Vector2f((tu + 1) * tileSize.x, tv * tileSize.y); //long grass
            quad[2].texCoords = sf::Vector2f((tu + 1) * tileSize.x, (tv + 1) * tileSize.y); //dirt path
            quad[3].texCoords = sf::Vector2f(tu * tileSize.x, (tv + 1) * tileSize.y); //cobble

            quad[4].texCoords = sf::Vector2f(tu * tileSize.x, tv * tileSize.y); //shrub
            quad[5].texCoords = sf::Vector2f((tu + 1) * tileSize.x, tv * tileSize.y); //rock
            quad[6].texCoords = sf::Vector2f((tu + 1) * tileSize.x, (tv + 1) * tileSize.y); //house top left
            quad[7].texCoords = sf::Vector2f(tu * tileSize.x, (tv + 1) * tileSize.y); //house top right      
           
            quad[8].texCoords = sf::Vector2f(tu * tileSize.x, tv * tileSize.y); //house bottom left
            quad[9].texCoords = sf::Vector2f((tu + 1) * tileSize.x, tv * tileSize.y); //house bottom right
            quad[10].texCoords = sf::Vector2f((tu + 1) * tileSize.x, (tv + 1) * tileSize.y);//tree top left
            quad[11].texCoords = sf::Vector2f(tu * tileSize.x, (tv + 1) * tileSize.y);//tree top right

            quad[12].texCoords = sf::Vector2f(tu * tileSize.x, tv * tileSize.y); //tree mid left
            quad[13].texCoords = sf::Vector2f((tu + 1) * tileSize.x, tv * tileSize.y); //tree mid right
            quad[14].texCoords = sf::Vector2f((tu + 1) * tileSize.x, (tv + 1) * tileSize.y); //tree bottom left
            quad[15].texCoords = sf::Vector2f(tu * tileSize.x, (tv + 1) * tileSize.y); //tree bottom right

            quad[16].texCoords = sf::Vector2f(tu * tileSize.x, tv * tileSize.y); //fire top left
            quad[17].texCoords = sf::Vector2f((tu + 1) * tileSize.x, tv * tileSize.y); //fire top right
            quad[18].texCoords = sf::Vector2f((tu + 1) * tileSize.x, (tv + 1) * tileSize.y); //fire bottom left
            quad[19].texCoords = sf::Vector2f(tu * tileSize.x, (tv + 1) * tileSize.y); //fire bottom right



            quad[20].texCoords = sf::Vector2f(tu * tileSize.x, tv * tileSize.y); //path corner grass top left
            quad[21].texCoords = sf::Vector2f((tu + 1) * tileSize.x, tv * tileSize.y); //path corner grass top right
            quad[22].texCoords = sf::Vector2f((tu + 1) * tileSize.x, (tv + 1) * tileSize.y);//path corner grass bottom left
            quad[23].texCoords = sf::Vector2f(tu * tileSize.x, (tv + 1) * tileSize.y);//path corner grass bottom right

            quad[24].texCoords = sf::Vector2f(tu * tileSize.x, tv * tileSize.y); //dirt path turn right
            quad[25].texCoords = sf::Vector2f((tu + 1) * tileSize.x, tv * tileSize.y); //dirt path both dirs
            quad[26].texCoords = sf::Vector2f((tu + 1) * tileSize.x, (tv + 1) * tileSize.y); //dirt path turn left
            quad[27].texCoords = sf::Vector2f(tu * tileSize.x, (tv + 1) * tileSize.y); //dirt path left verge

            quad[28].texCoords = sf::Vector2f(tu * tileSize.x, tv * tileSize.y); //dirt path no verge
            quad[29].texCoords = sf::Vector2f((tu + 1) * tileSize.x, tv * tileSize.y); //dirt path right verge
            quad[30].texCoords = sf::Vector2f((tu + 1) * tileSize.x, (tv + 1) * tileSize.y); //dirt path down turn right
            quad[31].texCoords = sf::Vector2f(tu * tileSize.x, (tv + 1) * tileSize.y); //dirt path walk down both dirs

            quad[32].texCoords = sf::Vector2f(tu * tileSize.x, tv * tileSize.y); //dirt path walk down turn left
            quad[33].texCoords = sf::Vector2f((tu + 1) * tileSize.x, tv * tileSize.y);//map boundary tile
            quad[34].texCoords = sf::Vector2f((tu + 1) * tileSize.x, (tv + 1) * tileSize.y);
            quad[35].texCoords = sf::Vector2f(tu * tileSize.x, (tv + 1) * tileSize.y);

        }

    return true;
}

void TileMap::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);
}
void TileMap::render(sf::RenderTarget& target)
{
    const int startArea[] =
    {
        33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,
        33,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,27,28,29,4,4,4,4,4,4,4,4,4,4,4,4,33,
        33,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,27,28,29,0,0,0,0,0,0,0,0,0,0,0,4,33,
        33,4,0,0,0,0,0,0,0,0,0,5,0,0,0,0,27,28,29,0,0,0,0,16,17,0,0,0,0,0,4,33,
        33,4,0,0,0,0,0,0,0,0,0,0,4,4,4,0,27,28,29,0,0,0,0,18,19,0,0,5,0,0,4,33,
        33,4,0,0,0,0,0,0,0,0,0,0,4,5,4,0,27,28,29,0,0,0,0,0,0,0,0,0,0,0,4,33,
        33,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,27,28,29,5,0,0,0,0,10,11,0,0,0,0,4,33,
        33,4,0,0,0,0,0,0,0,10,11,0,0,0,0,0,27,28,29,0,0,0,0,0,12,13,0,0,0,0,4,33,
        33,4,0,0,0,0,0,0,0,12,13,0,0,0,0,0,27,28,29,0,0,0,0,0,14,15,0,0,0,0,4,33,
        33,4,0,0,0,0,0,0,0,14,15,0,0,0,0,0,27,28,21,25,25,25,25,25,25,25,25,25,25,25,25,33,
        33,4,0,0,0,0,0,0,0,0,0,0,0,0,6,7,27,28,28,28,28,28,28,28,28,28,28,28,28,28,28,33,
        33,4,0,0,0,0,0,0,0,0,0,1,1,0,8,9,30,31,31,31,31,31,31,31,31,31,31,31,31,31,31,33,
        33,4,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,10,11,0,0,0,0,0,0,4,33,
        33,4,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,12,13,0,0,0,0,0,0,4,33,
        33,4,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,14,15,0,0,0,0,0,0,4,33,
        33,4,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,5,0,0,0,0,0,0,0,0,0,4,33,
        33,4,0,0,0,0,0,0,0,0,0,0,0,0,5,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4,33,
        33,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,33,
        33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,
    };

    // create the tilemap from the level definition
    TileMap tileMap;
       
    if (!tileMap.load("Textures/newtexture.png", sf::Vector2u(64, 64), startArea, 32, 19))
    {
        throw "ERROR::TILEMAP::COULD NOT LOAD TILEMAP";
    }
     
    target.draw(tileMap);
   
}


 

From the first image you can see that the amount of shrubs do not match to the tile numbers in the array and that the boundary tile does not spawn on the left side but does on the top.

The second image is my atlas.

The third image is what happened on the bottom right corner of the screen.

EDIT:
For all of the texCoords lines I am getting a compiler warning -> C4244   'argument': conversion from 'unsigned int' to 'T', possible loss of data. Could this have something to do with generating the map badly if some values are being lost??

4
Graphics / Re: Vertex arrays
« on: February 22, 2021, 11:01:35 am »
Thank you so much for your help, I've started to play with the texCoords and it's working well! There's still a bit of a distortion on the first column of tiles but I'm sure i'll figure it out from here. Is there any way to close this question now that you have answered it?

5
Graphics / Re: Vertex arrays
« on: February 22, 2021, 12:13:11 am »
Thank you for your reply!

So the tutorial shows an example that uses an atlas that contains 4 different tiles (that's what an atlas is right, same as a tile-set?). Say my 10 textures were now each a seperate tile in an atlas and I now have 1 texture with 10 tile options. The example demonstrates how to use the atlas that contains 4 tiles, but how can I adapt it to handle my 10? All I can see is quad[0].position to quad[3].position and quad[0].texCoords to quad[3].texCoords. I guess my question is, at what part of the tutorial am I able to change how many tiles that I can use from 4 to >4?

6
Graphics / [Solved]Vertex arrays
« on: February 21, 2021, 11:04:08 pm »
I am making a tile-based game and have just finished reading through the vertex array tutorial. After some background reading it seems that using vertex arrays to handle my tile generation I save alot of hassle and hardware stress. The part that confuses me, and I know it's probably a silly question, is how do I create a vertex array for more than 4 textures? E.g. my tile-map contains currently 10 different textures, but I can't see how the tutorial can be adapted for more than 4. Apologies for such a low level question.

Pages: [1]