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

Pages: 1 [2] 3
16
Graphics / Re: Scale sf::Texture
« on: June 21, 2015, 04:11:32 pm »
Scaling sprites is only a problem after reloading textures and I have to scale all the sprites in the game, which is around 320,000 sprites. This is why I said that I don't need an update to the whole SFML library, because the feature only makes my life a little easier.

17
Graphics / Re: Scale sf::Texture
« on: June 20, 2015, 08:18:50 pm »
The reason I want to resize the texture and I can't do it in an image editor is because I have a system where all tiles are displayed as 256x256px tiles, but all assets made by me are 16x16px. This is to save space but allow modders to create textures/texture packs that require a higher resolution. The only other game I can think of that also uses this system is Minecraft, because it uses 8x8 textures but modders can create resource packs that have resolutions upwards of 512x512px! (This also the reason I can't change the view, because the different textures will be different sizes)

18
Graphics / Scale sf::Texture
« on: June 20, 2015, 02:55:29 pm »
I see that sf::Sprite has sf::Sprite::setScale() and sf::Sprite::scale() functions, and I feel it would be better if I could scale my master texture, instead of the thousands of sprites that use that texture. I considered loading the image file into a texture, setting the sprite and scaling it, then putting the sprite into an image, then putting it into the original texture (which is way too long and doesn't even work). I'm not implying I want a sf:Texture::setScale() function, just that I want to know how I can achieve this (maybe even an algorithm that scales a pixel array)

19
That fixed it! Thank you Hiura and sorry for my stupidity and forgetfulness. The source code using the map container now works correctly!

20
Source code using the map container (also doesn't work):
#include <iostream>
#include <map>
#include <SFML/Graphics.hpp>

class TextureArray
{
    private:
        std::map<std::string, sf::Texture>textures;

    public:
        void addTexture(std::string textureName, sf::Texture newTexture)
        {
            textures.insert(std::pair<std::string, sf::Texture>(textureName, newTexture));
        }
        sf::Texture& getTexture(std::string textureName) {return textures.at(textureName);}
};

class ExampleObjectWithSprite
{
    private:
        sf::Sprite sprite;

    public:
        void setTexture(sf::Texture const& newTexture) {sprite.setTexture(newTexture, true);}
        void draw(sf::RenderWindow& targetWindow) {targetWindow.draw(sprite);}
};

int main()
{
    TextureArray textures;
    sf::Texture temp;
    temp.loadFromFile("Texture.png");
    textures.addTexture("texture", temp);

    ExampleObjectWithSprite object;
    object.setTexture(textures.getTexture("texture"));

    sf::RenderWindow window(sf::VideoMode(800, 600), "TEST");
    while (window.isOpen())
    {
        sf::Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
            {
                window.close();
                break;
            }
        }

        window.clear();
        object.draw(window);
        window.display();
    }
}
 
I can create source code from another container (like deque) but I'm doubting it's effectiveness

21
After playing around with the code that I added, I found that the bug is completely solved if you just use a normal sprite, rather than ExampleObjectWithSprite. Obviously this doesn't solve my issue, but it might be helpful in finding the root cause

22
If only loading at boot is such a huge constraint, how can I change the class so it is more like a resource manager, and won't invalidate any pointers after a resize (would this be achieved by using something like a deque, or does it call for much bigger changes)?

23
That's fine, the only time any elements are added is at the start of the program (in my actual program). I will also add the true condition, though it doesn't appear to change anything

24
I made some simplified source code which also contains the same issue:
#include <iostream>
#include <vector>
#include <SFML/Graphics.hpp>

class TextureArray
{
    private:
        std::vector<sf::Texture>textures;

    public:
        void addTexture(sf::Texture newTexture) {textures.push_back(newTexture);}
        sf::Texture& getTexture(int elementNumber) {return textures.at(elementNumber);}
};

class ExampleObjectWithSprite
{
    private:
        sf::Sprite sprite;

    public:
        void setTexture(sf::Texture newTexture) {sprite.setTexture(newTexture, true);}
        void draw(sf::RenderWindow& targetWindow) {targetWindow.draw(sprite);}
};


int main()
{
    TextureArray textures;
    sf::Texture txt;
    txt.loadFromFile("Texture.png");
    textures.addTexture(txt);

    ExampleObjectWithSprite object;
    object.setTexture(textures.getTexture(0));

    sf::RenderWindow window(sf::VideoMode(800, 600), "TEST");
    while (window.isOpen())
    {
        sf::Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
            {
                window.close();
                break;
            }
        }
       
        window.clear();
        object.draw(window);
        window.display();
    }
}

 
(The program requires a .png file called 'Texture', the picture in it doesn't matter because the texture isn't displayed)

Also, using a deque rather than a vector for TextureArray doesn't produce any different results (as suggested by Nexus)

25
1. What do you mean 'better suited container'? And how do I stop the data moving in that container

2. That's what it does already, it loads all the textures into the vector then sets the texture afterwards, but I still get a white square, but if the object has a copy it works perfectly

(Sorry for any delays, I am out so I get very little time to respond)

26
I had an idea where I created a class which stored textures in a vector, then all the other objects could have a pointer to the necessary texture in the vector, so that they could draw without needing their own copy. That idea didn't work because I got just a white square, which according to the tutorials means it can't find the texture. There are two ways I could get around this, I could have every object have a copy of its own texture (as stated above), or I could do sf::Sprite::setTexture every time I need to draw, which brings me to the question, which would be faster? The reason I am hesitant to have lots of copies of the same texture is because the game I am developing is a 2D tile based game (similar to terraria or starbound), and I don't think having lots of copies of the same dirt texture would be a good idea

27
General / Re: Segmentation error with example code and Ubuntu
« on: March 31, 2015, 07:20:01 pm »
Although this may not be helpful to anyone else who might see this thread, I fixed it. I don't really know how though, all I did was remove, then redo all the build options and I guess I got it to work  8).

28
General / Re: Segmentation error with example code and Ubuntu
« on: March 31, 2015, 03:14:35 pm »
Correct valgrind (hopefully):
Process terminating with default action of signal 11 (SIGSEGV)
Bad permissions for mapped region at address 0x5A6
 at 0x5A6: ???
 by 0x400FEC8: _dl_signal_error (dl-error.c:125)
 by 0x400E9C2: dl_map_object_deps (dl-deps.c:698)
 by 0x400315C: dl_main (rtld.c:1742)
 by 0x4017564: _dl_sysdep_start (dl-sysdep.c:249)
 by 0x4004CF7: _dl_start (rtld.c:332)
 by 0x40012D7: ??? (in /lib/x86_64-linux-gnu/ld-2.19.so)

29
General / Re: Segmentation error with example code and Ubuntu
« on: March 31, 2015, 02:06:54 pm »
I just compiled and found that the not found libraries is a completely different issue, so the text from valgrind is incorrect, and yes I'm using the release over Git version.

30
General / Re: Segmentation error with example code and Ubuntu
« on: March 31, 2015, 01:52:28 pm »
From valgrind I got:
./SFML Test: error while loading shared libraries: libsfml-graphics.so.2.2.0: cannot open shared object file: No such file or directory
From that snippet, I'm assuming the library is named wrong, so the program can't find it.
EDIT: After looking around, None of the libraries appear to have any typos, so I'm not sure why it's complaining about not finding the file

Pages: 1 [2] 3