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 ... 3 4 [5] 6 7 ... 34
61
Graphics / Re: Drawing Visual Noise Quickly
« on: September 05, 2021, 11:57:46 am »
Much of game making boils down to 'faking it' quite often ;) However the fastest way to do something like this programatically (and most fun way imo, cos shaders are awesome  8) ) is to use a noise shader like this:

namespace
{
    const std::string GreyFrag = R"(
        #version 120
        #define GREY

        )"
;

    const std::string ColourFrag = R"(
        #version 120

        )"
;

    const std::string NoiseFrag = R"(
        uniform float u_time;

        float rand(vec2 pos)
        {
            return fract(sin(dot(pos, vec2(12.9898, 4.1414) + u_time)) * 43758.5453);
        }

        void main()
        {
#if defined (GREY)
            gl_FragColor.rgb = vec3(rand(floor((gl_FragCoord.xy))));
#else
            // these are arbitrary numbers just to provide an offset.
            // you could use uniform values here for a variable effect
            gl_FragColor.r = rand(floor((gl_FragCoord.xy + 17.034765)));
            gl_FragColor.g = 1.0 - rand(floor((gl_FragCoord.xy)));
            gl_FragColor.b = rand(floor((gl_FragCoord.xy + 0.145)));
#endif

            gl_FragColor.a = 1.0;
        })"
;
}


int main()
{
    sf::RenderWindow window(sf::VideoMode(400, 200), "SFML works!");
    sf::CircleShape shape(100.f);

    sf::Shader greyShader;
    greyShader.loadFromMemory(GreyFrag + NoiseFrag, sf::Shader::Fragment);

    sf::Shader colourShader;
    colourShader.loadFromMemory(ColourFrag + NoiseFrag, sf::Shader::Fragment);

    sf::Clock shaderClock;

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

        float shaderTime = shaderClock.getElapsedTime().asSeconds();
        greyShader.setUniform("u_time", shaderTime);
        colourShader.setUniform("u_time", shaderTime);

        window.clear();
        shape.setPosition(0.f, 0.f);
        window.draw(shape, &greyShader);
        shape.setPosition(200.f, 0.f);
        window.draw(shape, &colourShader);
        window.display();
    }

    return 0;
}
 

62
General / Re: Project Files Organization
« on: May 29, 2021, 11:02:12 am »
That's an interesting question. In the world of C++ which is peppered with people preaching best practices and codes of conduct, I've never really seen an article or heard someone talk about file organisation. That's not to say no one ever has, I've just never met them :)

Personally I think it's down to preference, although the type of project does influence how I lay out my source directory. For instance both of my libraries have a relatively oragnised structure with files placed in directories based on what they do, eg graphics or audio. The header files are arranged like this too (much in the same way as SFML's) because it makes it much easier to include them in another project.

On the other hand, for projects which use those libraries I tend to dump all the files in a  single src folder, or possibly split them into src/include. This is mostly down to laziness as I tend to assume that, unlike libraries, I'll be the only person that ever really uses them :)


63
SFML projects / Re: Purcitop Garden - A mini adventure game
« on: May 12, 2021, 11:35:17 am »
Thanks for giving it a play!

You're quite right to point out all the mazes can get very repetitive. When I first started this project it was actually just to test to some procedural generation theory - originally it was just a never ending series of mazes! However, once I'd poured some significant time into it (this was back at the beginning of the first lockdown) I decided it was a waste to let it disappear into my bucket of unfinished projects which is when I started adding the story to it.

Originally I was looking at making it something like Alice in Wonderland, or one of the studio Ghibli stories. In fact the lead character was actually blonde to start with, but I changed her hair colour to make make her stand out more against the background. It also made her look more like American McGee's Alice, rather than Disney's  ;) The character of the daughter is loosely based on Chihiro from Spirited Away. Coincidentally it also made the characters look a bit like friends of mine, which, as it turns out, influenced the game further down the line...
I'd also read somewhere a quote from Steven Spielberg who had said one of the keys to making a fantasy story believable is to start it founded in real life - before dropping your characters down a rabbit hole (or into a talking TV ;) ), which is where the train ride comes from (that and, again, Spirited Away). The character of the Professor is actually an extension of an invisible character in another one of my games Mow Problem - I had actually considered making the entire experience basically one large advert for it, but wisely decided not to in the end  ;D

With this in mind it was a fairly logical step to add more mini-games, platform sections and collectibles and so on, to try and break the mazes up as much as possible. It worked to a certain extent, but I never finished some of the planned features such as the 'greenhouse' mode, where you could plant the seeds found in the main game, and nurture them in an entirely separate context - kind of like a plant based Tamagotchi. I may revisit this idea sometime in the future and add it via an update.

In the end it was just a fun project to make, and has proven quite popular with people who play it with their children - possibly because it only takes an hour or so to complete and can be done with a short attention span  8)

If I add any new features, I'll be sure to post them here!

64
SFML projects / Purcitop Garden - A mini adventure game
« on: May 08, 2021, 04:15:55 pm »
If you've been following me on Twitter you'll have seen updates over the past year to my newest game: Purcitop Garden. The game is a procedurally generated, family friendly adventure game made with my SFML based framework xygine.



You can download it (for free!) from itch.io: https://fallahn.itch.io/purcitop-garden

65
Feature requests / Re: Adding VertexArray[i].setTexture
« on: April 30, 2021, 10:45:04 pm »
I can think of a few solutions:

Maintain a vertex array for each different texture. Even if there are 10-20 different textures then drawing this many arrays is negligible. If a province needs to change texture, rebuild the array it was in, and the array it needs to be in, moving the province vertices from one to the other, and thus changing the texture.

Use some shader magic. This wiki page explains how multiple tiles can be drawn using a texture to look up tile indices:
https://github.com/SFML/SFML/wiki/Source%3A-ShaderTileMap
With some work, as long as you don't mind losing the ability to colour your vertices, it could be modified so that the vertex colour is used to select the correct tile, rather than using a lookup texture. Then at runtime changing the colour of the vertex would select the desired tile.

Use some shader and OpenGL magic. Probably over-engineering, but expanding on the previous suggestion you could use a texture array. Then, using the vertex colour property again, you could select the appropriate texture by indexing it via the colour value.

66
General / Re: Get the Screen Location of a VertexArray
« on: April 30, 2021, 06:23:28 pm »
Rather than use sf::Transform directly you might want to try inheriting sf::Transformable, which is what sf::Shape and other drawables do. It provides the getPosition() etc functions:

https://www.sfml-dev.org/documentation/2.5.1/classsf_1_1Transformable.php

67
General / Re: The way to construct 2D scene?
« on: April 21, 2021, 10:57:33 am »
A common approach is to use a scene graph. There's a topic in the SFML tutorials which touches on implementation, and it is covered in detail in the SFML Game Development book.

68
General / Re: getting pixels of a texture
« on: April 17, 2021, 10:31:05 am »
sf::Texture::loadFromFile() also allows you to supply an sf::IntRect which defines a smaller part of the texture you want to load

https://www.sfml-dev.org/tutorials/2.5/graphics-sprite.php#loading-a-texture

You can also use sf::Sprite::setTextureRect() to display only part of a texture

https://www.sfml-dev.org/tutorials/2.5/graphics-sprite.php#ok-can-i-have-my-sprite-now

69
General / Re: SFML and Compute Shaders
« on: April 05, 2021, 10:16:51 am »
You'll need to create a gl loader with something like https://glad.dav1d.de/ and include the resulting files in your project. Note that these may or may not mix well with sfml's graphic module, so you may need to omit that and use the window module directly with opengl. I believe there's an example in the tutorial section  ;D

70
General / Re: Stutter Occurs In Application
« on: March 18, 2021, 10:54:37 am »
To narrow down the cause you could try some code known to work, such as the source of the SFML game development book: https://github.com/SFML/SFML-Game-Development-Book or, if you're desperate ( ;) ), one of my projects: https://github.com/fallahn/xygine . There are of course others in the SFML projects sub-forum which you can check out.

If these run smoothly for you (although experience tells me you will need nvidia's threaded optimisation disabled) then the root cause is likely your code, and you can use the example source as a launching point for creating your own project.

If they don't then there's possibly a problem with your driver/hardware/OS combination. It may or may not also help to enable/disable v-sync. If you have access to another computer then try running your own and the sample code on there, to see if there's a difference.

71
General / Re: Stutter Occurs In Application
« on: March 13, 2021, 12:49:20 pm »
Do you have an nvidia gpu? If so disabling 'threaded optimization' in the nvidia control panel can help.

72
General / Re: 3D Model Projection in SFML
« on: March 08, 2021, 02:49:43 pm »
Broadly speaking it is possible to fudge 3D models with a sfml vertex array, some custom vertex shaders and the glm maths library - there's a proof of concept I came up with here: https://github.com/fallahn/osgc/tree/master/fist/src and a tool for converting models into vertex arrays here: https://github.com/fallahn/osgc/tree/master/lightmapper

If you're interested in how it works I don't mind explaining the concepts - but to be perfectly honest for the amount of work it takes you're better off just using OpenGL directly :)

73
SFML development / Re: C++ standards
« on: March 04, 2021, 01:52:47 pm »
final Can also help with devirtualization and offers performance increases in certain cases:

https://devblogs.microsoft.com/cppblog/the-performance-benefits-of-final-classes/

74
Graphics / Re: Camera Shake
« on: February 17, 2021, 10:52:10 am »
Take a look at views: https://www.sfml-dev.org/tutorials/2.5/graphics-view.php these are basically your in-game camera. Adding some movement to the position will create something akin to camera shake.

75
SFML projects / Re: Selba Ward
« on: February 16, 2021, 05:37:08 pm »
You need to treat your render texture like a window - that is, create it only once, then call renderTexture.clear() before you draw on it, followed by renderTexture.display() when you've finished drawing.

sf::RenderTexture rt;
sf::RenderWindow rw;

rt.create(w,h);
rw.create(w,h);

while(rw.isOpen())
{
    rt.clear();
    //draw stuff
    rt.display();

    rw.clear();
    //draw other stuff
    rw.display();
}

 

Pages: 1 ... 3 4 [5] 6 7 ... 34
anything