Re: glDrawElements() and glColorPointer()
Posted by gmseed on Dec 08, 2011; 10:35am
URL: https://forum.jogamp.org/glDrawElements-and-glColorPointer-tp3564836p3569970.html
Hi
My buffers are in a parent class:
public abstract class VertexObjectRenderer extends ObjectRenderer
{
////////////
// fields //
////////////
protected int mVertexCount = 0;
protected FloatBuffer mVertices = null;
protected IntBuffer mVertexIndices = null;
protected boolean mIsUsingVertexIndices = false;
protected FloatBuffer mVertexColours = null;
//...
and built by the following method:
private boolean buildRenderer_IndexTriMesh3D_Indices(GL gl)
{
ObjectAttributeManager objAttrManager = Model.getModel().getObjectAttributeManager();
IndexTriMesh3D triMesh = (IndexTriMesh3D)mGeometricObject;
int numberTriangles = triMesh.numberTriangles();
// vertices //
// number of vertices now set to actual size of points vector
IndexPoints3D triMeshVertices = triMesh.getPoints();
int numberVertices = triMeshVertices.size();
mVertexCount = numberVertices;
// allocate vertex buffer [3 for (x,y,z) for each vertex]
int vertexBufferSize = 4 * mVertexCount;
mVertices = Buffers.newDirectFloatBuffer(vertexBufferSize);
int vertexColoursBufferSize = 4 * mVertexCount;
mVertexColours = Buffers.newDirectFloatBuffer(vertexColoursBufferSize);
for (int i=0; i<numberVertices; i++)
{
Point3D v = triMeshVertices.getPoint(i);
mVertices.put(v.getXFloat()); mVertices.put(v.getYFloat()); mVertices.put(v.getZFloat()); mVertices.put(1.0f);
}
mVertices.flip();
// indices //
// number of indices equal to 3xnumberTris since ordered: {tri0[viIndex,vjIndex,vkIndex],...}
int indexBufferSize = 3 * numberTriangles;
mVertexIndices = Buffers.newDirectIntBuffer(indexBufferSize);
HashMap<ID,IndexAdjacentTriangle3D> tris = triMesh.getTriangles();
Iterator<Entry<ID,IndexAdjacentTriangle3D>> it = tris.entrySet().iterator();
while (it.hasNext())
{
Entry<ID,IndexAdjacentTriangle3D> entry = it.next();
ID itriID = entry.getKey();
IndexAdjacentTriangle3D itri = entry.getValue();
// vertex indices
int v0Index = itri.vertex0Index();
int v1Index = itri.vertex1Index();
int v2Index = itri.vertex2Index();
mVertexIndices.put(v0Index); mVertexIndices.put(v1Index); mVertexIndices.put(v2Index);
// vertex colours
ColourAttribute colourAttribute = (ColourAttribute)objAttrManager.getObjectAttribute(itriID,AttributeType.ColourAttributeType);
NormalisedRGBAlphaColour objectColour = null;
if (colourAttribute == null)
{
objectColour = RenderManager.getRenderManager().getDefaultFillColour();
}
else
{
objectColour = colourAttribute.getAttribute();
}
//objectColour = RenderManager.getRenderManager().getDefaultFillColour();
NormalisedRGBAlphaColour v0Colour = objectColour;
NormalisedRGBAlphaColour v1Colour = objectColour;
NormalisedRGBAlphaColour v2Colour = objectColour;
mVertexColours.put(v0Index+0,v0Colour.getRedFloat()); mVertexColours.put(v0Index+1,v0Colour.getGreenFloat()); mVertexColours.put(v0Index+2,v0Colour.getBlueFloat()); mVertexColours.put(v0Index+3,v0Colour.getAlphaFloat());
mVertexColours.put(v1Index+0,v1Colour.getRedFloat()); mVertexColours.put(v1Index+1,v1Colour.getGreenFloat()); mVertexColours.put(v1Index+2,v1Colour.getBlueFloat()); mVertexColours.put(v1Index+3,v1Colour.getAlphaFloat());
mVertexColours.put(v2Index+0,v2Colour.getRedFloat()); mVertexColours.put(v2Index+1,v2Colour.getGreenFloat()); mVertexColours.put(v2Index+2,v2Colour.getBlueFloat()); mVertexColours.put(v2Index+3,v2Colour.getAlphaFloat());
}
mVertexIndices.flip();
mVertexColours.rewind(); // note use of rewind() after using put(index,value)
return true;
}
PS. IS THERE A WAY TO INSERT TAGS FOR A CODE BLOCK TO MAKE IT MORE READABLE?