Vertex Array question [SOLVED]

Started by
9 comments, last by choffstein 18 years, 8 months ago
So I am trying to implement vertex arrays, but neither glDrawArrays, glDrawElements, or glInterleavedArrays are working for me. Here is my current code:

Geometry::vertex **vertices = pGeo->getVertexArray();
Geometry::vertex **normals = pGeo->getNormalArray();
Geometry::color **colors = pGeo->getColorArray();
//Geometry::texture **textures = pGeo->getTextureArray();
			
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_NORMAL_ARRAY);
glEnableClientState(GL_COLOR_ARRAY);
//glEnableClientState(GL_TEXTURE_ARRAY);
			
glVertexPointer( 3, GL_FLOAT, 0, vertices );
glNormalPointer( GL_FLOAT, 0, normals);
glColorPointer( 3, GL_FLOAT, 0, colors );
//glTexCoordPointer( 2, GL_FLOAT, 0, textures );
	
glDrawElements(GL_TRIANGLES, pGeo->getIndices().size(), GL_UNSIGNED_INT, pGeo->getIndexArray());
						
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_NORMAL_ARRAY);
glDisableClientState(GL_COLOR_ARRAY);


The screen just shows up blank. However, this code works:

vector<VertexPtr> vertices = pGeo->getVertices();
vector<int> indices = pGeo->getIndices();
			
glBegin(GL_TRIANGLES);
			
for(unsigned int i = 0; i < indices.size(); ++i)
{
     VertexPtr v = vertices[indices];
     Vector3Ptr pos = v->getPosition();
     Vector3Ptr normal = v->getNormal();
				
     glNormal3f(normal->x, normal->y, normal->z);
     glColor3f(v->getR(), v->getG(), v->getB());
     glVertex3f(pos->x, pos->y, pos->z);
}
glEnd();


Any idea whats going on? I don't think my vertice and indice arrays, et cetera, are corrupt, because I am directly copying them from my vectors<>. Thanks! <3 visage [Edited by - visage on August 12, 2005 2:24:36 PM]
Advertisement
I doubt this will make a difference, but if I recall correctly, the order

glNormalPointer( GL_FLOAT, 0, normals);
glColorPointer( 3, GL_FLOAT, 0, colors )
glVertexPointer( 3, GL_FLOAT, 0, vertices );

is better, since all the setup work happens in glVertexPointer.
I changed it (thanks for the tip), but it didn't seem to help (well, im sure it did, but no fix yet.)

Thanks!
Just to check, how many elements are you drawing? Have you tested with GL_POINTS?
I am drawing 2 elements (2 triangles...). 4 vertices, 6 indices.

Here is an example of my setup code...
        GeometryPtr gp("Geometry");//...	gp->addVertex(v0);	gp->addVertex(v1);	gp->addVertex(v2);	gp->addVertex(v3);		//indices are for the normals	gp->addIndex(0);	gp->addIndex(1);	gp->addIndex(2);		gp->addIndex(0);	gp->addIndex(1);	gp->addIndex(3);


	vertexArray = new vertex*[vertices.size()];	for(unsigned int i = 0; i < vertices.size(); ++i)	{		vertexArray = new vertex;		vertexArray->x = vertices->getPosition()->x;		vertexArray->y = vertices->getPosition()->y;		vertexArray->z = vertices->getPosition()->z;	}		indexArray = new unsigned int[indices.size()];	for(unsigned int i = 0; i < indices.size(); ++i)	{		indexArray = indices;	}



With GL_POINTS, I see 1 red dot.
Thanks for the help so far...
Hang on there. The size you pass to glDraw... is the number of indices, not the number of items of type GL_type you want to draw. So the original code would have been correct.
Yeah, I noticed that and changed it back. My last post reflects the correction...

I also realized my color struct has R,G,B,A, so I changed my glColorPointer to:

glColorPointer( 4, GL_FLOAT, 0, colors );

Now I see a blue dot with GL_POINTS, and GL_LINES makes some wierd lines show up -- but nothing like what I had with my original code before the arrays.
And you have verified that indices.size() is larger than 1?

If you use msn (rick_appleton theusualhere hotmail.com), or aim (RckAppleton) feel free to discuss this there.

And what videocard and driver are we talking about here?
hmm,

in the direct mode that works you have:

vector<VertexPtr> vertices = pGeo->getVertices();

VertexPtr is a pointer to something that holds, positions, colors and normals, hence I beleive pGeo->getVertices() returns something that is interleaved.

In the not working VA mode you have:

Geometry::vertex **vertices = pGeo->getVertexArray();

and you use this as a non-interleaved source of data. Does this mean that one of these two functions somehow makes in internal copy to the other format?
I have a method called "createArrayData()" which takes my vector<VertexPtr> that holds position, normal, color, and texture coords into 4 seperate arrays.

This topic is closed to new replies.

Advertisement