Results 1 to 5 of 5

Thread: Vertex Arrays

  1. #1
    Member Contributor
    Join Date
    Jun 2001
    Posts
    54

    Vertex Arrays

    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

  2. #2
    Senior Member Regular Contributor
    Join Date
    Feb 2001
    Location
    Australia
    Posts
    431

    Re: Vertex Arrays

    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).

  3. #3
    Member Contributor
    Join Date
    Jun 2001
    Posts
    54

    Re: Vertex Arrays

    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.

  4. #4
    Member Contributor
    Join Date
    Jun 2001
    Posts
    54

    Re: Vertex Arrays

    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

  5. #5
    Senior Member Regular Contributor
    Join Date
    Feb 2001
    Location
    Australia
    Posts
    431

    Re: Vertex Arrays

    And I was just about to reply pointing that out .. Gotta be quick I guess Don't worry, we all make stupid mistakes

Similar Threads

  1. arrays of arrays as vertex output/fragment input
    By tsojtsoj in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 05-17-2018, 08:02 PM
  2. Vertex Arrays, interleaved arrays, mouseMove func
    By Nibirue in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 02-13-2012, 11:17 AM
  3. Big problem show arrays with vertex arrays
    By Rondey in forum OpenGL: Basic Coding
    Replies: 13
    Last Post: 03-15-2009, 10:09 AM
  4. Vertex Arrays: Interleaved or seperated arrays?
    By Jan in forum OpenGL: Advanced Coding
    Replies: 16
    Last Post: 06-21-2005, 05:25 AM
  5. Vertex arrays and ... texture arrays
    By cix>foo in forum OpenGL: Advanced Coding
    Replies: 21
    Last Post: 06-25-2000, 08:15 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean