Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/40.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone OpenGL ES 2.0纹理_Iphone_Opengl Es_Glsl - Fatal编程技术网

Iphone OpenGL ES 2.0纹理

Iphone OpenGL ES 2.0纹理,iphone,opengl-es,glsl,Iphone,Opengl Es,Glsl,我试图在iPhone上用OpenGL ES 2.0渲染一个简单的纹理四边形。几何体很好,如果在着色器中使用纯色,我会得到预期的四边形: gl_FragColor = vec4 (1.0, 0.0, 0.0, 1.0); 。。。然后绑定纹理并按如下方式渲染: glActiveTexture (GL_TEXTURE0); glBindTexture (GL_TEXTURE_2D, _texture); // this is unnecessary, as it defaults t

我试图在iPhone上用OpenGL ES 2.0渲染一个简单的纹理四边形。几何体很好,如果在着色器中使用纯色,我会得到预期的四边形:

gl_FragColor = vec4 (1.0, 0.0, 0.0, 1.0); 。。。然后绑定纹理并按如下方式渲染:

glActiveTexture (GL_TEXTURE0); glBindTexture (GL_TEXTURE_2D, _texture); // this is unnecessary, as it defaults to 0, but for completeness... GLuint texLoc = glGetUniformLocation(_program, "tex"); glUniform1i(texLoc, 0); glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); 玻璃纹理(GL_纹理0); glBindTexture(GL_纹理_2D,_纹理); //这是不必要的,因为它默认为0,但为了完整性。。。 GLuint texLoc=glGetUniformLocation(_程序,“tex”); glUniform1i(texLoc,0); gldrawArray(GL_三角带,0,4); 。。。我什么也得不到。一辆黑色的四轮车
glGetError()
不返回错误,并且
glIsTexture(\u texture)
返回true


我做错了什么?我已经一遍又一遍地在网上找到了每个例子,但每个人都在像我一样做,调试器向各种GL函数显示了我的参数,这正是我所期望的。

在GLTEXAGE2D之后,用GLTEXAMENT设置MIN/MAG过滤器,默认情况下使用mipmap,因此该代码的纹理不完整。

我遇到了相同的问题(黑色四元组),在jfcalvo的回复引导我找到原因之前,无法找到答案。基本上确保您没有在不同的线程中加载纹理。

确保您使用正确的格式(常量)调用
(GLTEXAGE2D)

确保在
glTexImage2D

这就是我在android上的做法:

    int[] textures = new int[1];
            GLES20.glGenTextures(1, textures, 0);

            mTextureID = textures[0];
            GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mTextureID);

            GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER,
                    GLES20.GL_NEAREST);
            GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D,
                    GLES20.GL_TEXTURE_MAG_FILTER,
                    GLES20.GL_LINEAR);

            GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_S,
                    GLES20.GL_REPEAT);
            GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_T,
                    GLES20.GL_REPEAT);

            InputStream is = mContext.getResources()
                .openRawResource(R.drawable.ywemmo2);
            Bitmap bitmap;
            try {
                bitmap = BitmapFactory.decodeStream(is);
            } finally {
                try {
                    is.close();
                } catch(IOException e) {
                    // Ignore.
                }
 GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, bitmap, 0);
        bitmap.recycle();

确保在S和T方向上都将纹理包裹参数设置为“GL_CLAMP_to_EDGE”。否则,纹理将不完整并显示为黑色

也许你忘了

glEnable(GL_纹理_2D)


在这种情况下,着色器中的texture2D将返回黑色,因为OP似乎会受到影响

和您一样,我也看不出所提供的代码有任何明显的错误。如果你愿意的话,你能把整个项目发布到别的地方吗?一定有一些非常有趣的事情发生了。我不想发布整个项目,但OpenGL代码是在一个自包含的UIView子类中:代码中的其他地方有一些错误——您提供的东西在匆忙连接到测试项目中时可以完美地工作。这就是我写的所有东西,然后我抓起亚马逊首页上的Kindle图片,将其大小调整为1024x1024,并保存为testImage.png,将其作为资源添加到项目中。运行该程序导致我已经这样做了(我在glTexImage2D之前和之后都尝试过)。不走运。glEnable(GL_纹理_2D)在OpenGL ES 2.0上不做任何事情,它只生成GL_无效_枚举。 gl_FragColor = texture2D (tex, texCoord); glActiveTexture (GL_TEXTURE0); glBindTexture (GL_TEXTURE_2D, _texture); // this is unnecessary, as it defaults to 0, but for completeness... GLuint texLoc = glGetUniformLocation(_program, "tex"); glUniform1i(texLoc, 0); glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
    int[] textures = new int[1];
            GLES20.glGenTextures(1, textures, 0);

            mTextureID = textures[0];
            GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mTextureID);

            GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER,
                    GLES20.GL_NEAREST);
            GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D,
                    GLES20.GL_TEXTURE_MAG_FILTER,
                    GLES20.GL_LINEAR);

            GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_S,
                    GLES20.GL_REPEAT);
            GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_T,
                    GLES20.GL_REPEAT);

            InputStream is = mContext.getResources()
                .openRawResource(R.drawable.ywemmo2);
            Bitmap bitmap;
            try {
                bitmap = BitmapFactory.decodeStream(is);
            } finally {
                try {
                    is.close();
                } catch(IOException e) {
                    // Ignore.
                }
 GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, bitmap, 0);
        bitmap.recycle();