I tried to make a small example.
The problem of an empty variable is not clear yet. In a small example, something works. I don't even know why. I will analyze. But even in this small example, a lot of questions arose. Maybe I'm doing something wrong.
1. It is not clear why two identical variables produce a different value.
2. It is not clear how the sfClock_getElapsedTime function works
She's always returns the same value.
It seems that CSFML does not work like SFML ...
I'll test a little more, but I haven't won the time functions yet.
If necessary, I can post the project and the .exe file.
#pragma argsused
#include <Windows.h>
#include <stdio.h>
#pragma hdrstop
#include <SFML/Graphics.h>
#pragma link "csfml-system.lib"
#pragma link "csfml-window.lib"
#pragma link "csfml-graphics.lib"
int main()
{
sfRenderWindow *window;
sfVideoMode mode= {800, 600, 32};
window = sfRenderWindow_create(
mode ,
"Test",
sfResize | sfClose | sfTitlebar | sfClose,
NULL );
if (!window) return EXIT_FAILURE ;
sfFont *font1 = sfFont_createFromFile("resources/sansation.ttf") ;
sfFont *font2 = sfFont_createFromFile("resources/sansation.ttf") ;
if (!font1 ) return EXIT_FAILURE;
if (!font2 ) return EXIT_FAILURE;
sfText *message1 = sfText_create();
sfText_setFont(message1, font1);
sfText_setCharacterSize(message1, 40);
sfText_setFillColor(message1, sfWhite);
sfText *message2 = sfText_create();
sfText_setFont(message2, font2);
sfText_setCharacterSize(message2, 40);
sfText_setFillColor(message2, sfWhite);
sfClock *clock = sfClock_create();
sfClock_restart(clock) ;
sfTime test1 = sfMicroseconds(100000);
sfTime test2 = sfMicroseconds(100000);
while (sfRenderWindow_isOpen(window) )
{
sfEvent event;
while (sfRenderWindow_pollEvent(window, &event))
{
if ((event.type == sfEvtClosed) ||
((event.type == sfEvtKeyPressed) && (event.key.code == sfKeyEscape)))
{
sfRenderWindow_close(window);
break;
}
}
// float time = sfTime_asSeconds( sfClock_restart(clock) ) ; // update timer
// float ftest1 = time ;
float ftest1 = test1.microseconds ;
char c_test1[10];
sprintf(c_test1, "%f", ftest1);
sfVector2f sfTextPos1 = {50.f , 100.f };
sfText_setPosition(message1, sfTextPos1 );
sfText_setString(message1, c_test1 );
char c_test2[10];
float ftest2 = test2.microseconds ;
sprintf(c_test2, "%f", ftest2);
sfVector2f sfTextPos2 = {50.f , 150.f };
sfText_setPosition(message2, sfTextPos2 );
sfText_setString(message2, c_test2 );
sfRenderWindow_clear(window, sfColor_fromRGB(50, 200, 50));
sfRenderWindow_drawText(window, message1, NULL);
sfRenderWindow_drawText(window, message2, NULL);
sfRenderWindow_display(window);
}
sfClock_destroy(clock);
sfText_destroy(message1);
sfText_destroy(message2);
sfFont_destroy(font1);
sfFont_destroy(font2);
sfRenderWindow_destroy(window);
return EXIT_SUCCESS;
}