0
\$\begingroup\$

I am having trouble creating a sfRenderTexture in CSFML so that I can dynamically update my lighting.

Why does this code:

TerrainSquares[SquareM][SquareN].UpdatedLightMap 
    = sfRenderTexture_create (TEXTURESQUARESIZE, TEXTURESQUARESIZE, sfFalse);

TerrainSquares[SquareM][SquareN].UpdatedLightMapTexture
    = sfRenderTexture_getTexture (TerrainSquares[SquareM][SquareN].UpdatedLightMap);

TerrainSquares[SquareM][SquareN].GPULightMapSprite = sfSprite_create();

sfSprite_setTexture (
    TerrainSquares[SquareM][SquareN].GPULightMapSprite,
    TerrainSquares[SquareM][SquareN].GPULightMap,
    sfTrue
);

sfRenderTexture_drawSprite (
    TerrainSquares[SquareM][SquareN].UpdatedLightMap,
    TerrainSquares[SquareM][SquareN].GPULightMapSprite,
    NULL
);

sfRenderTexture_display (TerrainSquares[SquareM][SquareN].UpdatedLightMap);

Not produce the same result as this code:

TerrainSquares[SquareM][SquareN].UpdatedLightMapTexture
    = sfTexture_copy (TerrainSquares[SquareM][SquareN].GPULightMap);

Here is a visualisation of the problem I'm having.

https://imgur.com/hd6fIgB

Left: Result using sfRenderTexture. Middle: Result using sfTexture_copy. Right:Result using sfTexture_copy with terrain elevations enabled.

The following code works, but why?

TerrainSquares[SquareM][SquareN].UpdatedLightMap
    = sfRenderTexture_create (TEXTURESQUARESIZE, TEXTURESQUARESIZE, sfFalse);

TerrainSquares[SquareM][SquareN].UpdatedLightMapTexture
    = sfRenderTexture_getTexture (TerrainSquares[SquareM][SquareN].UpdatedLightMap);

TerrainSquares[SquareM][SquareN].GPULightMapSprite = sfSprite_create();

sfSprite_setTexture (
    TerrainSquares[SquareM][SquareN].GPULightMapSprite,
    TerrainSquares[SquareM][SquareN].GPULightMap,
    sfTrue);

sfVector2f origin;
origin.x = 0; origin.y = TEXTURESQUARESIZE; 

sfSprite_setOrigin(TerrainSquares[SquareM][SquareN].GPULightMapSprite, origin);

origin.x = 1; origin.y = -1;

sfSprite_setScale ( TerrainSquares[SquareM][SquareN].GPULightMapSprite, origin);

sfRenderTexture_drawSprite (
    TerrainSquares[SquareM][SquareN].UpdatedLightMap,
    TerrainSquares[SquareM][SquareN].GPULightMapSprite,
    NULL
);

sfRenderTexture_display (TerrainSquares[SquareM][SquareN].UpdatedLightMap);
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.