From 93e90b6031a2fd6032c137c2664bd32543941c51 Mon Sep 17 00:00:00 2001 From: David Williams Date: Mon, 16 Mar 2009 21:33:56 +0000 Subject: [PATCH] Work on new OpenGL example - Work on immediate mode. --- examples/OpenGL/main.cpp | 43 +++++++++++++++++++++++++++------------- 1 file changed, 29 insertions(+), 14 deletions(-) diff --git a/examples/OpenGL/main.cpp b/examples/OpenGL/main.cpp index 5f147618..0cf94f56 100644 --- a/examples/OpenGL/main.cpp +++ b/examples/OpenGL/main.cpp @@ -5,18 +5,18 @@ #include // Standard Header For Most Programs -//#define USE_OPENGL_IMMEDIATE_MODE +//#define USE_OPENGL_VERTEX_BUFFERS_OBJECTS -#ifdef USE_OPENGL_IMMEDIATE_MODE - #include - #include -#else +#ifdef USE_OPENGL_VERTEX_BUFFERS_OBJECTS #ifdef WIN32 #include "glew/glew.h" #else #include // The GL Header File #endif - #include // The GL Utility Toolkit (Glut) Header + #include // The GL Utility Toolkit (Glut) Header] +#else + #include + #include #endif #include @@ -27,17 +27,19 @@ using namespace std; using namespace PolyVox; using namespace std; +#ifdef USE_OPENGL_VERTEX_BUFFERS_OBJECTS struct OpenGLSurfacePatch { GLulong noOfIndices; GLuint indexBuffer; GLuint vertexBuffer; }; +#endif //Global variables are easier for demonstration purposes, especially //as I'm not sure how/if I can pass variables to the GLUT functions. //Global variables are denoted by the 'g_' prefix -const uint16 g_uVolumeSideLength = 128; +const uint16 g_uVolumeSideLength = 256; const uint16 g_uRegionSideLength = 16; const uint16 g_uVolumeSideLengthInRegions = g_uVolumeSideLength / g_uRegionSideLength; @@ -52,9 +54,13 @@ int g_frameCounter = 0; BlockVolume g_volData(logBase2(g_uVolumeSideLength)); //Rather than storing one big mesh, the volume is broken into regions and a mesh is stored for each region -OpenGLSurfacePatch g_openGLSurfacePatches[g_uVolumeSideLengthInRegions][g_uVolumeSideLengthInRegions][g_uVolumeSideLengthInRegions]; -IndexedSurfacePatch* g_indexedSurfacePatches[g_uVolumeSideLengthInRegions][g_uVolumeSideLengthInRegions][g_uVolumeSideLengthInRegions]; +#ifdef USE_OPENGL_VERTEX_BUFFERS_OBJECTS + OpenGLSurfacePatch g_openGLSurfacePatches[g_uVolumeSideLengthInRegions][g_uVolumeSideLengthInRegions][g_uVolumeSideLengthInRegions]; +#else + IndexedSurfacePatch* g_indexedSurfacePatches[g_uVolumeSideLengthInRegions][g_uVolumeSideLengthInRegions][g_uVolumeSideLengthInRegions]; +#endif +#ifdef USE_OPENGL_VERTEX_BUFFERS_OBJECTS OpenGLSurfacePatch BuildOpenGLSurfacePatch(IndexedSurfacePatch& isp) { OpenGLSurfacePatch result; @@ -146,6 +152,7 @@ OpenGLSurfacePatch BuildOpenGLSurfacePatch(IndexedSurfacePatch& isp) return result; } +#endif void createSphere(float fRadius, uint8 uValue) { @@ -237,7 +244,8 @@ void display ( void ) // Create The Display Function { for(uint16 uRegionX = 0; uRegionX < g_uVolumeSideLengthInRegions; ++uRegionX) { - /*glBindBuffer(GL_ARRAY_BUFFER, g_openGLSurfacePatches[uRegionX][uRegionY][uRegionZ].vertexBuffer); +#ifdef USE_OPENGL_VERTEX_BUFFERS_OBJECTS + glBindBuffer(GL_ARRAY_BUFFER, g_openGLSurfacePatches[uRegionX][uRegionY][uRegionZ].vertexBuffer); glVertexPointer(3, GL_FLOAT, 36, 0); glNormalPointer(GL_FLOAT, 36, (GLvoid*)12); glColorPointer(3, GL_FLOAT, 36, (GLvoid*)24); @@ -252,8 +260,9 @@ void display ( void ) // Create The Display Function glDisableClientState(GL_COLOR_ARRAY); glDisableClientState(GL_NORMAL_ARRAY); - glDisableClientState(GL_VERTEX_ARRAY); */ - + glDisableClientState(GL_VERTEX_ARRAY); + +#else IndexedSurfacePatch* ispCurrent = g_indexedSurfacePatches[uRegionX][uRegionY][uRegionZ]; const vector& vecVertices = ispCurrent->getVertices(); @@ -311,6 +320,7 @@ void display ( void ) // Create The Display Function } glEnd(); +#endif } } } @@ -401,6 +411,7 @@ void main ( int argc, char** argv ) // Create Main Function For Bringing It Al glutTimerFunc(1000, timerFunc, 0); glutIdleFunc(idle); +#ifdef USE_OPENGL_VERTEX_BUFFERS_OBJECTS #ifdef WIN32 //If we are on Windows we will need GLEW to access recent OpenGL functionality GLenum err = glewInit(); @@ -409,6 +420,7 @@ void main ( int argc, char** argv ) // Create Main Function For Bringing It Al /* Problem: glewInit failed, something is seriously wrong. */ cout << "Error: " << glewGetErrorString(err) << endl; } +#endif #endif //Make our volume contain a sphere in the center. @@ -437,8 +449,7 @@ void main ( int argc, char** argv ) // Create Main Function For Bringing It Al for(uint16 uRegionX = 0; uRegionX < g_uVolumeSideLengthInRegions; ++uRegionX) { //Create a new surface patch (which is basiaclly the PolyVox term for a mesh). - g_indexedSurfacePatches[uRegionX][uRegionY][uRegionZ] = new IndexedSurfacePatch(); - IndexedSurfacePatch* ispCurrent = g_indexedSurfacePatches[uRegionX][uRegionY][uRegionZ]; + IndexedSurfacePatch* ispCurrent = new IndexedSurfacePatch(); //Compute the extents of the current region //FIXME - This is a little complex? PolyVox could @@ -457,7 +468,11 @@ void main ( int argc, char** argv ) // Create Main Function For Bringing It Al //Extract the surface for this region extractReferenceSurface(&g_volData, Region(regLowerCorner, regUpperCorner), ispCurrent); +#ifdef USE_OPENGL_VERTEX_BUFFERS_OBJECTS g_openGLSurfacePatches[uRegionX][uRegionY][uRegionZ] = BuildOpenGLSurfacePatch(*ispCurrent); +#else + g_indexedSurfacePatches[uRegionX][uRegionY][uRegionZ] = ispCurrent; +#endif //delete ispCurrent; }