PDA

View Full Version : void DrawElements in client state vertex



wow
01-10-2004, 08:18 AM
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??

jwatte
01-10-2004, 08:56 AM
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.

wow
01-10-2004, 09:11 AM
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?

wow
01-10-2004, 09:15 AM
And suppose I need to render 1024x1024 trianlge,

i define SIZE = 1024
float g_terrain[SIZE*SIZE]; <-- 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)

Roderic (Ingenu)
01-10-2004, 09:19 AM
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.

wow
01-10-2004, 09:54 AM
So, if I am going to implement the gl_VERTEX_ARRAY and GL_TEXTURE_COORD_ARRAY,

I dont' need to set them again? right?

jwatte
01-10-2004, 01:49 PM
mv `grep -l wow advanced_forum/*` beginner_forum

SirKnight
01-10-2004, 01:55 PM
Originally posted by jwatte:

mv `grep -l wow advanced_forum/*` beginner_forum




hehe. http://www.opengl.org/discussion_boards/ubb/biggrin.gif


-SirKnight

orbano
01-10-2004, 02:53 PM
the number of indicies you use is independent from the vertex array. their value is important (it must not exceed SIZE*SIZE 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_UNS IGNED_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).]

wow
01-10-2004, 05:49 PM
Originally posted by orbano:
the number of indicies you use is independent from the vertex array. their value is important (it must not exceed SIZE*SIZE 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_UNS IGNED_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).]


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

wow
01-10-2004, 06:03 PM
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 (http://www.csis.hku.hk/~pytang/a.JPG)

wow
01-10-2004, 06:12 PM
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_SIZE*z][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

SirKnight
01-10-2004, 07:42 PM
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

SirKnight
01-10-2004, 07:51 PM
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

wow
01-10-2004, 08:17 PM
Originally posted by 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


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;
}
}

wow
01-10-2004, 08:19 PM
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~

SirKnight
01-10-2004, 09:08 PM
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

wow
01-10-2004, 10:05 PM
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...
}