Skip to main content
GameDev.net gamedev.net
🔒 Locked

Weird artifacts and Frame Independent Movement

Started by Toshio Aug 19, 2012 at 10:42 AM 5 replies 2k views
Original Post
Toshio
Toshio
Greetings. I have two problems here.

First off, I'm using OpenGL with SDL.

The first problem are weird lines around the transparent PNG picture as shown in the screenshot:
[attachment=10761:screenshot.png]

This is the PNG picture:
[attachment=10762:catanimate.png]

How can I make the lines disappear?

The second problem is Frame Independent Movement. I got it all set up, and I thought it worked until a lot of things went happening at the same time. At some places entities move very fast, at some very slow, depending on what's rendering on screen and what logic is currently happening.

Here is some code:

this is main.cpp:

Uint32 delta = SDL_GetTicks();
SDL_Event event;
g.OnInit();
while(g.running)
{
if(SDL_PollEvent(&event))
{
g.OnEvent(&event);
}
g.OnLoop(SDL_GetTicks() - delta);
delta = SDL_GetTicks();
g.OnRender();
}


and this is how the player, for example, moves:

x += xVel * (delta / 1000.0f);


Thank you for your help smile.png
HarriPellikka
HarriPellikka
I think the artifacts are caused by wrapping. Clamping the texture to edges should prevent this.
Toshio
Toshio

I think the artifacts are caused by wrapping. Clamping the texture to edges should prevent this.


I am using Clamp to edge.


The easiest way to fix those lines is probably to move the texture coordinates by 0.5 pixels. And for your timestepping problem: http://gafferongames...-your-timestep/


How can I move the texture coordinates by pixels?
Sponji
Sponji
Well... if your image's width is 512 pixels, and opengl wants it to the range 0.0-1.0, one pixel's width is then 1.0/512.0. Just move the texture coordinates by 0.5/512.0.
Derp
Hodgman
Hodgman
Another fix for your sprite problem is to insert a row/column of transparent pixels in between each 'cell'.
Toshio
Toshio
Thank you all, fixed the problem by moving the texture coordinates

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.