# Jittery Sprite On One PC, Blurry Textures On Another

## Recommended Posts

jackdbunny    122
I'm a bit stuck here. I had this working with no problems, but now I'm seeing weird behavior and I can't figure out where it's coming from. The project is more or less an asteroids clone. Left, right arrows rotate, Forward thrusts. THat's all so far. Like I said the ship was working and animating fine. I added in some code for the timer and so some code to make the physics more realistic and all of a sudden when the ship is moving it will "jitter" along the direction of its movement. Almost like for a frame or two it's being redrawn in a previous place, or further back than it should. Or it might be that it's just hanging and drawing the same frame a few times. I can't figure out what it is. I took the new code out that I mentioned I added and I'm still seeing the same thing, so I'm trying to figure out what I introduced that would have caused this. Earlier in development I was getting "double vision" on the image. I'm not sure why it would have caused it, but I had a memory leak due to not cleaning up an object when the program was shut down. When I fixed the memory leak the double vision problem went away. I'm not sure if this is related to that or not, but I can't find anywhere that would be giving memory problems. I would post code, but honestly I'm not sure what code would do the most good. Once the ship is coasting it's just basically like this:
//From inside ship class
this->position.x += (this->velocity.x * elapsedTime);
this->position.y += (this->velocity.y * elapsedTime);

At max speed the velocity comes out to be something like 2.2 pixels every .02 seconds or something like that. Which means I'm getting ~50 fps or more. I don't see why it would be running slow.. it's only one sprite on a black background. If anyone has any advice on how to trouble shoot this, or would like to see more code please let me know. I'm really stumped here. Thanks! EDIT: I forgot to mention how I'm actually translating the sprite. I'm using Direct3D so..
D3DXMATRIX mat;
D3DXVECTOR2 center(12.5, 12.5);
D3DXMatrixTransformation2D(&mat, NULL, 0, NULL, ¢er, D3DXToRadian(this->angle + this->textureRotationalOffset), &this->position);

The textureRotationalOffset is -90. This is because the graphic file points at 90 degrees in relation to the DirectX coordinate system. If anyone knows of a better way to do that I'm all ears also. [Edited by - jackdbunny on August 19, 2008 10:39:34 AM]

##### Share on other sites
MJP    19756
This is probably an issue with timing. How are you measuring your elapsed time per frame?

You may want to try enabling VSYNC, to see if that helps. It will help ensure that your frame is always takes the same amount of time, which isn't usually the case otherwise.

##### Share on other sites
jackdbunny    122

My timing code looks like this:
int WINAPI WinMain(HINSTANCE hInstance,					HINSTANCE hPrevInstance,					LPSTR lpCmdLine,					int nShowCmd){   //Zero memory and set up wc here..   //Register Windows Class   //Create window   //Init directx devices   //Set up game scene   InitGame(gessD3D);  //Shown below...  gets the ticks per second   while(TRUE)   {		      //Handle Windows Messages here	      QueryPerformanceCounter( (LARGE_INTEGER *)&gCurrentTime );      gElapsedTime = (float)(gCurrentTime - gLastTime) / (float)gTicksPerSecond;	gLastTime = gCurrentTime;	//Handle Inputs here...      gessD3D.RenderFrame(gameScene, gElapsedTime);  //Update geometry and draw    }    return msg.wParam;}void InitGame(GeSSD3D& gessD3D){   //Game Init Stuff Here   QueryPerformanceFrequency( (LARGE_INTEGER *)&gTicksPerSecond );}

From RenderFrame elapsed time gets passed down to other calculations. I don't have the problem on the machine I'm on now, so I'm wondering if it's not machine specific (then again the code I have here isn't identical to what I have at home).

How do I set VSync? I'll try it tonight. Is it a Direct3D Device setting? Thanks for all your help!

##### Share on other sites
MJP    19756
To enable VSYNC, set the PresentationInterval of your D3DPRESENT_PARAMETERS struct to D3DPRESENT_INTERVAL_ONE when you're creating or resetting your device. What this does, is it makes the driver wait for for the vertical refresh of your monitor effectively locking your framerate to the refresh rate. It's typically used to eliminate tearing, but will also give you the benefit of an even time period between frames.

##### Share on other sites
jackdbunny    122
I'll definitely give it a try tonight. I wish I could confirm that it's just a problem on my machine. It appears similar to choppy frame rates I'll get on newer games (my machine is a little older.. P4 3Ghz, 1GB of RAM) but I really doubt a single sprite is taxing it that much ;). I'm going to add in some code to provide real time data about the FPS and other things. Thanks for all your help. I'll let you know how the vsync works out.

##### Share on other sites
jackdbunny    122
The VSYNC was a no-go. Same thing. I've sent the exe to a friend to have him test to see if it's just my machine. I'm going to refine the way I'm loading textures, but I don't think it's going to make a difference in this case. Any other ideas?

##### Share on other sites
You could record a video with fraps (google for it) and then upload it. So we can go through each frame and watch the movement of the thing. Then we can see if it moves backward or just stays in one place at the time.

But I really would second that this has to do with bad timing. I'm using the same method to aquire the frametime, however there have been alot of threads (not only in this forum) around, that explained that QueryPerformanceCounter doesn't work on all machines (I'm not shure but I think it was all about multiple cores and different frequencies, but there might be more to this). Anyway, you could try to change the frametime method and use another function to aquire it.

##### Share on other sites
jackdbunny    122
I've tested out fraps. While I haven't found a place to upload the video yet, what I've found is that it's actually SKIPPING a frame. The jump before it skips seems smaller than the rest and then it skips, making it seem like it's hanging. Now even more interesting is that I tested the code on another machine and the ship movement is totally fluid. This machine is much faster which may or may not have something to do with it. However, on this machine my texture looks fine when it's still, but blurs horribly while in motion. Most of the blurring seems to be in the direction of motion. Has anyone seen this type of thing before? This makes me think I've got some setting wrong or that I'm drawing textures totally wrong.

I thought texture size might be a factor as my texture was 50x50 being scaled down to 25x25. So I made a new texture (png format) saved it as 64x64. Tried running it at 64x64 and also tried scaling it by a .5f, .5f vector. Major blurring on both. Any advice? Thanks.

EDIT: Okay I'm an Idiot. The blurring is in the monitor. I get the same effect when I drag a window.. I just never noticed before. Now the question stillr emains as to why I get jumpy animation on one computer but not the other.

Here's a link to the source if anyone wants to have a look:
http://www.reliveyourchildhood.com/files/GeSS.zip

[Edited by - jackdbunny on August 19, 2008 3:00:17 PM]

##### Share on other sites
Extrarius    1412
Depending on the frequency of the performance counter, float might not have enough mantissa bits to store the delta at full precision. Try changing:
gElapsedTime = (float)(gCurrentTime - gLastTime) / (float)gTicksPerSecond;
into
gElapsedTime = float(double(gCurrentTime - gLastTime) / double(gTicksPerSecond));