Added setElements to Vector.
Work on new OpenGL example.
This commit is contained in:
parent
0f4a4c0e2b
commit
bdea87d6d6
@ -3,10 +3,19 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
|
||||
PROJECT(OpenGLExample)
|
||||
|
||||
#Projects source files
|
||||
SET(SRC_FILES main.cpp)
|
||||
SET(SRC_FILES
|
||||
glew/glew.c
|
||||
main.cpp
|
||||
)
|
||||
|
||||
#Projects headers files
|
||||
#SET(INC_FILES)
|
||||
SET(INC_FILES
|
||||
glew/glew.h
|
||||
glew/glxew.h
|
||||
glew/wglew.h
|
||||
)
|
||||
|
||||
ADD_DEFINITIONS(-DGLEW_STATIC)
|
||||
|
||||
#Appends "_d" to the generated library when in debug mode
|
||||
SET(CMAKE_DEBUG_POSTFIX "_d")
|
||||
|
73
examples/OpenGL/glew/LICENSE.txt
Normal file
73
examples/OpenGL/glew/LICENSE.txt
Normal file
@ -0,0 +1,73 @@
|
||||
The OpenGL Extension Wrangler Library
|
||||
Copyright (C) 2002-2007, Milan Ikits <milan ikits[]ieee org>
|
||||
Copyright (C) 2002-2007, Marcelo E. Magallon <mmagallo[]debian org>
|
||||
Copyright (C) 2002, Lev Povalahev
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
* The name of the author may be used to endorse or promote products
|
||||
derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
|
||||
THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
|
||||
Mesa 3-D graphics library
|
||||
Version: 7.0
|
||||
|
||||
Copyright (C) 1999-2007 Brian Paul All Rights Reserved.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a
|
||||
copy of this software and associated documentation files (the "Software"),
|
||||
to deal in the Software without restriction, including without limitation
|
||||
the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
and/or sell copies of the Software, and to permit persons to whom the
|
||||
Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included
|
||||
in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
|
||||
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
|
||||
Copyright (c) 2007 The Khronos Group Inc.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a
|
||||
copy of this software and/or associated documentation files (the
|
||||
"Materials"), to deal in the Materials without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Materials, and to
|
||||
permit persons to whom the Materials are furnished to do so, subject to
|
||||
the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included
|
||||
in all copies or substantial portions of the Materials.
|
||||
|
||||
THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
|
12180
examples/OpenGL/glew/glew.c
Normal file
12180
examples/OpenGL/glew/glew.c
Normal file
File diff suppressed because it is too large
Load Diff
12262
examples/OpenGL/glew/glew.h
Normal file
12262
examples/OpenGL/glew/glew.h
Normal file
File diff suppressed because it is too large
Load Diff
1397
examples/OpenGL/glew/glxew.h
Normal file
1397
examples/OpenGL/glew/glxew.h
Normal file
File diff suppressed because it is too large
Load Diff
1165
examples/OpenGL/glew/wglew.h
Normal file
1165
examples/OpenGL/glew/wglew.h
Normal file
File diff suppressed because it is too large
Load Diff
@ -4,9 +4,19 @@
|
||||
#include "PolyVoxCore/Utility.h"
|
||||
|
||||
#include <windows.h> // Standard Header For Most Programs
|
||||
|
||||
#ifdef WIN32
|
||||
#include "glew/glew.h"
|
||||
#else
|
||||
#include <gl/gl.h> // The GL Header File
|
||||
#endif
|
||||
#include <gl/glut.h> // The GL Utility Toolkit (Glut) Header
|
||||
|
||||
#include <iostream>
|
||||
|
||||
|
||||
|
||||
|
||||
//Some namespaces we need
|
||||
using namespace std;
|
||||
using namespace PolyVox;
|
||||
@ -16,7 +26,7 @@ using namespace std;
|
||||
//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_uRegionSideLength = 16;
|
||||
const uint16 g_uRegionSideLength = 32;
|
||||
const uint16 g_uVolumeSideLengthInRegions = g_uVolumeSideLength / g_uRegionSideLength;
|
||||
|
||||
//Creates a volume 128x128x128
|
||||
@ -24,8 +34,10 @@ BlockVolume<uint8> 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
|
||||
IndexedSurfacePatch* g_ispRegionSurfaces[g_uVolumeSideLengthInRegions][g_uVolumeSideLengthInRegions][g_uVolumeSideLengthInRegions];
|
||||
GLuint buffers[g_uVolumeSideLengthInRegions][g_uVolumeSideLengthInRegions][g_uVolumeSideLengthInRegions];
|
||||
GLfloat* data[g_uVolumeSideLengthInRegions][g_uVolumeSideLengthInRegions][g_uVolumeSideLengthInRegions];
|
||||
|
||||
void createSphereInVolume(void)
|
||||
void createSphereInVolume(float fRadius, uint8 uValue)
|
||||
{
|
||||
//This vector hold the position of the center of the volume
|
||||
Vector3DFloat v3dVolCenter(g_volData.getSideLength() / 2, g_volData.getSideLength() / 2, g_volData.getSideLength() / 2);
|
||||
@ -42,11 +54,11 @@ void createSphereInVolume(void)
|
||||
//And compute how far the current position is from the center of the volume
|
||||
float fDistToCenter = (v3dCurrentPos - v3dVolCenter).length();
|
||||
|
||||
//If the current voxel is less than 50 units from the center,
|
||||
//If the current voxel is less than 'radius' units from the center
|
||||
//then we make it solid, otherwise we make it empty space.
|
||||
if(fDistToCenter <= 50.0f)
|
||||
if(fDistToCenter <= fRadius)
|
||||
{
|
||||
g_volData.setVoxelAt(x,y,z, static_cast<uint8>(fDistToCenter));
|
||||
g_volData.setVoxelAt(x,y,z, uValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -74,27 +86,37 @@ void display ( void ) // Create The Display Function
|
||||
glLoadIdentity(); // Reset The Current Modelview Matrix
|
||||
glTranslatef(-g_uVolumeSideLength/2,-g_uVolumeSideLength/2,-200.0f);
|
||||
|
||||
glBegin(GL_TRIANGLES);
|
||||
for(uint16 uRegionZ = 0; uRegionZ < g_uVolumeSideLengthInRegions; ++uRegionZ)
|
||||
{
|
||||
for(uint16 uRegionY = 0; uRegionY < g_uVolumeSideLengthInRegions; ++uRegionY)
|
||||
{
|
||||
for(uint16 uRegionX = 0; uRegionX < g_uVolumeSideLengthInRegions; ++uRegionX)
|
||||
{
|
||||
const vector<SurfaceVertex>& vecVertices = g_ispRegionSurfaces[uRegionX][uRegionY][uRegionZ]->getVertices();
|
||||
GLfloat* current = data[uRegionX][uRegionY][uRegionZ];
|
||||
|
||||
const vector<uint32>& vecIndices = g_ispRegionSurfaces[uRegionX][uRegionY][uRegionZ]->getIndices();
|
||||
for(vector<uint32>::const_iterator iterIndex = vecIndices.begin(); iterIndex != vecIndices.end(); ++iterIndex)
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, buffers[uRegionX][uRegionY][uRegionZ]);
|
||||
glVertexPointer(3, GL_FLOAT, 0, 0);
|
||||
|
||||
glEnableClientState(GL_VERTEX_ARRAY);
|
||||
|
||||
glDrawArrays(GL_TRIANGLES, 0, vecIndices.size());
|
||||
|
||||
glDisableClientState(GL_VERTEX_ARRAY);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
GLenum errCode;
|
||||
const GLubyte *errString;
|
||||
|
||||
if ((errCode = glGetError()) != GL_NO_ERROR)
|
||||
{
|
||||
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 + v3dRegionOffset;
|
||||
glVertex3f(v3dFinalVertexPos.getX(), v3dFinalVertexPos.getY(), v3dFinalVertexPos.getZ());
|
||||
errString = gluErrorString(errCode);
|
||||
cout << "OpenGL Error: " << errString << endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
glEnd();
|
||||
|
||||
|
||||
|
||||
glutSwapBuffers ( );
|
||||
@ -141,8 +163,29 @@ void arrow_keys ( int a_keys, int x, int y ) // Create Special Function (requir
|
||||
|
||||
void main ( int argc, char** argv ) // Create Main Function For Bringing It All Together
|
||||
{
|
||||
glutInit ( &argc, argv ); // Erm Just Write It =)
|
||||
init ();
|
||||
glutInitDisplayMode ( GLUT_RGB | GLUT_DOUBLE ); // Display Mode
|
||||
glutInitWindowSize ( 500, 500 ); // If glutFullScreen wasn't called this is the window size
|
||||
glutCreateWindow ( "PolyVox OpenGL Example" ); // Window Title (argv[0] for current directory as title)
|
||||
//glutFullScreen ( ); // Put Into Full Screen
|
||||
glutDisplayFunc ( display ); // Matching Earlier Functions To Their Counterparts
|
||||
glutReshapeFunc ( reshape );
|
||||
glutKeyboardFunc ( keyboard );
|
||||
glutSpecialFunc ( arrow_keys );
|
||||
|
||||
#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;
|
||||
}
|
||||
#endif
|
||||
|
||||
//Make our volume contain a sphere in the center.
|
||||
createSphereInVolume();
|
||||
createSphereInVolume(50.0f, 1);
|
||||
|
||||
//Our volume is broken down into cuboid regions, and we create one mesh for each region.
|
||||
//This three-level for loop iterates over each region.
|
||||
@ -157,7 +200,7 @@ void main ( int argc, char** argv ) // Create Main Function For Bringing It Al
|
||||
IndexedSurfacePatch* ispCurrent = g_ispRegionSurfaces[uRegionX][uRegionY][uRegionZ];
|
||||
|
||||
//Compute the extents of the current region
|
||||
//FIXME - This is a little coplex? PolyVox could
|
||||
//FIXME - This is a little complex? PolyVox could
|
||||
//provide more functions for dealing with regions?
|
||||
uint16 regionStartX = uRegionX * g_uRegionSideLength;
|
||||
uint16 regionStartY = uRegionY * g_uRegionSideLength;
|
||||
@ -172,20 +215,40 @@ 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);
|
||||
|
||||
const vector<SurfaceVertex>& vecVertices = g_ispRegionSurfaces[uRegionX][uRegionY][uRegionZ]->getVertices();
|
||||
const vector<uint32>& vecIndices = g_ispRegionSurfaces[uRegionX][uRegionY][uRegionZ]->getIndices();
|
||||
|
||||
data[uRegionX][uRegionY][uRegionZ] = new GLfloat[vecIndices.size() * 3];
|
||||
GLfloat* current = data[uRegionX][uRegionY][uRegionZ];
|
||||
|
||||
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 + v3dRegionOffset;
|
||||
//glVertex3f(v3dFinalVertexPos.getX(), v3dFinalVertexPos.getY(), v3dFinalVertexPos.getZ());
|
||||
*current = v3dFinalVertexPos.getX();
|
||||
current++;
|
||||
*current = v3dFinalVertexPos.getY();
|
||||
current++;
|
||||
*current = v3dFinalVertexPos.getZ();
|
||||
current++;
|
||||
}
|
||||
|
||||
glGenBuffers(1, &(buffers[uRegionX][uRegionY][uRegionZ]));
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, buffers[uRegionX][uRegionY][uRegionZ]);
|
||||
glBufferData(GL_ARRAY_BUFFER, vecIndices.size() * sizeof(GLfloat) * 3, data[uRegionX][uRegionY][uRegionZ], GL_STATIC_DRAW);
|
||||
|
||||
delete data[uRegionX][uRegionY][uRegionZ];
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
glutInit ( &argc, argv ); // Erm Just Write It =)
|
||||
init ();
|
||||
glutInitDisplayMode ( GLUT_RGB | GLUT_DOUBLE ); // Display Mode
|
||||
glutInitWindowSize ( 500, 500 ); // If glutFullScreen wasn't called this is the window size
|
||||
glutCreateWindow ( "PolyVox OpenGL Example" ); // Window Title (argv[0] for current directory as title)
|
||||
//glutFullScreen ( ); // Put Into Full Screen
|
||||
glutDisplayFunc ( display ); // Matching Earlier Functions To Their Counterparts
|
||||
glutReshapeFunc ( reshape );
|
||||
glutKeyboardFunc ( keyboard );
|
||||
glutSpecialFunc ( arrow_keys );
|
||||
|
||||
glutMainLoop ( ); // Initialize The Main Loop
|
||||
|
||||
//Delete all the surface patches we created.
|
||||
|
@ -65,7 +65,7 @@ namespace PolyVox
|
||||
///Division and Assignment Operator.
|
||||
Vector<Size,Type>& operator/=(const Type& rhs) throw();
|
||||
|
||||
///Element Access
|
||||
///Element Access.
|
||||
Type getElement(uint32 index) const throw();
|
||||
///Get the x component of the vector.
|
||||
Type getX(void) const throw();
|
||||
@ -76,8 +76,14 @@ namespace PolyVox
|
||||
///Get the w component of the vector.
|
||||
Type getW(void) const throw();
|
||||
|
||||
///Element Access
|
||||
///Element Access.
|
||||
void setElement(uint32 index, Type tValue) throw();
|
||||
///Element Access.
|
||||
void setElements(Type x, Type y) throw();
|
||||
///Element Access.
|
||||
void setElements(Type x, Type y, Type z) throw();
|
||||
///Element Access.
|
||||
void setElements(Type x, Type y, Type z, Type w) throw();
|
||||
///Set the x component of the vector.
|
||||
void setX(Type tX) throw();
|
||||
///Set the y component of the vector.
|
||||
|
@ -397,6 +397,50 @@ namespace PolyVox
|
||||
m_tElements[index] = tValue;
|
||||
}
|
||||
|
||||
/**
|
||||
Sets several elements of a vector at once.
|
||||
\param x x component to set.
|
||||
\param y y component to set.
|
||||
*/
|
||||
template <uint32 Size,typename Type>
|
||||
inline void Vector<Size,Type>::setElements(Type x, Type y) throw()
|
||||
{
|
||||
m_tElements[0] = x;
|
||||
m_tElements[1] = y;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
Sets several elements of a vector at once.
|
||||
\param x x component to set.
|
||||
\param y y component to set.
|
||||
\param z z component to set.
|
||||
*/
|
||||
template <uint32 Size,typename Type>
|
||||
inline void Vector<Size,Type>::setElements(Type x, Type y, Type z) throw()
|
||||
{
|
||||
m_tElements[0] = x;
|
||||
m_tElements[1] = y;
|
||||
m_tElements[2] = z;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
Sets several elements of a vector at once.
|
||||
\param x x component to set.
|
||||
\param y y component to set.
|
||||
\param z z component to set.
|
||||
\param w w component to set.
|
||||
*/
|
||||
template <uint32 Size,typename Type>
|
||||
inline void Vector<Size,Type>::setElements(Type x, Type y, Type z, Type w) throw()
|
||||
{
|
||||
m_tElements[0] = x;
|
||||
m_tElements[1] = y;
|
||||
m_tElements[2] = z;
|
||||
m_tElements[3] = w;
|
||||
}
|
||||
|
||||
/**
|
||||
\param tX The new value for the X component of a 1, 2, 3, or 4 dimensional Vector.
|
||||
*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user