作者chrisho (sudoku)
看板GameDesign
標題[程式] Android開發opengl UV貼圖會怪?
時間Tue Oct 25 13:09:01 2011
目前在使用 OpenGL 想移植以前寫在 SurfaceView 的遊戲, 有些地方有問題:
裝置是 defy cm7 2.3.7
Android 搭配 OpenGL 秀圖,使用Vertex array drawing(沒有frame buffer)
如果一張圖要用uv移位來存取 texture 的某一區域, 會受到 GLU.gluOrtho2D
的影響嗎? 例如 我要從 x=1,y=1 取 32x32 的大小, 秀在某些位置(不一定)
會出現不是想要的結果(變成 x=1,y=0,取32x32的大小)
圖1:
http://i1105.photobucket.com/albums/h355/ch_mac/device_str5.png
右邊那塊超長由上畫到下的是只有 32x1 的大小, 從0畫到480,
結果不是圖2這樣 :
圖2:
http://i1105.photobucket.com/albums/h355/ch_mac/device_str6.png
用 SurfaceView 則正常..
不知是哪裡有問題,
stackoverflow 全文 :
http://bit.ly/s6JdNh
OnSurfaceChanged 的程式碼 :
//抓得到 w=854,h=480
gl.glViewport(0, 0, w, h);
gl.glMatrixMode(GL10.GL_PROJECTION);
gl.glLoadIdentity();
//如果不設定這兩行, 畫面會很小(原本就只繪製480x320)
w=480;
h=320;
GLU.gluOrtho2D(gl,0, w, h, 0);
//本來想用 glScalef 來調整畫面比例去縮放, 好像在某些倍率有破碎情況
//ex:貼圖邊緣各有 1 像素不定位的出現誤差(如圖1).
float ratio_w=1.0f;
float ratio_h=1.0f;
ratio_w=1.78f;
ratio_h=1.5f;
//gl.glScalef(ratio_w, ratio_h, 0f);
Log.d(TAG,"changed in:"+w+","+h+","+aspect_w);
// Select the modelview matrix
gl.glMatrixMode(GL10.GL_MODELVIEW);
// Reset the modelview matrix
gl.glLoadIdentity();
--
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 203.74.126.198