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.


Topics - Cadisol87

Pages: [1]
1
Network / How to transfer data from a non-SFML client to a SFML Server
« on: January 25, 2015, 12:29:46 am »
Im currently learning java, and I'm developing a chat application for android (in java).
The chat application takes a username and text from the user and sends it to a server application on my computer.
The server application is written in C++ with the SFML Network library.

Here's my very simple Server (It's supposed to just write out the sent text at the moment):
#include <SFML/Network.hpp>
#include <iostream>

using namespace std;

int main()
{

    sf::TcpListener listener;
    if (listener.listen(4242) != sf::Socket::Done)
    {
        cerr<< endl << "Error: Couldn't set up TCP listener";
    }

    sf::TcpSocket client;
    listener.accept(client);
    cout << endl <<"New client connected: " << client.getRemoteAddress() << endl;
    char data[100];
    std::size_t received;

    if (client.receive(data, 100, received) != sf::Socket::Done)
    {
    cerr<<endl<<"Error while receiving data";
    }
    else
    cout << endl << "Data received: " << data;


}
 
Here's a snippet of my java code in which the message is being sent:
            try {
                Socket socket = new Socket("192.168.1.126",4242);
                OutputStream out = socket.getOutputStream();

                PrintWriter output = new PrintWriter(out);
                output.println("Hello World!"); // Hello World will be replaced by the actual text message in the future

                socket.close();

            } catch (UnknownHostException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
 

When I run both applications, the phone actually connects to my server, and the server writes "New client connected..." to the console, but I'm unable to send the "Hello World!" text. The server doesn't receive any data.

So my question is: Is it possible that the Server receives the data? And If yes, how can I achieve that and what do I have to keep in mind?

2
Graphics / [Android] SFML Application runs very slow
« on: December 30, 2014, 01:46:37 pm »
A few days ago I compiled SFML 2.2 for Android and already made a few small Apps. Now I'm trying to create something bigger, but there's a problem: The application needs a relatively long time to start up and react, for example when I rotate the phone. I think my phone is fast enough to run the App smoothly( I have an OnePlus One with a Qualcomm Snapdragon 801 and 3GB RAM), and other Apps created with SFML (For example Kroniax) run smoothly. If I compile the code on my PC, it runs fast, so I guess my code is just very resource-heavy.
The following code reproduces the problem:
#include <SFML/Graphics.hpp>

inline void adjustCharacterSize(sf::Text& text, const sf::Vector2u& windowSize, unsigned short factor)
{
        while(text.getGlobalBounds().width < windowSize.x - windowSize.x / factor && text.getCharacterSize() < 500)
                text.setCharacterSize(text.getCharacterSize() + 1);
                 
        while(text.getGlobalBounds().width > windowSize.x - windowSize.x / factor && text.getCharacterSize() > 10)
                  text.setCharacterSize(text.getCharacterSize() - 1);

}


int main(int argc, char *argv[])
{
    sf::RenderWindow window(sf::VideoMode::getDesktopMode(), "", sf::Style::Fullscreen);
    window.setVerticalSyncEnabled(true);

    sf::Font font;
    font.loadFromFile("Lato-Light.ttf");

    sf::Text text;
    text.setFont(font);
    text.setString("Hello World!");
    text.setColor(sf::Color::Green);
    text.setCharacterSize(100);
    adjustCharacterSize(text, window.getSize(), 4);
    text.setPosition(150, 150);

    sf::View view = window.getDefaultView();


    while (window.isOpen())
    {

        sf::Event event;

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

            if (event.type == sf::Event::Resized)
            {
                view.setSize(event.size.width, event.size.height);
                view.setCenter(event.size.width/2, event.size.height/2);
                adjustCharacterSize(text, window.getSize(), 4);
                window.setView(view);
            }
        }


        window.clear();
        window.draw(text);
        window.display();
    }
}
 
I already found out that the function  'adjustCharacterSize' seems to be responsible for the slow behavior, but I don't know why. I modified the function several times, but with no success.
Any ideas oft what I could do?

3
Graphics / sf::Quad Vertex Array Gradient isn't always 'smooth'
« on: November 16, 2014, 11:23:37 am »
Im currently making a Game, where the background should consist of a smooth, color-changing gradient.
In order to achieve that, I have a sf::Quad vertex array, each vertex is positioned in a corner of the window, and the vertices change color. This works pretty well, except that for some reason, sometimes the gradient isn't smooth.
Smooth:

Not Smooth (Ignore the blue fragment in the bottom right corner, my screen capturing program messed that up, I mean the green line which goes from the top right corner to the bottom left):


Why does this happen, and how can I avoid it?

4
General / A few questions regarding Android development
« on: November 01, 2014, 07:13:14 pm »
I want to start developing C++ Android applications using SFML.
Unfortunately, I don't have any experience developing apps for the Android platform, so I have a few(a bunch of) questions:
  • Do I have to modify my existent C++ code to compile it for android?
  • What else do I have to include to my project? (Maybe a manifest file?)
  • Can I use sort of an Android API in my C++ project? (For example to get the screen resolution of the device)
  • How do I compile my C++ code?
  • Can I continue using my favorite IDE?

If somebody has the time to answer my questions or just give me a link to a website or forum topic which helps me, I would really appreciate it! :)

5
Graphics / Render special characters from a variable
« on: September 21, 2014, 04:16:32 pm »
I want to render a sf::Text, which contains special characters.
I know that if the text wouldn't be a variable, I could do somenthing like this:
text.setString(L"öüäßê");
But in my case, the text is entered by the user.
How can I render the sf::Text, without having to use a switch statement to check if the character the user entered is a special one?

6
Graphics / sf::Font size not accurate
« on: September 19, 2014, 06:00:19 pm »
Hey guys! It has been a while since I have been around on the forum. But now I'm back with a question:

I recently have been developing stuff under Linux. When I was working with Fonts, I noticed that the font size isn't accurate; I had to move the font to achieve what I wanted. Then I compiled the same code under Windows and It looked weird, because the font size was right. I also noticed that this doesn't happen with every font.

Example:
I compiled the following code under both operating systems(I used the font facile sans):
#include <SFML/Graphics.hpp>

int main()
{
    sf::RenderWindow window(sf::VideoMode(500, 500), "Example");
    sf::Font font;
    font.loadFromFile("font.ttf");
    sf::Text text;
    text.setFont(font);
    text.setPosition(0, 0);
    text.setCharacterSize(84);
    text.setString("Text");
    text.setColor(sf::Color::Black);
    while (window.isOpen())
    {
        sf::Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
                window.close();
        }

        window.clear(sf::Color::White);
        window.draw(text);
        window.display();
    }

    return 0;
}
 

This is how it looks under Linux:


Under Windows:


Does anyone know why this happens and how to fix it?
I appreciate any help :)

7
Graphics / Collision Response doesn't work properly
« on: March 20, 2014, 11:39:46 pm »
Hey guys!

I have a question about collision response.
In my program I check if some circles collide, and if they do, the collision is being resolved and the new velocities are being set.
That works fine if the circles have the same radii, but when the radii are different, the circles stick together sometimes.
a video showing the problem. ( I recommend you to watch it in fullscreen mode. The password is 'sfml')

Here's my resolve circle to circle collusion function:
void resCtcCollision(elasticCircle &circleA, elasticCircle &circleB) //Resolve Circle to Circle Collision
{
    sf::Vector2<long double> v1(circleA.getVel());
    sf::Vector2<long double> v2(circleB.getVel());
    sf::Vector2<long double> ap(circleA.getPosition());
    sf::Vector2<long double> bp(circleB.getPosition());
    sf::Vector2<long double> n = ap - bp;
    n = Normalize(n);

    long double a1 = dotProduct(v1, n);
    long double a2 = dotProduct(v2, n);
    long double optimizedP = (2.0 * (a1 - a2)) / (circleA.getMass() + circleB.getMass());

    v1 = v1 - optimizedP * circleB.getMass() * n;
    v2 = v2 + optimizedP * circleA.getMass() * n;

    circleA.setVel(v1);
    circleB.setVel(v2);

}
 

My timestep is correct.

Has anyone an Idea what I've could done wrong?

8
Graphics / [Beginner] Help with fixed Timestep
« on: February 26, 2014, 09:30:13 pm »
Here am I again! :)

So here's my second question that I have (If you don't know of what I'm talking about, see here)

So my problem is, that sometimes the circles are bouncing in the window and hit another circle, they "glitch" and stick to each other. So I got a possible solution from Golden Eagle, he said that I should read this Article, so I read it and tried to understand it.

So, I assume that what I have to do is to save the state of the program , and if the 'accummulator' is bigger than the delta time, set the old state before collision to the new, and then adjust the time?( I hope you can understand what I'm trying to say with my bad english ;)  ) Please correct my if I'm wrong!

But would that method be efficient? Because while the game is 'lagging' I have to update the game, which would be very complicated if you have a look at my code... And it wouldn't be good for the performance to save a lot of states in the loop...

Does anybody have an idea how to solve this more efficiently, without re-writing nearly all my code?
(Maybe I just misunderstood the article.. :) )

Any help is appreciated!


9
Graphics / [Beginner] Help with random-colored Circles
« on: February 22, 2014, 12:21:07 am »
Hey Guys, I'm here again with my problem:
I got some circles bouncing around in a window. But I want that the circles change their color when they collide with a wall.

This may seems very simple, but trust me, it's harder than It looks.
The problem I have, is that the colors are always similar.

Let me explain the problem more in detail:

I got a random function, which generates a random number between 1 and 255. I uses the elapsed time of a clock in microseconds as seed. The function works fine.

But now theres a problem: When I try to set the FillColor of the Circle like this:
Circle.setFillColor(sf::Color(Random(clockSeed) , Random(clockSeed) , Random(clockSeed));
 

The Circle will always get a grey color, because Red, Green and Blue have the same value.

Then I tried something like this:
Circle.setFillColor(sf::Color(Random(clockSeed * 2) , Random(clockSeed * clockSeed) , Random(clockSeed));
 

And a LOT of other methods to give each color a different value.
But that works neither, now the Circles have similar colors, because the 'proportions' of the color's values are always the same.

I have some Ideas for nasty solutions, but does anyone have an smart solution?

(Probably the solution is obvious and my brain is just stuck...)

Thanks In advance for your answers! :)

10
Graphics / [Beginner] Help with Bouncing Circles
« on: January 31, 2014, 10:53:49 pm »
Hello everybody!

First of all: Excuse my terrible English  ;)

Im new to SFML and I made a little Program that shows some Circles Bouncing around in the window. That works fine.
But now I want that the Circles bounce away when the collide with another Circle.
How can I implement that?


Pages: [1]
anything