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

Pages: [1]
1
Graphics / Re: Problem when getting things to fade to black
« on: May 20, 2013, 02:30:38 pm »
Thanks.
I fixed it. The solution seems a bit dirty but it works. :)



Updated fragment shader:
uniform sampler2D texture;

void main()
{
    // lookup the pixel in the texture
        int range = 255;
        float unit = 1.0f/255;
    vec4 pixel = texture2D(texture, gl_TexCoord[0].xy);
       
        int red = (int)(pixel.r / unit);
        int green = (int)(pixel.g / unit);
        int blue = (int)(pixel.b / unit);
        int alpha = (int)(pixel.a / unit);
       
        red -= 1;
        green -= 1;
        blue -= 1;
        alpha -= 1;
       
        vec4 newCol = vec4((float)red*unit,(float)green*unit,(float)blue*unit,(float)alpha*unit);

    // multiply it by the color
    gl_FragColor = gl_Color * newCol;
}

2
Graphics / [SOLVED] Problem when getting things to fade to black
« on: May 20, 2013, 12:44:04 pm »
Hello everyone,

I setup a RenderTexture today to use for a little test project I've been working on.
I apply a shader to it which darkens the original result and then I render the latest frame/draw call onto the texture.

I expected the colours to fade to black basically creating this nice sort of 'tail'.
Instead the colours stop fading at some point. This 'threshold' changes depending on the darkening amount I pick.



Draw code (The red layer is the RenderTexture.)
//Darken red layer
        sf::RectangleShape fxRect;
        fxRect.setPosition(0,0);
        fxRect.setSize(sf::Vector2f(1280,720));
        fxRect.setTexture(&redLayer.getTexture());

        fxShader.setParameter("texture", sf::Shader::CurrentTexture);
        redLayer.draw(fxRect, &fxShader);

        //Draw red layer
        redLayer.display();
        sf::RectangleShape redRect;
        redRect.setPosition(0,0);
        redRect.setSize(sf::Vector2f(1280,720));
        redRect.setTexture(&redLayer.getTexture());
        appRef->GetWindow().draw(redRect);

        swiz_ent_list_t::iterator iter;
        for (iter = ent_list.begin(); iter != ent_list.end(); ++iter)
        {
                SwizEntity* ent = *iter;
                int entType = ent->GetBaseType();
                if((entType & ENT_DRAWABLE) != 0)
                {
                        if(SwizDrawableEntity* drawable_ent = dynamic_cast<SwizDrawableEntity*>(ent))
                        {
                                if((entType & ENT_CRITTER) != 0)
                                {
                                        redLayer.draw(drawable_ent->GetDrawable());
                                }
                                else
                                {
                                        appRef->GetWindow().draw(drawable_ent->GetDrawable());
                                }
                        }
                }
        }

Vertex shader:
void main()
{
    // transform the vertex position
    gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;

    // transform the texture coordinates
    gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;

    // forward the vertex color
    gl_FrontColor = gl_Color;
}

Fragment shader:
uniform sampler2D texture;

void main()
{
    // lookup the pixel in the texture
    vec4 pixel = texture2D(texture, gl_TexCoord[0].xy);
        vec4 blackpixel = vec4(0.0f,0.0f,0.0f,0.01f);

    // multiply it by the color
    gl_FragColor = gl_Color * pixel * blackpixel;
}

PS: The circle symbol in the screenshot is the mouse cursor.

3
Network / Re: UDP | Make client receive response from server
« on: February 05, 2013, 04:58:27 pm »
I got it to work sort of but currently both the server and client require their ports to be open for it to work.  :-\

4
Network / Re: UDP | Make client receive response from server
« on: February 05, 2013, 04:28:00 pm »
The 'Socket' sample code only does both sending and receiving for the TCP portion.
I'm using UDP.

Main problem with my code is that I don't know how to make get the client to receive the message from the server.

Which is most likely caused by the port I'm trying to bind it to.
I set it to port 0 because I don't know how to get the port the server will be sending the message to.
It seems that only the server knows which port the client used to communicate with it.
                //Listen for connection on port ...
                ClientSocket.Bind(0);

                char Buffer2[128];
                size_t Received;
                sf::IPAddress Sender;
                unsigned short Port;

                //Receive data from server
                if(ClientSocket.Receive(Buffer2,sizeof(Buffer2),Received,Sender,Port) == sf::Socket::Done)
                {
                        std::cout<<Buffer2<<std::endl;
                }

5
Network / UDP | Make client receive response from server
« on: February 05, 2013, 04:09:58 pm »
Hello everyone,

I've been trying to setup a simple UDP server and client but I've got this one issue.
I would like to make it so that the server sends a message back to the client after the server has received a message from that client.

It would go like this.
  • Client sends message to server.
  • Server receives message. Sends another message back to client.
  • Client receives message.

My idea is that the client will send a command to the server for example. Like a request.
The server would then send a packet back to the client containing the requested information.
For example position info.

I might be doing it all wrong and if so. Please feel free to take out the hammer and bash my brains in.

:)

Client (area that is most likely responsible for the issue)
                //Listen for connection on port ...
                ClientSocket.Bind(0);

                char Buffer2[128];
                size_t Received;
                sf::IPAddress Sender;
                unsigned short Port;

                //Receive data from server
                if(ClientSocket.Receive(Buffer2,sizeof(Buffer2),Received,Sender,Port) == sf::Socket::Done)
                {
                        std::cout<<Buffer2<<std::endl;
                }

Client console output
Failed to receive data ; the UDP socket first needs to be bound to a port

6
SFML projects / GravNav - simple glitchy planet simulation prototype
« on: February 04, 2013, 09:29:37 pm »
Hey guys,

My first post here on the forums after having lurked for a bit.

I started messing with SFML a few days ago and I have to say that I'm liking it so far.

After familiarizing myself with SFML for a bit I setup this little project.
Right now it's pretty glitchy and when the player crashes into a planet it actually crashes the game right now. :3

It runs in windowed mode @ 720p



Download | Public build

Issues I'm trying to work out:
  • Make new planet adjust velocity based on distance from closest planet to get into an orbit
  • Fix player crash (once I got going the code got rather messy so this pretty much equals a cleanup)
  • Drawing the trajectories (past or maybe even future) of the planets

It would be great if you guys could give me some hints as to how I can make it so a trail is drawn behind the planets to show where they have been. To sort of visualize the trajectories.

Pages: [1]
anything