PDA

View Full Version : Big problem show arrays with vertex arrays



Rondey
03-12-2009, 11:46 AM
Is a anormal problem with the structure vertex arrays:

---------------------------
glTexCoordPointer(2, GL_FLOAT, 0, @COORDENADAS); glVertexPointer(3, GL_FLOAT, 0, @VERTEXS);
glDrawElements(GL_QUADS, 4, GL_UNSIGNED_INT, @INDEX);

Why is a anormal problem; because show this with:
GLTEXTCOORD(1,2);
glvertexf(A,B,C);

Show very fine all the elements in the array; but with vertex arrays only show the first array....the others not.

my questions is ...maybe enable the flag edge ?

I don't know ....

help me please..!

scratt
03-13-2009, 04:08 AM
Have you enabled the array pointers with glEnableClientState()?
In your case you need to enable the GL_TEXTURE_COORD_ARRAY and GL_VERTEX_ARRAY pointers, and of course disable them (glDisableClientState), after drawing so they are not used in subsequent calls.

Also, what is @INDEX?

Rondey
03-13-2009, 09:29 AM
Thanks Scratt;
yes;glEnableClientState()is enable; GL_TEXTURE_COORD_ARRAY ; and GL_VERTEX_ARRAY pointers are enable too; the problem is the same trouble; the program not show everything in the file; the file have 3000 records with vectorial directions; but "vertex array" only show always the first record...show perfect...but just one ...the first record...the others records show with problems; ...when I delete the first record for see what is the problem,,,,continue the trouble....just show one record....always the first record...

Rondey
03-13-2009, 09:34 AM
ah-... o.k Scratt;

@index is the array of indexs; into this array ..to have 4 directions of records 1,2,3,4 1 have 3 records --2 have 3 records....4 have 3 records ..total are 12 vectorial directions ....it work with direct draw mode....but vertex array not....

why ...I don't know.

Rondey
03-13-2009, 09:39 AM
the picture when I write a post; "the avatar" is a screenshot from my program. Is a world easy ; single; but with 5 important tools; can draw squares; triangles; lines; uses too glut mode to draw sphere; but all this is make with direct draw mode. Vertex arrays is the next step; but I'm frozen in that by now.

scratt
03-13-2009, 12:30 PM
If you can post more of your code I am happy to try and figure it out..

Rondey
03-13-2009, 12:37 PM
structure glvertex or direct draw mode:
----------------------------
for COUNT:= 1 TO SIZE DO

BEGIN
glbegin(GL_QUADS);
glTextcood2f(1[count],2[count]);
glvertexf(A1[count],B1[count],C1[count]);
.
.
.
glTextcood2f(7[count],8[count]);
glvertexf(A4[count],B4[count],C4[count]);
glend();

END;

show all the arrays very well; but when I have running the code Vertex array only show the first array in file; the others arrays show incomplete information not draw the square else triangles :

vertex array code:
-----------------------------------------------------
glTexCoordPointer(2, GL_FLOAT, 0, @COORDENADAS);
glVertexPointer(3, GL_FLOAT, 0, @VERTEXS);
glDrawElements(GL_QUADS, 4, GL_UNSIGNED_INT, @INDEX);

Rondey
03-13-2009, 12:46 PM
all that is testing the program because after that I test the structure ;I will implement with the cycle
for count:=1 to size do "the complet file records"



here show the first record of 3000 "here do it very well just only the first" always the first record....I don't know

COUNT:=1; //// count array in array number 1


VERTICE[1].X1 := VERTICE[COUNT].X1;
VERTICE[1].Y1 := VERTICE[COUNT].Y1;
VERTICE[1].Z1 := VERTICE[COUNT].Z1;
COORDENADA[1].A:=COORDENADA[COUNT].A;
COORDENADA[1].S:=COORDENADA[COUNT].S;
INDEX[1] := 0;

VERTICE[2].X2 := VERTICE[COUNT].X2;
VERTICE[2].Y2 := VERTICE[COUNT].Y2;
VERTICE[2].Z2 := VERTICE[COUNT].Z2;
COORDENADA[2].D:=COORDENADA[COUNT].D;
COORDENADA[2].F:=COORDENADA[COUNT].F;
INDEX[2] := 1;


VERTICE[3].X3 := VERTICE[COUNT].X3;
VERTICE[3].Y3 := VERTICE[COUNT].Y3;
VERTICE[3].Z3 := VERTICE[COUNT].Z3;
COORDENADA[3].G:=COORDENADA[COUNT].G;
COORDENADA[3].H:=COORDENADA[COUNT].H;
INDEX[3] := 2;


VERTICE[4].X4 := VERTICE[COUNT].X4;
VERTICE[4].Y4 := VERTICE[COUNT].Y4;
VERTICE[4].Z4 := VERTICE[COUNT].Z4;
COORDENADA[4].J:=COORDENADA[COUNT].J;
COORDENADA[4].K:=COORDENADA[COUNT].K;
INDEX[4] := 3;



glEnableClientState(GL_INDEX_ARRAY);
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);



glTexCoordPointer(2, GL_FLOAT, 0, @COORDENADA);
glVertexPointer(3, GL_FLOAT, 0, @VERTICE);
glDrawElements(GL_QUADS, 4, GL_UNSIGNED_INT, @INDEX);


glDisableClientState(GL_INDEX_ARRAY);
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);


---------------------------------------
here show the 3th record of 3000 ....but not do it




COUNT:=3; //// count array in array number 3


VERTICE[1].X1 := VERTICE[COUNT].X1;
VERTICE[1].Y1 := VERTICE[COUNT].Y1;
VERTICE[1].Z1 := VERTICE[COUNT].Z1;
COORDENADA[1].A:=COORDENADA[COUNT].A;
COORDENADA[1].S:=COORDENADA[COUNT].S;
INDEX[1] := 0;

VERTICE[2].X2 := VERTICE[COUNT].X2;
VERTICE[2].Y2 := VERTICE[COUNT].Y2;
VERTICE[2].Z2 := VERTICE[COUNT].Z2;
COORDENADA[2].D:=COORDENADA[COUNT].D;
COORDENADA[2].F:=COORDENADA[COUNT].F;
INDEX[2] := 1;


VERTICE[3].X3 := VERTICE[COUNT].X3;
VERTICE[3].Y3 := VERTICE[COUNT].Y3;
VERTICE[3].Z3 := VERTICE[COUNT].Z3;
COORDENADA[3].G:=COORDENADA[COUNT].G;
COORDENADA[3].H:=COORDENADA[COUNT].H;
INDEX[3] := 2;


VERTICE[4].X4 := VERTICE[COUNT].X4;
VERTICE[4].Y4 := VERTICE[COUNT].Y4;
VERTICE[4].Z4 := VERTICE[COUNT].Z4;
COORDENADA[4].J:=COORDENADA[COUNT].J;
COORDENADA[4].K:=COORDENADA[COUNT].K;
INDEX[4] := 3;



glEnableClientState(GL_INDEX_ARRAY);
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);



glTexCoordPointer(2, GL_FLOAT, 0, @COORDENADA);
glVertexPointer(3, GL_FLOAT, 0, @VERTICE);
glDrawElements(GL_QUADS, 4, GL_UNSIGNED_INT, @INDEX);


glDisableClientState(GL_INDEX_ARRAY);
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);

scratt
03-13-2009, 09:26 PM
You are enabling GL_INDEX_ARRAY, but are not setting up a glIndexPointer.
This will cause undefined behavior.

I think you might be getting confused and think that glIndexPointer is to do with Indexed arrays. It's not. It's to do with indexed colour.

http://www.opengl.org/wiki/Common_Mistakes#glEnableClientState.28GL_INDEX_ARR AY.29

So get rid of that and see how things look. Perhaps post a picture of what you get so I can see the output, if it's still bad.

btw What language are you working in?

I would also suggest that perhaps you are not using indexed arrays in the best way anyway. From your example it seems that each vertex is unique in your implementation. If that is the case glDrawArrays is going to be more efficient than glDrawElements (and less confusing). If you actually sort your vertex data and spot duplicates so that you can index them multiple times in one model / scene then glDrawElements becomes worthwhile.

Rondey
03-14-2009, 09:43 AM
I believe so; I see the problem....according to the documentation the array vertex can't loaded from a normal array.

so ..How I load the file data.txt to a vertex array ...???

I was try doing in this way :

in a cycle with a pointer ; example:
vertice[count].x1 ....vertice[count].z1


really I don't know ; how load the records from the file into the vertex array...

scratt
03-14-2009, 08:50 PM
Perhaps I am misunderstanding you.. If you are loading data that already has index data for vertices in it then it may well be optimized and may well be worth you continuing that way..

In any case any data you load for geometry should just be loaded as chunks of data into memory interpreted from text into the numerical units you are using : float, int etc.

Did getting rid of the GL_INDEX_ARRAY stuff help?

Rondey
03-15-2009, 06:07 AM
Of course the file (data.txt) is interpreted and change as float values.

The trouble is the missing pointer in the array; all the time loss the pointer; and everytime begin in the first place in the array.


why..? I not to have a clue.

scratt
03-15-2009, 08:27 AM
You have not responded to my questions..

Has removing the GL_INDEX_ARRAY code changed anything?

Can you post a picture of what you get against what you should get (using immediate mode commands).

What language are you working in?

Rondey
03-15-2009, 09:09 AM
Yes ; I was removed the function glEnable(GL_INDEX_ARRAY);

send me a private message with your e-mail for send you screenshot of the program and code.

Language Visual c++; but I doing too in others.