// mesh01
static float mesh01_coords[] = {
0, -42.31, 0,
8.25427, -41.497, 0,
...
static int mesh01_indices[] = {
0, 2, 1,
3, 5, 4,
6, 8, 7,
...
draw_mesh() {
glEnableClientState( GL_VERTEX_ARRAY );
glVertexPointer(3, GL_FLOAT, 5*sizeof(float), meshvrtx);
glDrawElements(GL_LINE_LOOP, 96, GL_UNSIGNED_BYTE, meshindc);
glDisableClientState( GL_VERTEX_ARRAY );
}
🔒 Locked
glDrawElements?
Advertisement
Original Post
Here is some code I found on the web, along with my code: What gets displayed is a single point with lines, like rays, extending from the point outwards. I think it is going from center to the vertex of each face. BTW this mesh is a sphere. What am I doing wrong? I've researched this vertex array thingy for about four hours collectively, only barely able to piece together examples here.
I can't see the actual points, but if they are correct, then the problem is that you are using GL_LINE_LOOP, that would give some weird results. Try GL_TRIANGLES instead and see if that works. Also, this(5*sizeof(float)) is wrong. That value is the "stride" between sets of vertices, and since yours are tightly packed, as in you have nothing in between vertices, that should be 0. and the GL_UNSIGNED_BYTE you have in the Draw elements function I think is wrong too, because you are using ints for that array of indices. You need to change that parameter accordingly and just to be safe, I would make the array static unsigned int as well. Or you could use bytes since your values aren't larger than 256. I left the GL_LINE_LOOP that way because it may have supposed to be wireframe line loop, but if it doesn't work then, switch to triangles. Try this.
draw_mesh() { glEnableClientState( GL_VERTEX_ARRAY ); glVertexPointer(3, GL_FLOAT, 0, meshvrtx); glDrawElements(GL_LINE_LOOP, 96, GL_UNSIGNED_INT, meshindc); glDisableClientState( GL_VERTEX_ARRAY );}
What are meshvrtx and meshindc? How are they defined? I would think you would be using mesh01_coords and mesh01_indices. If they are the same as those static arrays, then I see two things wrong.
You are setting the stride in the vertex array to 5*sizeof(float) when it should be 3*sizeof(float) (or just 0 since they are tightly packed).
You are also saying that the index array is an array of unsigned bytes when mesh01_indices is declared as an array of ints. Change it to an array of unsigned ints (or unsigned shorts if there's less than 65536 vertices) and change the type parameter to GL_UNSIGNED_INT (or GL_UNSIGNED_SHORT).
EDIT: Doh, 10 seconds.
You are setting the stride in the vertex array to 5*sizeof(float) when it should be 3*sizeof(float) (or just 0 since they are tightly packed).
You are also saying that the index array is an array of unsigned bytes when mesh01_indices is declared as an array of ints. Change it to an array of unsigned ints (or unsigned shorts if there's less than 65536 vertices) and change the type parameter to GL_UNSIGNED_INT (or GL_UNSIGNED_SHORT).
EDIT: Doh, 10 seconds.
Quote:
Original post by Kalidor
What are meshvrtx and meshindc? How are they defined? I would think you would be using mesh01_coords and mesh01_indices.
I just assumed that the arrays were converted to those names due to passing pointers through functions. That could be the problem though.
You probably know more than I, Kalidor, so tell me this, if he used bytes instead of ints, the value is up to 256 for an GL_UNSIGNED_BYTE right, so He could use bytes instead since he only has 96 indices. Could you confirm that for me, because the example he used may have used bytes, just to clarify for the OP as well.
Quote:The count parameter to glDrawElements is just the number of indices to draw starting from where the indices parameter points. To use unsigned bytes you wouldn't be able to index any vertices with an index greater than 255 (2^8-1). In most cases, however, you are rendering all vertices and going through the entire index array in one go, so the count parameter will usually correspond to the maximum vertex index as well. That is most likely the case here so since the greatest index would be 95 (always start from 0) he should be able to get away with using unsigned bytes.
Original post by kburkhart84
You probably know more than I, Kalidor, so tell me this, if he used bytes instead of ints, the value is up to 256 for an GL_UNSIGNED_BYTE right, so He could use bytes instead since he only has 96 indices. Could you confirm that for me, because the example he used may have used bytes, just to clarify for the OP as well.
It still might not be as fast as unsigned shorts though. I believe (ie: ~90% sure) that the preferred format for indices on the video card is unsigned short, so they are optimized for that and using anything different may negatively affect performance. If you are very highly bandwidth limited it is best to send as little data to the card as possible though, so in that case it may be better to use unsigned bytes.
But as always, profile and then optimize the parts that are proven to be slow, not the parts you think are slow (they often don't coincide).
OK, I thought as much about the bytes, but now I know which is prefered by video cards, though I've never had to optimize that. Good one to know. Thanks.
Thanks, that was it - added unsigned to mesh and passing values - plus it was too big to show in my window. I scaled the scene out.
How would I create a wireframe view of it? The view looks a little sloppy, but the unnormalized mesh as a solid looks ok. I can't tell much about the faces yet.
I'm passing it as this:
DrawMesh(&mesh01_indices[0], &mesh01_coords[0]);
DrawMesh(unsigned int *, float *);
How would I create a wireframe view of it? The view looks a little sloppy, but the unnormalized mesh as a solid looks ok. I can't tell much about the faces yet.
I'm passing it as this:
DrawMesh(&mesh01_indices[0], &mesh01_coords[0]);
DrawMesh(unsigned int *, float *);
Quote:To render in wireframe is as simple as calling glPolygonMode with GL_LINE as the mode parameter, after which all rendering will be in wireframe mode. There is also GL_POINT and GL_FILL (the default).
Original post by drarem
...How would I create a wireframe view of it?...
I like this poster. He confirms if we were right or not. A lot don't even do that... Also, OP, good luck and don't quit anytime soon, there is more and better to come.
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement