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

Pages: 1 ... 18 19 [20] 21 22 ... 34
286
Graphics / Re: Shape "following" the end position of a sprite
« on: April 13, 2016, 11:47:31 pm »
Look up Scene Graphs. The SFML Game Development book provides a good example of this.  ;)

287
Graphics / Re: Blending colors
« on: April 09, 2016, 11:26:50 pm »
Unfortunately you can't just draw on top of things and expect them to blend. You should probably look at blend modes. In this case I believe you want sf::BlendMultiply (255 * 255 * 0 = 0 == Black).

288
Graphics / Re: SceneGraph + Layers Concept
« on: April 09, 2016, 12:12:21 pm »
I've not tried it with a scene graph, but you might be able to adapt this technique.

289
Graphics / Re: SceneGraph + Layers Concept
« on: April 08, 2016, 11:19:22 pm »
For the concept of layers I use multiple root nodes. Assuming your graph is set up so that draw(node) traverses the node's tree drawing each child node from the bottom up, then drawing multiple root nodes one after each other effectively draws in layers. For example:

std::array<Node, 4u> layers;
for(const auto& layer : layers)
{
    draw(layer);
}
 

Each of these is a root node, so layers[0] draws all its children, followed by layers[1] and so on. If it helps you can label them with an enum:

enum LayerID
{
    Back = 0,
    Middle,
    Front,
    UI
}

layers[LayerID::UI].addChild(myUINode);
 

I have a practical example of it here.

290
Graphics / Re: Incorrect vertex data in shader with certain drawables
« on: April 08, 2016, 11:31:12 am »
Ah, OK, thanks for clearing that up. I had it in my head that the light should be in the drawable's space if I wanted it to be relative to it - it makes much more sense now (and, of course, probably would be more apparent if I were using modern shaders ;) )

291
Graphics / Re: Check collision with vector of shapes
« on: April 06, 2016, 03:02:17 pm »
Take a look at this for beginner collision :)

292
Apologies for the vague title, it's a little difficult to summarise in a few words. The problem is this: as far as I can tell drawables with more than a certain number for vertices have incorrect vertex data sent to the vertex shader. I noticed when trying to apply lighting to a scene that drawables such as sf::CircleShape or vertex arrays with a lot of vertices are not lit correctly in relation to the light source. sf::Sprites and quads created with a vertex array are lit fine, however. In this video the light position is set to the cursor:



The only difference between the first and second half of the videos is how the drawables are constructed. Notice in the second half the (rather dark) drawable on the right is only lit when the light source is in the top left corner, as if the drawable was sat at 0, 0. The world transform relative to the light source is not accounted for. Here is a minimal example which draws a sprite and a circle shape. The effect is more noticable: when the mouse cursor is over the sprite a small red dot is drawn - but the mouse has to be in the top left corner for the dot to appear over the circle shape. Apologies for the length of the shader, I gut it best I could.

#define SFML_NO_DEPRECATED_WARNINGS
#include <SFML/Graphics.hpp>

static const std::string vertex =
"#version 120\n"

"uniform vec3 u_pointLightPosition;\n"

"varying vec3 v_eyeDirection;\n"
"varying vec3 v_pointLightDirection;\n"

"const vec3 cameraWorldPosition = vec3(400.0, 300.0, 1780.0);\n"

"void main()\n"
"{\n" \
"    gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;\n"
"    gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;\n"
"    gl_FrontColor = gl_Color;\n"

"    vec3 viewVertex = vec3(gl_ModelViewMatrix * gl_Vertex);\n"
"    v_pointLightDirection = vec3(gl_ModelViewMatrix * vec4(u_pointLightPosition, 1.0)) - viewVertex;\n"
"    v_eyeDirection = ((gl_ModelViewMatrix * vec4(cameraWorldPosition, 1.0)).xyz - viewVertex);\n"
"}";

static const std::string fragment =
"#version 120\n"

"varying vec3 v_eyeDirection;\n"
"varying vec3 v_pointLightDirection;\n"

"vec4 diffuseColour;\n"

"vec3 calcLighting(vec3 normal, vec3 lightDirection, vec3 lightDiffuse, vec3 lightSpec, float falloff)\n"
"{\n"
"    float diffuseAmount = max(dot(normal, lightDirection), 0.0);\n"
"    diffuseAmount = pow((diffuseAmount * 0.5) + 0.5, 2.0);\n"
"    vec3 mixedColour = lightDiffuse * diffuseColour.rgb * diffuseAmount * falloff;\n"
"    return mixedColour;\n"
"}\n"

"void main()\n"
"{\n"
"    diffuseColour = gl_Color;\n"
"    vec3 normalVector = vec3(0.0, 0.0, 1.0);\n"
"    vec3 blendedColour = diffuseColour.rgb * vec3(0.2, 0.2, 0.2);\n"

"    vec3 pointLightDir = v_pointLightDirection * 0.001;\n"
"    float falloff = clamp(1.0 - sqrt(dot(pointLightDir, pointLightDir)), 0.0, 1.0);\n"
"    blendedColour += calcLighting(normalVector, normalize(v_pointLightDirection), vec3(1.0, 0.0, 0.0), vec3(1.0), falloff);\n"

"    gl_FragColor.rgb = blendedColour;\n"
"    gl_FragColor.a = diffuseColour.a;\n"
"}";

int main()
{
    sf::RenderWindow rw;
    rw.create({ 800, 600 }, "Buns");

    sf::Texture texture;
    texture.loadFromFile("whiteSquare.png");
    sf::Sprite sprite(texture);
    sprite.setPosition(100.f, 500.f);

    sf::CircleShape circle(50.f);
    circle.setTexture(&texture);
    circle.setPosition(600.f, 500.f);

    sf::Shader shader;
    shader.loadFromMemory(vertex, fragment);

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

        auto pos = rw.mapPixelToCoords(sf::Mouse::getPosition(rw));
        shader.setParameter("u_pointLightPosition", sf::Vector3f(pos.x, pos.y, 10.f));

        rw.clear(sf::Color::Blue);
        rw.draw(sprite, &shader);
        rw.draw(circle, &shader);
        rw.display();
    }

    return 0;
}
 


293
General / Re: Distribute linux binary using SFML
« on: April 04, 2016, 10:54:23 am »
I had this problem when I wanted to place binaries of my game on itch.io. In the end I found the best solution was to statically link all the dependencies.

294
SFML projects / Re: Screenshot Thread
« on: March 19, 2016, 06:34:36 pm »


A little I8080 based arcade emulator I've been working on, using SFML for rending / input / audio :)

295
SFML projects / Re: Chip8 - A CHIP-8 / SuperCHIP Interpreter
« on: March 04, 2016, 03:12:44 pm »
Is this a problem with the interpreter or recorder that the "sprites" flash sometimes?

Neither, this is how the original machines actually worked :) If there's any problem it's due to the fact the orignal spec defines no process speed, so the result is highly dependent on frame rate :/

296
SFML projects / Chip8 - A CHIP-8 / SuperCHIP Interpreter
« on: March 04, 2016, 03:03:09 pm »
These are a dime a dozen, but I thought I'd have a go too just for funses. I cobbled this together in about 4 days.



A selection of games can be found here and the source here. Requires SFML and SFGUI. The CMake file is tested on linux and there is a VS2015 project for windows. I may possibly add MegaCHIP support, but for now I'm bored and am going to move on :)

EDIT: I've also written a short blog post about the bytecode format it uses, for those interested.

297
General / Re: Installing TMX Loader
« on: March 03, 2016, 11:10:38 am »
mkdir build && cd build (makedir didn't work, so i changed it with mkdir)
cmake .. && make

Oops, that was a typo, thanks for pointing that out. If you got SFML via apt there is a chance it may be out of date. Your best bet to make sure you're up to date is to completely remove any SFML libraries via the package manager then clone/configure/build/install SFML from source.

298
General / Re: Having trouble with tmxloader
« on: February 26, 2016, 11:27:12 am »
An unresolved external symbol is when the linker can't find the definitions of the requested functions. This is usually because you haven't linked the library in which they reside, or because you didn't compile the .cpp containing them (although there are other causes).

299
General / Re: Having trouble with tmxloader
« on: February 23, 2016, 10:39:19 am »
Did it not come with the zlib library? Where did you get zlib from? This link from the loader wiki explains how to properly build zlib for visual studio.

300
SFML projects / Re: Cendric: An RPG Platformer
« on: February 13, 2016, 09:06:17 am »

Wow, that's your game, isn't it? Looks awesome, I'd love to see more :)

Long abandoned unfortunately since I realised I should have built in networking from the ground up. (It is open source though). Anyway you're doing a far better job, keep it up :)

Pages: 1 ... 18 19 [20] 21 22 ... 34
anything