5

I'm currently developing a 2D isometric map editor. I display entity(cube, player) which contains points and textures. Each cubes are composed by 12 points.(12 points, but handled as 3 sides of 4 points when displayed by sfml(sf::VertexArray).

(I know I include some '.cpp' times to times, I have a problem with my IDE(visual studio) which I'm trying to resolve, please do not care about it.)

main.cpp

#pragma once
#include "globalfunctions.h" //global functions + main headers + class headers

int main() {
    int mapSize = 0;
    int cubeSize = 0;

    cout << "Map size: "; cin >> mapSize; cout << endl;
    cout << "Cube size: "; cin >> cubeSize; cout << endl;

    int windowWidth = (mapSize * cubeSize) - (cubeSize * 2);
    int windowHeight = ((mapSize * cubeSize) - (cubeSize * 2)) / 2;

    renderWindow window(windowWidth, windowHeight, mapSize, cubeSize);
        int nbMaxTextures = 9;
        for (int t = 0; t < nbMaxTextures; t++) {
            window.loadTexture("test", t);
        }

    window.run();

    return EXIT_SUCCESS;
}

globalfunctions.h

#pragma once
#include <SFML/System.hpp>
#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>
#include <iostream>
#include <math.h>
//#include <sstream>
#include <vector>

using namespace std;

sf::Vector2u isometricToCartesian(int i, int j, int cubeSize) {
    sf::Vector2u carth;
        carth.x = (j - i) * (cubeSize / 2);
        carth.y = (j + i) * (cubeSize / 4);

    return carth;
}

sf::Vector2u cartesianToIsometric(int x, int y, int cubeSize) {//TODO
    sf::Vector2u iso;
        iso.x = 0;
        iso.y = 0;

    return iso;
}

#include "entity.h"
#include "renderWindow.h"

renderWindow.h

#pragma once

class renderWindow {
    public:
        renderWindow(float WIDTH, float HEIGHT, int MAPSIZE, int CUBESIZE);
        void run();
        void loadTexture(sf::String folder, int numTexture);

        //SETTERS
        //...

        //GETTERS
        //...

    private:
        int mCurrentLayerID;
        int mMapSize;
        int mCubeSize;
        int mSelectedTexture;

        vector<entity> mMap;

        sf::RenderWindow mWindow;
        vector<sf::Texture> mTextures;
            sf::Texture mMemoryTexture;

        void processEvent();
        void update(sf::Time deltaTime);
        void render();

//CUBE ACTION-------------------------------------------
        void addCube(int layerID, float x, float y);
        entity& getCube(int ID);
        entity& getCubeAt(float x, float y);
        vector<sf::VertexArray> loadCube(int cubeID);//UPDATE DATA LIKE COORDINATES -> create/chnge the vertex
        void drawCube(int cubeID);//draw the vertex

        //VARIABLES
        vector<sf::VertexArray> verticesSide1;
        vector<sf::VertexArray> verticesSide2;
        vector<sf::VertexArray> verticesSide3;
//CUBE ACTION-------------------------------------------
};

#include "renderWindow.cpp"

renderWindow.cpp

#pragma once

renderWindow::renderWindow(float WIDTH, float HEIGHT, int MAPSIZE, int CUBESIZE) : mWindow(sf::VideoMode(WIDTH, HEIGHT), "") {
    mMapSize = MAPSIZE;
    mCubeSize = CUBESIZE;

    mSelectedTexture = 6;

    mCurrentLayerID = -1;

    int x = 0;
    int y = 0;

    //default layer
    for (int j = 0; j < mMapSize; j++) {
        for (int i = 0; i < mMapSize; i++) {
            x = isometricToCartesian(i, j, mCubeSize).x;
            y = isometricToCartesian(i, j, mCubeSize).y;
            addCube(0, x, y);
        }
    }

    for (int c = 0; c < mMap.size(); c++) {
        verticesSide1.push_back(loadCube(c)[0]);
        verticesSide2.push_back(loadCube(c)[1]);
        verticesSide3.push_back(loadCube(c)[2]);

        //then only do that when something the cube's coordinate changed
    }
}

void renderWindow::run() {
    sf::Clock clock;
    sf::Time timeSinceLastUpdate = sf::Time::Zero;
    sf::Time TimePerFrame = sf::seconds(1.f / 60.f);

    while (mWindow.isOpen()) {
        processEvent();

        timeSinceLastUpdate += clock.restart();

        while (timeSinceLastUpdate > TimePerFrame) {
            timeSinceLastUpdate -= TimePerFrame;

            processEvent();
            update(TimePerFrame);
        }

        render();
    }
}

void renderWindow::loadTexture(sf::String folder, int numTexture) {
    if (mMemoryTexture.loadFromFile("textures/" + folder + "/" + to_string(numTexture) + ".jpg"))
        mTextures.push_back(mMemoryTexture);
    else
        cout << "Texture n°" << numTexture << " as failed to load." << endl;
}


//SETTERS
//...

//GETTERS
//...

//PRIVATE METHODE
void renderWindow::processEvent() {
    sf::Event event;

    while (mWindow.pollEvent(event)) {
        switch (event.type) {
        case sf::Event::Closed:
            mWindow.close();
            break;

        case sf::Event::KeyPressed:
            if (event.key.code == sf::Keyboard::Escape)
                mWindow.close();
            break;

        case sf::Event::MouseButtonPressed:
            if (event.MouseButtonPressed == sf::Mouse::Left)
                getCubeAt(event.mouseButton.x, event.mouseButton.y).setTexture(0, mSelectedTexture);//TEST
                getCubeAt(event.mouseButton.x, event.mouseButton.y).setTexture(1, mSelectedTexture + 1);//TEST
                getCubeAt(event.mouseButton.x, event.mouseButton.y).setTexture(2, mSelectedTexture + 2);//TEST
            break;

            /*case sf::Event::MouseMoved:
                cout << "(" << event.mouseMove.x << ", " << event.mouseMove.y << ")" << endl;
                break;*/
        }
    }
}

void renderWindow::update(sf::Time deltaTime) {
    //REMEMBER: distance = speed * time
    //MOVEMENT, ANIMATIONS ETC. ...
}

void renderWindow::render() {
    mWindow.clear();

    for (int c = 0; c < mMap.size(); c++) {
        drawCube(c);
    }

    mWindow.display();
}

//CUBE ACTION-------------------------------------------
void renderWindow::addCube(int layerID, float x, float y) {
    //Thoses make the code more readable:
        int half_cubeSize = mCubeSize / 2;
        int oneQuarter_cubeSize = mCubeSize / 4;
        int twoQuarter_cubeSize = oneQuarter_cubeSize * 2;
        int treeQuarter_cubeSize = oneQuarter_cubeSize * 3;

    mCurrentLayerID = layerID;

    entity dummy(mMap.size(), 0, layerID);
        dummy.addPoint(12);
        dummy.addTexture(6);
        dummy.addTexture(7);
        dummy.addTexture(8);
    //SIDE 1------------------------------------------------
        dummy.setPoint(0, x, y + oneQuarter_cubeSize);
        dummy.setPoint(1, x + half_cubeSize, y + twoQuarter_cubeSize);
        dummy.setPoint(2, x + half_cubeSize, y + mCubeSize);
        dummy.setPoint(3, x, y + treeQuarter_cubeSize);
    //SIDE 2------------------------------------------------
        dummy.setPoint(4, x + half_cubeSize, y + twoQuarter_cubeSize);
        dummy.setPoint(5, x + mCubeSize, y + oneQuarter_cubeSize);
        dummy.setPoint(6, x + mCubeSize, y + treeQuarter_cubeSize);
        dummy.setPoint(7, x + half_cubeSize, y + mCubeSize);
    //SIDE 3------------------------------------------------
        dummy.setPoint(8, x, y + oneQuarter_cubeSize);
        dummy.setPoint(9, x + half_cubeSize, y);
        dummy.setPoint(10, x + mCubeSize, y + oneQuarter_cubeSize);
        dummy.setPoint(11, x + half_cubeSize, y + twoQuarter_cubeSize);

    mMap.push_back(dummy);
}

entity& renderWindow::getCube(int ID) {
    for (int c = 0; c < mMap.size(); c++) {
        if (mMap[c].getID() == ID)
            return mMap[c];
    }
}

entity& renderWindow::getCubeAt(float x, float y) {//TO DO
    return entity(-1, 0, 0);
}

vector<sf::VertexArray> renderWindow::loadCube(int cubeID) {
    vector<sf::VertexArray> vertices;
    vertices.push_back(sf::VertexArray());
    vertices.push_back(sf::VertexArray());
    vertices.push_back(sf::VertexArray());

    vertices[0].setPrimitiveType(sf::Quads);
    vertices[0].resize(4);

    vertices[1].setPrimitiveType(sf::Quads);
    vertices[1].resize(4);

    vertices[2].setPrimitiveType(sf::Quads);
    vertices[2].resize(4);

    sf::Vector2f tv0 = sf::Vector2f(0, 0);
    sf::Vector2f tv1 = sf::Vector2f(mCubeSize, 0);
    sf::Vector2f tv2 = sf::Vector2f(mCubeSize, mCubeSize);
    sf::Vector2f tv3 = sf::Vector2f(0, mCubeSize);

    sf::Vector2f v0 = sf::Vector2f(getCube(cubeID).getPoint(0, 0), getCube(cubeID).getPoint(0, 1));
    sf::Vector2f v1 = sf::Vector2f(getCube(cubeID).getPoint(1, 0), getCube(cubeID).getPoint(1, 1));
    sf::Vector2f v2 = sf::Vector2f(getCube(cubeID).getPoint(2, 0), getCube(cubeID).getPoint(2, 1));
    sf::Vector2f v3 = sf::Vector2f(getCube(cubeID).getPoint(3, 0), getCube(cubeID).getPoint(3, 1));

    sf::Vector2f v4 = sf::Vector2f(getCube(cubeID).getPoint(4, 0), getCube(cubeID).getPoint(4, 1));
    sf::Vector2f v5 = sf::Vector2f(getCube(cubeID).getPoint(5, 0), getCube(cubeID).getPoint(5, 1));
    sf::Vector2f v6 = sf::Vector2f(getCube(cubeID).getPoint(6, 0), getCube(cubeID).getPoint(6, 1));
    sf::Vector2f v7 = sf::Vector2f(getCube(cubeID).getPoint(7, 0), getCube(cubeID).getPoint(7, 1));

    sf::Vector2f v8 = sf::Vector2f(getCube(cubeID).getPoint(8, 0), getCube(cubeID).getPoint(8, 1));
    sf::Vector2f v9 = sf::Vector2f(getCube(cubeID).getPoint(9, 0), getCube(cubeID).getPoint(9, 1));
    sf::Vector2f v10 = sf::Vector2f(getCube(cubeID).getPoint(10, 0), getCube(cubeID).getPoint(10, 1));
    sf::Vector2f v11 = sf::Vector2f(getCube(cubeID).getPoint(11, 0), getCube(cubeID).getPoint(11, 1));

    vertices[0][0] = sf::Vertex(v0, tv0);
    vertices[0][1] = sf::Vertex(v1, tv1);
    vertices[0][2] = sf::Vertex(v2, tv2);
    vertices[0][3] = sf::Vertex(v3, tv3);

    vertices[1][0] = sf::Vertex(v4, tv0);
    vertices[1][1] = sf::Vertex(v5, tv1);
    vertices[1][2] = sf::Vertex(v6, tv2);
    vertices[1][3] = sf::Vertex(v7, tv3);

    vertices[2][0] = sf::Vertex(v8, tv0);
    vertices[2][1] = sf::Vertex(v9, tv1);
    vertices[2][2] = sf::Vertex(v10, tv2);
    vertices[2][3] = sf::Vertex(v11, tv3);

    return vertices;
}

void renderWindow::drawCube(int cubeID) {
    mWindow.draw(verticesSide1[cubeID], &mTextures[getCube(cubeID).getTexture(0)]);
    mWindow.draw(verticesSide2[cubeID], &mTextures[getCube(cubeID).getTexture(1)]);
    mWindow.draw(verticesSide3[cubeID], &mTextures[getCube(cubeID).getTexture(2)]);
}

//CUBE ACTION-------------------------------------------

entity.h

    #pragma once

    class entity {
    public:
        entity();
        entity(int id, int type, int numlayer);
        void addPoint(int nbPoints);
        void addTexture(int numTexture);

        //SETTERS
        void setPoint(int numPoint, float x, float y);
        void setTexture(int textureID, int numTexture);

        //GETTERS
        int getID();
        float getPoint(int numPoint, int numIndex);//if numIndex = 0 -> x || if numIndex = 1 -> y
        int getType();
        int getNumLayer();
        int getTexture(int numTexture);

    private:
        int mID;
        int mType;
        int mNumLayer;
        vector<sf::Vector2u> mPoints;
        vector<int> mTextures;
    };

    #include "entity.cpp"

entity.cpp

#pragma once

entity::entity() {
    mID = 0;
    mType = -1;
    mNumLayer = 0;
}

entity::entity(int id, int type, int numlayer) {
    mID = id;
    mType = type;
    mNumLayer = numlayer;
}

void entity::addPoint(int nbPoints) {
    mPoints.clear();

    int newSize = 0;
    for (int p = 0; p < nbPoints; p++) {
        newSize++;
    }

    mPoints = vector<sf::Vector2u>(newSize);
}

void entity::addTexture(int numTexture) {
    mTextures.push_back(numTexture);
}

//SETTERS
void entity::setPoint(int numPoint, float x, float y) {
    mPoints[numPoint].x = x;
    mPoints[numPoint].y = y;
}

void entity::setTexture(int textureID, int numTexture) {
    mTextures[textureID] = numTexture;
}

//GETTERS
int entity::getID() {
    return mID;
}

float entity::getPoint(int numPoint, int numIndex) {
    if (numIndex == 0)
        return mPoints[numPoint].x;
    else
        return mPoints[numPoint].y;
}

int entity::getType() {
    return mType;
}

int entity::getNumLayer() {
    return mNumLayer;
}

int entity::getTexture(int numTexture) {
    return mTextures[numTexture];
}

I've done a lot of test, too much, so I won't post them right now, but if you have any question, feel free to ask.

Here is the problem described in the title :

enter image description here

And here, screens with only one face displayed(in the same order in the code):

Side 1 only displayed

Side 2 only displayed

Side 3 only displayed

The only thing I don't understand is that a cube displayed alone work perfectly fine if you enter the coordinates manually. Even the extended ones. But the coordinates formula is ok... (I noticed that the cube n°50 for a 15x15 map with 64x64 cube display a rectangle 'infinite' in width) If the texture is extended(maybe to the infinite), it suggest that the coordinates are continuously increasing somewhere ? Then, why the cubes are still well placed ?

Here are the assets(64*64 png) : enter image description hereenter image description hereenter image description here Directories : textures/test/

Madz
  • 287
  • 3
  • 14
  • What would be the expected results? – Andreas Apr 02 '16 at 13:17
  • Oh my bad, I should describe them. A diamond map with the cubes. As you can see in the screen, It's almost that. – Madz Apr 02 '16 at 16:44
  • so your errors are the horizontal striped background and the diagonal lines along boxes to the left, am I right? – Andreas Apr 02 '16 at 17:33
  • Yes, + The weird form of some sides of the cubes(first line from top to bottom). – Madz Apr 02 '16 at 20:13
  • Have been looking at your code for a while know... Could you tell me of your coordinate systems; isometric and cartesian in particular? – Andreas Apr 02 '16 at 21:22
  • 1
    Are you aware that you lose precision in cube sizes not divisable by 4 because of the integer division in isometricToCartesian? – Andreas Apr 02 '16 at 21:25
  • Absolutely not. The problem could come from here ? I'v trouble to see how it can cause the striped thing problem. – Madz Apr 02 '16 at 21:44
  • It will be easier to debug your code if you have fewer bugs to begin with. don't think that is where the problem comes from though, sorry. I give up, best of luck! – Andreas Apr 03 '16 at 07:58
  • why you are using cubes instead sprites? You are limiting your isometric engine with cubes so much ... see [64x64 isometric sprites](http://opengameart.org/content/isometric-64x64-outside-tileset) I use. Also have a look at [Improving performance of click detection on a staggered column isometric grid](http://stackoverflow.com/a/35917976/2521214) and [How to procedurlly generate a Zelda like make in java](http://stackoverflow.com/a/36263999/2521214) for some additional ideas/features. – Spektre Apr 04 '16 at 09:11
  • I use cubes because I want to be able to changes any faces i want(texture, etc. ..). Sometimes being able to change the form of them. It will make what I'v in mind easier when the base will be done. Anyway, amazing links ! Thanks. – Madz Apr 04 '16 at 10:19
  • @Madz to make changes in tiles I made separate app (sprite editor). you can render the cubes into sprites and use both representations. Sprites are faster and allows pixel art. Mesh allows texture change... Also for editing the tile sprites I use features like back to front or ceiling to floor and vice versa to obtain rotations of sprites and possible combinations of sprites to obtain missing tile sprites. btw I am doing right now some coding in my map editor adding features like make hollow ground (to speed up rendering of big maps/resolutions) – Spektre Apr 04 '16 at 11:26
  • @Spektre Thanks for all of thoses informations, I had no clue about that method. I'm gonna recode all of this using all of the informations you gave. It's like i was doing it wrong ha ha. Should I close this question ? – Madz Apr 04 '16 at 12:05
  • @Madz I would leave the question as is. It still may help others... – Spektre Apr 04 '16 at 12:34
  • I noticed you have `int newSize = 0; for (int p = 0; p < nbPoints; p++) { newSize++; }`, why not just do `newSize = nbPoints` ? (in entity::addPoint) – Chara Apr 05 '16 at 17:51
  • @Chara `mPoints = vector(newSize);` Its the size of my vector of points. – Madz Apr 05 '16 at 19:06
  • @Madz I was just pointing out that you don't need a loop for that, you can just assign `newSize = nbPoints` and it does the same thing – Chara Apr 05 '16 at 19:12
  • @Chara ooh yes thanks ! – Madz Apr 05 '16 at 19:56
  • @Madz in fact you can just do `mPoints = vector(nbPoints)` :D – Chara Apr 05 '16 at 20:02
  • @Chara Thanks for the reminder ! I'm always forgetting obvious stuff (>_<) – Madz Apr 05 '16 at 20:27
  • @Madz happens to the best of us ;) – Chara Apr 05 '16 at 20:35
  • @Chara I agree ... it is funny to look at my older code and see the things I did not see while writing it... – Spektre Apr 06 '16 at 10:59
  • @Madz I added "answer" with some hints and summary of mine comments + some insight and pictures... – Spektre Apr 06 '16 at 14:41

3 Answers3

3

Not really an answer (as the code will be rewritten anyway) so few hints for the new code instead (some of them are already mentioned in the comments).

  1. Tileset

    In the final isometric engine use sprites. They are faster and support pixel art. For my purposes I use compilation of these two free to use tilesets (64x64):

    Both are compatible. I compiled and edited them to suite the needs of my engine. So this is what I use (still work in progress):

    my tileset

    White color 0x00FFFFFF means transparent. The sprite is not enough. I added info about the height of tile and rotations.

    If you see first 4 tiles from upper left corner they all are the same thing rotated by 90 degrees. So all my tiles have index of 4 tiles (the 90 degree rotations) int rot[4]. This way I can rotate the whole map or just view. I compile the set so the rotations are next to each other. There are 3 options:

    • tile[ix].rot[]={ ix,ix,ix,ix }; where ix is tile without rotation (ground)
    • tile[ix].rot[]={ ix,ix+1,ix,ix+1 }; where ix is tile with 2 rotations (those 2 tiles with chunk of chopped tree in the middle right)
    • tile[ix].rot[]={ ix,ix+1,ix+2,ix+3 }; where ix is tile with 4 rotations (like the first tile)

    The indexes are valid of coarse only for the first tile only, the others have the whole rot[] array rotated by 1 value from neighbor. Some rotations are invisible (see the wide trees) but the tile is still present to allow rotations.

    The tile height is important for placing tiles while editing and also for automatic map generations.

    tileset info

    I plan to add also A* map for each tile so I can use path finding or compute watter flows and more.

  2. Map editor

    I prefer 3D maps. with bigger resolution you need to properly select the viewed area for viewing to maximize performance. Also a good idea is to create hollow underground so the rendering is much faster (this can be also done virtually during rendering process without the need of updating map).

    I recommend to code these features:

    • make ground hollow
    • make ground solid
    • random terrain (diamond & square)
    • filter out small holes and smooth edges (add the slope tiles to cubic ones)
  3. tile editor

    Apart from the obvious paint editor you should add also another features like:

    1. floor <-> ceiling
    2. left <-> right
    3. front <-> back
    4. divide large sprite into regular tiles
    5. copy/merge/paste
    6. adjust lighting after left <-> right mirror operation

    They are really handy while compiling/editing tileset resources. As you can see my tileset has many of tiles not present in the source tilesets. They were created by these functions + some minor paint editing... The colored masks on the bottom of the tileset are used to mask out and properly combine parts of tiles to create the missing ones ... (you can take one side form one tile and other from other ...)

    tile operations

[Notes]

For more info/ideas have a look at some related Q/As:

Spektre
  • 49,595
  • 11
  • 110
  • 380
  • Big thanks for all thoses ressources and informations (i did not understood them all right now, but Im gonna take times to understand all of that). Big big thanks for this big answer, I think you're gonna help so much people with that. – Madz Apr 07 '16 at 12:49
  • @Madz Added link with my demo at the end of my answer (read the txts). The rotations in diamond layout are so cool :) – Spektre Apr 07 '16 at 14:00
  • Awsome work ! What did you used to make the gui for the diamond one ? – Madz Apr 07 '16 at 19:14
  • Can I ask you a question ? How did you make that big map not lagging at all(diamond one) ? I mean I'm tryharding like hell to have no CPU problem to display big big big maps. – Madz Apr 07 '16 at 19:17
  • @Madz the GUI (just the upper panel buttons) are basic Borlands VCL buttons. Both diamond and staggered programs are the same they just use different define in the code for computing cell position the rest is the same. All graphics is done by GDI (just the grid lines and texts) and CPU with direct pixel access to bitmap from C++ (see the linked QA about the clicking performance there you will find older source code of this). The trick is to use hollow ground so practically I am rendering just 1 or 2 cells thick map and render only cells visible on screen (not the whole map !!!) – Spektre Apr 07 '16 at 20:28
  • @Madz take screen middle position `(xs/2,ys/2)` then transform it to map cell position on the floor `scr2cell()` and render only tiles around this position. How big area depends on the tile size and screen size ... This way does not matter how big map you have the render speed will be depending only on screen size and complexity of visible surface. btw diamond layout is set in my source code by `#define isometric_layout_1` PS the numbers in caption of the app are render time and number of rendered/processed cells per last frame – Spektre Apr 07 '16 at 20:39
  • Thanks for thoses information ! You don't imagine how you help us ^^ . We're on a big project, but since we're complete amateur, it's really tough ha ha . Recoding's gonna take long but I hope we'll code a better version thanks to your advices :) . – Madz Apr 09 '16 at 16:32
  • By the way, what is an hollow ground :o ? – Madz Jun 28 '16 at 05:45
  • @Madz nothing just grid overlay if rendered... select should return the ground cell if selected ... so you can add a piece to it ...btw what state are you in? some image would be nice to see a progress :) – Spektre Jun 28 '16 at 05:50
  • @Madz in case you mean what does it mean `hollow ground` then the ground in map has only the top cell present ... all the inner cells are empty to ease up rendering and stuff... so if you remove the top most ground cell there would be hole in the map... – Spektre Jun 28 '16 at 13:28
  • Thanks for your answer ! I recoded it from 0, it became better but.. I struggle to code a proper structure for my engine. I also do not understand how framerate works and thread : i'm like "where, why". + I started to develop an UI, but I'm sure Its gonna be crappy xD. So yeah, i'm doing well xDDD. I' can't post code here to show progress, stackoverflow is not for that, sorry > – Madz Jun 29 '16 at 08:21
  • @Madz glad to hear it. I was more hopping for some nice image instead of code. Btw may be this [Simple Drag&Drop editor example in C++](http://stackoverflow.com/a/20924609/2521214) will help you bit with the structure problem. BTW the fps based rendering topic is worthy of a question ... – Spektre Jun 29 '16 at 08:47
  • I'm sorry I'm afraid I do not understand the code in the link you gave (>_<). Anyway, I'm curious too about your engine, since you did awsome work on it :D . How its doing ? – Madz Jun 29 '16 at 10:45
  • @Madz it is resting in piece ... lastly I add some block operation as preparation for adding trees/buildings/stuff to random terrain like copy,paste,rotate,delete,cut. Also some improvements in map file format and dynamically changeable layout between staggered and diamond layouts preserving the map contents. And lastly mode to move mouse cursor with keys to select unseen cells (behind obstacles). I was more playing with random map generation that I want to use for this when I got the time/mood for this see [Island map generator](http://stackoverflow.com/a/36647622/2521214) – Spektre Jun 29 '16 at 11:02
  • Wow, awsome work ! I'm almost ashamed to code something when I see all the thing you implemented ha ha. It doesn't rly look like it's resting in piece to me :o – Madz Jun 29 '16 at 13:21
  • @Madz didn't code a line of code on it for months ... this stuff is far away from awesome class (just few simple codes)... If you wanna see what is in awesome class from production of mine take a look at this: [Atmospheric scattering](http://stackoverflow.com/a/19659648/2521214) or [Is it possible to make realistic n-body solar system simulation in matter of size and mass?](http://stackoverflow.com/a/28020934/2521214) which is still in the fun category, but most of my really awesome work is not shareable due to corporate rules ... and you would need specific HW to run it anyway ... – Spektre Jun 29 '16 at 13:47
  • Awsome work here ^^ Are you in science or something ? Btw, I have put images since I have a new issue with my code ... : http://stackoverflow.com/questions/38121699/2d-isometric-game-engine-reversed-sprites all my sprites are reversed ha ha – Madz Jun 30 '16 at 11:24
  • @Madz luckily not anymore I hated how the academic and science environment works its more corrupt then governments Now I am in **R&D** and much much happier (involved in much more science then before). – Spektre Jun 30 '16 at 14:16
  • @Madz hi there I just updated demo link with newer version still 1.5 year old as I did not code anything in it since but in comparison to old version has many added features like converting between layouts without losing the map content, better tileset (I think I repaired/added some tiles) hmm looks like I forget to translate the new.txt to English :( too lazy to repost again ... – Spektre Jul 03 '18 at 08:08
0

In OpenGL, when you are creating a OpenGL texture manually, you can assign 4 types:

GL_REPEAT, GL_CLAMP_TO_EDGE, GL_CLAMP  and GL_CLAMP_TO_BORDER

If you want to learn more from the openGL textures differences, take a look here. Basically, it extend the last pixel in a image to the rest of the reserved memory.

In order to solve your problem, try to load the texture, modifing the parameters. I don't know if sfml allow to do it with Texture.hpp header, in the reference appear setRepeated, try to set true to see if solve the problem. Other way, loadfromfile with a size sf::IntRect(0, 0, 32, 32) in example.

This code is not tested, but teorically, using OpenGL will work:

void renderWindow::loadTexture(sf::String folder, int numTexture) 
{

    if (mMemoryTexture.loadFromFile("textures/" + folder + "/" + to_string(numTexture) + ".jpg"))
        mTextures.push_back(mMemoryTexture);
    else
        cout << "Texture n°" << numTexture << " as failed to load." << endl;

    // Generate OpenGL Texture manually
    GLuint texture_handle;
    glGenTextures(1, &texture_handle);

    // Attach the texture
    glBindTexture(GL_TEXTURE_2D, texture_handle);

    // Upload to Graphic card
    glTexImage2D(
        GL_TEXTURE_2D, 0, GL_RGBA,
        mMemoryTexture.GetWidth(), mMemoryTexture.GetHeight(),
        0,
        GL_RGBA, GL_UNSIGNED_BYTE, mMemoryTexture.GetPixelsPtr()
    );

    // Set the values
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
}

Maybe this helps you to solve your problem.

vgonisanz
  • 11,831
  • 13
  • 78
  • 130
  • Thanks for your answer. There is no solution without OpenGl ? – Madz Mar 31 '16 at 19:03
  • I mean, i'm sure it's a problem with my code's logic. There was no problem to display that kind of isometric map with sfml before. It doesn't work since I changed the structure of my code. – Madz Mar 31 '16 at 20:50
  • No i rewrited it entirely and deleted it. The code wasn't really optimised, i had lags. – Madz Apr 01 '16 at 12:24
  • Next time try using git or some repository, to have differents versions. If you had the code in github or bitbucket, I could try to debug it, but without it is very complicated to locate the problem. – vgonisanz Apr 01 '16 at 12:27
  • Why it's complicated(there is the whole code here) ? We have a git but a private one. – Madz Apr 01 '16 at 18:31
  • Well, I had to do some changes in the code, create a cmake file to compile... but the problems is I have not the test resources to imitate your problem, testing with some tile files I get: http://imgur.com/KXlKUOB – vgonisanz Apr 03 '16 at 13:27
  • Oh my ! I forgot to put the assets. I'm gonna upload them. – Madz Apr 03 '16 at 13:54
  • Ops, I didn't saw you update 3 tiles. Are textures/test/0.jpg, 1 , 2? I won't have time to check this until the night, sorry. – vgonisanz Apr 05 '16 at 11:10
  • By the way, the test I did seems you have a offset in the last iteration of the for, and you write an extra line without stopping after end the tile space, filling the complete buffer and jumping to the next line. That explain why lines are draw in my image. – vgonisanz Apr 05 '16 at 11:13
0

I endend by finding better way to do this code, thanks to members of stackoverflow. For people who got there by looking for a solution to a similar problem, I invite you to look at the comments for some usefull links and comment.

Madz
  • 287
  • 3
  • 14