void DrawElements in client state vertex

The command

void DrawElements ( enum mode, sizei count, enum type, void *indices ) ;

do anyone understand the meaning of this sentence?

"with one exception: the current edge flag, texture coordinates, color, color index, and normal coordinates are each indeterminate after the execution of DrawElements , if the corresponding array is enabled. Current values corresponding to disabled arrays are not modified by the execution of DrawElements . "

what is indeterminate??

Think “undefined”.

I e, if you do this:

glColor4f( 1, 1, 1, 1 );

glEnableClientState( GL_COLOR_ARRAY );
glColorPointer( … );
glDrawArrays( … );
glDisableClientState( GL_COLOR_ARRAY );

Then the value of the current color after this code will vary between different implementations (it won’t be 1,1,1,1) and it may vary between different calls to the same code.

Thx!! So, if I am going to deal with glVertexPointer, and I call the glDrawElemetns in RenderScene() every frame, will it mean that the positon are undefined? In this way, do i need to initialize the array at every frame?

And suppose I need to render 1024x1024 trianlge,

i define SIZE = 1024
float g_terrain[SIZESIZE]; <-- deal with glVertexPointer()
float g_colorArray[SIZE
SIZE][3]; <-- deal with glColorPOinter()

then what should the g_indexArray size be? (this array is passed to the glDrawElements)

It means that if you use GL_COLOR_ARRAY, the current color is undefined at the end of the DrawElements call. Basically is says that there’s no way you can know if the current implementation does keep the last color of the COLOR_ARRAY, a default color or the previous glColor color after a DrawElements call.

So if you want to use OpenGL color there after you must set it to make sure it’s what you want. Your Vertex arrays are still selected.

So, if I am going to implement the gl_VERTEX_ARRAY and GL_TEXTURE_COORD_ARRAY,

I dont’ need to set them again? right?

mv grep -l wow advanced_forum/* beginner_forum

Originally posted by jwatte:
[b]
mv grep -l wow advanced_forum/* beginner_forum

[/b]

hehe.

-SirKnight

the number of indicies you use is independent from the vertex array. their value is important (it must not exceed SIZESIZE in this case).
Btw you should call something like this every frame:
glVertexPointer( 3, GL_FLOAT, 0, VertexArray );
glNormalPointer( GL_FLOAT, 0, NormalArray );
glTexCoordPointer(2, GL_FLOAT, 0, TextCoordArray );
glDrawElements(GL_TRIANGLES,TriangleCount
3,GL_UNSIGNED_SHORT,IndexArray);

1024*1024 vertices seems to be too much for a terrain to be drawn every time. (dont know what kind of application you are makeing, but even with VBO’s it a huge amount).It is twice as much as a modern game engine uses for example.

[This message has been edited by orbano (edited 01-10-2004).]

Originally posted by orbano:
[b]the number of indicies you use is independent from the vertex array. their value is important (it must not exceed SIZESIZE in this case).
Btw you should call something like this every frame:
glVertexPointer( 3, GL_FLOAT, 0, VertexArray );
glNormalPointer( GL_FLOAT, 0, NormalArray );
glTexCoordPointer(2, GL_FLOAT, 0, TextCoordArray );
glDrawElements(GL_TRIANGLES,TriangleCount
3,GL_UNSIGNED_SHORT,IndexArray);

1024*1024 vertices seems to be too much for a terrain to be drawn every time. (dont know what kind of application you are makeing, but even with VBO’s it a huge amount).It is twice as much as a modern game engine uses for example.

[This message has been edited by orbano (edited 01-10-2004).][/b]

o…I am going to make a war tank game that is going to accomodate near hundred users…

Hi all, I don’t know why I still can’t draw it successfully, pls take a look for that…
(I want to use the clinet state vertex to draw the triangle in the terrain

I am very frustrated…

Picture

Here is my program abt the client state vertex (Thx for helping me, as it is quite urgent and I am of deeply frustration…)

In the Init() part, I called InitializeArray().

And this is the Initialize Array() code:

void InitializeArrays()
{
// used to track current entry in the index array
int index = 0;
int currentVertex;

// loop over all vertices in the terrain map
for (int z = 0; z < MAP_SIZE; z++)
{
for (int x = 0; x < MAP_SIZE; x++)
{

  // set the values in the texture coordinate array. since the texture
  // is tiled over each "square", we can use texture wrapping
  g_texcoordArray[currentVertex][0] = (float) x;
  g_texcoordArray[currentVertex][1] = (float) z;
}

}

for (z = 0; z < MAP_SIZE - 1; z++)
{
for (int x = 0; x < MAP_SIZE; x++)
{
currentVertex = z * MAP_SIZE + x;
g_indexArray[index++] = currentVertex + MAP_SIZE;
g_indexArray[index++] = currentVertex;
}
}

// enable the vertex arrays being used
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);

// pass the pointers to OpenGL
glVertexPointer(3, GL_FLOAT, 0, g_terrain);

glTexCoordPointer(2, GL_FLOAT, 0, g_texcoordArray);
}

And I get the g_terrain data in this way:

for(int z=0; z< MAP_SIZE; ++z)
{
for(int x=0; x< MAP_SIZE; ++x)
{
g_terrain[x+MAP_SIZEz][0]=float(x);
g_terrain[x+MAP_SIZE
z][1]=float(Height(pHeightMap, x, z ));
g_terrain[x+MAP_SIZE*z][2]=float(z);
}

}

And in the displayscene() which is going to be called every frame, I have the code:

glVertexPointer(3, GL_FLOAT, 0, g_terrain);

glTexCoordPointer(2, GL_FLOAT, 0, g_texcoordArray);
for (int z = 0; z < MAP_SIZE-1; z++)
{
glDrawElements(GL_TRIANGLE_STRIP, MAP_SIZE * 2, GL_UNSIGNED_INT, &g_indexArray[z * MAP_SIZE * 2]);
}

I sincerely express my gratitude for your hlep…really thx

Can you draw everything correctly using immediate mode? ie. glVertex3f and friends. I remember having programs a long time ago where everything worked fine in immediate mode but when trying to port it to using vertex arrays things would get all messed up. It can be tricksey at first. But if you CAN get everything working fine in immediate mode, then getting it ported and working using vertex arrays will be a bit easier than starting out with vertex arrays right off the bat. Unless you are very experienced with vertex arrays already, then it’s not much of a problem.

-SirKnight

I did notice one thing while scanning your code there. You declare currentVertex but never assign it a value. Unless I’m blind. Then you proceed to use it in a few places unassigned. So currentVertex at this point could be holding who knows what value, definately not the value you intend probably. This I’m sure is one of your major problems.

Also, about the algorithms you use to compute the texcoords and indicies. Did you go through these on paper step by step to make sure they are producing the correct results?

-SirKnight

Originally posted by SirKnight:
[b]I did notice one thing while scanning your code there. You declare currentVertex but never assign it a value. Unless I’m blind. Then you proceed to use it in a few places unassigned. So currentVertex at this point could be holding who knows what value, definately not the value you intend probably. This I’m sure is one of your major problems.

Also, about the algorithms you use to compute the texcoords and indicies. Did you go through these on paper step by step to make sure they are producing the correct results?

-SirKnight [/b]

Dear SirKnight,
I did assign value for the current vertex:

for (z = 0; z < MAP_SIZE - 1; z++)
{
for (int x = 0; x < MAP_SIZE; x++)
{
currentVertex = z * MAP_SIZE + x; *******
g_indexArray[index++] = currentVertex + MAP_SIZE;
g_indexArray[index++] = currentVertex;
}
}

And yes, everything goes fine if I render it in immediate mode…however, when i try to change it to client state vertex,
i can’t mange to render it …

Thx for your help~

Yes you do assign it before calculating the indicies but you don’t assign it when you compute the tex coords.

int currentVertex;

// loop over all vertices in the terrain map
for (int z = 0; z < MAP_SIZE; z++)
{
for (int x = 0; x < MAP_SIZE; x++)
{

// set the values in the texture coordinate array. since the texture
// is tiled over each “square”, we can use texture wrapping
g_texcoordArray[currentVertex][0] = (float) x;
g_texcoordArray[currentVertex][1] = (float) z;
}
}

-SirKnight

Sorry for that. However, even I have added the code and change it as follows:

for (int z = 0; z < MAP_SIZE; z++)
{
for (int x = 0; x < MAP_SIZE; x++)
{
// vertices are numbered left to right, top to bottom
currentVertex = z * MAP_SIZE + x;

      // set the values in the texture coordinate array. since the texture
  // is tiled over each "square", we can use texture wrapping
  g_texcoordArray[currentVertex][0] = (float) x;
  g_texcoordArray[currentVertex][1] = (float) z;
}

I still can’t succeed in doing it…
}