使用 glDrawRangeElements() 渲染无法正常工作

发布于 2024-12-06 19:36:06 字数 2879 浏览 0 评论 0 原文

这是我之前问题的后续。我的所有问题都在我的上一个帖子中得到了解答,但这是我遇到的一个新错误。当以中间模式渲染时,一切看起来都很棒。

实际上: https://i.sstatic.net/AQgiK.png

现在,我使用 glDrawRangeElements 进行渲染() 看看会发生什么:

https://i.sstatic.net/vvFnH.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;

        }
    }
}

我已经完成了大量的调试信息,表明我的最小/最大值设置正确。此时,我认为索引可能有错误,所以我将继续查看/重写该函数。

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:
https://i.sstatic.net/AQgiK.png

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

https://i.sstatic.net/vvFnH.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[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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

天暗了我发光 2024-12-13 19:36:06

设法让它发挥作用。非常感谢另一个论坛上的某人准确地标记了他的问题,其中第三个顶点是在原点绘制的。

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

看来我需要将索引数据类型从 int 更改为 Short。效果非常好,我的 FPS 提高了 1500%。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文