Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 7 of 7

Thread: What in the world am I doing wrong??

Hybrid View

  1. #1
    Member Regular Contributor
    Join Date
    Sep 2001
    Location
    macedon, ny
    Posts
    289

    What in the world am I doing wrong??

    /*
    I am attempting to render a set of triangles, and this is my setup:

    I am implementing strips, but cant get that to work, so I am attempting just the triangles for the first run.
    */

    enum primitive_type
    {
    PT_Triangles = 0x0004,
    PT_Triangle_Strip = 0x0005
    };

    struct primitives
    {
    std::vector<unsigned int> m_Indices;
    primitive_type m_Type;
    };

    /*
    A list of strips, each containing a list of indecies, and a type value
    */
    std::vector<primitives> Triangles;

    /*
    I then send a set of parameters to a function, I send a pointer to std::vector<primitives> Triangles; And call it strips inside the function, I also send the verticies, but that isnt important here.
    I have the below in a for loop (hence the [B]), and I call it to render my mesh.
    */

    glDrawElements(GL_TRIANGLES, (*strips)[B].m_Indices.size(), GL_UNSIGNED_INT, &(*strips)[B].m_Indices);

    But it crashs before it renders. I have tried to turn off everything along the way, and it ONLY crashs when it reaches this step. I am realy bad w/pointers, am I possibly doign something wrong? Or what?

  2. #2
    Junior Member Regular Contributor
    Join Date
    Jan 2004
    Location
    Los Angeles, CA, USA
    Posts
    216

    Re: What in the world am I doing wrong??

    Take a look at pages 67-75 of the red book. glDrawElements is for drawing OpenGL Vertex Arrays. It sounds like you are just shoving an array of integers at it. I'm not suprised it's crashing.

    That said I havn't used vertex arrays, soo I can't really help you beyond pointing you to the fine manual.

  3. #3
    Junior Member Regular Contributor
    Join Date
    Jan 2004
    Location
    Los Angeles, CA, USA
    Posts
    216

    Re: What in the world am I doing wrong??

    Looking back at your code, I see one level of what you are doing wrong: you are giving glDrawElements a pointer to a std::vector<unsigned int> and not an array at all. (Since the function strictly speaking takes a void*, the compiler won't complain.) Since sizeof(std::vector<unsigned int> is probably much less than the length of the vector, glDrawElements will quickly crash.

  4. #4
    Member Regular Contributor
    Join Date
    Sep 2001
    Location
    macedon, ny
    Posts
    289

    Re: What in the world am I doing wrong??

    Ok, so how would I go about fixing that? Should I create an array, and move the data?? but that will be kind of a waiste of time and space... Is there a better way?? Can I pass a pointer??

  5. #5

    Re: What in the world am I doing wrong??

    vectors are always contiguous in memory. Just pass a pointer to the first element and you'll get the same effect. I don't think this is the problem however.

  6. #6
    Member Regular Contributor
    Join Date
    Sep 2001
    Location
    macedon, ny
    Posts
    289

    Re: What in the world am I doing wrong??

    Bunny, YOU ROCK, FIRST ELEMENT!!!!! I was passing a pointer to the vector itself NOT its first element, what a difference [0] makes at teh end of a vector reference. THANK YOU for jogging my memory.

  7. #7
    Senior Member OpenGL Guru
    Join Date
    Mar 2001
    Posts
    2,704

    Re: What in the world am I doing wrong??

    Can you take this to the beginner's board? Or, even better, to a beginning C++ programming board?
    "If you can't afford to do something right,
    you'd better make sure you can afford to do it wrong!"

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •