#Visual Artifacts when rendering any Texture2D

22 messages · Page 1 of 1 (latest)

real ivy
#

Right now I"m getting a bunch of different line artifacts when rendering textures. One is similar to Tile Bleed, another is tile bleed but with the top of our player texture where black or white lines appear on the edges of the texture. rlDrawRenderBatchActive() seems to help somewhat, but it doesn't completely solve the problem. Any thoughts? I provided a code sample below:

static void update_draw_game_frame() {
if (!has_entered_gameplay) {
has_entered_gameplay = true;
camera.target = player.position;
camera.rotation = 0.0f;
camera.zoom = SCREEN_WIDTH / 640.0f;
}
float deltaTime = GetFrameTime();
Player *playerPointer = &player;

// Call update camera function by its pointer
// Store pointers to the multiple update camera functions
//----------------------------------------------------------------------------------

// Build up the light mask

// Update Player State
update_player(&player, &tilemap, deltaTime);

// Draw
//----------------------------------------------------------------------------------
BeginDrawing();

rlDrawRenderBatchActive();
ClearBackground(RAYWHITE);

BeginMode2D(camera);

for (int i = 0; i < MAX_PROJECTILES; i++) {
Projectile *projectile = &projectiles[i];
if (projectile->is_active) {
DrawTexturePro(
projectile->texture,
projectile->rect,
(Rectangle){projectile->position.x + 24 + (float)(projectile->parity < 0 ? 0 : 16), projectile->position.y + 29, 48, 32},
(Vector2){projectile->velocity.x < 0 ? 0 : 48, 16},
projectile->fire_angle * 180 / PI * (float)projectile->parity,
WHITE);
}
}

// Draw the tile background

draw_tilemap(&tilemap);

DrawTexturePro(
        playerPointer->texture,
        playerPointer->rect,
        (Rectangle) { playerPointer->position.x, playerPointer->position.y, 64, 64},
        Vector2Zero(),
        0.0f,
        WHITE);

EndMode2D();

EndDrawing();

cameraUpdaters[camera_option](&camera, &player, deltaTime, SCREEN_WIDTH, SCREEN_HEIGHT);

}

I'm also calling DrawTexturePro in the draw_tilemap function

#

We are also wrapping all textures with the CLAMP variation

naive lake
#

inset your source rect by a quarter pixel, and/or add a gutter around your tilesheet

real ivy
#

What do you mean by a gutter?

naive lake
#

space between tiles

real ivy
#

Awesome! It worked. Can I ask why?

naive lake
#

because all sprites are 3d geometry with UV maps

#

the GPU will blend with texels around the UV coordinate

#

you can also set the texture filter to point

#

thta can minimize blending

#

the default is bilinear

#

everything in raylib is 3d geometry and is processed by the GPU as 3d geometry

#

none of it is per pixel operations

#

so there are can always be floating point rounding issues and blending like that

#

it's the price you pay for hardware acceleration

real ivy
#

Hey fair enough. Small price to pay.

naive lake
#

if you know you aren't going to scale or rotate, then setting the filter to point will help

#

also, you are on a mac?

real ivy
#

Yes

naive lake
#

yeah, they seem to have very flakey GL drivers

real ivy
#

Unsurprising

naive lake
#

OpenGL is deprecated on the mac