Page 1 of 2 12 LastLast
Results 1 to 10 of 17

Thread: Problems with DrawElements :(

  1. #1
    Senior Member Frequent Contributor
    Join Date
    Nov 2002
    Location
    Latvia
    Posts
    626

    Problems with DrawElements :(

    Code :
    float *va, *na, *ta;
    unsigned int *i3, *i4;
    sizes temp;
    temp = GetPointerSizes("1.obj");
    va = new float[temp.vert*3+3];
    na = new float[temp.vert*3+3];
    ta = new float[temp.vert*2+2];
    i3 = new unsigned int[temp.i3*3];
    i4 = new unsigned int[temp.i4*4];
    Loader("1.obj", va, na, ta, i3, i4);
    glEnableClientState( GL_VERTEX_ARRAY );
    glVertexPointer(3, GL_FLOAT, 0, va);
    rhino = glGenLists (1);
    glNewList(rhino, GL_COMPILE);
    glColor4f(1,0,0,1);
    (temp.i3==0)?NULL:glDrawElements(GL_TRIANGLES, temp.i3, GL_UNSIGNED_INT, i3);
    (temp.i4==0)?NULL:glDrawElements(GL_QUADS, temp.i4, GL_UNSIGNED_INT, i4);
    glEndList();
    glDisableClientState (GL_VERTEX_ARRAY);
    This is the part that dosn't seem to work temp.i3,i4&vert are integer values. I just don't know what is wrong here

    [This message has been edited by M/\dm/\n (edited 11-24-2002).]

    [This message has been edited by M/\dm/\n (edited 11-24-2002).]

  2. #2
    Senior Member Frequent Contributor
    Join Date
    Nov 2002
    Location
    Latvia
    Posts
    626

    Re: Problems with DrawElements :(

    Heeeeeeeelp plzzzzzzzzz!!

  3. #3
    Senior Member OpenGL Guru
    Join Date
    Feb 2000
    Location
    Sweden
    Posts
    2,978

    Re: Problems with DrawElements :(

    You can begin with explaining what "dosn't seem to work" mean. As far as I know, vertex arrays can "not work" in quite a few different ways, including craches during runtime dues to invalid pointers or indices, compile time errors due wrong parameters, and currupt models due to messed up indices.

    If you want any help, at least say what is wrong. We can't just guess.

  4. #4
    Senior Member Frequent Contributor
    Join Date
    Nov 2002
    Location
    Latvia
    Posts
    626

    Re: Problems with DrawElements :(

    Sorry. The problem is in fact that program draws nothing, all arrays called through pointers have real values from files, inices are all right (I even substracted 1 from value in the file to get array elements starting from 0, as it's not implemented in standart obj files, indices start from 1) I had feeling that DrawElements is incompatible with pointers so that I should have "real" array, but it seems that NVIDIAs cg_simple demo uses pointers with no problems, *va notation also gives nothing . I'can send my all program importer code, or maybe it'll be sufficient for me to take a look at simple, working obj imported (without p_mender.objectrender->vertexarray.pointer(get)) )

  5. #5
    Senior Member OpenGL Guru
    Join Date
    Feb 2000
    Location
    Sweden
    Posts
    2,978

    Re: Problems with DrawElements :(

    ...draws nothing...
    Are you sure the viewpoit is correctly set up so the model is actually within the view volume? Are you sure it's not being drawn in the same color as the background? There are other factors affecting what is show and not show other than how you set up your vertex arrays.
    I had feeling that DrawElements is incompatible with pointers...
    A pointer is the only thing it accepts. You can't pass an array to it. When using an array, you actually pass the address of the first element in the array, which is a pointer.

    Can you draw the model correct without vertex arrays? That is, with glVertex-calls.

  6. #6
    Senior Member Frequent Contributor
    Join Date
    Nov 2002
    Location
    Latvia
    Posts
    626

    Re: Problems with DrawElements :(

    Actually it's a 3D game, I have a maze & outdoor environment, with walls, operational doors, multitexturing & cg, I can move, look up&down and so on. Currently I'm trying to import cube with coords -1,-1,-1, 1,1,1, which simply stands centred at point 0,0,0 (I can walk to that point ) because I'm NOT calling glLoadIdentity before drawing it. Or else it would move with me, it would be drawn around me & polygon culling would do the job.
    By the way, I'm trying to get this cube in to the display list, maybe that's the problem? Also, I tried to call few of the vertices with Vertex3f and they worked!?

    [This message has been edited by M/\dm/\n (edited 11-27-2002).]

  7. #7
    Senior Member Regular Contributor
    Join Date
    Dec 2001
    Location
    London, England
    Posts
    160

    Re: Problems with DrawElements :(

    You are trying to put your drawElements calls in a display list.
    Is VERTEX_ARRAY enabled when you call the list??

  8. #8
    Senior Member Frequent Contributor
    Join Date
    Nov 2002
    Location
    Latvia
    Posts
    626

    Re: Problems with DrawElements :(

    Yes, for sure

  9. #9
    Junior Member Newbie
    Join Date
    Nov 2002
    Posts
    19

    Re: Problems with DrawElements :(

    M/\dm/\n, this sounds remarkably like what I am doing at the moment as well (3d maze etc).... u wouldn't happen to be in your 3rd year at Hull uni would u?

    Music_Man

  10. #10
    Senior Member OpenGL Guru Relic's Avatar
    Join Date
    Apr 2000
    Posts
    2,450

    Re: Problems with DrawElements :(

    If temp.i3 is the number of triangles and temp.i4 the number of quads, the drawelements calls are both using the wrong amount of indices.

    glDrawElements manual:
    "When you call the glDrawElements function, it uses count sequential elements from indices to construct a sequence of geometric primitives. The mode parameter specifies what kind of primitives are constructed, and how the array elements are used to construct these primitives. If GL_VERTEX_ARRAY is not enabled, no geometric primitives are generated."

    Is VERTEX_ARRAY enabled when you call the list??

    Yes, for sure
    Huh? No, you don't want that.

    Also from the glDrawElements manual:
    "You can include the glDrawElements function in display lists. When glDrawElements is included in a display list, the necessary array data (determined by the array pointers and enables) is also entered into the display list. Because the array pointers and enables are client-side state variables, their values affect display lists when the lists are created, not when the lists are executed."

    And wouldn't be
    if (temp.i3!=0) glDrawElements(GL_TRIANGLES, temp.i3*3, GL_UNSIGNED_INT, i3);
    if (temp.i4!=0) glDrawElements(GL_QUADS, temp.i4*4, GL_UNSIGNED_INT, i4);
    be much nicer in the above code.

Page 1 of 2 12 LastLast

Similar Threads

  1. drawElements
    By gnitsuk in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 03-14-2014, 09:30 AM
  2. DrawArrays vs DrawElements
    By nik_bg in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 08-31-2005, 09:31 PM
  3. VBO and DrawElements slow?
    By mentat in forum OpenGL: Advanced Coding
    Replies: 7
    Last Post: 08-19-2003, 12:30 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