PDA

View Full Version : Vertex Arrays



Zeus_666
06-17-2001, 11:46 PM
Hi,
I am getting stuck with,

glDrawArrays (GL_QUADS, 0, 4);

I am trying to draw a sequence of quads from an array of vertex's. I have the following in Init()

glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer (3, GL_FLOAT, 0, rectangles);

rectangles is the array that holds all my vertex data.

I would be mostgrateful for any help, thanks.

Paul

ffish
06-17-2001, 11:54 PM
Can you post more data? Does your quad draw if you use the same vertices in immediate mode? Is the colour correct when you call glDrawArrays? Is the orientation correct, etc? Like I say, it would be helpful if you post more of your rendering code (like the whole drawing function).

Zeus_666
06-18-2001, 12:06 AM
Hi,
There is more to this than meets the eye from this mornings experimenting, it is likly not a problem with the drawing of the vertex data but tha actual reading of the vertex data.
I have written a function to read in data from a text file and store that data in an array. This function is below:

void OpenMapAndParse ()
{
ifstream fin; //FILE POINTER TO MAP FILE
float rectangles[MAX_SIZE];
float triangles[MAX_SIZE];
int i;

fin.open("map1.map"); //OPEN THE FILE

//GET WORLD DATA
fin >> worldWidth;
fin >> worldDepth;
fin >> numberRectangles;
fin >> numberTriangles;

//READ RECTANGLE VERTEX DATA
for(i = 0; i < (12 * numberRectangles); i++)
fin >> rectangles[i];

//READ TRIANGLE VERTEX DATA
for(i = 0; i < (9 * numberTriangles); i++)
fin >> triangles[i];

fin.close(); //CLOSE THE FILE
}

(not sure that looks, box is too small), and the data file is:

60
40
6
4

5.0 5.0 -4.0 -5.0 5.0 -4.0 -5.0 0.0 -4.0 5.0 0.0 -4.0
1.0 2.0 3.0 1.0 2.0 3.0 1.0 2.0 3.0 1.0 2.0 3.0
1.0 2.0 3.0 1.0 2.0 3.0 1.0 2.0 3.0 1.0 2.0 3.0
1.0 2.0 3.0 1.0 2.0 3.0 1.0 2.0 3.0 1.0 2.0 3.0
1.0 2.0 3.0 1.0 2.0 3.0 1.0 2.0 3.0 1.0 2.0 3.0
1.0 2.0 3.0 1.0 2.0 3.0 1.0 2.0 3.0 1.0 2.0 3.0

1.0 2.0 3.0 1.0 2.0 3.0 1.0 2.0 3.0
1.0 2.0 3.0 1.0 2.0 3.0 1.0 2.0 3.0
1.0 2.0 3.0 1.0 2.0 3.0 1.0 2.0 3.0
1.0 2.0 3.0 1.0 2.0 3.0 1.0 2.0 3.0

------------------------------------
This is reading in the data but the array gets emptyed as soon as the function is left.

Zeus_666
06-18-2001, 12:08 AM
Hi,
Sorry to waste your time, i made a hell of a stupid mistake, i had declared the variable rectangles in the function and as a global, once commenting this line out, it worked. Sorry again. This has been bugging me since friday, god i feel a fool.

Thanks

ffish
06-18-2001, 12:13 AM
And I was just about to reply pointing that out .. Gotta be quick I guess http://www.opengl.org/discussion_boards/ubb/smile.gif Don't worry, we all make stupid mistakes http://www.opengl.org/discussion_boards/ubb/wink.gif