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

Pages: [1]
1
General / Re: hebrew and arabic strings
« on: December 05, 2013, 03:56:34 pm »
Looks like the text file is in a different encoding than you assume when reading it in your code.
Try to use a text editor to load the file and save it as UTF-8 (thats the most compatible format for files) without BOM (to avoid the 3 funny characters at start), then change your code to not use those w-things (because wide char is only vaguely defined in C and can be different on another system), then use the appropriate function to construct an sf::String (that internally is UTF-32) from UTF-8 data (I personally use sf::Utf but there may be a helper function in sf::String), then give that to sf::Text.
1) I fixed the format (it was UTF-8 but probably with BOM)
2) I changed the std::wstrings to normal std::strings
3) I didn't get all the sf::Utf stuff. I don't think I do it right. Can you give me an example of how to use it or how you use it please? I tried to work with it but I get compiler-errors which brings me to the definition of utf (utf.inl).
This is what I tried:
#include <SFML/Graphics.hpp>
#include <fstream>
#include <string>
int main()
{
        sf::RenderWindow window(sf::VideoMode(500, 500), "SFML");
        sf::Font font;
        font.loadFromFile("arial.ttf");
        sf::Text engText;
        sf::Text hebText;
        engText.setFont(font);
        hebText.setFont(font);
        engText.setPosition(200.0f, 200.0f);
        hebText.setPosition(200.0f, 240.0f);
        std::ifstream ifs("text.txt");
        std::string engStr;
        std::string hebStr;
        sf::String str;
        sf::Utf8 utf8;
        while ( ifs >> engStr >> hebStr)
        {      
                engText.setString(engStr);
                str = utf8.fromAnsi(hebStr.begin(),hebStr.end(),str);
                hebText.setString(hebStr);
        }
        ifs.close();
        while (window.isOpen())
        {
                sf::Event event;
                while (window.pollEvent(event))
                {
                        if (event.type == sf::Event::Closed)
                                window.close();
        }
                window.clear();
                window.draw(engText);
                window.draw(hebText);
                window.display();
    }
    return 0;
}
This is the error:
Error   4   error C2676: binary '++' : 'sf::String' does not define this operator or a conversion to a type acceptable to the predefined operator.
I get this error 5 times exactly the same.
And this warning:
Warning   1   warning C4101: 'utf8' : unreferenced local variable

2
General / Re: hebrew and arabic strings
« on: December 05, 2013, 01:03:08 pm »
I noticed i have picked the wrong "Arial" font for Hebrew (should be "arial" instead of "ARIALN"), and the code I gave in the first post works.
Now I want to read the text from file and display it on the screen.
So first of all here is the font:https://www.mediafire.com/?lr85ypt8lyajuy2.
Here is my code:
#include <SFML/Graphics.hpp>
#include <fstream>
#include <string>
int main()
{
        sf::RenderWindow window(sf::VideoMode(500, 500), "SFML");
        sf::Font font;
        font.loadFromFile("arial.ttf");
        sf::Text engText;
        sf::Text hebText;
        engText.setFont(font);
        hebText.setFont(font);
        engText.setPosition(200.0f, 200.0f);
        hebText.setPosition(200.0f, 240.0f);
        std::wifstream wifs("text.txt");
        std::wstring wEngStr;
        std::wstring wHebStr;
        while ( wifs >> wEngStr >> wHebStr)
        {
                engText.setString(wEngStr);
                hebText.setString(wHebStr);
        }
        wifs.close();
        while (window.isOpen())
        {
                sf::Event event;
                while (window.pollEvent(event))
                {
                        if (event.type == sf::Event::Closed)
                                window.close();
        }
                window.clear();
                window.draw(engText);
                window.draw(hebText);
                window.display();
    }
    return 0;
}
On screen it looks like this:


The text.txt file contains:
hello שלום

Thanks.

3
General / Re: AW: hebrew and arabic strings
« on: December 05, 2013, 10:09:26 am »
Does it work if you put, an L infront of the string like: txt = L"ÜÆØΠ₱";

Thanks for the answer but I already tried it and it doesn't work. it shows empty square for each letter.

Any other suggestions?

4
General / hebrew and arabic strings
« on: December 04, 2013, 11:30:14 pm »
Hey everybody!
First of all I must say I really enjoy working with sfml.

I want to create a program that read hebrew and arabic text from files (.txt files). The problem is that I can't hold the text in any string: not std::string, not std::wstring and not sf::String.
here is the minimal code:

#include <SFML/Graphics.hpp>
int main()
{
        sf::RenderWindow window(sf::VideoMode(500, 500), "SFML");
        sf::Font font;
        font.loadFromFile("ARIALN.ttf");
        sf::Text text;
        text.setFont(font);
        text.setPosition(200.0f, 200.0f);
        text.setString("&#1513;&#1500;&#1493;&#1501;");
        while (window.isOpen())
        {
                sf::Event event;
                while (window.pollEvent(event))
                {
                        if (event.type == sf::Event::Closed)
                                window.close();
        }
                window.clear();
                window.draw(text);
                window.display();
    }
    return 0;
}

It displays "uiai" with weird sign above each char.
The font I chose supports hebrew letters.

What should I do to fix it?
Thanks.
edit: I noticed that here it changes my hebrew letters to &#1513;&#1500;&#1493;&#1501;
There should be the word "שלום" instead.

5
Network / Problem| receving packets
« on: October 14, 2013, 10:10:18 am »
Hello everybody!
recently I started working with sfml and I am trying to make a simple network game.
1 player will be the server and the other one will be the client.

I made it work to each player able to move and see the other player moving too.
Now I want that each player will be able to shoot bullets.
it work nice on each separately but when I try it when they players are connected, it doesn't work quite well...
It send the bullet position to the other player but set it to to player position instead.
here is the code:
void Game :: update(sf::Time elapsedTime, sf::TcpSocket& socket)
{
        sf::Packet playerPacket;
        sf::Packet bulletPacket;
        player.update(elapsedTime);
        mOtherBullets = mBullets;       //these are to std::vectors to hold each player bullets.  
       
        if(mBullets.size() > 0)
        {
                for(int i=0; i<mBullets.size(); ++i)
                {
                        mOtherBullets[i].setSprite(mBullets[i].getSprite());    //don't know if this line is nessecery
                        bulletPacket << mBullets[i].getSprite().getPosition().x <<    mBullets[i].getSprite().getPosition().y;
                }
                if(socket.send(bulletPacket) == sf::Socket::Done)
                {
                        //wrote here messege
                }
        }
        if(mOtherBullets.size()>0)
        {
                if(socket.receive(bulletPacket) == sf::Socket::Done)
                {
                        for (int j = 0; j < mOtherBullets.size(); ++j)
                        if( bulletPacket >> mNewBulletPosition.x >> mNewBulletPosition.y)
                        {      
                                 //code doesn't reach here
                                std::cout << "bullets successfully receied\n ";          
                                mOtherBullets[j].getSprite().setPosition(mNewBulletPosition);
                        }
                 }
        }
        //this part works just fine but when one player shoots the other one see the player moving in the bullet direction
        if(prevPlayerPosition != player.getSprite().getPosition())
        {
                playerPacket << player.getSprite().getPosition().x << player.getSprite().getPosition().y;
                if(socket.send(playerPacket) == sf::Socket::Done)
                {
                }
        }
        if(socket.receive(playerPacket) == sf::Socket::Done)
        {
                if(playerPacket >> mNewPlayerPosition.x >> mNewPlayerPosition.y)
                {
                        mSecondPlayerSprite.setPosition(mNewPlayerPosition);   
                }
        }
}
 
I hope will get some help here.
Thanks.

Pages: [1]
anything