trying to draw background image but seems offset...

Started by VoS, December 28, 2009, 17:57:47

Previous topic - Next topic


Went through the 3d Asteroids tutorial and think i understand most of it.
Anyways Im trying to make a 2d side artillery game just to get a better feel for the engine.

im generating a random terrain in two stages, first a 2d array of 1 and zeroes used for collision detection and secondly a .png image to place as a backdrop on the screen.

I'm drawing a the background using.
private void drawBackground(GameWindow window) {

		int x = ((int) player.getX()) - world.getMaxXWidth();//- world.getMaxXWidth()-850);
		int y = ((int) player.getY() - 15) ;

		System.out.println(((int) player.getX()) + " x "+ ((int) player.getY()) +" - - "+x + " . " + y + " img: "+ databank.getBackgroundStillImage().getImageWidth()+"x"+databank.getBackgroundStillImage().getImageHeight() );



As you can see im adding and subtracting the width and height of the image just to get it into the place it is now...
Even so, for some reason this does not seem to be on the same scale as when i draw my 3d model (thats done in the same way as showed in the 3d asteroids game tutorial,


My image is 400x400 pixels big.

When i get the image to line up with my world's 0,0 (bottom left) the top right corner of the image is not at 400, 400.
It is instead around 300x300.. it s like the image is being scaled down.

Not sure whats causing it, most likely im doing something wrong, documentation isent exactly heavy so what i have now ive mostly gotten by testing.

Heres a picture to help explain ( im still using the space ship model in the tutorial untill i can make my own ;) )
The ship in the picture is at the edge of the world, 400 x 400 but the image is not, when im at 0,0 i have gotten it to align

I placed the red box in the image to check if i was stretching it..

The output below is from the system.out visible in the code.


it is scaling it down by about 25% in all directions =/

When i add 100 px to width and height it is about the size of the original image (comparing to an image editing program holding the windows by each other).

So somewhere ive done something stupid.. dammnit this is annoying...


figured out that the problem was that my image wasent 512 x 512..

So now im at a new problem.

How do i draw a
  of ANY given size?


The  problem is that older graphic cards are not able to draw graphics with non-power of 2 height and width. They are able but they mess the graphics up massivly.

The only way to handle this problem properly is to create a new image with the next larger power of 2 size and draw the graphic you want to draw onto.
When drawing your image you only have to draw a part of the larger image version.