Sign in to follow this  
Witchcraven

Losing resolution

Recommended Posts

Witchcraven    564
I am making 2d sidescrolling game. I am also using opengl for a really high frame rate. And this is causing me some problems. When I animate movement I get calulations like, move starfield 0.3 pixels to the left. All my stars have x,y coords of type int. So what happens is they only move when they move fast enough, which only happens like 1/8th of the time. So what happens is they dont move enough. I solved this by converting the coords to float. But I dont like that solution. Takes more ram than I want to use. Are there any other good solutions? I could store lost precision, but that would take memory,

Share this post


Link to post
Share on other sites
Dmytry    1151
if you do something like
for(every star){move star} ,
it's certanly a bad idea You just need to draw 'em with offset that can be floating point. (
like
float offsetX,offsetY;
.....
offsetX+=0.3;
.....
load your matrix;
glTranslate by offsetX and offsetY;
Draw all stars;
....
)

If you don't want stars to jump by 1 px alltogethe when you're slowly movingr, you may need "fixed point" (that is, store position multiplied by some power of 2, say, 2^4 is enough)

Share this post


Link to post
Share on other sites
ToohrVyk    1595
1- An int is 4 bytes, which is as much as a float (a double is 8 bytes, though), so a float will not take up more memory than an int.

2- Supposing you're using a short int, you will only double your memory consumption. This would add 4 bytes per star, at this rate you would need to have as much as 4000 stars for the additional memory to take up as much memory as a 64x64 texture. Do you ask yourself these memory questions whenever you add a 64x64 texture? Besides, you'll usually have less than 4000 stars (200 seems like a good number : a 8x8 texture).

3- If you really don't want to use anything but short int, use a fixed-point system: store all your objects as short int, but so that the variable contains, say, 10 times the actual value. You can then perform the operations:

Render( x_position/10 y_position/10);
x_position += (int)(0.3f*10);
y_position += (int)(0.3f*10);

This would allow you to have 6553 x 6553 pixel screens without noticeable errors, but should be used as a last resort (slows things down to divide, multiply, and convert to float). (EDIT: yes, dividing/multiplying by 16 instead of 10 accelerates everything).

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
If the whole starfield is to be moved the same way I don't see why you would update the coordinates of each and every star. Just keep the offset for the starfield as a whole in a separate floating point variable and keep the star coordinates in whatever format you like.

Share this post


Link to post
Share on other sites
doynax    850
You probably want to draw objects with subpixel accuracy too (i.e. feed gl with floats).
Things will look a lot better for slow-moving objects.

Share this post


Link to post
Share on other sites
Witchcraven    564
Thats right, floats are only 32 bit. I kept on thinking they were 64 for some reason. Unless opengl can wrap points around the screen as they move, I cannot use gltranslatef to move em, as they need to wrap around. Thanks.

Multiplying by 10 would work too. I thought something like that may work just a second ago.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this