OpenGL ES 2.0: My parsed .obj is all wrong

Started by
0 comments, last by Tchom 10 years, 11 months ago

So, I've recently begun exploring OpenGL ES 2.0 and I've been trying to render and .obj model that I've loaded with a parser that I worked with using OpenGL 1.x (its from Mario Zechner's "Beginning Android Games"). The parsed data is stored in an IntBuffer called 'vertices' in my renderer.

When I try to draw the mesh, however, my "spaceship" ends up looking like this:

LrDF6RR.png

Here's how I'm drawing it:


//Set up program, handles, etc etc

vertices.position(0);
GLES20.glVertexAttribPointer(mPositionsHandle, 3, GLES20.GL_FLOAT, false, 0, vertices);        
GLES20.glEnableVertexAttribArray(mPositionsHandle);        
        
if(hasColor){
	// Pass in the color information
        vertices.position(3);
	GLES20.glVertexAttribPointer(mColoursHandle,  4, GLES20.GL_FLOAT, false, 0,  vertices);        
	GLES20.glEnableVertexAttribArray(mColoursHandle);
}
                
if(hasTexCoords){
	 // Pass in the texture coordinate information
        vertices.position(hasColor ? 7 : 3);
	GLES20.glVertexAttribPointer(mTextureCoordinatesHandle, 2, GLES20.GL_FLOAT, false, 0,  vertices);
	GLES20.glEnableVertexAttribArray(mTextureCoordinatesHandle);
}
    	
if(hasNormals){
       // Pass in the normal information
    	int offset = 3;
        if (hasColor)
                offset += 4;
         if (hasTexCoords)
                offset += 2;
        vertices.position(offset);
        GLES20.glVertexAttribPointer(mNormalsHandle,  3, GLES20.GL_FLOAT, false, 0, vertices);
        GLES20.glEnableVertexAttribArray(mNormalsHandle);
}

GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0, getNumVertices());

Is there anything I'm forgetting to do that I'm meant to? Or am I doing something wrong stupid? I appreciate any help - I'm an OpenGL beginner and I'm a bit lost.

Advertisement

And I have figured it out... I left out the "stride" argument in all those glVertexAttribPointer calls. Sorry for chewing up forum space

This topic is closed to new replies.

Advertisement