我在下面的代码中得到了一些奇怪的宽度/高度值,导致拉伸的图片或根本没有图片。在OpenGL(-ES)中设置纵横比,得到奇怪的值
public void onSurfaceChanged(GL10 gl, int w, int h) {
screenHeight = h; // actual height in pixels
screenWidth = w; // actual width in pixels
worldWidth = 20; // width of the projection (20 units)
worldHeight = (int) (worldWidth * (screenHeight/screenWidth));
gl.glMatrixMode(GL10.GL_PROJECTION);
gl.glViewport(0, 0, screenWidth, screenHeight); //new viewport
gl.glLoadIdentity();
GLU.gluOrtho2D(gl, 0, worldWidth, 0, worldHeight); set the 2D projection
所以我记录的变量,这些都是从人像模式:
screenHeight = 455
screenWidth = 320
worldHeight = 20
worldWidth = 20
而(worldWidth * (screenHeight/screenWidth)
应该给20 *三百二十零分之四百五十五为worldHeight = 28。
它会变得在横向模式下的陌生人,其中worldHeight突然等于0
我在做什么错?
哦ofcoarse,适合症状完美!明天去试试看。 – user717572