CodeGuru Forums -
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic Newsletters VB Forums Developer.com


Newest CodeGuru.com Articles:

  • Installing SQL Server 2008
  • Writing UDFs for Firebird Embedded SQL Server
  • [Updated] Shutdown Manager
  • Building Windows Azure Cloud Service Applications with Azure Storage and the Azure SDK

  • Search CodeGuru:
     



    Go Back   CodeGuru Forums > Visual C++ & C++ Programming > Graphics Programming
    FAQ Members List Calendar Search Today's Posts Mark Forums Read

    Graphics Programming Discussion graphics programming using C++. Valid topics include OpenGL, DirectX, GDI/GDI+, Aero, and more.

    Reply
     
    Thread Tools Search this Thread Rate Thread Display Modes
      #1    
    Old November 6th, 2009, 04:24 AM
    rakeshthp rakeshthp is offline
    Member
     
    Join Date: Jul 2009
    Location: Bangalore, INDIA
    Posts: 30
    rakeshthp is an unknown quantity at this point (<10)
    glDrawElements () draws only part of my mesh... What to do.??

    Hello..

    I have recently shifted from Display lists to VBOs... It's a very nice thing in OpenGL i found to render huge amount of data smoothly..

    Let me explain you the scenario.. I have maintained a list of triangle objects as

    Code:
    std::map<unsigned int, EObjects*> MeshElements
    Thus, MeshElements contains all the triangles generated by the mesh generator. Now inorder to display, i call a routine first as shown below:
    Code:
    mVertexCount = MeshElements.size();
    
    mVertices = new GLfloat[mVertexCount * 6];
    mIndices = new GLuint[mVertexCount * 3];
    
    int v_ind = 0, i_ind = 0;
    
    for( std::map<unsigned int, EObjects*>::iterator it = MeshElements.begin(); it != MeshElements.end(); it++ )
    {
         EObjects *ob = (*it).second;
         mVertices[v_ind] = ob->GetNodeOne().GetX(); v_ind++;
         mVertices[v_ind] = ob->GetNodeOne().GetY(); v_ind++;
         mIndices[i_ind] = ob->GetNodeOneIndex(); i_ind++;
         mVertices[v_ind] = ob->GetNodeTwo().GetX(); v_ind++;
         mVertices[v_ind] = ob->GetNodeTwo().GetY(); v_ind++;
         mIndices[i_ind] = ob->GetNodeTwoIndex(); i_ind++;
         mVertices[v_ind] = ob->GetNodeThree().GetX(); v_ind++;
         mVertices[v_ind] = ob->GetNodeThree().GetY(); v_ind++;
         mIndices[i_ind] = ob->GetNodeThreeIndex(); i_ind++;
    }
    
    glGenGuffersARB(BufferSize, BufferName);

    where BufferSize and BufferName are declared globally as follows:

    Code:
    enum{
      INDEX_OBJECT = 0,
      POSITION_OBJECT = 1
    };
    
    static const int BufferSize = 2;
    static GLuint BufferName[BufferSize];
    Below is my rendering code:

    Code:
    glBindBufferARB( GL_ARRAY_BUFFER_ARB, BufferName[POSITION_OBJECT]);
    glBufferDataARB( GL_ARRAY_BUFFER_ARB, mVertexCount * 6 * sizeof(float), mVertices, GL_STREAM_DRAW_ARB );
    glVertexPointer(2, GL_FLOAT, 0, 0);
    
    glBindBufferARB( GL_ELEMENT_ARRAY_BUFFER_ARB, BufferName[INDEX_OBJECT] );
    glBufferDataARB( GL_ELEMENT_ARRAY_BUFFER_ARB, mVertexCount * 3 * sizeof(GLuint), mIndices, GL_STREAM_DRAW_ARB );
    
    glEnableClientState(GL_VERTEX_ARRAY);
    glEnableClientState(GL_INDEX_ARRAY);
    
    glDrawElements( GL_TRIANGLES, mVertexCount*3, GL_UNSIGNED_INT, NULL );
    
    glDisableClientState(GL_INDEX_ARRAY);
    glDisableClientState(GL_VERTEX_ARRAY);
    This code is working fine.. But, only the outer part of the mesh is displayed.. the Inner part is not displayed.. I mean to say, if the mesh is of shape "D", it should have filled all the triangles in "D".. Instead of doing so, it is rather, drawing triangles only along the border of the shape "D" Inner part, triangles are not drawn..

    Before using glDrawElements(), i was using glDrawArrays().. It also produced the same output.. So I used, GL_POINTS with glDrawArrays(), just to check if it is reading all the points.. In response to this test, it rendered all the points.. But when i said, GL_TRIANGLES, it is not rendering the inner part..

    On the other hand, GL_POINTS with glDrawElements() is also rendering only at the boundaries.. Not inner part like glDrawArrays()..

    Is something wrong with my code above..?? Please someone guide me properly..

    Thanks in advance..
    Reply With Quote
      #2    
    Old November 7th, 2009, 09:18 AM
    DrYap DrYap is offline
    Junior Member
     
    Join Date: Aug 2009
    Posts: 8
    DrYap is an unknown quantity at this point (<10)
    Re: glDrawElements () draws only part of my mesh... What to do.??

    Hi,

    I don't know much about the OpenGL but it looks like you have a problem with types. The v_ind and i_ind variables are both ints with a max value of 32, 767.

    I don't know how big your mesh is, but if it has over 11,000 triangles then i_ind will need to be able to reach 33,000 so will wrap round.

    Try setting the i_ind and v_ind as a unsigned long ints and see what happens.

    Let me know if that helps.
    Reply With Quote
      #3    
    Old November 12th, 2009, 07:46 AM
    rakeshthp rakeshthp is offline
    Member
     
    Join Date: Jul 2009
    Location: Bangalore, INDIA
    Posts: 30
    rakeshthp is an unknown quantity at this point (<10)
    Re: glDrawElements () draws only part of my mesh... What to do.??

    Hi.

    Thanks to bring me the notice of the logical mistake.. But it still doesn't work.. With the same above mentioned code, it works for points.. In my previous post i had mentioned

    [quote]So I used, GL_POINTS with glDrawArrays(), just to check if it is reading all the points.. In response to this test, it rendered all the points..[\quote]

    i.e.
    if i use

    [code]glDrawArrays( GL_POINTS, 0, mVertexCount * 3);[\code]

    it works absolutely fine.. All points are being displayed properly...

    Any, suggestions..??

    Thanks
    Reply With Quote
    Reply

    Bookmarks
    Go Back   CodeGuru Forums > Visual C++ & C++ Programming > Graphics Programming


    Thread Tools Search this Thread
    Search this Thread:

    Advanced Search
    Display Modes Rate This Thread
    Rate This Thread:

    Posting Rules
    You may not post new threads
    You may not post replies
    You may not post attachments
    You may not edit your posts

    BB code is On
    Smilies are On
    [IMG] code is On
    HTML code is Off
    Forum Jump


    All times are GMT -5. The time now is 11:00 AM.



    Acceptable Use Policy

    internet.comMediabistrojusttechjobs.comGraphics.com

    WebMediaBrands Corporate Info


    Advertise | Newsletters | Feedback | Submit News

    Legal Notices | Licensing | Permissions | Privacy Policy


    Powered by vBulletin® Version 3.7.3
    Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
    Copyright WebMediaBrands Inc. 2002-2009