开发者

Rendering with glDrawRangeElements() not working properly

This is a followup to my previous question. All of my questions were answered in my last thread but this is a new error that I am having. When rendering in intermediate mode, everything looks great.

In fact: http://i.imgur.com/OFV6i.png

Now, I am rendering with the glDrawRangeElements() and look what happens:

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

Has anyone seen something like this before? It looks as if some of the indices are simply in the middle, which makes no sense at all.

This is the function I am using to render my level.

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开发者_StackOverflow[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;

        }
    }
}

I've done a ton of debug information indicating that my min/max values are set up correctly. At this point, I think it might be an error with the indices so I am going to go ahead an look over/rewrite that function.


Managed to get it to work. Very thankful that someone on another forum labeled his question accurately where a third vertex was being drawn at the origin.

http://www.gamedev.net/topic/583558-gldrawelements-is-drawing-all-of-my-vertices-with-one-vertex-at-the-origin-solved/page_gopid_4867052#entry4867052

Seems I needed to change my indices datatype from int to short. Works like a charm and I am getting a %1500 increase in FPS.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜