Jump to content
  • Advertisement
Sign in to follow this  
choffstein

Vertex Array question [SOLVED]

This topic is 4844 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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]

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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...

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
I have a method called "createArrayData()" which takes my vector<VertexPtr> that holds position, normal, color, and texture coords into 4 seperate arrays.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!