trying to draw background image but seems offset...

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

Previous topic - Next topic

VoS

Hey.
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) {

		window.enterOrtho();
		
		databank.getBackgroundStillImage().bind();
		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() );

		GL11.glBegin(GL11.GL_QUADS);
			GL11.glTexCoord2f(0,1);
			GL11.glVertex2i(0-x,0+y);
			GL11.glTexCoord2f(0,0);
			GL11.glVertex2i(0-x,world.getMaxYHeight()+y);
			GL11.glTexCoord2f(1,0);
			GL11.glVertex2i(world.getMaxXWidth()-x,world.getMaxYHeight()+y);
			GL11.glTexCoord2f(1,1);
			GL11.glVertex2i(world.getMaxXWidth()-x,0+y);
		GL11.glEnd();
		
		window.leaveOrtho();

	}

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, http://www.cokeandcode.com/asteroidstutorial)

GL11.glTranslatef(positionX,positionY,0);


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.

VoS

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...

VoS

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
BufferedImage
  of ANY given size?

Nitram

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.

Nitram