Reputation: 321
I use Blender with .obj
and .mtl
export files for android OpenGL ES 2.0
Below image describe what i want to draw with vertices,and faces..
ObjParse obje = new ObjParse(context,R.raw.sample_obj,R.raw.sample_mtl);
float[] koordinates = obje.getVertexKoordinates();
byte[] indicies = obje.getIndicies();
float[] colors = obje.getColors();
This codes bring me some array data for drawing.
And i made FLoatBuffer
and ByteBuffer
this arrays..
GLES20.glVertexAttribPointer(position, 3, GLES20.GL_FLOAT, false, stride,floatBufKoor);
GLES20.glEnableVertexAttribArray(position);
GLES20.glVertexAttribPointer(color, 4, GLES20.GL_FLOAT, false, stride, floatBufColors);
GLES20.glEnableVertexAttribArray(color);
GLES20.glDrawElements(GLES20.GL_TRIANGLES,cizilecek,GLES20.GL_UNSIGNED_BYTE,byteBufIndicies);
Finally i get gradient colors,but i want solid color per faces.. How can i do this?
EDIT:
When i compile app i get this screenshot:
Upvotes: 0
Views: 1593
Reputation: 283
There is a limited way to color the faces of your glDrawElements mesh by triangle (as shown in Blender) instead of by vertex (as shown in the lower image):
You can use a little more creativity (binary masks?) to index more colors but each strategy is limited to using a single w for the color (without being able to use a mat3 as an attribute in glDrawElements in ES2.0). You can also pass float[] colors (only one entry per color) as a uniform vec3 array and read color values from there.
Upvotes: 2