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

Pages: [1]
1
Graphics / Re: Convert Vertices into Image
« on: December 09, 2013, 01:59:59 pm »
Yeah, i noticed a bit too late =)

Thank you for your help!

2
Graphics / Re: Convert Vertices into Image
« on: December 09, 2013, 01:11:56 pm »
Shouldn't my lag disappear after using the Image class?
I mean, the operation from GPU to CPU is slow, but then, i have an image which i can use without lag, am i wrong?

I still wonder why is my texture inverted :/


Quote
I really wonder why so many people just don't call display...
->I just wanted to create a random tilemap and the collision tilemap associated.
For my collision tilemap, i need to call the GetPixel function, which is relative to the Image class.
That's why i'm trying to convert VerticesArray into an Image.

Anyway, thank you for helping, it's really kind and i appreciate.


Edit : The texture is no more rotated, after calling the Display() function once.

3
Graphics / Re: Convert Vertices into Image
« on: December 09, 2013, 11:40:16 am »
TileMap map;

//Initialisation of the tilemap
//...

RenderTexture rt;
rt.create(6000,6000);
rt.draw(map);
Image background_image;
background_image = rt.getTexture().copyToImage();

Texture bg_texture;
bg_texture.loadFromImage(background_image);
 


It works, but it's very laggy, and my tiles are inverted vertically (and maybe horizontally, i'm not sure)!

4
Graphics / Re: Convert Vertices into Image
« on: December 09, 2013, 11:24:55 am »
That sounds really good =)
Thank you mate, you made my day =D

5
Graphics / Convert Vertices into Image
« on: December 09, 2013, 11:02:34 am »
Hello everybody,

I'd like to use the TileMaping Tutorial from SFML, and save the result in an Image class.
But I don't find any way to convert this, can anyone help me a bit please?

Here is the code of the tutorial :


class TileMap : public sf::Drawable, public sf::Transformable
{
public:

    bool 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 * 4);

        // 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);
                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);
            }

        return true;
    }

private:

    virtual void 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);
    }

    sf::VertexArray m_vertices;
    sf::Texture m_tileset;
};

I need the Image class to call all the Image functions (GetPixel, SaveToFile etc.).

Thank you!

6
General / Re: Program crashes on exit (but only after moving characters)
« on: October 20, 2013, 07:19:01 pm »
Well it seems that i have a bunch of errors that i hadn't notice yet, due to my allocations.
I have to clear my code before coming back to you.
Thank you anyway!

7
General / Re: Program crashes on exit (but only after moving characters)
« on: October 20, 2013, 06:43:42 pm »
It only uses attributes from the Character class.

It fills the "deque<Vector2f> path" from Character.
entite->path.push_back(node);

It moves the "Sprite collision_sprite_large" from Character.
collision_sprite_large.setPosition(entite->getPosition());

8
General / Re: Program crashes on exit (but only after moving characters)
« on: October 20, 2013, 05:37:51 pm »
It finds a proper way to get to an aim from a starting point.

It creates a node matrix around the character, and tests each 8 directions, first from the character, and then from the child nodes that have been tested (it's a PathFinder).

I test the collision on each tested node, so i need to put the sprites as arguments, and the array containing the characters not to collide with them neither.

But the strange point is : why does it work for the child class, and not for the parent class?
Well, when i say it doesn't work, i mean it works, but it make a crash occuring at exit.

9
General / Re: Program crashes on exit (but only after moving characters)
« on: October 20, 2013, 05:17:38 pm »
Thank you for your answers,

I'd like to find the bug myself, but this is quite hard for me.

I tested much things and already found something anyway, but i don't understand why it happens :

Here are my two main classes, character and zombie (zombie extending the first one) :

class Character : public Transformable
{
public :

        int speed;
        int width;
        bool stuck;
        e_direction direction;
        bool deplacement;
        bool selected;
        bool hovered;
        Vector2i aim_position;
        Texture char_texture, collision_texture, collision_texture_large;
        Sprite char_sprite, collision_sprite, collision_sprite_large;
        CircleShape circle,circle_hover;
        bool draw_circle;
        int move_delay;
        Vector2f temp_aim_position;
        deque<Vector2f> path;

        Character()
        {
                setPosition(Vector2f(rand()%300+400, rand()%300+300));
                //setPosition(Vector2f(30,620));
                char_texture.loadFromFile("character.png");
                char_sprite.setTexture(char_texture);
                char_sprite.setOrigin(CHARWIDTH,CHARHEIGHT);
                char_sprite.setPosition(getPosition());
                circle.setPosition(getPosition());
                circle.setOrigin(CHARWIDTH, CHARHEIGHT);
                circle.setFillColor(Color(0,255,255,0));
                circle.setRadius(15);
                circle.setOutlineColor(Color(0,255,24,255));
                circle.setOutlineThickness(3);
                circle_hover=circle;
                circle_hover.setOutlineColor(Color(200,255,24,255));
                circle_hover.setOrigin(CHARWIDTH, CHARHEIGHT);
                CreateTextureAndBitmask(collision_texture, "collision_circle.png");
                collision_sprite.setTexture(collision_texture);
                collision_sprite.setOrigin(10, 10);
                collision_sprite.setPosition(getPosition());
                CreateTextureAndBitmask(collision_texture_large, "collision_circle_large.png");
                collision_sprite_large.setTexture(collision_texture_large);
                collision_sprite_large.setOrigin(CHARWIDTH, CHARHEIGHT);
                collision_sprite_large.setPosition(getPosition());
                speed=1;
                deplacement=false;
                selected=false;
                draw_circle=false;
                hovered=false;
                direction=Droite;
                move_delay=0;
                stuck=false;
        }
};

class Zombie : public Character
{
public:

        vector<int> cibles;
        bool chasing;
        float range;
        int chasing_timer;

        Zombie()
        {
                Zombie::Character();
                char_texture.loadFromFile("ennemy.png");
                char_sprite.setTexture(char_texture);
                range=100;
                setPosition(Vector2f(rand()%300+1000, rand()%300+300));
                //setPosition(Vector2f(700,420));
                char_sprite.setPosition(getPosition());
                collision_sprite.setPosition(getPosition());
                chasing=false;
                chasing_timer=0;
        }
};
 

My program is crashing on exit if i use the searching function for a character type (and works properly if i use it for a zombie type, which extends character:

Here is the prototype of the function, and its call:

//Prototype
void search(node*** matrix, deque<node>* n, deque<node>* m, Sprite collision_map, Sprite collision_sprite_large, Vector2f position, Vector2f aim,
Character* entite, int index, Character* tab_entite, vector<Building*>* batiments, grid_node** grid_bg)

//Call for character type (make the program crashing at exit)
search(matrix, tree, tree_to_sort, collision_map, entite[i]->collision_sprite_large, entite[i]->getPosition(),
Vector2f(entite[i]->aim_position.x, entite[i]->aim_position.y), entite[i], i, *entite, batiments, grid_bg);

//Call for zombie type (make the program exiting properly)
search(matrix, tree, tree_to_sort, collision_map, zombies[i]->collision_sprite_large, zombies[i]->getPosition(),
Vector2f(zombies[i]->aim_position.x, zombies[i]->aim_position.y), zombies[i], i, *zombies, batiments, grid_bg);

 

I really don't get it :D

10
General / Re: Program crashes on exit (but only after moving characters)
« on: October 20, 2013, 04:15:58 pm »
I don't have any errors while compiling, i wrote an example code to "sum up" what my program does, it is not the real code, which is thousands lines long.

Sorry for the ambiguities about that!

So i don't have any errors, only an "Access Violation" when i try to call "window.close()".
My program is running well, i can even call the "window.close()" function properly if i don't move any characters.
But if i do move a character, then the window.close() call make it crash.

Have you ever had this error before?
Do i have to clean some ressources before closing the window, like iterators, arrays or something else?

I do have a working program, the only problem occurs on "window.close()" (i marked it with a breakpoint and the instruction fails).

11
General / Re: Program crashes on exit (but only after moving characters)
« on: October 20, 2013, 02:04:53 pm »
Well, i'll try to put some lines to sum it up.

if(event.type == Event::KeyPressed)
{
        if(Keyboard::isKeyPressed(Keyboard::Escape))
        {
                window.close();
        }
        else if(//blabla
        {
                entity[i]->path.clear();
                entity[i]->collision_sprite_large.setPosition(entity[i]->getPosition());
       
                search(//Some parameters including entity[i]);
                //This function fill the path of the entity, which is a deque type.
        }
}

//Back in the game loop

for(int i=0; i<NB_CHAR; i++)
        if(entity[i]->in_movement)
                move(*entity, entity[i], i, buildings);

//This function move the entity->sprite, step by step, following the path


window.clear();
window.draw(entity->sprite)
etc.
 

My entity class :

class Character : public Transformable
{
public :

        bool in_movement;
        Vector2i aim_position;
        Texture char_texture, collision_texture, collision_texture_large;
        Sprite char_sprite, collision_sprite, collision_sprite_large;
        Vector2f temp_aim_position;
        deque<Vector2f> path;

        void Character()
        {
                char_texture.loadFromFile("character.png");
                char_sprite.setTexture(char_texture);
                CreateTextureAndBitmask(collision_texture, "collision_circle.png");
                collision_sprite.setTexture(collision_texture);
                //Etc.
        }
}
 

I hope it's enough.
There's a lot of lines in my program, so ask me for other classes/functions if you suspect them to cause the crash.

12
General / Program crashes on exit (but only after moving characters)
« on: October 20, 2013, 01:19:47 pm »
Hello everybody,

I've got some trouble in my program : when i call the window.close() function, it crashes with an "Access Violation" type error

If i try to close the program just after i started it, it works properly.
But a problem occurs if i close the program after moving some of my characters.

When i move a character, i use pointers and dynamic arrays like Vector or Deque.
Dynamic arrays are to create a dynamic path (with an A* algorithm) my characters will follow.

I'm quite new in C++ and SFML, so i don't really succeed in finding a way to debug this, please give me some help ^_


PS : I'm using Windows 7, latest SFML version (must be 2.1), and Visual Studio 11

Thank you!

13
SFML projects / Re: SFML Light System - Let There Be Light
« on: September 30, 2013, 10:01:05 am »
Well, i'm actually a new user,  yes.
I tried SFML a week ago for the first time.

And I actually read the documentation about Textures and other classes, but my code is still not working.

Here is where i need a few help precisely:

(in the LightSystem.cpp, for example)

m_softShadowTexture->bind();

This function is no more accepted, and so i have to change it.
So i look at the documentation, as usual, and see the Texture class have a bind() public method :

static void    bind (const Texture *texture, CoordinateType coordinateType=Normalized)
    Bind a texture for rendering.


I tried to replace with something like :
sf::Texture::bind(&m_softShadowTexture);

No more errors, but no lights appear!

Can somebody tell me where i am wrong please?


Edit : sorry for the lack of traduction, i didn't notice in time

14
SFML projects / Re: SFML Light System - Let There Be Light
« on: September 29, 2013, 08:54:48 pm »
Hello everybody!

I've been really excited when i saw this project, but i must admit i'm now losing my faith trying to add it into my SFML project.

Please help me someone! ^_

Let me try to explain my situation :

I'm using VS11(2012) and i already succeeded in including and using SFML 2.1.
My project is actually working, but i now want to add lights into it.

So :
-I downloaded LTBL 1.5
-I read the .pdf many times
-I pasted the Source directory into my project directory (in order to access to headers)
-I added all the .cpp from Constructs, Light, QuadTree (and the 'utils' one) to my project
-I pasted the example from the .pdf step by step
-I corrected a few changes in my code (for example Light() is no more accepted, i had to use a Light_point())
-I tried to compile and run

Here are the errors VS then returns :

Erreur  4       error C2039: 'unbind' : n'est pas membre de 'sf::Shader'        C:\Users\Shacker\Documents\Visual Studio 2012\Projects\SFML TEST\SFML TEST\Source\LTBL\Light\LightSystem.cpp    732     1       SFML TEST
Erreur  3       error C2660: '
sf::Shader::bind' : la fonction ne prend pas 0 arguments  C:\Users\Shacker\Documents\Visual Studio 2012\Projects\SFML TEST\SFML TEST\Source\LTBL\Light\LightSystem.cpp    717     1       SFML TEST
Erreur  1       error C2660: '
sf::Texture::bind' : la fonction ne prend pas 0 arguments C:\Users\Shacker\Documents\Visual Studio 2012\Projects\SFML TEST\SFML TEST\Source\LTBL\Light\EmissiveLight.cpp  58      1       SFML TEST
Erreur  2       error C2660: '
sf::Texture::bind' : la fonction ne prend pas 0 arguments C:\Users\Shacker\Documents\Visual Studio 2012\Projects\SFML TEST\SFML TEST\Source\LTBL\Light\LightSystem.cpp    267     1       SFML TEST
Erreur  5       error C2660: '
sf::Texture::bind' : la fonction ne prend pas 0 arguments C:\Users\Shacker\Documents\Visual Studio 2012\Projects\SFML TEST\SFML TEST\Source\LTBL\Light\LightSystem.cpp    777     1       SFML TEST
Erreur  6       error C2660: '
sf::Texture::bind' : la fonction ne prend pas 0 arguments C:\Users\Shacker\Documents\Visual Studio 2012\Projects\SFML TEST\SFML TEST\Source\LTBL\Light\LightSystem.cpp    795     1       SFML TEST
Erreur  7       error C2660: '
sf::Texture::bind' : la fonction ne prend pas 0 arguments C:\Users\Shacker\Documents\Visual Studio 2012\Projects\SFML TEST\SFML TEST\Source\LTBL\Light\LightSystem.cpp    820     1       SFML TEST
Erreur  8       error C2660: '
sf::Texture::bind' : la fonction ne prend pas 0 arguments C:\Users\Shacker\Documents\Visual Studio 2012\Projects\SFML TEST\SFML TEST\Source\LTBL\Light\LightSystem.cpp    845     1       SFML TEST
Erreur  9       error C2660: '
sf::Texture::bind' : la fonction ne prend pas 0 arguments C:\Users\Shacker\Documents\Visual Studio 2012\Projects\SFML TEST\SFML TEST\Source\LTBL\Light\LightSystem.cpp    870     1       SFML TEST
Erreur  10      error C2660: '
sf::Texture::bind' : la fonction ne prend pas 0 arguments C:\Users\Shacker\Documents\Visual Studio 2012\Projects\SFML TEST\SFML TEST\Source\LTBL\Light\LightSystem.cpp    898     1       SFML TEST
Erreur  11      error C2660: '
sf::Texture::bind' : la fonction ne prend pas 0 arguments C:\Users\Shacker\Documents\Visual Studio 2012\Projects\SFML TEST\SFML TEST\Source\LTBL\Light\LightSystem.cpp    965     1       SFML TEST
Erreur  12      error C2660: '
sf::Texture::bind' : la fonction ne prend pas 0 arguments C:\Users\Shacker\Documents\Visual Studio 2012\Projects\SFML TEST\SFML TEST\Source\LTBL\Light\LightSystem.cpp    979     1       SFML TEST

Can someone help me please?
I think there are few changes that have not been updated, and i'm not able to find them.

Pages: [1]
anything