1
\$\begingroup\$

I'm currently developing a sprite based 2D game for android using opengles 2.0. I've got some basic rendering done that mimics the spritebatch functionality of xna (draw sprite, rotation, color). But all of this works for a fixed projection matrix, but android has a lot of screen sizes.

Q1)Would this be an okay method to scale up/down the drawing?

1)Draw the whole screen to a texture. 2)Draw the above texture as a quad to the device.

I found the above through some searching, not sure if it's the best one, are there any alternatives?

Q2)How do you handle inputs for different resolutions? I currently get the position of a touch and use it raw. Would it be okay to get the position, and then scale the position to size of the texture used for rendering, and the perform calculations on it?

Thanks.

\$\endgroup\$

1 Answer 1

0
\$\begingroup\$

A1. Drawing to a texture and then using it to draw a quad on screen has several problems:

  • you could be rendering more than you have to if the actual screen is smaller
  • you'd get a lower quality rendering if the actual screen is larger
  • that doesn't solve the issue of different screen aspect ratios and you would end up with stretched/squashed image if it's different than the ratio you used for rendering.

The only proper way to solve it is to modify your projection matrix. As you're developing a 2D game you're probably using an ortho projection so this shouldn't be a problem as you only need to scale its height (or top/bottom parameters, depends how you calculate the matrix) with glViewport() taking care of horizontal scaling.

A2. Convert your input to a virtual unit system and have your game accept it, e.g. float virtualX = pointer.getX() / resolutionX; This way if the pointer got moved by 50% of the screen it will always end up being 0.5.

\$\endgroup\$
1
  • \$\begingroup\$ Ahhh, okay. I think I need to use virtual units for everything, and just change my projection matrix depending on the screen size.Previously I wrote for windows phone that had a fixed size for all phones,so I based my logic of those hard values, which was a bad thing. So I guess I need to use virtual units and keep the game logic independent of the phone's numbers. \$\endgroup\$
    – kkan
    Mar 19, 2012 at 0:55

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .