Upgrade Irrlicht to use 32 bit indices in the mesh buffers

A forum to store posts deemed exceptionally wise and useful
Post Reply
Spintz
Posts: 1688
Joined: Thu Nov 04, 2004 3:25 pm

Upgrade Irrlicht to use 32 bit indices in the mesh buffers

Post by Spintz »

http://www.spintz.com/irrlicht/32bitindices

I've made a webpage describing the steps to take to upgrade the Irrlicht engine to use 32 bit indices in the mesh buffers! This is a definite bonus if you also decide to upgrade the engine to use my GeoMipMapSceneNode, allowing you to use very large terrains ( with this patch ).

The GeoMipMap change can be read up at

http://www.spintz.com/irrlicht/geomipmapscenenode/

If you want to just download the code for the new engine with the GeoMipMap changes and the 32 bit index changes you can do so here -

http://www.spintz.com/irrlicht/Irrlicht_Spintz.rar
http://www.spintz.com/irrlicht/Irrlicht_Spintz.zip

Only the Visual Studio solution is configured for the new build, and it was done with Visual Studio .NET 2003 ( VS 7.1 ). For other versions/compiled, you'll need to add the files IGeoMipMapSceneNode.h, CGeoMipMapSceneNode.h, CGeoMipMapSceneNode.cpp, CGeoMipMapTriangleSelector.h and CGeoMipMapTriangleSelector.cpp to the makefile or whatever your compiler uses to configure the project/solution.
Last edited by Spintz on Sun Jan 23, 2005 2:51 am, edited 1 time in total.
Guest

Post by Guest »

it does not work for me :( you write "In file xxxx.cpp add:" but at which line do i have to include which things? i get alot of errors in CVideoOpengl.cpp because i dont know where to add which piece of code.

as im getting a few errors like this i cannot get to solve, could you may send me the modified files or upload them? or tell me at which lines i have do put the code pieces.

i would really like to use 32bit indices since then i could finally use your geomipmap code with really big heightmaps :)


this is the error i get:

Code: Select all

CVideoOpenGL.cpp: In member function `virtual void 
   irr::video::CVideoOpenGL::drawIndexedTriangleList(const 
   irr::video::S3DVertex*, int, const u32*, int)':
CVideoOpenGL.cpp:1741: error: syntax error before `)' token
CVideoOpenGL.cpp:1744: error: syntax error before `;' token

CVideoOpenGL.cpp: In member function `virtual void 
   irr::video::CVideoOpenGL::drawIndexedTriangleList(const 
   irr::video::S3DVertex2TCoords*, int, const u32*, int)':
CVideoOpenGL.cpp:1773: error: syntax error before `{' token
CVideoOpenGL.cpp:1775: error: syntax error before `;' token
CVideoOpenGL.cpp: In member function `virtual void 
   irr::video::CVideoOpenGL::drawIndexedTriangleFan(const 
   irr::video::S3DVertex*, int, const u32*, int)':
CVideoOpenGL.cpp:1824: error: syntax error before `{' token
CVideoOpenGL.cpp:1826: error: syntax error before `;' token
CVideoOpenGL.cpp: In member function `virtual void 
   irr::video::CVideoOpenGL::drawIndexedTriangleFan(const 
   irr::video::S3DVertex2TCoords*, int, const u32*, int)':
CVideoOpenGL.cpp:1855: error: syntax error before `{' token
CVideoOpenGL.cpp:1857: error: syntax error before `;' token

make.exe: *** [CVideoOpenGL.o] Error 1
the code which causes the error is this:

Code: Select all

 //! draws an u32 indexed triangle list
        void CVideoOpenGL::drawIndexedTriangleList(const S3DVertex* vertices, s32 vertexCount, const u32* indexList, s32 triangleCount)
        {
            if (!checkPrimitiveCount(triangleCount))
                return;
            CVideoNull::drawIndexedTriangleList(vertices, vertexCount, indexList, triangleCount);
            setRenderStates3DMode();
            extGlClientActiveTextureARB(GL_TEXTURE0_ARB);
            glEnableClientState(GL_COLOR_ARRAY);
            glEnableClientState(GL_VERTEX_ARRAY);
            glEnableClientState(GL_TEXTURE_COORD_ARRAY );
            glEnableClientState(GL_NORMAL_ARRAY );
            // convert colors to gl color format.
            const S3DVertex* p = vertices;
            ColorBuffer.set_used(vertexCount);
            for (s32 i=0; i
            {
                ColorBuffer[i] = p->Color.toOpenGLColor();
                ++p;
            }
            // draw everything
            glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(video::SColor), &ColorBuffer[0]);
            glNormalPointer(GL_FLOAT, sizeof(S3DVertex), &vertices[0].Normal);
            glTexCoordPointer(2, GL_FLOAT, sizeof(S3DVertex), &vertices[0].TCoords);
            glVertexPointer(3, GL_FLOAT, sizeof(S3DVertex), &vertices[0].Pos);
            glDrawElements(GL_TRIANGLES, triangleCount * 3, GL_UNSIGNED_INT, indexList);
            glFlush();
            glDisableClientState(GL_COLOR_ARRAY);
            glDisableClientState(GL_VERTEX_ARRAY);
            glDisableClientState(GL_TEXTURE_COORD_ARRAY );
            glDisableClientState(GL_NORMAL_ARRAY );
        }
        //! draws an u32 indexed triangle list
        void CVideoOpenGL::drawIndexedTriangleList(const S3DVertex2TCoords* vertices, s32 vertexCount, const u32* indexList, s32 triangleCount)
        {
            if (!checkPrimitiveCount(triangleCount))
                return;
            CVideoNull::drawIndexedTriangleList(vertices, vertexCount, indexList, triangleCount);
            setRenderStates3DMode();
            glEnableClientState(GL_COLOR_ARRAY);
            glEnableClientState(GL_VERTEX_ARRAY);
            glEnableClientState(GL_TEXTURE_COORD_ARRAY );
            glEnableClientState(GL_NORMAL_ARRAY );
            // convert colors to gl color format.
            const S3DVertex2TCoords* p = vertices;
            ColorBuffer.set_used(vertexCount);
            for (s32 i=0; i
            {
                ColorBuffer[i] = p->Color.toOpenGLColor();
                ++p;
            }
            // draw everything
            glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(video::SColor), &ColorBuffer[0]);
            glNormalPointer(GL_FLOAT, sizeof(S3DVertex2TCoords), &vertices[0].Normal);
            glVertexPointer(3, GL_FLOAT, sizeof(S3DVertex2TCoords), &vertices[0].Pos);
            // texture coordiantes
            if (MultiTextureExtension)
            {
                extGlClientActiveTextureARB(GL_TEXTURE0_ARB);
                glEnableClientState ( GL_TEXTURE_COORD_ARRAY );
                glTexCoordPointer(2, GL_FLOAT, sizeof(S3DVertex2TCoords), &vertices[0].TCoords);
                extGlClientActiveTextureARB(GL_TEXTURE1_ARB);
                glEnableClientState ( GL_TEXTURE_COORD_ARRAY );
                glTexCoordPointer(2, GL_FLOAT, sizeof(S3DVertex2TCoords), &vertices[0].TCoords2);
            }
            else
                glTexCoordPointer(2, GL_FLOAT, sizeof(S3DVertex2TCoords), &vertices[0].TCoords);
            glDrawElements(GL_TRIANGLES, triangleCount * 3, GL_UNSIGNED_INT, indexList);
            glFlush();
            glDisableClientState(GL_COLOR_ARRAY);
            glDisableClientState(GL_VERTEX_ARRAY);
            if (MultiTextureExtension)
            {
                extGlClientActiveTextureARB(GL_TEXTURE0_ARB);
                glDisableClientState ( GL_TEXTURE_COORD_ARRAY );
                extGlClientActiveTextureARB(GL_TEXTURE1_ARB);
                glDisableClientState ( GL_TEXTURE_COORD_ARRAY );
            }
            else
                glDisableClientState(GL_TEXTURE_COORD_ARRAY );
            glDisableClientState(GL_NORMAL_ARRAY );
        }
        //! draws an u32 indexed triangle fan
        void CVideoOpenGL::drawIndexedTriangleFan(const S3DVertex* vertices, s32 vertexCount, const u32* indexList, s32 triangleCount)
        {
            if (!checkPrimitiveCount(triangleCount))
                return;
            CVideoNull::drawIndexedTriangleFan(vertices, vertexCount, indexList, triangleCount);
            setRenderStates3DMode();
            extGlClientActiveTextureARB(GL_TEXTURE0_ARB);
            glEnableClientState(GL_COLOR_ARRAY);
            glEnableClientState(GL_VERTEX_ARRAY);
            glEnableClientState(GL_TEXTURE_COORD_ARRAY );
            glEnableClientState(GL_NORMAL_ARRAY );
            // convert colors to gl color format.
            const S3DVertex* p = vertices;
            ColorBuffer.set_used(vertexCount);
            for (s32 i=0; i
            {
                ColorBuffer[i] = p->Color.toOpenGLColor();
                ++p;
            }
            // draw everything
            glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(video::SColor), &ColorBuffer[0]);
            glNormalPointer(GL_FLOAT, sizeof(S3DVertex), &vertices[0].Normal);
            glTexCoordPointer(2, GL_FLOAT, sizeof(S3DVertex), &vertices[0].TCoords);
            glVertexPointer(3, GL_FLOAT, sizeof(S3DVertex), &vertices[0].Pos);
            glDrawElements(GL_TRIANGLE_FAN, triangleCount+2, GL_UNSIGNED_INT, indexList);
            glFlush();
            glDisableClientState(GL_COLOR_ARRAY);
            glDisableClientState(GL_VERTEX_ARRAY);
            glDisableClientState(GL_TEXTURE_COORD_ARRAY );
            glDisableClientState(GL_NORMAL_ARRAY );
        }
        //! draws an u32 indexed triangle fan
        void CVideoOpenGL::drawIndexedTriangleFan(const S3DVertex2TCoords* vertices, s32 vertexCount, const u32* indexList, s32 triangleCount)
        {
            if (!checkPrimitiveCount(triangleCount))
                return;
            CVideoNull::drawIndexedTriangleFan(vertices, vertexCount, indexList, triangleCount);
            setRenderStates3DMode();
            glEnableClientState(GL_COLOR_ARRAY);
            glEnableClientState(GL_VERTEX_ARRAY);
            glEnableClientState(GL_TEXTURE_COORD_ARRAY );
            glEnableClientState(GL_NORMAL_ARRAY );
            // convert colors to gl color format.
            const S3DVertex2TCoords* p = vertices;
            ColorBuffer.set_used(vertexCount);
            for (s32 i=0; i
            {
                ColorBuffer[i] = p->Color.toOpenGLColor();
                ++p;
            }
            // draw everything
            glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(video::SColor), &ColorBuffer[0]);
            glNormalPointer(GL_FLOAT, sizeof(S3DVertex2TCoords), &vertices[0].Normal);
            glVertexPointer(3, GL_FLOAT, sizeof(S3DVertex2TCoords), &vertices[0].Pos);
            // texture coordiantes
            if (MultiTextureExtension)
            {
                extGlClientActiveTextureARB(GL_TEXTURE0_ARB);
                glEnableClientState ( GL_TEXTURE_COORD_ARRAY );
                glTexCoordPointer(2, GL_FLOAT, sizeof(S3DVertex2TCoords), &vertices[0].TCoords);
                extGlClientActiveTextureARB(GL_TEXTURE1_ARB);
                glEnableClientState ( GL_TEXTURE_COORD_ARRAY );
                glTexCoordPointer(2, GL_FLOAT, sizeof(S3DVertex2TCoords), &vertices[0].TCoords2);
            }
            else
                glTexCoordPointer(2, GL_FLOAT, sizeof(S3DVertex2TCoords), &vertices[0].TCoords);
            glDrawElements(GL_TRIANGLE_FAN, triangleCount+2, GL_UNSIGNED_INT, indexList);
            glFlush();
            glDisableClientState(GL_COLOR_ARRAY);
            glDisableClientState(GL_VERTEX_ARRAY);
            if (MultiTextureExtension)
            {
                extGlClientActiveTextureARB(GL_TEXTURE0_ARB);
                glDisableClientState ( GL_TEXTURE_COORD_ARRAY );
                extGlClientActiveTextureARB(GL_TEXTURE1_ARB);
                glDisableClientState ( GL_TEXTURE_COORD_ARRAY );
            }
            else
                glDisableClientState(GL_TEXTURE_COORD_ARRAY );
            glDisableClientState(GL_NORMAL_ARRAY );
        }
any suggestions? i think it has something to do with the :

Code: Select all

 for (s32 i=0; i
            {
                ColorBuffer[i] = p->Color.toOpenGLColor();
                ++p;
            }
shouldnt the for (blabla) brackets be closed and not open?

please help me :roll:


edit: ok, now i changed the code above to:

Code: Select all

 for (s32 i=0; i<vertexCount; i++)
            {
                ColorBuffer[i] = p->Color.toOpenGLColor();
                ++p;
            }
it compiles clean now! i even can use the geomipmaps! but if i use heightmaps bigger than 256 pixels i get nothing, no terrain at all! why is this so?


edit2: ok it works now! the map does load a textured u32 indiced irrlicht geomipmap terrain! yeah i feel like god ! :D
Spintz
Posts: 1688
Joined: Thu Nov 04, 2004 3:25 pm

Post by Spintz »

oops, sorry bout that, HTML parser was confusing '<'

I changed the '<' to < and the '>' to %gt; so the code will show properly.

Glad it works! So the large terrains are working for ya now! That's sweet, let's see some screenshots!!!
Post Reply