0

I am new to Android OpenGl2.0.and I have got one issue while creating 3D model from .obj file. While rendering the 3D model,I am getting blank screen. Sharing the code below,

@Override
public void onSurfaceCreated(GL10 glUnused, EGLConfig config) 
{
    GLES20.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);

    // Enable texture mapping
     GLES20.glEnable(GLES20.GL_TEXTURE_2D);

    // Position the eye in front of the origin.
    final float eyeX = 0.0f;
    final float eyeY = 0.0f;
    final float eyeZ = -0.5f;

    // We are looking toward the distance
    final float lookX = 0.0f;
    final float lookY = 0.0f;
    final float lookZ = -8.0f;

    // Set our up vector. This is where our head would be pointing were we holding the camera.
    final float upX = 0.0f;
    final float upY = 1.0f;
    final float upZ = 0.0f;

    Matrix.setLookAtM(mViewMatrix, 0, eyeX, eyeY, eyeZ, lookX, lookY, lookZ, upX, upY, upZ);        

    final String vertexShader = RawResourceReader.readTextFileFromRawResource(mActivityContext, R.raw.per_pixel_vertex_shader_tex_and_light);           
    final String fragmentShader = RawResourceReader.readTextFileFromRawResource(mActivityContext, R.raw.per_pixel_fragment_shader_tex_and_light);           

    final int vertexShaderHandle = ShaderHelper.compileShader(GLES20.GL_VERTEX_SHADER, vertexShader);       
    final int fragmentShaderHandle = ShaderHelper.compileShader(GLES20.GL_FRAGMENT_SHADER, fragmentShader);     

    mProgramHandle = ShaderHelper.createAndLinkProgram(vertexShaderHandle, fragmentShaderHandle, 
            new String[] {"a_Position",  "a_Normal", "a_TexCoordinate"});   

     // Load the texture
    mTextureDataHandle = TextureHelper.loadTexture(mActivityContext, R.drawable.bumpy_bricks_public_domain);

    // Initialize the accumulated rotation matrix
    Matrix.setIdentityM(mAccumulatedRotation, 0);
}   

*Load texture Function()

        // Read in the resource
        final Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), resourceId, options);

        // Bind to the texture in OpenGL
        GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textureHandle[0]);

        // Set filtering
        GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_NEAREST);
        GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_NEAREST);

        // Load the bitmap into the bound texture.
        GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, bitmap, 0);

        // Recycle the bitmap, since its data has been loaded into OpenGL.
        bitmap.recycle();       

OnDrawFrame() Of Renderer-

// Set the active texture unit to texture unit 0. GLES20.glActiveTexture(GLES20.GL_TEXTURE0);

    // Bind the texture to this unit.
    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mTextureDataHandle);

....

    GLES20.glUniform1i(mTextureUniformHandle, 0);

    // Pass in the position information
    mCubePositions.position(0);
    GLES20.glVertexAttribPointer(mPositionHandle, POSITION_DATA_SIZE_IN_ELEMENTS, GLES20.GL_FLOAT, false, 0, mCubePositions);
    GLES20.glEnableVertexAttribArray(mPositionHandle);

    // Pass in the normal information
    mCubeNormals.position(0);
    GLES20.glVertexAttribPointer(mNormalHandle, NORMAL_DATA_SIZE_IN_ELEMENTS, GLES20.GL_FLOAT, false, 0, mCubeNormals);
    GLES20.glEnableVertexAttribArray(mNormalHandle);

    // Pass in the texture information
    mCubeTextureCoordinates.position(0);
    GLES20.glVertexAttribPointer(mTextureCoordinateHandle, TEXTURE_DATA_SIZE_IN_ELEMENTS, GLES20.GL_FLOAT, false,
            0, mCubeTextureCoordinates);
    GLES20.glEnableVertexAttribArray(mTextureCoordinateHandle);

    GLES20.glDrawElements(GLES20.GL_TRIANGLE_STRIP ,m3DModel.getIndicesLength(), GLES20.GL_UNSIGNED_SHORT, m3DModel.getIndices());

if anyone have an idea or knows this issue,Please give me reply, I am not getting where i did the mistake in the code,

genpfault
  • 51,148
  • 11
  • 85
  • 139
Timmon
  • 19
  • 5
  • Do your shaders compile? Do you get valid handles for program, textures etc? – Simon Nov 06 '13 at 12:15
  • You can also try calling `glGetError` to get some clues to what is wrong. – Simon Nov 07 '13 at 08:23
  • thanks for advice Simon,I have checked with glGetError and it gives an **error code 1280** at, `final int[] textureHandle = new int[1]; GLES20.glGenTextures(1, textureHandle, 0);` what does that mean,and i am not getting any exception on shaders. – Timmon Nov 08 '13 at 09:27
  • i was able to remove the error,just commented the GLES20.glEnable(GLES20.GL_TEXTURE_2D); Now there is no error but still giving blank screen. – Timmon Nov 08 '13 at 09:45

0 Answers0