Opengl es 在opengl es 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 }; 以及绘制方法: 公共空间框架(GL10胶合) { 现在我正在用位图尺寸设置视口(不工作)。我应该如何计算纹理的视口尺寸以适应屏幕并保持比例Opengl es 在opengl es 2.0中以全屏居中和正确的比例渲染纹理,opengl-es,Opengl Es,我正在加载一个位图到渲染器类中,我想以正确的比例渲染屏幕中央的纹理,并且尽可能大 顶点和纹理数据: 私有最终浮点[]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 }; 以及绘制方法:
谢谢。也许你应该使用ModelViewPrjoection矩阵。看看这个源代码
private final short[] mIndicesData =
{
0, 1, 2, 0, 2, 3
};
// 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 );
}