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

Pages: [1] 2 3
1
Graphics / Re: SFML_T.exe has stopped working error
« on: April 17, 2015, 01:16:59 pm »
Hi oOhttpOo, You need to read the tutorials again, It's all really well explained. Start with the Drawing 2D stuff



               
                window1.clear(sf::Color::Black);

                if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
                {
                        sf::Texture texture;
                        if (!texture.loadFromFile("pic.jpg"))
                        {
                                //error
                        }

                        sf::Sprite sprite1;
                        sprite1.setTexture(texture);
                        window1.draw(sprite1);
                }
               
                window1.display();
 


The problem with your code is that you are creating the texture and sprite inside the if, and it's destroyed when the if finishes. You must define it before the game loop (while (window1.isOpen())).

#include <SFML/Graphics.hpp>

int main()
{
    sf::RenderWindow window1(sf::VideoMode(400, 400), "Window");
    window1.setVerticalSyncEnabled(true); // call it once, after creating the window

    sf::Texture texture;
    if (!texture.loadFromFile("pic.jpg"))
    {
        //error
    }

    sf::Sprite sprite1;
    sprite1.setTexture(texture);

    while (window1.isOpen())
    {
        sf::Event event;
        while (window1.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
                window1.close();
        }
        window1.clear(sf::Color::Black);
        window1.draw(sprite1);
        window1.display();
    }
}
 

2
Graphics / Re: Basic rendering crashing
« on: February 20, 2015, 10:14:43 pm »
Nobody knows how to fix it? Only crash with the SFML 2.2, 2.1 works fine.  :-[ 

3
Graphics / Re: Im doing the setup of SFML
« on: January 24, 2015, 07:04:40 pm »
It seems to be the same problem that I have, I explain in this topic.

Do you have an ATI graphic card? It's possible with blend changes in SFML 2.2, has returned again the old ATI bug? I don't find another explanation. The drivers are right and SFML 2.1 works fine.


4
Graphics / Re: Basic rendering crashing
« on: January 18, 2015, 08:39:52 pm »
Thanks eXpl0it3r. Yes I'm sure  ;)

I tried that you say but doesn't work. Anyway i don't understand why the same project and configuration works on my laptop and not in desktop. Specially when with SFML 2.1 all works fine.



Additionally the window module depends on gdi32 and winmm, as such they need to be a least on after the window module, better yet put them after all the SFML libs.

You mean this way:



The problem still here  >:(

Thanks for your answers.

5
Graphics / Re: Basic rendering crashing
« on: January 18, 2015, 07:00:16 pm »
Hi, sorry for not open a new thread, I don't see the need because I think I have the same problem with SFML 2.2 in my Desktop PC.

Normally I work on my laptop and SFML 2.2 works perfect. Yesterday I tried to run my project in my Desktop PC and doesn't work.
If I compile with SFML 2.1 runs OK, but if I try to SFML 2.2, compiles fine but crash on run.

Desktop info:

Windows XP Home Edition SP3
CPU Intel Pentium 4 2.53 GHz
RAM 1.5 GB
ATI radeon 9000 Pro graphics card (driver update at least version, I think)

I use: Codeblocks 13.12 (codeblocks-13.12mingw-setup.exe) with GCC 4.7.1 TDM (SJLJ) 32-bit
         SFML 2.2 version GCC 4.7.1 TDM (SJLJ) 32-bit (SFML-2.2-windows-gcc-4.7.1-tdm-32-bit)

For example if I try with this simple code:

#include <SFML/Graphics.hpp>

int main()
{
    sf::RenderWindow window(sf::VideoMode(200, 200), "SFML works!");
    sf::CircleShape shape(100.f);
    shape.setFillColor(sf::Color::Green);

    while (window.isOpen())
    {
        sf::Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
                window.close();
        }

        window.clear(sf::Color::Red);
        window.draw(shape);
        window.display();
    }

    return EXIT_SUCCESS;
}


Compiles fine but doesn't run. If I comment the drawing call ( window.draw(shape)), works perfect and show a red window. So the problem it's on rendering.

I debugged a simple code and crashes on render function. I get this error messages:

Quote
Error while reading shared library symbols for C:\Archivos de programa\CodeBlocks\MinGW\bin\libstdc++-6.dll
Process terminated with status -1073741510
Process terminated with status -1073741819

Screenshot with error message and output verbose build information:





Any idea what I'm doing wrong? Thanks!


6
General discussions / Re: SFML 2.2 Released!
« on: December 17, 2014, 11:51:43 pm »
Congratulations, downloading!! It's a good Christmas gift, thank you guys  :)

7
General discussions / Re: SFML 2.2 - Next-Gen Multimedia Capability Today
« on: December 11, 2014, 09:00:31 pm »
Awesome, good job!!  ;)

8
Network / Re: Packets and Arrays
« on: August 13, 2013, 10:10:53 pm »
Ouuch, sorry  ;D

9
Network / Re: Packets and Arrays
« on: August 13, 2013, 10:07:22 pm »
A loop? ???

I mean:

sf::Packet DataPacket;
for (int i = 0; i < sizeData; i++)
{
      DataPacket << data[i];
}
 

 ::)

10
Network / Re: Packets and Arrays
« on: August 13, 2013, 09:56:35 pm »
You can use a For loop to fill the packet or just overload the operators >> and << as its explained in the tutorials Extending Packets

11
Graphics / Re: How to fix white square problem when used vectors?
« on: August 10, 2013, 11:12:23 pm »
Yes, it should be private, I made public only in this test for simplify work.

With rivals.back().sprPlayer.setTexture(rivals.back().texturePlayer); it Works. But still don't like having to setTexture() two times. I'll keep thinking about how to solve. Thank you binary1248.

12
I looks great, good job and thanks for sharing  :D

13
Graphics / Re: How to fix white square problem when used vectors?
« on: August 10, 2013, 10:03:22 pm »
Another way to get around this problem would be to have an asset manager hold all your textures(so they don't get moved around in memory) then when the player is created have them set their textures to the ones in the texture manager. 

You'd probably want to do this anyways once your project starts getting bigger and bigger, that way you can load all your textures right at the start and don't have to worry when new entities get added or deleted.

Please can you show me and example of doing this, I don't know how make it. Thank you for your answers.

You could also try setting your vectors reserve size big enough to hold all your entities.  I think vector elements get moved in memory when the vector has to resize itself, at which a new vector is created(new memory location), all the contents are copied over with the new element added and the old is destroyed.  If you have a vector reserved big enough already I don't think it moves around in memory.

I'm doing this but doesn't work.
  std::vector <Player> rivals;
   rivals.reserve(maxPlayers);
 

You need to set the texture of the sprite after you insert into the std::list. If you set before and insert, the memory location of the data you will reference in the future will change since the std::list makes a copy of whatever you insert into it.

The problem is I load the texture in the constructor, I can't set after insert to vector. May be the solution is create an empty constructor and define a setPlayer() function??
Thanks for your answer.

14
Graphics / Re: How to fix white square problem when used vectors?
« on: August 09, 2013, 05:58:21 pm »
Thanks for reply binary1248. I tried with std::list but still doesn't work. Don't show the texture. I'm confused  ???

std::list <Player> rivals;

....

Player rival(sf::Vector2i(3 + numRivals, 0), pColors[numRivals], spriteSheets[numRivals]);
rivals.push_back(rival);
....

std::list<Player>::iterator e;
for (e = rivals.begin(); e != rivals.end(); ++e)
{
      (*e).Draw(Window);
}
 

15
Graphics / How to fix white square problem when used vectors?
« on: August 09, 2013, 04:54:25 pm »
Hi, first of all I know the "White square problem" described in the sprite tutorial. I understand it.

In my case, I create a Player class with a sprite and texture members. In main code, when  a user press M key, create a new instance of Player and add it into a vector. I known that the elements of a vector move in memory when the vector change and then lost the reference of the sprite texture.

Now, my question is how I can fix it? I tried with add setTexture every time I draw, but I don't know if its a good solution.

I attach an screenshoot about I'm saying.



I wrote a minimal example. This is the code, can download here.
I use SFML-2.1 with Code:Blocks (Windows 8 Pro, 32bits)

Player.h
//Player class

#ifndef PLAYER_H
#define PLAYER_H

#include <SFML/Graphics.hpp>
#include <iostream>

class Player
{
    public:
        Player(sf::Vector2i position, sf::Color colorSpr,  sf::String filenameSpr);
        ~Player();
        void Draw(sf::RenderWindow &Window);

        sf::Sprite sprPlayer;
        sf::Texture texturePlayer;
        int sprWidth, sprHeight;

    protected:
    private:
};

#endif
 

Player.cpp
#include "Player.h"

//constructor
Player::Player(sf::Vector2i position, sf::Color colorSpr,  sf::String filenameSpr)
{
    if(!texturePlayer.loadFromFile(filenameSpr, sf::IntRect(0, 0, 32, 32)))
        std::cout << "Error, can't load SpriteSheet " << std::endl;

    sprPlayer.setTexture(texturePlayer);
    sprPlayer.setColor(colorSpr);
    sprWidth = sprPlayer.getTextureRect().width;
    sprHeight = sprPlayer.getTextureRect().height;
    sprPlayer.setPosition(position.x * sprWidth, position.y * sprHeight);
}

//destructor
Player::~Player()
{
}

//draw player
void Player::Draw(sf::RenderWindow &Window)
{
    //sprPlayer.setTexture(texturePlayer); //<- with this it works
    Window.draw(sprPlayer);
}
 

Main.cpp

#include <SFML/Graphics.hpp>
#include <vector>
#include "Player.h"

const int maxPlayers = 10;

//colors for players
sf::Color pColors[maxPlayers] = {sf::Color(255, 0, 0, 255), sf::Color(0, 255, 0, 255),
                                 sf::Color(100, 100, 0, 255), sf::Color(0, 0, 255, 255),
                                 sf::Color(80, 200, 120, 255), sf::Color(100, 100, 155, 255),
                                 sf::Color(123, 160, 90, 255), sf::Color(200, 0, 255, 255),
                                 sf::Color(254, 195, 172, 255), sf::Color(255, 255, 255, 255)
                                   };
sf::String spriteSheets[maxPlayers] = {"punky2.png", "punky.png", "punky.png", "punky.png", "punky.png",
                                       "punky.png", "punky.png", "punky.png", "punky.png", "punky.png"
                                      };
int main()
{
    sf::Vector2i playerPosition(0, 0);
    int numRivals = 0;

    std::vector <Player> rivals;
    rivals.reserve(maxPlayers);

    sf::RenderWindow Window(sf::VideoMode(640, 480, 32), "Test");
    Window.setKeyRepeatEnabled(false);

    //create player
    Player hero(playerPosition, pColors[0], spriteSheets[0]);

    while (Window.isOpen())
    {
        sf::Event event;
        while (Window.pollEvent(event))
        {
            switch (event.type)
            {
            case sf::Event::Closed:
                {
                    Window.close();
                    break;
                }
            case sf::Event::KeyPressed:
                if (event.key.code == sf::Keyboard::Escape)
                {
                    Window.close();
                }
                else if (event.key.code == sf::Keyboard::Right)
                {
                    hero.sprPlayer.move(3, 0);
                }
                else if (event.key.code == sf::Keyboard::Left)
                {
                    hero.sprPlayer.move(-3, 0);
                }
                else if (event.key.code == sf::Keyboard::Down)
                {
                    hero.sprPlayer.move(0, 3);
                }
                else if (event.key.code == sf::Keyboard::Up)
                {
                    hero.sprPlayer.move(0, -3);
                }
                else if (event.key.code == sf::Keyboard::M)
                {
                    if (numRivals < maxPlayers - 1)
                    {
                        numRivals++;
                        Player rival(sf::Vector2i(3 + numRivals, 0), pColors[numRivals], spriteSheets[numRivals]);
                        rivals.push_back(rival);
                    }
                }
                break;
           }
        }

        //draw stuff
        hero.Draw(Window);
        if (numRivals > 0)
        {
            for (int k = 0; k < rivals.size(); k++)
            {
                rivals[k].Draw(Window);
            }
        }

        Window.display();
        Window.clear(sf::Color(255, 255, 0, 255));
    }
    return 0;
}
 


Pages: [1] 2 3