我在下面的代碼中得到了一些奇怪的寬度/高度值,導致拉伸的圖片或根本沒有圖片。在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