【问题标题】:Render texture in fullscreen centered and with the right ratio in opengl es 2.0在opengl es 2.0中以全屏居中并以正确的比例渲染纹理
【发布时间】:2012-08-26 01:41:01
【问题描述】:

我正在将位图加载到渲染器类中,并且我想以正确的比例渲染位于屏幕中心的纹理,并且尽可能大

顶点和纹理数据:

私有最终浮点数[] 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 
};

还有draw方法:

public void 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 );
}

现在我用位图尺寸设置视口(不起作用)。我应该如何计算纹理的视口尺寸以适应屏幕并保持比例?

谢谢。

【问题讨论】:

    标签: opengl-es


    【解决方案1】:
    猜你喜欢
    • 1970-01-01
    • 2016-07-23
    • 2012-01-16
    • 1970-01-01
    • 2019-06-30
    • 1970-01-01
    • 2014-10-28
    • 1970-01-01
    • 2013-07-05
    相关资源
    最近更新 更多