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

Pages: [1]
1
Hey guys,

I have the following Code in my main loop
                if (sf::Keyboard::isKeyPressed(sf::Keyboard::Z) && ChernarusSprite.getScale().x <= 0.95f)
                {
                        ChernarusSprite.setScale(ChernarusSprite.getScale().x + 0.05f, ChernarusSprite.getScale().y + 0.05f);                  
                }

It allways stopped working after a few times, so I decided to check wether the Keys are still recognized like this:
                if (sf::Keyboard::isKeyPressed(sf::Keyboard::Z))
                        std::cout << "Z" << std::endl;
And it doesnt get recognized. Any Ideas why this part of SFML 2.1 stops working?


int main()
{
        sf::RenderWindow window(sf::VideoMode(1200, 900), "asdasfasfasd", sf::Style::Close | sf::Style::Resize);
        window.setFramerateLimit(60);
        tgui::Gui gui(window);
        sf::RectangleShape MapBG;
        sf::Image Chernarus;
                Chernarus.loadFromFile("chernarus_8000x7999px.jpg");
        sf::Texture ChernarusTexture;
                ChernarusTexture.loadFromImage(Chernarus);
                ChernarusTexture.setSmooth(true);
                sf::Sprite ChernarusSprite(ChernarusTexture);
                ChernarusSprite.scale(sf::Vector2f(0.1f, 0.1f));
                ChernarusSprite.setPosition(12, 12);

        MapBG.setPosition(sf::Vector2f(12, 12));
        MapBG.setSize(sf::Vector2f(800, 800));
        MapBG.setOutlineThickness(2.0f);
        MapBG.setOutlineColor(sf::Color(80, 80, 80));
        MapBG.setFillColor(sf::Color(0, 0, 0));

        if (gui.setGlobalFont("fonts/DejaVuSans.ttf") == false)
                return 1;

        loadWidgets(gui);

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

                        gui.handleEvent(event);
                }

                tgui::Callback callback;
                while (gui.pollCallback(callback))
                {
                        switch (callback.id)
                        {
                                case 1:
                                        window.setTitle(gen_random(32));
                                break;
                                case 2:
                                       
                                break;
                                case 3:
                               
                                break;
                                default:

                                break;
                        }
                }



                if (sf::Keyboard::isKeyPressed(sf::Keyboard::Z) && ChernarusSprite.getScale().x <= 0.95f)
                {
                        ChernarusSprite.setScale(ChernarusSprite.getScale().x + 0.05f, ChernarusSprite.getScale().y + 0.05f);                  
                }
               
                if (sf::Keyboard::isKeyPressed(sf::Keyboard::Z))
                        std::cout << "Z" << std::endl;

                if (sf::Keyboard::isKeyPressed(sf::Keyboard::H) && ChernarusSprite.getScale().x >= 0.15f)
                {
                        ChernarusSprite.setScale(ChernarusSprite.getScale().x - 0.05f, ChernarusSprite.getScale().y - 0.05f);
                       
                }
                       
                if (sf::Keyboard::isKeyPressed(sf::Keyboard::H))
                        std::cout << "H" << std::endl;

                window.clear(sf::Color(245, 245, 255));
                gui.draw();
                window.draw(MapBG);
                window.draw(ChernarusSprite);
                window.display();
        }
        return 0;
}

Dont now, wether this is important, but im using tgui for GUI

2
Graphics / Re: Image.loadFromFile() also fails in SFML 2.0
« on: May 26, 2013, 07:38:13 pm »
What a fail.  :-[

@Laurent all this was done when I was trying to find my fail after the error appeared.

Thanks for your help. I feel a bit ashamed now :/

Luapina

3
Graphics / Re: Image.loadFromFile() also fails in SFML 2.0
« on: May 26, 2013, 04:30:36 pm »
Maybe its a problem because of my bad english but:
The biggest part of my Problem is, that sfml does NOT give any output.
I call the loadFromFile function:
    if(!CaptchaImage.loadFromFile(Filename));    //Load the file into our Image
    {
        std::cout << "I couldnt read the image from " << Filename << std::endl;
        exit(12);
    }

And it only says "I couldnt read the image from cb.bmp". That is my output and the function itself doesnt give any output. This is what makes it so hard for me to solve this Problem.

My three files:

main.cpp
#include "Word_Position.hpp"

Position Position("cb.bmp"); //Calling the constructor here

int main()
{
    Position.SetWordRect();

    std::cout << "Left: " << Position.tX
                << "\nTop: " << Position.tY
                << "\nWidth: " << Position.tWidth
                << "\nHeight: " << Position.tHeight
                << std::endl;
}

 

Word_Position.cpp:


/*
        Word_Position.cpp

        Paul Brandt
        24.05.2013

    This code preforms a simple Pixel-by-Pixel check, to get the position and size of the word in the captcha.
*/


#include "Word_Position.hpp"



bool Position::PixelIsNonWhite(int pX, int pY)  //Preform a simple test if one single pixel is set to a non-white color
{
        if(CaptchaImage.getPixel(pX, pY) != sf::Color(255, 255, 255))   //Check if the Pixel has an other color than white
                return true;    //Pixel is not white (HIT)
        else
                return false;   //Pixel is white (NO HIT)
}

void Position::SetWordRect() //Store the Position, Size(Pixel) of a word we found. Also provides some usefull memberfunctions.
{

        //Our first step is to find out the X-Coordinate
        for(int x = 0; x<IMAGE_WIDTH; x++)      //Use the X-Coordinate as Outer-LOOP
        {
                for(int y = 0; y<IMAGE_HEIGHT; y++)     //Use the Y-Coordinate as Inner-LOOP
                {
                        if(PixelIsNonWhite(x, y)) tX = x;
                }
        }

        //Next step is to find out the Y-Coordinate
        for(int y = 0; y<IMAGE_HEIGHT; y++)     //Use the Y-Coordinate as Outer-LOOP
        {
                for(int x = 0; x<IMAGE_WIDTH; x++)      //Use the Y-Coordinate as Inner-LOOP
        {
                        if(PixelIsNonWhite(x, y)) tY = y;
                }
        }

        // We did some great work on finding the upper left corner
        // Now we will find the downer right corner.
        // Same procedure just the other was round:

        //Our first step is to find out the X-Coordinate
        for(int x = IMAGE_WIDTH; x>0; x--)      //Use the X-Coordinate as Outer-LOOP
        {
                for(int y = IMAGE_HEIGHT; y>0; y--)     //Use the Y-Coordinate as Inner-LOOP
                {
                        if(PixelIsNonWhite(x, y)) tWidth = x - tX;
                }
        }

        //Next step is to find out the Y-Coordinate
        for(int y = IMAGE_HEIGHT; y>0; y--)     //Use the Y-Coordinate as Outer-LOOP
        {
                for(int x = IMAGE_WIDTH; x>0; x--)      //Use the Y-Coordinate as Inner-LOOP
                {
                        if(PixelIsNonWhite(x, y)) tHeight = y - tY;
                }
        }
}

Position::Position(const char* Filename)
{
    CaptchaImage.create(IMAGE_WIDTH, IMAGE_HEIGHT, sf::Color(0, 0, 0)); //Create an empty Image
    if(!CaptchaImage.loadFromFile(Filename));   //Load the file into our Image
    {
        std::cout << "I couldnt read the image from " << Filename << std::endl;
        exit(12);
    }
}

 


Word_Position.hpp:
#include <SFML/Graphics.hpp>    //We use the SFML library to preform our image-checks
#include <iostream>


#define IMAGE_WIDTH     300             //300 by 57 is the Defaut Image Size in ReCaptcha.
#define IMAGE_HEIGHT    57              //Change it with you needs.

#define POS_ENABLED             true    //Define if we want to scan for pixel with tolerance in Position - Doesnt make that much sense without
#define ROT_ENABLED             false   //Define if we want to scan for pixel with tolerance in Rotation - Mostly we dont need this
#define POS_TOLERANCE   0.05f
#define ROT_TOLERANCE   0.10f
#define COLOR_TOLERANCE 0.30f


class Position
{
    private:
        sf::Image CaptchaImage;
        bool PixelIsNonWhite(int pX, int pY);

    public:
        void SetWordRect();
        Position(const char* Filename);

        int tX; //We store the Coordinates public since this is the fastest way to access them.
        int tY;

        int tWidth; //Same here
        int tHeight;



};


 


EDIT:
Made a video which descibes the problem better than I do:

4
Graphics / [Solved]Image.loadFromFile() also fails in SFML 2.0
« on: May 26, 2013, 05:21:05 am »
Dear SFML-Community,

i started a topic ealier, where i searched for help with a strange problem. The "Solution" of my last topic was, that i updated to sfml 2.0.

So here's my problem now in sfml 2.0:

I have a class called "Position" with an sfml-Image as member. Declared as following:
class Position
{
    private:
        sf::Image CaptchaImage;
[...]
}

The constructor of the Class:
Position::Position(const char* Filename)
{
    CaptchaImage.create(IMAGE_WIDTH, IMAGE_HEIGHT, sf::Color(0, 0, 0));    //Create an empty Image
    if(!CaptchaImage.loadFromFile(Filename));    //Load the file into our Image
    {
        std::cout << "I couldnt read the image from " << Filename << std::endl;
        exit(12);
    }
}
 

So in my main.cpp I create an Instance of class Position:
Position Position("cb.bmp");

And guess what? I get the same output as in sfml 1.6:
"I couldnt read the image from cb.bmp".
This is the output I do, NOT the output that the loadFromFile() does.
So loadFromFile() fails loading the image and is not giving any Reason.

The Image IS compatible with SFML because if I do the following in the main.cpp:
sf::Image image;
if(!image.loadFromFile("cb.bmp"))
    std::cout << "Failed";
else
    std::cout << "Success";
 

It works fine!! Is this just me or is this kind of strange? I can post more code if needed.
Many thanks in advance,
Luapina


Edit:

Even IN THE SAME project but in the main.cpp the following code works:
sf::Image image;
if(!image.loadFromFile("cb.bmp"))
    std::cout << "Failed";
else
    std::cout << "Success";
 

5
Graphics / Re: Image.LoadFromFile fails?
« on: May 25, 2013, 04:20:39 pm »
OK. So this kind of solved now. Ill switch to 2.0.
The only reason why I used 1.6 is, that it is still the newest Version of sfml in most linux repositories.

Thanks,
Luapina

6
Graphics / Re: Image.LoadFromFile fails?
« on: May 25, 2013, 11:14:38 am »
The function itself did NOT give me any error Message. I just know it fails beacause of my own error check:

    if(!CaptchaImage.LoadFromFile(Filename));    //Load the file into our Image
    {
        std::cout << "I couldnt read the image from " << Filename << std::endl;
        exit(12);
    }

Im also sure that it is NOT a problem with incompatibility because i also tried loading an image i loaded in earlier projects.

Tried the minimal example code in another project and it worked. Ill try it in this project as well soon.

7
Graphics / [Solved]Image.LoadFromFile fails?
« on: May 24, 2013, 08:09:29 pm »
Hello SFML-Community!

I've still done some projects with sfml but with my new project I seem to fail very fast.

I created a class that loads an Image from File and scans the x and y Coordinate where the Image really starts. (White gets ignored)

The LoadFromFile() Function allways tells me it failed. Here is the code I guess its something very stupid:

main.cpp
#include "Word_Position.hpp"

Position Position("captcha.jpg");

int main()
{
    Position.SetWordRect();

    std::cout << "Left: " << Position.tX
                << "\nTop: " << Position.tY
                << "\nWidth: " << Position.tWidth
                << "\nHeight: " << Position.tHeight
                << std::endl;
}
 

Word_Position.cpp
/*
        Word_Position.cpp

        Paul Brandt
        24.05.2013

    This code preforms a simple Pixel-by-Pixel check, to get the position and size of the word in the captcha.
*/


#include "Word_Position.hpp"



bool Position::PixelIsNonWhite(int pX, int pY)  //Preform a simple test if one single pixel is set to a non-white color
{
        if(CaptchaImage.GetPixel(pX, pY) != sf::Color(255, 255, 255))   //Check if the Pixel has an other color than white
                return true;    //Pixel is not white (HIT)
        else
                return false;   //Pixel is white (NO HIT)
}

void Position::SetWordRect() //Store the Position, Size(Pixel) of a word we found. Also provides some usefull memberfunctions.
{

        //Our first step is to find out the X-Coordinate
        for(int x = 0; x<IMAGE_WIDTH; x++)      //Use the X-Coordinate as Outer-LOOP
        {
                for(int y = 0; y<IMAGE_HEIGHT; y++)     //Use the Y-Coordinate as Inner-LOOP
                {
                        if(PixelIsNonWhite(x, y)) tX = x;
                }
        }

        //Next step is to find out the Y-Coordinate
        for(int y = 0; y<IMAGE_HEIGHT; y++)     //Use the Y-Coordinate as Outer-LOOP
        {
                for(int x = 0; x<IMAGE_WIDTH; x++)      //Use the Y-Coordinate as Inner-LOOP
        {
                        if(PixelIsNonWhite(x, y)) tY = y;
                }
        }

        // We did some great work on finding the upper left corner
        // Now we will find the downer right corner.
        // Same procedure just the other was round:

        //Our first step is to find out the X-Coordinate
        for(int x = IMAGE_WIDTH; x>0; x--)      //Use the X-Coordinate as Outer-LOOP
        {
                for(int y = IMAGE_HEIGHT; y>0; y--)     //Use the Y-Coordinate as Inner-LOOP
                {
                        if(PixelIsNonWhite(x, y)) tWidth = x - tX;
                }
        }

        //Next step is to find out the Y-Coordinate
        for(int y = IMAGE_HEIGHT; y>0; y--)     //Use the Y-Coordinate as Outer-LOOP
        {
                for(int x = IMAGE_WIDTH; x>0; x--)      //Use the Y-Coordinate as Inner-LOOP
                {
                        if(PixelIsNonWhite(x, y)) tHeight = y - tY;
                }
        }
}

Position::Position(const char* Filename)
{
    CaptchaImage.Create(IMAGE_WIDTH, IMAGE_HEIGHT, sf::Color(0, 0, 0));    //Create an empty Image
    if(!CaptchaImage.LoadFromFile(Filename));    //Load the file into our Image
    {
        std::cout << "I couldnt read the image from " << Filename << std::endl;
        exit(12);
    }
}
 


Word_Position.hpp:
#include <SFML/Graphics.hpp>    //We use the SFML library to preform our image-checks
#include <iostream>


#define IMAGE_WIDTH     300             //300 by 57 is the Defaut Image Size in ReCaptcha.
#define IMAGE_HEIGHT    57              //Change it with you needs.

#define POS_ENABLED             true    //Define if we want to scan for pixel with tolerance in Position - Doesnt make that much sense without
#define ROT_ENABLED             false   //Define if we want to scan for pixel with tolerance in Rotation - Mostly we dont need this
#define POS_TOLERANCE   0.05f
#define ROT_TOLERANCE   0.10f
#define COLOR_TOLERANCE 0.30f


class Position
{
    private:
        sf::Image CaptchaImage;
        bool PixelIsNonWhite(int pX, int pY);

    public:
        void SetWordRect();
        Position(const char* Filename);

        int tX; //We store the Coordinates public since this is the fastest way to access them.
        int tY;

        int tWidth; //Same here
        int tHeight;



};
 

What am i doing wrong? Is it someting in the Code or am i failing about the Image-Path or Image-Format here?

Pages: [1]