Work on new OpenGL example - Splitting into several files.
This commit is contained in:
parent
877396af31
commit
74292f7a62
@ -1,4 +1,5 @@
|
||||
#include "OpenGLImmediateModeSupport.h"
|
||||
#include "OpenGLSupport.h"
|
||||
|
||||
#include "PolyVoxCore/IndexedSurfacePatch.h"
|
||||
|
||||
@ -8,59 +9,28 @@ using namespace std;
|
||||
void renderRegionImmediateMode(PolyVox::IndexedSurfacePatch& isp)
|
||||
{
|
||||
const vector<SurfaceVertex>& vecVertices = isp.getVertices();
|
||||
const vector<uint32>& vecIndices = isp.getIndices();
|
||||
const vector<uint32>& vecIndices = isp.getIndices();
|
||||
|
||||
glBegin(GL_TRIANGLES);
|
||||
for(vector<uint32>::const_iterator iterIndex = vecIndices.begin(); iterIndex != vecIndices.end(); ++iterIndex)
|
||||
{
|
||||
const SurfaceVertex& vertex = vecVertices[*iterIndex];
|
||||
const Vector3DFloat& v3dVertexPos = vertex.getPosition();
|
||||
//const Vector3DFloat v3dRegionOffset(uRegionX * g_uRegionSideLength, uRegionY * g_uRegionSideLength, uRegionZ * g_uRegionSideLength);
|
||||
const Vector3DFloat v3dFinalVertexPos = v3dVertexPos + static_cast<Vector3DFloat>(isp.m_v3dRegionPosition);
|
||||
glBegin(GL_TRIANGLES);
|
||||
for(vector<uint32>::const_iterator iterIndex = vecIndices.begin(); iterIndex != vecIndices.end(); ++iterIndex)
|
||||
{
|
||||
const SurfaceVertex& vertex = vecVertices[*iterIndex];
|
||||
const Vector3DFloat& v3dVertexPos = vertex.getPosition();
|
||||
//const Vector3DFloat v3dRegionOffset(uRegionX * g_uRegionSideLength, uRegionY * g_uRegionSideLength, uRegionZ * g_uRegionSideLength);
|
||||
const Vector3DFloat v3dFinalVertexPos = v3dVertexPos + static_cast<Vector3DFloat>(isp.m_v3dRegionPosition);
|
||||
|
||||
|
||||
|
||||
|
||||
GLfloat red = 0.0f;
|
||||
GLfloat green = 0.0f;
|
||||
GLfloat blue = 0.0f;
|
||||
|
||||
uint8 material = vertex.getMaterial() + 0.5;
|
||||
|
||||
switch(material)
|
||||
{
|
||||
case 1:
|
||||
red = 1.0;
|
||||
green = 0.0;
|
||||
blue = 0.0;
|
||||
break;
|
||||
case 2:
|
||||
red = 0.0;
|
||||
green = 1.0;
|
||||
blue = 0.0;
|
||||
break;
|
||||
case 3:
|
||||
red = 0.0;
|
||||
green = 0.0;
|
||||
blue = 1.0;
|
||||
break;
|
||||
case 4:
|
||||
red = 1.0;
|
||||
green = 1.0;
|
||||
blue = 0.0;
|
||||
break;
|
||||
case 5:
|
||||
red = 1.0;
|
||||
green = 0.0;
|
||||
blue = 1.0;
|
||||
break;
|
||||
}
|
||||
uint8 material = vertex.getMaterial() + 0.5;
|
||||
|
||||
glColor3f(red, green, blue);
|
||||
glNormal3f(vertex.getNormal().getX(), vertex.getNormal().getY(), vertex.getNormal().getZ());
|
||||
glVertex3f(v3dFinalVertexPos.getX(), v3dFinalVertexPos.getY(), v3dFinalVertexPos.getZ());
|
||||
|
||||
|
||||
}
|
||||
glEnd();
|
||||
OpenGLColour colour = convertMaterialIDToColour(material);
|
||||
|
||||
glColor3f(colour.red, colour.green, colour.blue);
|
||||
glNormal3f(vertex.getNormal().getX(), vertex.getNormal().getY(), vertex.getNormal().getZ());
|
||||
glVertex3f(v3dFinalVertexPos.getX(), v3dFinalVertexPos.getY(), v3dFinalVertexPos.getZ());
|
||||
|
||||
|
||||
}
|
||||
glEnd();
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
#include "OpenGLSupport.h"
|
||||
|
||||
using namespace PolyVox;
|
||||
|
||||
OpenGLColour convertMaterialIDToColour(PolyVox::uint8 materialID)
|
||||
{
|
||||
OpenGLColour colour;
|
||||
|
||||
switch(materialID)
|
||||
{
|
||||
case 1:
|
||||
colour.red = 1.0;
|
||||
colour.green = 0.0;
|
||||
colour.blue = 0.0;
|
||||
break;
|
||||
case 2:
|
||||
colour.red = 0.0;
|
||||
colour.green = 1.0;
|
||||
colour.blue = 0.0;
|
||||
break;
|
||||
case 3:
|
||||
colour.red = 0.0;
|
||||
colour.green = 0.0;
|
||||
colour.blue = 1.0;
|
||||
break;
|
||||
case 4:
|
||||
colour.red = 1.0;
|
||||
colour.green = 1.0;
|
||||
colour.blue = 0.0;
|
||||
break;
|
||||
case 5:
|
||||
colour.red = 1.0;
|
||||
colour.green = 0.0;
|
||||
colour.blue = 1.0;
|
||||
break;
|
||||
}
|
||||
|
||||
return colour;
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
#ifndef __OpenGLExample_OpenGLSupport_H__
|
||||
#define __OpenGLExample_OpenGLSupport_H__
|
||||
|
||||
#include "PolyVoxCore/PolyVoxForwardDeclarations.h"
|
||||
|
||||
#include "glew/glew.h"
|
||||
|
||||
struct OpenGLColour
|
||||
{
|
||||
GLfloat red;
|
||||
GLfloat green;
|
||||
GLfloat blue;
|
||||
};
|
||||
|
||||
OpenGLColour convertMaterialIDToColour(PolyVox::uint8 materialID);
|
||||
|
||||
#endif //__OpenGLExample_OpenGLSupport_H__
|
@ -1,3 +1,4 @@
|
||||
#include "OpenGLSupport.h"
|
||||
#include "OpenGLVertexBufferObjectSupport.h"
|
||||
|
||||
#include "PolyVoxCore/IndexedSurfacePatch.h"
|
||||
@ -49,46 +50,15 @@ OpenGLSurfacePatch BuildOpenGLSurfacePatch(IndexedSurfacePatch& isp)
|
||||
*ptr = vertex.getNormal().getZ();
|
||||
ptr++;
|
||||
|
||||
GLfloat red = 0.0f;
|
||||
GLfloat green = 0.0f;
|
||||
GLfloat blue = 0.0f;
|
||||
|
||||
uint8 material = vertex.getMaterial() + 0.5;
|
||||
|
||||
switch(material)
|
||||
{
|
||||
case 1:
|
||||
red = 1.0;
|
||||
green = 0.0;
|
||||
blue = 0.0;
|
||||
break;
|
||||
case 2:
|
||||
red = 0.0;
|
||||
green = 1.0;
|
||||
blue = 0.0;
|
||||
break;
|
||||
case 3:
|
||||
red = 0.0;
|
||||
green = 0.0;
|
||||
blue = 1.0;
|
||||
break;
|
||||
case 4:
|
||||
red = 1.0;
|
||||
green = 1.0;
|
||||
blue = 0.0;
|
||||
break;
|
||||
case 5:
|
||||
red = 1.0;
|
||||
green = 0.0;
|
||||
blue = 1.0;
|
||||
break;
|
||||
}
|
||||
OpenGLColour colour = convertMaterialIDToColour(material);
|
||||
|
||||
*ptr = red;
|
||||
*ptr = colour.red;
|
||||
ptr++;
|
||||
*ptr = green;
|
||||
*ptr = colour.green;
|
||||
ptr++;
|
||||
*ptr = blue;
|
||||
*ptr = colour.blue;
|
||||
ptr++;
|
||||
}
|
||||
|
||||
|
@ -12,9 +12,9 @@
|
||||
#define USE_OPENGL_VERTEX_BUFFERS_OBJECTS
|
||||
|
||||
#ifdef WIN32
|
||||
#include "glew/glew.h"
|
||||
#include "glew/glew.h"
|
||||
#else
|
||||
#include <gl/gl.h> // The GL Header File
|
||||
#include <gl/gl.h> // The GL Header File
|
||||
#endif
|
||||
#include <gl/glut.h> // The GL Utility Toolkit (Glut) Header]
|
||||
|
||||
@ -78,7 +78,7 @@ void display ( void ) // Create The Display Function
|
||||
|
||||
glMatrixMode ( GL_MODELVIEW ); // Select The Model View Matrix
|
||||
glLoadIdentity(); // Reset The Current Modelview Matrix
|
||||
|
||||
|
||||
//Moves the camera back so we can see the volume
|
||||
glTranslatef(0.0f, 0.0f, -100.0f);
|
||||
|
||||
@ -101,9 +101,9 @@ void display ( void ) // Create The Display Function
|
||||
}
|
||||
else
|
||||
{
|
||||
IndexedSurfacePatch* ispCurrent = g_indexedSurfacePatches[uRegionX][uRegionY][uRegionZ];
|
||||
renderRegionImmediateMode(*ispCurrent);
|
||||
|
||||
IndexedSurfacePatch* ispCurrent = g_indexedSurfacePatches[uRegionX][uRegionY][uRegionZ];
|
||||
renderRegionImmediateMode(*ispCurrent);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -183,7 +183,7 @@ default:
|
||||
|
||||
void main ( int argc, char** argv ) // Create Main Function For Bringing It All Together
|
||||
{
|
||||
g_bUseOpenGLVertexBufferObjects = false;
|
||||
g_bUseOpenGLVertexBufferObjects = true;
|
||||
glutInit ( &argc, argv ); // Erm Just Write It =)
|
||||
glutInitDisplayMode ( GLUT_RGB | GLUT_DOUBLE ); // Display Mode
|
||||
glutInitWindowSize ( 500, 500 ); // If glutFullScreen wasn't called this is the window size
|
||||
@ -199,13 +199,13 @@ void main ( int argc, char** argv ) // Create Main Function For Bringing It Al
|
||||
if(g_bUseOpenGLVertexBufferObjects)
|
||||
{
|
||||
#ifdef WIN32
|
||||
//If we are on Windows we will need GLEW to access recent OpenGL functionality
|
||||
GLenum err = glewInit();
|
||||
if (GLEW_OK != err)
|
||||
{
|
||||
/* Problem: glewInit failed, something is seriously wrong. */
|
||||
cout << "Error: " << glewGetErrorString(err) << endl;
|
||||
}
|
||||
//If we are on Windows we will need GLEW to access recent OpenGL functionality
|
||||
GLenum err = glewInit();
|
||||
if (GLEW_OK != err)
|
||||
{
|
||||
/* Problem: glewInit failed, something is seriously wrong. */
|
||||
cout << "Error: " << glewGetErrorString(err) << endl;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -257,11 +257,11 @@ void main ( int argc, char** argv ) // Create Main Function For Bringing It Al
|
||||
|
||||
if(g_bUseOpenGLVertexBufferObjects)
|
||||
{
|
||||
g_openGLSurfacePatches[uRegionX][uRegionY][uRegionZ] = BuildOpenGLSurfacePatch(*ispCurrent);
|
||||
g_openGLSurfacePatches[uRegionX][uRegionY][uRegionZ] = BuildOpenGLSurfacePatch(*ispCurrent);
|
||||
}
|
||||
else
|
||||
{
|
||||
g_indexedSurfacePatches[uRegionX][uRegionY][uRegionZ] = ispCurrent;
|
||||
g_indexedSurfacePatches[uRegionX][uRegionY][uRegionZ] = ispCurrent;
|
||||
}
|
||||
//delete ispCurrent;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user