【问题标题】:GL ES 2.0 Failing to create opengl objectsGL ES 2.0 无法创建 opengl 对象
【发布时间】:2013-06-24 00:00:25
【问题描述】:

基本上我刚刚深入研究了一些 Android 和 OpenGL ES 2.0 编程并遇到了一些问题。

我的代码编译良好并且可以运行,但 opengl 函数似乎无法正常工作。

GLES20.createShader(GLES20.GL_VERTEX_SHADER); 
GLES20.glCreateProgram();

所有都将返回 0。

类似的:

int posHandle = GLES20.glGetAttribLocation(mShader.getProgramId(), "vPosition");

将返回 -1 以此类推。

我如何创建我的活动:

// Activity

protected void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);

    mSurfaceView = new GLESSurfaceView(this);

    final ActivityManager activityManager = (ActivityManager)getSystemService(Context.ACTIVITY_SERVICE);
    final ConfigurationInfo configInfo = activityManager.getDeviceConfigurationInfo();
    final boolean supports_gles2 = configInfo.reqGlEsVersion >= 0x20000;

    if (supports_gles2)
    {
        mSurfaceView.setEGLContextClientVersion(2);
        mSurfaceView.setRenderer(new GLESRenderer());
    }
    else
    {
        //Log.e("", "Doesn't support GLES 2.0");
    }

    setContentView(mSurfaceView);
}

我在 AndroidManifest.xml 中有这个

<uses-feature android:glEsVersion="0x00020000" android:required="true" />

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="16" />   

我认为应该是让 GLES 2.0 的功能正常工作吧?如果需要,我可以提供更多代码,但它基本上只是着色器设置、创建顶点缓冲区然后渲染基本形状。

大家好

编辑:我应该添加 GLES20.glGetError() 返回 GL_NO_ERROR 标志

【问题讨论】:

    标签: android opengl-es


    【解决方案1】:

    好吧,我发现我做错了什么。我在 Renderer 类的构造函数中创建了我的着色器和几何体。我所做的只是将它移到 onSurfaceCreated() 中,一切都很好。

    【讨论】:

      【解决方案2】:

      在 Android 上,所有 OpenGL ES 调用必须从同一个线程执行。如果您使用 GLSurfaceView,它会为您处理线程。本文详细讲解:

      http://software.intel.com/en-us/articles/porting-opengl-games-to-android-on-intel-atom-processors-part-1

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多