示例#1
0
void Particles::InitMemory()
{
	assert(!initFlag);

	pos = new float[numParticles * 4];
	vel = new float[numParticles * 4];
	//density = new float[numParticles];
	memset(pos, 0, numParticles * 4 * sizeof(float));
	memset(vel, 0, numParticles * 4 * sizeof(float));
	//memset(density, 0, numParticles * sizeof(float));

	cellStart = new uint[numParticles];
	cellEnd = new uint[numParticles];
	memset(cellStart, 0, numParticles*sizeof(uint));
	memset(cellEnd, 0, numParticles*sizeof(uint));

	uint memSize = sizeof(float) * 4 * numParticles;
	posVbo = CreateVBO(memSize,POSITION);
	registerGLBufferObject(posVbo, &m_cuda_posvbo_resource);

	allocateArray((void **)&velGpu, memSize);
	allocateArray((void **)&sortedPos, memSize);
	allocateArray((void **)&sortedVel, memSize);
	allocateArray((void **)&gridParticleHash, numParticles*sizeof(uint));
	allocateArray((void **)&gridParticleIndex, numParticles*sizeof(uint));
	allocateArray((void **)&cellStart, (mparams.wholeNumCells)*sizeof(uint));
	allocateArray((void **)&cellEnd, (mparams.wholeNumCells)*sizeof(uint));

	InitColor();
	InitSolid();
	setParameters(&mparams);
	initFlag = true;
}
示例#2
0
void OpenGLBookApp::setup()
{
    LoadShaders();
    CreateShaders();
    CreateVBO();
    glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
}
示例#3
0
PostProcess::PostProcess(int w, int h) {
    m_nScreenW = w;
    m_nScreenH = h;
    
    int u2 = 1;
    int v2 = 1;
    while(u2 < w) u2 *= 2;
    while(v2 < h) v2 *= 2;
    w = u2;
    h = v2;
    
    m_nTextureUniform = 0;
    m_nScaleUniform = 0;
    m_nMVPUniform = 0;
    m_nScreenSpaceVBO = 0;
    m_nBlitShader = 0;
    m_nFramebufferId = 0;
    m_nPositionAttrib = 0;
    m_nUvAttrib = 0;
    
    m_strInputUniform = "texture";
    m_strTypeUniform = "isDepth";
    m_strMvpUniform = "mvp";
    m_strClipPlanesUniform = "clip";
    m_strPositionAttribute = "position";
    m_StrUvAttribute = "uv";
    
    m_pInputTexture = 0;
    m_pOutputTexture = new Texture(w, h, Texture::RGBA_24);
    m_pShader = 0;
    CreateBlitShader();
    CreateFBO(w, h);
    CreateVBO();
}
示例#4
0
void Initialize (int argc, char *argv[])
{
  GLenum GlewInitResult;
  TempString = (char *) malloc (512 + strlen(WINDOW_TITLE_PREFIX));
  TempString[0]='\0';

  InitWindow (argc, argv);

  glewExperimental = GL_TRUE;
  GlewInitResult = glewInit();

  if (GLEW_OK != GlewInitResult) {
    fprintf (stderr,
	     "ERROR: %s\n",
	     glewGetErrorString (GlewInitResult) );
    exit (EXIT_FAILURE);
  }

  fprintf (stdout, "INFO: OpengGL Version: %s\n", glGetString (GL_VERSION));

  CreateShaders ();
  CreateVBO ();

  glClearColor (0.0f, 0.0f, 0.0f, 0.0f);
}
示例#5
0
void PrepareData()
{
	p_mesh = muggle::GeometryMesh::GenerateSphere(1.0f, 30, 30);

	CreateVBO();
	CreateVAO();
}
示例#6
0
void Initialize(int argc, char* argv[])
{
  GLenum GlewInitResult;

  InitWindow(argc, argv);

  glewExperimental = GL_TRUE;
  GlewInitResult = glewInit();

  if (GLEW_OK != GlewInitResult) {
    fprintf(
      stderr,
      "ERROR: %s\n",
      glewGetErrorString(GlewInitResult)
    );
    exit(EXIT_FAILURE);
  }
  
  fprintf(
    stdout,
    "INFO: OpenGL Version: %s\n",
    glGetString(GL_VERSION)
  );

  CreateShaders();
  CreateVBO();

  glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
}
示例#7
0
GLMesh::GLMesh(void const *vertexArray, size_t size) 
	: m_vboID(0)
	, m_iboID( 0 )
	, m_iboNumIndexes( 0 )
	, m_vboNumBytes( 0 )
{
	CreateVBO(vertexArray, size);
	
}
示例#8
0
void PrepareData()
{
	p_mesh = muggle::Mesh::Load("res/Stanford 3D Scanning/bunny/reconstruction/bun_zipper.ply");
	// p_mesh = muggle::Mesh::Load("res/Stanford 3D Scanning/dragon_recon/dragon_vrip.ply");
	// p_mesh = muggle::Mesh::Load("res/Stanford 3D Scanning/happy_recon/happy_vrip.ply");

	CreateVBO();
	CreateVAO();
}
示例#9
0
ASprite::ASprite(void): ATextureNode(){
	// initialize the indices array
	_indices = new GLubyte[4];
	_indices[0] = 3;
	_indices[1] = 0;
	_indices[2] = 2;
	_indices[3] = 1;

	CreateVBO();
}
示例#10
0
ASprite::ASprite(const std::string& $fileName, const Recti& $rect): ATextureNode($fileName, $rect){
	// initialize the indices array
	_indices = new GLubyte[4];
	_indices[0] = 3;
	_indices[1] = 0;
	_indices[2] = 2;
	_indices[3] = 1;

	CreateVBO();
}
示例#11
0
void Visual::Main()
{
    // create VBO
    CreateVBO(&_vbo, &_vboResource, cudaGraphicsMapFlagsWriteDiscard);

    // run the cuda part
    RunCuda(&_vboResource);

    // start rendering mainloop
    glutMainLoop();
}
示例#12
0
// --------------------------------------------------------------------
Landscape::Landscape(int ClipmapRimWidth, float VerticesInterval):
RestartIndex(0xFFFFFFFF), Offset(VerticesInterval), VBOSize(0), IBOSize(0), TBOSize(0), HeightData(0), HeightDataSize(0), StartIndexX(0), StartIndexY(0)
{
	ClipmapIBOsData = new unsigned int*[IBO_MODES_AMOUNT];

	IBOSize = new unsigned int[IBO_MODES_AMOUNT];

	ClipmapVBOWidth = ClipmapRimWidth * 4 + 4;
	TBOSize = ClipmapRimWidth * 4 + 5;

	CreateVBO();

	for (int i = 0; i < IBO_MODES_AMOUNT; ++i)
		CreateIBO((ClipmapIBOMode)i);


	HeightDataSize = 424;
	StartIndexX = StartIndexY = 210;

	HeightData = new float[HeightDataSize * HeightDataSize];

	LOG("Generating terrain data...");

	for (unsigned int i = 0; i < HeightDataSize; ++i)
	{
		for (unsigned int j = 0; j < HeightDataSize; ++j)
		{
			//HeightData[i + HeightDataSize * j] = 10.0f + i / 10.0f;
			//HeightData[i + HeightDataSize * j] = (i % 32) / 8.0f + 430.0f;
			//HeightData[i + HeightDataSize * j] = (j % 512 == 113 || i % 512 == 113) ? (20.0f) : (0.0f);
			//HeightData[i + HeightDataSize * j] = 93.8f;
			//HeightData[i + HeightDataSize * j] = 50.0f + sin(float(i) / 3.0f) * 1.0f + sin(float(j) / 5.6f) * 1.6f;
			//HeightData[i + HeightDataSize * j] = 20.0f + j / 11.0f + i / 4.36f;
			//HeightData[i + HeightDataSize * j] = sin(float(j) / 400.f) * 80.0f + 300.0f;
			HeightData[i + HeightDataSize * j] = 70.0f + sin(float(i) / 10.0f) * 2.0f + sin(float(j) / 25.6f) * 10.6f;

			//float a = sin(float(i) / (1.0 * 704.0f)) * 30.0f;
			//float b = sin(float(i) / (1.0 * 352.0f)) * 25.0f;
			//float c = (sin(float(j) / (1.0 * 469.4f)) - (cos(float(j) / (1.0 * 234.7f)) + 1.0f) / 4.5f) * 30.0f;
			//float d = sin(float(j) / (2.0 * 58.f)) * 3.0f + sin(float(i) / (2.0 * 122.f)) * 5.0f;
			//float e = sin(float(i) / (3.0 * 2.0f)) * 0.8f * cos(float(j) / (3.0 * 6.2f)) * 0.6f + sin(float(j) / (3.0 * 2.3f)) * 0.8f * cos(float(i) / (3.0 * 6.4f)) * 0.5f;
			//HeightData[i + HeightDataSize * j] = (a + b + c + d + e) * 5.0f;
		}

		if (HeightDataSize > 10 && i % (HeightDataSize / 10) == 0)
			LOG("Progress: " << i / (HeightDataSize / 10) * 10 << "%");
	}

	StartIndexX += TBOSize / 2;
	StartIndexY += TBOSize / 2;

	LOG("Terrain Ready!\n");
}
示例#13
0
/**
 * Model3DS
 * Konstruktor. Lädt das Modell.
 * @param filepointer der 3ds-Dateis
 * @param tex Enum der Textur
 */
Model3DS::Model3DS(FILE* f, GLuint tex) {
	m_TotalFaces = 0;
	m_tex = tex;
	m_model = lib3ds_file_load(f);
	// If loading the model failed, we throw an exception
	if(!m_model)
	{
		LOGI("Unable to load model\n");
	}
	else
	{
		CreateVBO();
	}

}
示例#14
0
void Particles::InitColor()
{
	colorVbo = CreateVBO(numParticles * 4 * sizeof(float),COLOR);
	registerGLBufferObject(colorVbo, &m_cuda_colorvbo_resource);
	glBindBufferARB(GL_ARRAY_BUFFER_ARB, colorVbo);
	float *data = (float *)glMapBufferARB(GL_ARRAY_BUFFER_ARB, GL_WRITE_ONLY);
	float *ptr = data;
	for (uint i = 0; i<numParticles; i++)
	{
		*ptr++ = rand()/ (float)RAND_MAX;
		*ptr++ = rand() / (float)RAND_MAX;
		*ptr++ = rand() / (float)RAND_MAX;
		*ptr++ = 1.0f;
	}
	glUnmapBufferARB(GL_ARRAY_BUFFER_ARB);
}
示例#15
0
GModelSphere::GModelSphere(const int rows, const int cols, const float rad)
{
	VertexAttribute.clear();
	Index.clear();

	for (int i = 0; i < rows + 1; i++){
		float r = (float)M_PI / (float)rows * i;
		float ry = cos(r);
		float rr = sin(r);

		for (int j = 0; j < cols + 1; j++){
			float tr = (float)M_PI * 2 / (float)cols * j;
			float tx = rr * rad * cos(tr);
			float ty = ry * rad;
			float tz = rr * rad * sin(tr);
			float rx = rr * cos(tr);
			float rz = rr * sin(tr);

			GVertexAttribute vertexAttr;
			vertexAttr.position = vec3(tx, ty, tz);
			vertexAttr.normal = vec3(rx, ry, rz);
//			vertexAttr.color = vec4(1.0, 0.0, 1.0, 1.0);
			vec3 hsv(360.0f / (float)rows * i, 1.0, 1.0);
			vertexAttr.color = vec4(hsv2rgb(hsv), 1.0);

			VertexAttribute.push_back(vertexAttr);
		}

		for (int i = 0; i < rows; i++){
			for (int j = 0; j < cols; j++){
				int r = (cols + 1) * i + j;
				Index.push_back(u16vec3(r, r + 1, r + cols + 2));
				Index.push_back(u16vec3(r, r + cols + 2, r + cols + 1));
			}
		}

	}

	CreateVBO();
	CreateIBO();
	BindVBO();
	BindIBO();


}
示例#16
0
GLTexture* UIOpenGLTextures::CreateTexture(QSize ActualSize, bool UsePBO,
                                           uint Type, uint DataType,
                                           uint DataFmt, uint InternalFmt,
                                           uint Filter, uint Wrap)
{
    if (!Type)
        Type = m_defaultTextureType;

    QSize totalsize = GetTextureSize(Type, ActualSize);

    GLuint tex;
    glGenTextures(1, &tex);
    glBindTexture(Type, tex);

    if (tex)
    {
        GLTexture *texture = new GLTexture(tex);
        texture->m_type        = Type;
        texture->m_dataType    = DataType;
        texture->m_dataFmt     = DataFmt;
        texture->m_internalFmt = InternalFmt;
        texture->m_size        = totalsize;
        texture->m_actualSize  = ActualSize;
        texture->m_dataSize    = GetBufferSize(ActualSize, DataFmt, DataType);
        texture->m_internalDataSize = GetBufferSize(totalsize, InternalFmt, GL_UNSIGNED_BYTE);
        SetTextureFilters(texture, Filter, Wrap);
        ClearTexture(texture);
        if (UsePBO)
            CreatePBO(texture);
        CreateVBO(texture);

        m_textures.insert(tex, texture);

        return texture;
    }

    return NULL;
}
示例#17
0
// Builds the vertex buffer objects
void _Graphics::BuildVertexBuffers() {
	VertexBuffer[VBO_NONE] = 0;

	// Circle
	{
		float Triangles[GRAPHICS_CIRCLE_VERTICES * 2];

		// Get vertices
		for(int i = 0; i < GRAPHICS_CIRCLE_VERTICES; i++) {
			float Radians = ((float)i / GRAPHICS_CIRCLE_VERTICES) * (glm::pi<float>() * 2.0f);
			Triangles[i * 2] = std::cos(Radians);
			Triangles[i * 2 + 1] = std::sin(Radians);
		}

		VertexBuffer[VBO_CIRCLE] = CreateVBO(Triangles, sizeof(Triangles), GL_STATIC_DRAW);
	}

	// Textured 2D Quad
	{
		// Vertex data for quad
		float Triangles[] = {
			-0.5f,  0.5f,
			 0.5f,  0.5f,
			-0.5f, -0.5f,
			 0.5f, -0.5f,
			 0.0f, 1.0f,
			 1.0f, 1.0f,
			 0.0f, 0.0f,
			 1.0f, 0.0f,
		};

		VertexBuffer[VBO_QUAD] = CreateVBO(Triangles, sizeof(Triangles), GL_STATIC_DRAW);
	}

	// Dynamic vbo for drawing animations
	{

		float Triangles[] = {
			-0.5f, 0.5f,
			 0.5f,  0.5f,
			-0.5f, -0.5f,
			 0.5f, -0.5f,
			 0.0f,  0.0f,
			 0.0f,  0.0f,
			 0.0f,  0.0f,
			 0.0f,  0.0f,
		};

		VertexBuffer[VBO_ATLAS] = CreateVBO(Triangles, sizeof(Triangles), GL_DYNAMIC_DRAW);
	}

	// Cube
	{

		float Triangles[] = {

			// Top
			1.0f,  0.0f,  1.0f,  1.0f,  0.0f,  0.0f,  0.0f,  1.0f,
			0.0f,  0.0f,  1.0f,  0.0f,  0.0f,  0.0f,  0.0f,  1.0f,
			1.0f,  1.0f,  1.0f,  1.0f,  1.0f,  0.0f,  0.0f,  1.0f,
			0.0f,  1.0f,  1.0f,  0.0f,  1.0f,  0.0f,  0.0f,  1.0f,

			// Front
			1.0f,  1.0f,  1.0f,  1.0f,  0.0f,  0.0f,  1.0f,  0.0f,
			0.0f,  1.0f,  1.0f,  0.0f,  0.0f,  0.0f,  1.0f,  0.0f,
			1.0f,  1.0f,  0.0f,  1.0f,  1.0f,  0.0f,  1.0f,  0.0f,
			0.0f,  1.0f,  0.0f,  0.0f,  1.0f,  0.0f,  1.0f,  0.0f,

			// Left
			0.0f,  1.0f,  1.0f,  1.0f,  0.0f, -1.0f,  0.0f,  0.0f,
			0.0f,  0.0f,  1.0f,  0.0f,  0.0f, -1.0f,  0.0f,  0.0f,
			0.0f,  1.0f,  0.0f,  1.0f,  1.0f, -1.0f,  0.0f,  0.0f,
			0.0f,  0.0f,  0.0f,  0.0f,  1.0f, -1.0f,  0.0f,  0.0f,

			// Back
			0.0f,  0.0f,  1.0f,  1.0f,  0.0f,  0.0f, -1.0f,  0.0f,
			1.0f,  0.0f,  1.0f,  0.0f,  0.0f,  0.0f, -1.0f,  0.0f,
			0.0f,  0.0f,  0.0f,  1.0f,  1.0f,  0.0f, -1.0f,  0.0f,
			1.0f,  0.0f,  0.0f,  0.0f,  1.0f,  0.0f, -1.0f,  0.0f,

			// Right
			1.0f,  0.0f,  1.0f,  1.0f,  0.0f,  1.0f,  0.0f,  0.0f,
			1.0f,  1.0f,  1.0f,  0.0f,  0.0f,  1.0f,  0.0f,  0.0f,
			1.0f,  0.0f,  0.0f,  1.0f,  1.0f,  1.0f,  0.0f,  0.0f,
			1.0f,  1.0f,  0.0f,  0.0f,  1.0f,  1.0f,  0.0f,  0.0f,

		};

		VertexBuffer[VBO_CUBE] = CreateVBO(Triangles, sizeof(Triangles), GL_STATIC_DRAW);
	}
}
void TerrainGenerator::RenderHeightMap()					// This Renders The Height Map As Quads
{
	glPushMatrix();
	int X = 0, Y = 0;									// Create Some Variables To Walk The Array With.
	int x, y, z;										// Create Some Variables For Readability
	glScalef(scaleValue, scaleValue * HEIGHT_RATIO, scaleValue);
	glTranslatef(-512,-120,-512);
	if(!g_HeightMap.size()) return;								// Make Sure Our Height Data Is Valid
	glCullFace(GL_BACK);
	glEnable(GL_CULL_FACE);

	fVector3d first;
	fVector3d second;
	fVector3d third;
	fVector3d a;
	fVector3d b;
	fVector3d n;
	double l;

	if(_vboInit) 
	{ 
		for ( X = 0; X < (MAP_SIZE-STEP_SIZE); X += STEP_SIZE )
		{
			for ( Y = 0; Y < (MAP_SIZE-STEP_SIZE); Y += STEP_SIZE )
			{
				//calcNormals
				first.x = X;
				first.y = Height(X, Y );
				first.z = Y;
				second.x = X;
				second.y = Height(X, Y + STEP_SIZE);
				second.z = Y + STEP_SIZE;
				third.x = X + STEP_SIZE;
				third.y = Height(X + STEP_SIZE, Y );
				third.z = Y;

				a.x = second.x - first.x;
				a.y = second.y - first.y;
				a.z = second.z - first.z;

				b.x = third.x - first.x;
				b.y = third.y - first.y;
				b.z = third.z - first.z;

				n.x = (a.y * b.z) - (a.z * b.y);
				n.y = (a.z * b.x) - (a.x * b.z);
				n.z = (a.x * b.y) - (a.y * b.x);

				// Normalize (divide by root of dot product)
				l = sqrt(n.x * n.x + n.y * n.y + n.z * n.z);
				n.x /= l;
				n.y /= l;
				n.z /= l;

				// Get The (X, Y, Z) Value For The Bottom Left Vertex
				x = X;							
				y = Height(X, Y );	
				z = Y;							

				SetTex(1.0f, 1.0f);
				SetNormal(n.x,n.y,n.z);
				SetVertice(x,y,z);
				
				// Get The (X, Y, Z) Value For The Top Left Vertex
				x = X;										
				y = Height(X, Y + STEP_SIZE );  
				z = Y + STEP_SIZE ;	

				SetTex(0.0f, 1.0f);
				SetNormal(n.x,n.y,n.z);
				SetVertice(x,y,z);							// Send This Vertex a VBO then To OpenGL To Be Rendered

				// Get The (X, Y, Z) Value For The Top Right Vertex
				x = X + STEP_SIZE; 
				y = Height(X + STEP_SIZE, Y + STEP_SIZE ); 
				z = Y + STEP_SIZE ;

				SetTex(0.0f, 0.0f);
				SetNormal(n.x,n.y,n.z);
				SetVertice(x,y,z);
				
				// Get The (X, Y, Z) Value For The Bottom Right Vertex
				x = X + STEP_SIZE; 
				y = Height(X + STEP_SIZE, Y ); 
				z = Y;

				SetTex(1.0f, 0.0f);
				SetNormal(n.x,n.y,n.z);
				SetVertice(x,y,z);
			}
		}
		InitVBO(); 
		_vboInit = false;
	}

	CreateVBO();							// Render Polygon
	glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
	glPopMatrix();
}
示例#19
0
void Sphere::Draw()
{
    CreateVBO();
    ApplyTransform();
    glDrawElements(GL_TRIANGLE_STRIP, m_indices.size(), GL_UNSIGNED_INT, 0);
}
示例#20
0
///------------------------------------------------------
///
///------------------------------------------------------
void GLMesh::CreateBufferFromC23File(const std::string& filePath, const std::string& fourChars)
{
	BinaryFileParser modelParser(filePath);
	std::string nextFourChars = modelParser.ReadNextString(4);

	if (!Utility::TestFourChars((unsigned char*)nextFourChars.data(), fourChars))
	{
		return ;
	}
	unsigned char subType;
	subType = modelParser.ReadNextUnsignedChar();
	unsigned char version = modelParser.ReadNextChar();
	std::string comments = modelParser.ReadNextString();
	version;
	//////////////////////////////////////////////////////////////////////////
	if (subType == 1 || subType == 2)
	{	
	unsigned int vertsNum = modelParser.ReadNextUnsignedInt();
	//qNTBVertex3D_PCT* vertexArray = new NTBVertex3D_PCT[vertsNum];
	NTBVertex3D_PCT* vertexArray = new NTBVertex3D_PCT[vertsNum];
	for (unsigned int i = 0; i < vertsNum; i++)
	{
		NTBVertex3D_PCT newVert;
		newVert = modelParser.ReadNextNTB_Vert3D();
		vertexArray[i] = newVert;
	}
	CreateVBO(vertexArray, vertsNum*sizeof(NTBVertex3D_PCT));
	unsigned int intIndexNum = modelParser.ReadNextUnsignedInt();
	unsigned int* intIndex = new unsigned int[intIndexNum];
	for (unsigned int i = 0; i < intIndexNum;i++)
	{
		intIndex[i] = modelParser.ReadNextUnsignedInt();
	}

	CreateIBO(intIndex, intIndexNum*4);
	return;
	}
	//////////////////////////////////////////////////////////////////////////
	if (subType == 4)
	{
		unsigned int vertsNum = modelParser.ReadNextUnsignedInt();
		//qNTBVertex3D_PCT* vertexArray = new NTBVertex3D_PCT[vertsNum];
		Vertex3D_Skeletal* vertexArray = new Vertex3D_Skeletal[vertsNum];
		vertexArray = new Vertex3D_Skeletal[vertsNum];
		for (unsigned int i = 0; i < vertsNum; i++)
		{
			Vertex3D_Skeletal newVert;
			newVert = modelParser.ReadNextSkeletonVert();
			vertexArray[i] = newVert;
		}
		CreateVBO(vertexArray, vertsNum*sizeof(Vertex3D_Skeletal));
		unsigned int intIndexNum = modelParser.ReadNextUnsignedInt();
		unsigned int* intIndex = new unsigned int[intIndexNum];
		for (unsigned int i = 0; i < intIndexNum; i++)
		{
			intIndex[i] = modelParser.ReadNextUnsignedInt();
		}

		CreateIBO(intIndex, intIndexNum * 4);
		return;
	}
	//////////////////////////////////////////////////////////////////////////
	//newVert.
}
示例#21
0
GModelCube::GModelCube(const float side){
	const float hs = side*0.5f;
	VertexAttribute.resize(4 * 6);
	int i = 0;
	VertexAttribute[i++].position = vec3(-hs, -hs, hs);
	VertexAttribute[i++].position = vec3(hs, -hs, hs);
	VertexAttribute[i++].position = vec3(hs, hs, hs);
	VertexAttribute[i++].position = vec3(-hs, hs, hs);

	VertexAttribute[i++].position = vec3(-hs, -hs, -hs);
	VertexAttribute[i++].position = vec3(-hs, hs, -hs);
	VertexAttribute[i++].position = vec3(hs, hs, -hs);
	VertexAttribute[i++].position = vec3(hs, -hs, -hs);

	VertexAttribute[i++].position = vec3(-hs, hs, -hs);
	VertexAttribute[i++].position = vec3(-hs, hs, hs);
	VertexAttribute[i++].position = vec3(hs, hs, hs);
	VertexAttribute[i++].position = vec3(hs, hs, -hs);

	VertexAttribute[i++].position = vec3(-hs, -hs, -hs);
	VertexAttribute[i++].position = vec3(hs, -hs, -hs);
	VertexAttribute[i++].position = vec3(hs, -hs, hs);
	VertexAttribute[i++].position = vec3(-hs, -hs, hs);

	VertexAttribute[i++].position = vec3(hs, -hs, -hs);
	VertexAttribute[i++].position = vec3(hs, hs, -hs);
	VertexAttribute[i++].position = vec3(hs, hs, hs);
	VertexAttribute[i++].position = vec3(hs, -hs, hs);

	VertexAttribute[i++].position = vec3(-hs, -hs, -hs);
	VertexAttribute[i++].position = vec3(-hs, -hs, hs);
	VertexAttribute[i++].position = vec3(-hs, hs, hs);
	VertexAttribute[i++].position = vec3(-hs, hs, -hs);

	i = 0;
	VertexAttribute[i++].normal = vec3(-1.0, -1.0, 1.0);
	VertexAttribute[i++].normal = vec3(1.0, -1.0, 1.0);
	VertexAttribute[i++].normal = vec3(1.0, 1.0, 1.0);
	VertexAttribute[i++].normal = vec3(-1.0, 1.0, 1.0);

	VertexAttribute[i++].normal = vec3(-1.0, -1.0, -1.0);
	VertexAttribute[i++].normal = vec3(-1.0, 1.0, -1.0);
	VertexAttribute[i++].normal = vec3(1.0, 1.0, -1.0);
	VertexAttribute[i++].normal = vec3(1.0, -1.0, -1.0);

	VertexAttribute[i++].normal = vec3(-1.0, 1.0, -1.0);
	VertexAttribute[i++].normal = vec3(-1.0, 1.0, 1.0);
	VertexAttribute[i++].normal = vec3(1.0, 1.0, 1.0);
	VertexAttribute[i++].normal = vec3(1.0, 1.0, -1.0);

	VertexAttribute[i++].normal = vec3(-1.0, -1.0, -1.0);
	VertexAttribute[i++].normal = vec3(1.0, -1.0, -1.0);
	VertexAttribute[i++].normal = vec3(1.0, -1.0, 1.0);
	VertexAttribute[i++].normal = vec3(-1.0, -1.0, 1.0);

	VertexAttribute[i++].normal = vec3(1.0, -1.0, -1.0);
	VertexAttribute[i++].normal = vec3(1.0, 1.0, -1.0);
	VertexAttribute[i++].normal = vec3(1.0, 1.0, 1.0);
	VertexAttribute[i++].normal = vec3(1.0, -1.0, 1.0);

	VertexAttribute[i++].normal = vec3(-1.0, -1.0, -1.0);
	VertexAttribute[i++].normal = vec3(-1.0, -1.0, 1.0);
	VertexAttribute[i++].normal = vec3(-1.0, 1.0, 1.0);
	VertexAttribute[i++].normal = vec3(-1.0, 1.0, -1.0);


	for (int i = 0; i < VertexAttribute.size(); i++){
		vec3 hsv(360.0f / (float)i, 1.0, 1.0);
		VertexAttribute[i].color = vec4(hsv2rgb(hsv), 1.0);
	}


	Index.resize(2 * 6);
	i = 0;
	Index[i++] = u16vec3(0, 1, 2);
	Index[i++] = u16vec3(0, 2, 3);

	Index[i++] = u16vec3(4, 5, 6);
	Index[i++] = u16vec3(4, 6, 7);

	Index[i++] = u16vec3(8, 9, 10);
	Index[i++] = u16vec3(8, 10, 11);

	Index[i++] = u16vec3(12, 13, 14);
	Index[i++] = u16vec3(12, 14, 15);

	Index[i++] = u16vec3(16, 17, 18);
	Index[i++] = u16vec3(16, 18, 19);

	Index[i++] = u16vec3(20, 21, 22);
	Index[i++] = u16vec3(20, 22, 23);

	CreateVBO();
	CreateIBO();
	BindVBO();
	BindIBO();

}