简体   繁体   English

OpenGL ES Android位图纹理未显示

[英]OpenGL ES Android Bitmap Texture not showing

I'm trying to draw a square and add a texture to it. 我正在尝试绘制一个正方形并为其添加纹理。 I'm just starting with OpenGL and I'm following this tutorial http://blog.uncle.se/2012/02/opengl-es-tutorial-for-android-part-vi-textures/ . 我只是从OpenGL开始,正在关注本教程http://blog.uncle.se/2012/02/opengl-es-tutorial-for-android-part-vi-textures/

Here is the code for my squares draw procedure: 这是我的正方形绘制过程的代码:

public void draw(float[] mvpMatrix) {
    // Add program to OpenGL environment
    GLES20.glUseProgram(mProgram);

    // get handle to vertex shader's vPosition member
    mPositionHandle = GLES20.glGetAttribLocation(mProgram, "vPosition");

    // Enable a handle to the triangle vertices
    GLES20.glEnableVertexAttribArray(mPositionHandle);

    // Prepare the triangle coordinate data
    GLES20.glVertexAttribPointer(mPositionHandle, COORDS_PER_VERTEX,
                                 GLES20.GL_FLOAT, false,
                                 vertexStride, vertexBuffer);

    // get handle to fragment shader's vColor member
    mColorHandle = GLES20.glGetUniformLocation(mProgram, "vColor");

    // Set color for drawing the square
    GLES20.glUniform4fv(mColorHandle, 1, color, 0);

    /** now trying to add the texture */

    Bitmap bitmap = BitmapFactory.decodeResource(chamRenderer.context.getResources(), 
            R.drawable.ic_launcher);

    // Create an int array with the number of textures we want, 
    // in this case 1.
    int[] textures = new int[1]; 
    // Tell OpenGL to generate textures.
    GLES20.glGenTextures(1, textures, 0);
    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textures[0]);
    // Scale up if the texture if smaller.
    GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, 
            GLES20.GL_TEXTURE_MAG_FILTER, 
            GLES20.GL_LINEAR); 
    // scale linearly when image smalled than texture
    GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, 
            GLES20.GL_TEXTURE_MIN_FILTER, 
            GLES20.GL_LINEAR);

    // get handle to shape's transformation matrix
    mMVPMatrixHandle = GLES20.glGetUniformLocation(mProgram, "uMVPMatrix");
    Renderer.checkGlError("glGetUniformLocation");

    // Apply the projection and view transformation
    GLES20.glUniformMatrix4fv(mMVPMatrixHandle, 1, false, mvpMatrix, 0);
    Renderer.checkGlError("glUniformMatrix4fv");

    // Draw the square
    GLES20.glDrawElements(GLES20.GL_TRIANGLES, drawOrder.length,
                          GLES20.GL_UNSIGNED_SHORT, drawListBuffer);

    // Disable vertex array
    GLES20.glDisableVertexAttribArray(mPositionHandle);
}

The blue colour display fine but theirs no hope with the texture, no errors, just nothing their. 蓝色显示效果很好,但是他们对纹理没有希望,没有错误,只是他们没有。 Like I said I'm very now to OpenGL. 就像我说的,我现在非常喜欢OpenGL。 Thanks :) 谢谢 :)

If I am reading this right it is displaying the blue and white squares (that looks like tiles) but not the texture? 如果我没看错,它显示的是蓝色和白色的正方形(看起来像瓷砖),而不是纹理? The texture is the image stored in bitmap variable. 纹理是存储在位图变量中的图像。 You do not do anything after creating the bitmap. 创建位图后,您无需执行任何操作。 It looks like you have not finished the tutorial yet; 看来您尚未完成本教程。 the code is that they use to render it is not in your code. 代码是他们用来渲染的代码不在您的代码中。 Look under the part that says UV mapping and look at that code and make sure you include that code. 查看显示UV映射的部分,然后查看该代码,并确保您包括该代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM