렌더러 클래스에 비트 맵을로드하면 텍스처에 올바른 비율로 텍스처를 렌더링하려고합니다.텍스처를 전체 화면 중앙에 렌더링하고 OpenGL 2.0에서 올바른 비율로 렌더링합니다.
정점 데이터와 텍스처 :
전용 최종 플로트 [] mVerticesData = { -1f, 1F, 0.0f를 // 위치 0 은 0.0f, 0.0f를 // TEXCOORD 0 -1f, -1f , 0.0f, // 위치 1 0.0f, 1.0f, // TexCoord 1 1f, -1f, 0.0f, // 위치 2 1.0f, 1.0f, // TexCoord 2 1f, 1f, 0.0f, // 위치 3 1.0f, 0.0f // TexCoord 3 }};
private final short[] mIndicesData =
{
0, 1, 2, 0, 2, 3
};
그리고 그리기 방법 :
공공 무효 onDrawFrame (GL10 glUnused) {
// Set the viewport
GLES20.glViewport(0, 0, bitmap.width, bitmap.height);
// Clear the color buffer
GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);
// Use the program object
GLES20.glUseProgram(mProgramObject);
// Load the vertex position
mVertices.position(0);
GLES20.glVertexAttribPointer (mPositionLoc, 3, GLES20.GL_FLOAT,
false,
5 * 4, mVertices);
// Load the texture coordinate
mVertices.position(3);
GLES20.glVertexAttribPointer (mTexCoordLoc, 2, GLES20.GL_FLOAT,
false,
5 * 4,
mVertices);
GLES20.glEnableVertexAttribArray (mPositionLoc);
GLES20.glEnableVertexAttribArray (mTexCoordLoc);
// Bind the texture
GLES20.glActiveTexture (GLES20.GL_TEXTURE0);
GLES20.glBindTexture (GLES20.GL_TEXTURE_2D, mTextureId);
// Set the sampler texture unit to 0
GLES20.glUniform1i (mSamplerLoc, 0);
GLES20.glDrawElements (GLES20.GL_TRIANGLES, 6, GLES20.GL_UNSIGNED_SHORT, mIndices);
}
가 지금 임 (작동하지 않는) 비트 맵 크기와 뷰포트를 설정. 비율을 유지하면서 화면에 맞게 텍스처의 뷰포트 크기를 계산하려면 어떻게해야합니까?
감사합니다.