Jump to content

View more

Image of the Day

#ld38 #screenshotsaturday Mimosa Fizz action gif #2 https://t.co/TUzdppvfUL
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.


Sign up now

OpenGL ES 2.0: My parsed .obj is all wrong

4: Adsense

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.


  • You cannot reply to this topic
1 reply to this topic

#1 Tchom   Members   

197
Like
0Likes
Like

Posted 08 May 2013 - 05:16 AM

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.



#2 Tchom   Members   

197
Like
0Likes
Like

Posted 08 May 2013 - 05:59 AM

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






Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.