Failed to Load and Render wavefront 3D Object with Colors

53 Views Asked by At

After extracting data from the Wavefront OBJ (.obj and .mlt files), I divided my object into submeshes based on each material. In the process, I extracted various buffers such as VBO and IBO ... while also handling cases of duplicated vertices,also, I extracted all the necessary buffers (diffuse, specular, ambient, etc.) from each material. When my object was a cube with 6 textures, one per face,i was able to render it successfully using my program. Each face was drawn using the corresponding index buffer. Everything worked as expected. However, when my object had only five textures and one color, I encountered an issue where the textures loaded correctly, but the color did not load. To further investigate the problem, I decided to test drawing a cube with six colors. Unfortunately, the results were incorrect, with some faces being rendered correctly while others disappeared. I have tried different approaches, including binding the color using glUniform4f and glVertexAttribPointer, but i obtained the same undesirable outcome. I would greatly appreciate any suggestions or insights to help resolve this issue.

draw method :

for (int i = 0; i < glbGenMesh.grpMaterials.size(); i++) {
    if (glbGenMesh.grpMaterials.get(i).texture != null) {
             GLES32.glUniform1i(hastexturehandle, 1);
             GLES32.glActiveTexture(GLES32.GL_TEXTURE0+i);
             GLES32.glBindTexture(GLES32.GL_TEXTURE_2D,
             GLES32.glUniform1i(TextureSampleHandle1, i);

      } else {
            GLES32.glUniform1i(hastexturehandle, 0);
            GLES32.glUniform4f(mColorHandle,
                      glbGenMesh.grpMaterials.get(i).diffuse[0],
                      glbGenMesh.grpMaterials.get(i).diffuse[1],
                      glbGenMesh.grpMaterials.get(i).diffuse[2],1.0f);

                    /* GLES32.glEnableVertexAttribArray(mColorHandle);
                    GLES32.glVertexAttribPointer(mColorHandle, 4, GLES32.GL_FLOAT,
                   false, 0, colorBuffers(glbGenMesh.grpMaterials.get(i).diffuse));
                    */

 }

         GLES32.glDrawElements(GLES32.GL_TRIANGLES, myIndexBuffers.get(i).capacity(), GLES32.GL_UNSIGNED_INT, myIndexBuffers.get(i));

         }

fragment shader :

private final String fragmentShaderCode = " precision mediump float ; " +
        "uniform vec4 uColor ;" +
        "varying float vDiffuseLightWeighting ; " +
        "varying float vSpecularLightWeighting ; " +
        "varying vec3 vAmbientLight ; " +
        "varying vec3 vDiffuseLight ; " +
        "varying vec3 vSpecularLight ; " +
        "varying float vAlpha ; " +
        "uniform int uhastexture ; " +
        "varying vec2 vTextureCoordinate ; " +
        "uniform sampler2D uTextureSampler1; " + //texture

        "void main() { " +
        "vec4 fragmentColor ; " +
        "vec4 diffuseColor = vDiffuseLightWeighting*vec4(vDiffuseLight,1.0) ; " +
        "vec4 specularColor = vSpecularLightWeighting*vec4(vSpecularLight,1) ; " +
        "vec2 textureCoord = vec2(vTextureCoordinate.s , 1.0 -
        vTextureCoordinate.t);" +
        " if (uhastexture == 1) { " +
        " fragmentColor = texture2D(uTextureSampler1, textureCoord )  ; " +
        "} " +
        "else { " +
        " fragmentColor =  vec4(uColor.xyz,vAlpha ) + vec4(vAmbientLight,0) +
        specularColor + diffuseColor ; " +
        "} " +
        "gl_FragColor = vec4(fragmentColor.xyz,vAlpha ) ; " +

        "}";
0

There are 0 best solutions below