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

Pages: [1] 2
SFML projects / Another Snake Clone
« on: December 29, 2017, 02:29:51 pm »
Hello everyone,

i wanna show you my actual project, its another Snake Clone.
Its actually in "Demo Mode" xd
Link for the download: Snake.7z
Code is in my Github(but its not every time actual).

- Windows OS(just tested it on Windows 10)
- SSE and rdrand feature of your CPU could be nice
- About 60-80MB Video Ram
- Pixel Shader Support

Some Details:
- Actually 2 "maps"
- Different items to get score/speed/health
- An autokill function, otherwise you could play it infinite
- Pause
- Speed Up Items x2,4,8 are not really x2,4,8, because it would be to fast for you ;-)
- Not directly dead if you hit a wall or the snake themself. Game decides the next movement
- You can control the snake with the Arrow Keys, Escape is for pause

Dev Details:
- Compiled with C11 and gcc on Windows 10. (Codeblocks)
- CSFML used
- Sounds are from freesounds
- Pictures are self created with gimp
- tile based maps, a big picture file + tile data file

Known Bugs:
- Setting & Highscore system got some bugs(setting page has only 15-30fps oO)
- Sometimes Items are spawned in the same position as other items, so maybe you wonder why you picked a food item, and you get faster or get health, iam actually not sure, where the problem is.
- After get died, a weird sound appears in the finish screen.
- The Auto Direction Set for Wallhit/Selfhit is not 100% working. A "Deadlock" Moving(like a spiral) will sometimes not cause a direct dead, sometime the snake moving through themself.

Next Steps:
- searching item spawn problem
- cleaning up my header managment and structure managment(actully its a big dumping ground xd)
- Rework Settings & Highscore subsystem
- Split CSFML subsystem and Menu subsystem(actually in one file)
- Rework completly menu subsystem(need to make more generic)
- implement the enemy subsystem
- implement the event subsystem(needs an enemy subsystem, blank part in level are existent)
- making a little syscheck subsystem(for checking for sse and rdrand)
- maybe rework Movement View(if youre near the wall, you will see black outside the map)
- making it complete in english, actually is mixed with german and english language^^

A picture:

My actually highscore in the map 2 is 14.332. Maybe you could beat me^^

Any criticism, proposals, tips are welcome!

Greetz MOP

C / Re: I want to make my cursor
« on: November 28, 2017, 09:46:44 am »
Hey Laurent,

thanks for feedback. That hint must be a secret ! :o
I should read some of the auto-suggestions exactlier if i type some functions in my editor ;-)

Greetz MOP

C / Re: I want to make my cursor
« on: November 27, 2017, 11:16:02 pm »
Hey Hiura,

thanks for replay. As you saw in my last post, i wrote "magic stuff with CPP", in this answer you can see, i dont have any bit of knowledge of C++.

In my highly noobyness i would say, just append another Function with an other function argument in the Mouse.cpp ( https://github.com/SFML/CSFML/blob/master/src/SFML/Window/Mouse.cpp )
and rename the other function.
Use a generic define in Mouse.h File and go?

Code: [Select]
// Renamed
sfVector2i sfMouse_getPosition_WN(const sfWindow* relativeTo)
    sf::Vector2i sfmlPos;
    if (relativeTo)
        sfmlPos = sf::Mouse::getPosition(relativeTo->This);
        sfmlPos = sf::Mouse::getPosition();

    sfVector2i position = {sfmlPos.x, sfmlPos.y};
    return position;

// with RenderWindow
sfVector2i sfMouse_getPosition_RW(const sfRenderWindow* relativeTo)
    sf::Vector2i sfmlPos;
    if (relativeTo)
        sfmlPos = sf::Mouse::getPosition(relativeTo->This);
        sfmlPos = sf::Mouse::getPosition();

    sfVector2i position = {sfmlPos.x, sfmlPos.y};
    return position;

In the Mouse.h
Code: [Select]
CSFML_WINDOW_API sfVector2i sfMouse_getPosition_WN(const sfWindow* relativeTo); // The Normal Function
CSFML_WINDOW_API sfVector2i sfMouse_getPosition_RW(const sfRenderWindow* relativeTo); // The RenderWindow Function
#define sfMouse_getPosition(X) _Generic((X), sfWindow*: sfMouse_getPosition_WN, sfRenderWindow*: sfMouse_getPosition_RW)(X)

I just make a minimal example with the generic stuff
Code: [Select]
float Test1(const float* A)
    return A[0] + 2.0f;

int Test2(const int* B)
    return B[0] + 4;

#define Test(X) _Generic((X), float*: Test1, int*: Test2)(X)

int main (void)
    float Float_Array[2] = {5.0f, 0}; // just for testing a pointer type
    int Int_Array[2] = {10, 0}; // just for testing a pointer type
    printf("Test Float: %f\n", Test(Float_Array)); // Outputs 5.00 + 2.00 = 7.0000
    printf("Test Integer: %d\n", Test(Int_Array)); // Outputs 10 + 4 = 14
    return 0;

(compiled -std=c11)

Maybe theres a easier way in magic cpp. Not easy to oversee the billion of semantics in CPP.

Greetz MOP

C / Re: I want to make my cursor
« on: November 24, 2017, 08:55:17 pm »
Hey luffy50660,

first of all, clear created "objects" and set it to NULL, to let dangling pointer no chance to act.

If i understand your problem right, you wanna use a custom mouse cursor picture, instead of the OS Cursor?

Code: [Select]
sfWindow_setMouseCursorVisible(window, sfFalse);
// Sets the OS Cursor invisible

sfSprite_setTexture(cursor, texture2, sfTrue);
// Sets your custom texture to the sprite

sfVector2i cursor_coord;
cursor_coord.x = 1280;
cursor_coord.y = 769;
sfMouse_setPosition(cursor_coord, window);
// Sets your invisible OS Mouse Cursor at application start to bottom right
// there is no sense in there

In your main loop, i dont find anything about update your cursor position.


First set the Initial Position of Your Cursor Sprite and update it in your main loop.

I made some minimal running example.
Code: [Select]
#include <stdio.h>
#include <stdlib.h>
#include <SFML/Audio.h>
#include <SFML/Graphics.h>
#include <SFML/Window.h>
#include <SFML/System.h>

int main()
    // Variables
    sfVideoMode mode = {600, 600, 32};
    sfEvent EventLoop;
    sfRenderWindow *screen;
    sfSprite *Cursor_Sprite;
    sfTexture *Cursor_Texture;
    sfVector2f Cursor_Position;

    // Init Stuff
    screen = sfRenderWindow_create(mode, "Minimal Example", sfClose, NULL);

    Cursor_Texture = sfTexture_createFromFile("MouseCursor.png", sfFalse);
    Cursor_Sprite = sfSprite_create();

    // Check created Stuff
    if(screen == NULL || Cursor_Sprite == NULL || Cursor_Texture == NULL)
        return 0;

    // Get Initial Position
    Cursor_Position.x = sfMouse_getPosition(screen).x;
    Cursor_Position.y = sfMouse_getPosition(screen).y;

    // Set Texture to Sprite
    sfSprite_setTexture(Cursor_Sprite, Cursor_Texture, sfFalse);
    sfSprite_setPosition(Cursor_Sprite, Cursor_Position);

    // Set Windows Cursor invisible
    sfRenderWindow_setMouseCursorVisible(screen, sfFalse);

    // Main Loop
    while (sfRenderWindow_isOpen(screen))
        // Proceed Events
        while (sfRenderWindow_pollEvent(screen, &EventLoop))
            if(EventLoop.type == sfEvtClosed)

        // Update Stuff
        Cursor_Position.x = sfMouse_getPosition(screen).x;
        Cursor_Position.y = sfMouse_getPosition(screen).y;
        sfSprite_setPosition(Cursor_Sprite, Cursor_Position);

        // Draw Stuff
        sfRenderWindow_drawSprite(screen, Cursor_Sprite, NULL);

        // Display it

        // Clear Window
        sfRenderWindow_clear(screen, sfBlack);

    // Clean up
    Cursor_Sprite = NULL;
    Cursor_Texture = NULL;
    screen = NULL;

    return 0;

Hope that will solve your problem

Greetz MOP

passing argument 1 of 'sfMouse_getPosition' from incompatible pointer type [-Wincompatible-pointer-types]

Please make an update for csfml, and make magic stuff with CPP.

I saw a topic about this at the year: on: 2012

Thats atleast 5 Years...

Is there no support anymore for the C Binding ? That makes me sad...

C / Re: Memory Leak CSFML 2.4
« on: November 16, 2017, 01:52:39 pm »
How to find that out?

My laptop got a iGPU(630) and dedicated GTX1050Ti, when i switch the GPU for running my app, the amount of leaking mem is the same.

As i said, it doesnt affect me. Just for interest.

C / Re: Memory Leak CSFML 2.4
« on: November 15, 2017, 12:25:35 pm »
Hey Leandre

i consider youre using some linux distribution, if youre using valgrind.
I got same little memory leaks with CSFML. I use Dr Memory. I got some leaks with sfRenderWindow & sfView. But it doesnt rly affect me(around 30kb)
But why you want to clear it? If it doesnt affect your application, it is ok. Linux got a MPU, which cleans all Memory at processs termination, like in windows.
An little example, free() doesnt give always the memory back to the OS. This is not guaranteed. That makes the OS himself at process termination.

On the other side, you cant change that maybe. And not every leak that is reported by a memory tool, is a really or dangerous leak.

Maybe read this:

There also some posts about the memory tools.


Graphics / Problem Calculating Step Movement by Time
« on: November 10, 2017, 08:39:01 pm »
Hi people,

actually i got some problems by timestep calculation (for sfView Movement).
I get for my Snake a block-wise movement, cause block-wise setup for it. Iam using bigger "tilemaps" for an level. So i decided to create some custom view. Actually, the view is moved also block-wise. But imo i could be possible to make the View move smoother. Since the snake setup is block-wise, it couldnt be make a smooth movement.

I build up a central "managment" for time things, in which i set a SecondTick and SnakeTick flag.
SecondTick is just for update my score "+1".
SecondTick release every second, and SnakeTick release "1 Second / Snake Speed".

My Handle Items, Snake Movement is updated every SnakeTick. And Rendering Stuff has no time limit.
(my Movement to the View is actually inserted in the Snake Handle). So the View Move is also block-wise.

(I Call my Update Functions HandleXXXX, dont be confused for the terminology ).

Okay thats was the background.

Now i tried some calculations.

sfView Movement per Tick: 25.0f (x or y depent on direction)
Actually my SnakeTick is: 1 Second / 3 Speed = 333ms
If we have SnakeTick: 1 Second / 4 Speed = 250ms
and so on..

So at 333ms the View must be moved by 25.0f
And at 1 Second the View must be moved by 75.0f

TestValue shall be the Value to be Moved.
The Exactly Frame Move is similar. The Sum into a Full SnakeTick must be exactly.

My Idea which i test:
(its C)
Code: [Select]
TestValue += (GameClock.GC_DeltaTime * 25.0f * GameSnake.S_Speed);

        printf("TestValue must be 25.0f: %f\n", TestValue);
        TestValue_Extended += TestValue;
        TestValue = 0.0f;

        printf("TestValue_Extended must be 75.0f: %f\n", TestValue_Extended);
        TestValue_Extended = 0.0f;

But i get the following Output:
Code: [Select]
TestValue must be 25.0f: 25.320147
TestValue must be 25.0f: 25.297354
TestValue must be 25.0f: 25.276875
TestValue_Extended must be 75.0f: 75.894379
TestValue must be 25.0f: 25.344891
TestValue must be 25.0f: 25.220773
TestValue must be 25.0f: 25.210583
TestValue_Extended must be 75.0f: 75.776245

As you see, i cant actually the "right value".

The Movement by a frame is similar. But the Sum to a full SnakeTick have to be exactly 25.0f, otherwise it will definitly lead to crazy bugs.

Do you have an idea, what can i do?

Thanks in advance

Greetz MOP.

General / General question about Rotation Function
« on: November 07, 2017, 11:29:59 pm »
Hello people,

just a general question / ask for feature.

In my actual project i need some rotation, and i was really confused and suprised, that the object rotate in the wrong direction x) Firstly i thought i got some brainbugs, then i realized that the rotation is every time clockwise. So i looked up for an option to inverse that. Actually i realized with it in my shader for the object.

I read the article on the tutorial, and i understand why it is clockwise, becuase of the down mirrored coordinate system.

So why is this a bit nervy for me, i created my object texture aligned to the first quadrant. If i would use the current clockwise rotation, the code could be a bit non-comprehensible imo.

Whats about a feature like:
sfSprite_setRotation(90.0f, true) [C] true = anticlockwise, false = clockwise
Sprite.setRotation(90.0f, true) [C++]

I looked up the source, maybe it is just an extra rotation matrix which is inversed.

I know this seems like a bit fussy, but i get really brainbugs, with the clockwise rotation. I learned that rotation is every time anti clockwise according to euclidean room ;)

Dont hate me  :(

Greetz MOP

C / Re: Shader set a Float Uniforms causes to Crash
« on: November 03, 2017, 08:43:05 am »
I did this. But in the Debugger it doesn't crash :o

I found another way to check the problem. I found it and resolve it.

My shader array of pointers got a bug, element 0 and element 1 got the same pointer address, which cause to segmentation fault.

C / Shader set a Float Uniforms causes to Crash
« on: November 01, 2017, 10:23:10 pm »
Hello folks,

iam currently working on my Snake Project, actually trying to implement some Item Stuff. I applied for every Item(Food, Speedups, Healthups) a file, which contains simplify a Struct. In this Struct are some propertys saved and Path Names to Shader and Textures. For every Item i load Stuff.

Actually i have the Problem, if i "out-comment" this line here:
(in CSFMLGameClock.c)
Code: [Select]
// Set GameTime to Item Shaders
        size_t it;
        for(it = 0; it<GameItem.GI_Items_Count; it++)
            if(GameItem.GI_Coordinates_Setted[it] && GameItem.GI_Placed[it])
                //sfShader_setFloatUniform(GameItem.GI_Shaders[it], "Time", GameClock.GC_Time); // <- This

On Start, it works fine, if i move my Snake then with a key, it directly lead to a crash. Iam not sure, where's the problem. Maybe you can give me some tip.
If it outcommentated, it works fine.

I applied fast a github repo, if you want to see the full code.
You can see it here: https://github.com/MasterOfPenetrator/SnakeGame


C / Re: Error csfml 2.4 & 2.3 codeblocks
« on: October 26, 2017, 09:51:36 am »
Cool, have fun.

Maybe someone of the Dev Team will update/proof the files of the C-Bindings and update on official download site^^

C / Re: Error csfml 2.4 & 2.3 codeblocks
« on: October 24, 2017, 08:34:47 pm »
Hey gldsn,

got same errors few days ago. The Static Libary for GCC doesnt contain the Default Color Symbols.
Its a bug by the converting Tool, which the SFML Dev's used.

See here: https://en.sfml-dev.org/forums/index.php?topic=22626.0

In my last post, i created my own Libary(Graphics), you can download it and replace it, with yours.
It should work.


C / Send a Struct Array to a Shader
« on: October 23, 2017, 12:46:18 pm »
Hi folks,

actually iam faced with a little problem. Iam actually using a pixel shader for diffuse/normal/specular mapping with different lights(point and cone lighting). I wanna reorganize my shader Input to a single Struct.
But iam not to find a function to set a uniform struct directly to a shader.

Iam actually making a snake game, with different "levels"(levels splitted to a texture, a textform tilemap, a eventmap(e.g. for boss "fights")). The Map-Texture included all Tiles, excluded dynamiclly tiles(like bosses, foods, powerups etc.), to reduce Texture handles and resources. Okay thats was a bit OT.

Also i wanna place and remove dynamiclly lights to the maps.
Actually my solution is very creepy :x

I got a struct-like organisation(C):
Code: [Select]
// Game Lichter
sfGlslVec3 *GameLight_Lightpos;
sfGlslVec3 *GameLight_Conepos;
float *GameLight_Coneactive;
float *GameLight_FBMactive;
float *GameLight_Ambientactive;
float *GameLight_Coneangle;
bool *GameLight_type;
size_t light_count;

And when i add or remove lights, i use the mm functions from std, like malloc/realloc etc.
My Shader contains this(did in german language):
Code: [Select]
uniform vec3 Licht_Position[MAX_LIGHTS];
uniform vec3 Kegel_Position[MAX_LIGHTS];
uniform float Licht_Kegel_Aktiv[MAX_LIGHTS];
uniform float FBM_Kegel_Aktiv[MAX_LIGHTS];
uniform float Ambient_Aktiv[MAX_LIGHTS];
uniform float Licht_Kegel_Winkel[MAX_LIGHTS];
uniform int Anzahl_Lichter;

As you see, i setted up the bool-like variables to a float, cause, i dont find a function like:

Now i wanna reorganize my Shader Input to a single Structure, also in my C Code.

Is there any possibility with the SFML Framework to do this?

Thanks in advance!

Greetz MOP

i was successfully, now the tool generated a good .a file.

I put all missing symbols from the graphics libary manually to the .def file. My compiling and linking now works good.

In my attachment you find the .def file and the .a file.

Some things got my attention, in your Source Code

All exported "Structs" got his own ExampleStruct.h File.
On the other Side, such like BlendModes or Colors, got no own .h File.
The defines are in the .cpp file. Maybe there's a problem?

Iam not the expert on C++ and your code of course, but it is maybe an idea ?!


some update from me about linking.

If you built up a 32 Bit project, MinGW supports for 32 Bit also *.lib libarys, i tested it. But i just got the same error, with the default Colors / Blend Modes.

Another try, i used the converter tool LIB2A. This tool generate a .def File without these symbols...

It seems the Tool just generates symbols, which has some functions

sfTestSymbol ---struct
sfTestSymbol_FunctionTest ---function to the struct
sfTestSymbol_FunctionTest2 ---another function to the struct

All of these symbols are exported.

If you got:
sfTestSymbol1 ---struct
sfTestSymbol2 ---struct
sfTestSymbol3 ---struct
sfTestSymbol4 ---struct
sfTestSymbol4_Explode ---function to the struct

It just export the last 2 Symbols and ignores the first 3.

And the converter uses the .def file to generate an .a file.
If i open the .a lib with 7zip (a tip from me, if you want to see Symbols in a,lib,dl file).
I only see the symbols in my .a file which was defined in the .def File.

It is maybe a bug in LIB2A tool, or desired?

I try to put manually missing symbols to the .def file and post for update.

Pages: [1] 2