2011-09-29 34 views
1

這是我以前的問題的後續。我的所有問題都在我的最後一個線索中回答,但這是我遇到的一個新錯誤。在中間模式下渲染時,一切看起來都很棒。使用glDrawRangeElements()渲染不能正常工作

事實上: http://i.imgur.com/OFV6i.png

現在,我與glDrawRangeElements渲染(),看看會發生什麼:

http://i.imgur.com/mEmH5.png

有沒有人見過這樣的事情之前?看起來好像有些指數只是在中間,這根本沒有意義。

這是我用來呈現我的關卡的功能。

void WLD::renderIntermediate(GLuint* textures, long curRegion, CFrustum cfrustum) 
{ 
    // Iterate through all of the regions in the PVS 
    for(int i = 0; i < regions[curRegion].visibility.size(); i++) 
    { 
     // Grab a visible region 
     int vis = regions[curRegion].visibility[i]; 

     // Make sure it points to a mesh 
     if(regions[vis].meshptr == NULL) 
      continue; 

     // Make sure it is in our PVS 
     if(!cfrustum.BoxInFrustum(regions[vis].meshptr->minX, regions[vis].meshptr->minY, regions[vis].meshptr->minZ, regions[vis].meshptr->maxX, regions[vis].meshptr->maxY, regions[vis].meshptr->maxZ)) 
      continue; 

     // Optional: Only render the region we are in (for testing) 
     //if(vis != curRegion) 
     // continue; 

     // Now find the ID of the zone mesh in the array 
     int id = regions[vis].meshptr->id; 

     // Figure out how many calls we will have to do to render it (different textures) 
     int calls = zmeshes[id].numPolyTex; 

     int count = 0; 

     // Render each call in batches 
     for(int j = 0; j < calls; j++) 
     { 

      // Bind the correct texture 
      glBindTexture(GL_TEXTURE_2D, textures[zmeshes[id].polyTexs[j].texIndex]); 

      // Set up rendering states 
      glEnableClientState(GL_VERTEX_ARRAY); 
      glEnableClientState(GL_TEXTURE_COORD_ARRAY); 

      errorLog.writeSuccess("Drawing debug: ID: %i - Min: %i - Max: %i - Polys in this call %i - Count: %i - Location: %i", id, zmeshes[id].minmax[j].min, zmeshes[id].minmax[j].max, zmeshes[id].polyTexs[j].polyCount, zmeshes[id].polyTexs[j].polyCount * 3, count); 

      glVertexPointer(3, GL_FLOAT, sizeof(Vertex), &zmeshes[id].vertices[0].x); 
      glTexCoordPointer(2, GL_FLOAT, sizeof(Vertex), &zmeshes[id].vertices[0].u); 

      // Draw 
      glDrawRangeElements(GL_TRIANGLES, zmeshes[id].minmax[j].min, zmeshes[id].minmax[j].max, zmeshes[id].polyTexs[j].polyCount * 3, GL_UNSIGNED_SHORT, zmeshes[id].indices + count); 

      // End of rendering - disable states 
      glDisableClientState(GL_VERTEX_ARRAY); 
      glDisableClientState(GL_TEXTURE_COORD_ARRAY); 

      // Add the number of indices rendered 
      count += zmeshes[id].polyTexs[j].polyCount * 3; 

     } 
    } 
} 

我已經做了大量的調試信息,表明我的最小/最大值設置正確。在這一點上,我認爲這可能是指數的錯誤,所以我將繼續查看/重寫該函數。

+0

好吧,好像它們都在原點合併(0,0,0)。令人難以置信的離奇。任何人有任何建議? –

回答