8
我試圖將我的紋理映射到在opengl es 2.0中製作的正方形,當我這樣做時,紋理看起來顛倒了,是我的映射是否錯誤?或者我在繪製它的方式?這裏是什麼樣子的圖片:顛倒的質地? | OpenGL-ES 2.0(android)
,這裏是我的onDrawFrame(代碼)
public void onDrawFrame(GL10 glUnused) {
GLES20.glClearColor(0.0f, 0.0f, 1.0f, 1.0f);
GLES20.glClear(GLES20.GL_DEPTH_BUFFER_BIT | GLES20.GL_COLOR_BUFFER_BIT);
GLES20.glUseProgram(mProgram);
GLES20.glEnable(GLES20.GL_BLEND);
GLES20.glBlendFunc(GLES20.GL_ONE, GLES20.GL_ONE_MINUS_SRC_ALPHA);
GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mTextureID);
mTriangleVertices.position(TRIANGLE_VERTICES_DATA_POS_OFFSET);
GLES20.glVertexAttribPointer(maPositionHandle, 3, GLES20.GL_FLOAT,
false, TRIANGLE_VERTICES_DATA_STRIDE_BYTES, mTriangleVertices);
mTriangleVertices.position(TRIANGLE_VERTICES_DATA_UV_OFFSET);
GLES20.glEnableVertexAttribArray(maPositionHandle);
GLES20.glVertexAttribPointer(maTextureHandle, 2, GLES20.GL_FLOAT,
false, TRIANGLE_VERTICES_DATA_STRIDE_BYTES, mTriangleVertices);
GLES20.glEnableVertexAttribArray(maTextureHandle);
Matrix.orthoM(mProjMatrix, 0, 0, 200, 0, 100, -5, 5);
GLES20.glUniformMatrix4fv(muMVPMatrixHandle, 1, false, mProjMatrix, 0);
GLES20.glDrawElements(GLES20.GL_TRIANGLES, drawOrder.length,
GLES20.GL_UNSIGNED_SHORT, drawListBuffer);
}
爲方形和映射UV協調是:
private final float[] mTriangleVerticesData = {
// X, Y, Z, U, V
0f, 0f, 0, 0.0f, 0.0f,
50f, 0f, 0, 1.0f, 0.0f,
50f, 50f, 0, 1.0f, 1.0f,
0f, 50f, 0.0f, 0.0f, 1.0f };
private short drawOrder[] = { 0, 1, 2, 0, 2, 3 };
我怎樣才能實現右側視圖?
交換方向是不必要的運算有對GPU做。當您加載並翻轉它們時,檢測「顛倒」紋理*一次*是最佳選擇。 – GraphicsMuncher 2013-07-23 00:44:31