示例#1
0
bool TextureManager::LoadTexture(const KFbxFileTexture * pTexture, unsigned int * pTextureObject)
{
	TextureMapType::RecordType * lTextureRecord = mTextureMap.Find(pTexture);
	if (lTextureRecord)
	{
		if (pTextureObject)
			*pTextureObject = lTextureRecord->GetValue();
		return true;
	}

	const KString lFileName = pTexture->GetFileName();
	unsigned int lTextureObject = 0;
	bool lStatus = LoadTextureFromFile(lFileName, lTextureObject);

	if (!lStatus)
	{
		const KString lRelativeFileName = mWorkingDir + "/" + pTexture->GetFileName();
		lStatus = LoadTextureFromFile(lRelativeFileName, lTextureObject);
	}

	if (lStatus)
	{
		K_ASSERT(glIsTexture(lTextureObject));
		mTextureMap.Insert(pTexture, lTextureObject);
		if (pTextureObject)
			*pTextureObject = lTextureObject;
		return true;
	}

	return false;
}
示例#2
0
sf::Sprite* TextureBuffer::LoadTexture(std::string filename,bool middle)
{
    std::map<std::string,sf::Texture>::iterator it;
    it=textures.find(filename);
    if(it!=TextureBuffer::textures.end())
    {
            sf::Sprite* temp = new sf::Sprite(it->second);
            if(middle)
            {
                sf::Vector2u vec = it->second.getSize();
                temp->setOrigin(vec.x/2,vec.y/2);
            }
            return(temp);
    }
    else
    {
        LoadTextureFromFile(filename);
        it=textures.find(filename);
        if(it!=TextureBuffer::textures.end())
        {
            sf::Sprite* temp = new sf::Sprite(it->second);
            if(middle)
            {
                sf::Vector2u vec = it->second.getSize();
                temp->setOrigin(vec.x/2,vec.y/2);
            }
            return(temp);
        }
        else
        {
            return(NULL);
        }
    }
}
示例#3
0
bool AddFileReference(const String& fileName, const String& reference, SDL_Renderer* renderer)
{
	if(textureReferences[reference] = LoadTextureFromFile(fileName, renderer))
		return true;
	else
		return false;
}
示例#4
0
void CSpriteAnimated::InitSpriteAnimated(const std::string& aPathToTexture, const u32 aCols, const u32 aRows, const u32 aNumFrames, const f32 aSpeed)
{
	if ( !GetFrameDataFromXml( aPathToTexture) )
	{
		LoadTextureFromFile(aPathToTexture, aCols, aRows, aNumFrames);
	}
	m_speedAnimation = aSpeed;
	m_TimerID  = CCoreEngine::Instance().GetTimerManager().CreateTimer(m_speedAnimation,true );
}
示例#5
0
文件: Texture.cpp 项目: Dwarfius/GP2
Texture::Texture(const string& fileName)
{
	textureId = LoadTextureFromFile(fileName);

	glBindTexture(GL_TEXTURE_2D, textureId);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_MIRRORED_REPEAT);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_MIRRORED_REPEAT);
	glGenerateMipmap(GL_TEXTURE_2D);
}
示例#6
0
    void Browser::Init(const char *pRessourcePath) {
        InitActionEntry();
#ifdef WIN32		
        sprintf(bTmp, "%s%s", pRessourcePath, "\\bg.png");
#else
        sprintf(bTmp, "%s%s", pRessourcePath, "/bg.png");
#endif
        Create(pRessourcePath, 0xFF0000FF, 0xFFFFFF00);
        LoadTextureFromFile(g_pVideoDevice, bTmp, &bg);

    };
示例#7
0
SkyBox::SkyBox(
    const char* x1Path,
    const char* x2Path,
    const char* y1Path,
    const char* y2Path,
    const char* z1Path,
    const char* z2Path)
    : m_sphere(500.0f, 2)
{
    glGenTextures(1, &m_textureID);
    glBindTexture(GL_TEXTURE_CUBE_MAP, m_textureID);

    const char* texturePaths[] =
    {
        x1Path, x2Path,
        y1Path, y2Path,
        z1Path, z2Path
    };

    GLenum textureTypes[] =
    {
        GL_TEXTURE_CUBE_MAP_POSITIVE_X, GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
        GL_TEXTURE_CUBE_MAP_POSITIVE_Y, GL_TEXTURE_CUBE_MAP_NEGATIVE_Y,
        GL_TEXTURE_CUBE_MAP_POSITIVE_Z, GL_TEXTURE_CUBE_MAP_NEGATIVE_Z,
    };

    unsigned int width = 0;
    unsigned int height = 0;
    unsigned int* texels = NULL;

    for(int i = 0; i < 6; ++i)
    {
        LoadTextureFromFile(texturePaths[i], width, height, texels);

        glTexImage2D(textureTypes[i], 0, GL_RGBA, width, height, 0, GL_BGRA, GL_UNSIGNED_BYTE, texels);

        CleanPreviousTextureLoad();
    }

    glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
    glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
    glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);

    glBindTexture(GL_TEXTURE_CUBE_MAP, 0);

    m_program = new GLProgram("Data/Shaders/Skybox.vert", "Data/Shaders/Skybox.frag");

    m_cubeMap = new GLTexture(m_textureID, width, height);

    m_program->SetUnifromTexture("cubeMap", m_cubeMap, true);
}
示例#8
0
void LoadFile(const String& fileName, const String& reference, SDL_Renderer* renderer)
{
	//Setup the text data filename
	String dataFileName = fileName.substr(0, fileName.length() - 4) + ".txt";

	#ifdef __ANDROID__

		//Open the file with RWops function and process each line
		SDL_RWops *rw = SDL_RWFromFile(dataFileName.c_str(), "rb");

		if(rw > 0)
		{
			__android_log_write(ANDROID_LOG_INFO, "Chain Drop", "Loading texture file");
			ProcessAndroidTextFile(rw, reference);
			SDL_FreeRW(rw);
			textureReferences[reference] = LoadTextureFromFile(fileName, renderer);
		}
		else
			logError(std::cout, "LoadFile: error opening: " + dataFileName);

	#elif _WIN32

		//Open the file with a filestream and process each line
		std::ifstream file(dataFileName);

		if (file.is_open())
		{
			String line;

			while(getline(file, line))
			{
				ProcessFileLine(line, reference);
			}
			file.close();
			textureReferences[reference] = LoadTextureFromFile(fileName, renderer);
		}
		else
			logError(std::cout, "LoadFile: error opening: " + dataFileName);
	#endif
}
void HUD::Init()
{
	// Reset gameplay related variables

	HiScore = 1000000;
	CurrentScore = 0;
	StageTimer = 0;

	Graze = 0;
	PlayerX = 0;
	PlayerY = 0;

	Lives = 2;
	Bombs = 3;
	DeathCount = 0;
	BombCount = 0;

	LoadTextureFromFile(L"Frame+.png", FrameTex);
	LoadTextureFromFile(L"front01.png", HUDTex);


	Sources[0] = { 0,0,1280,960 };
}
示例#10
0
void MyConsole::Init() {

    char *pngPath = (char*)malloc(256);
    char *ressourcesPath = (char*)malloc(256);
    sprintf(ressourcesPath,"%s/ressources/",rootpath);
    sprintf(pngPath, "%stank.png", ressourcesPath);
    
    Create(ressourcesPath, 0xFF0000FF, 0xFFFFFF00);
    LoadTextureFromFile(g_pVideoDevice, pngPath, &bg);
    srand(time());  
    P1.sCount = rand()%4;
    
    P1.sPoint[0].x = 100;
    P1.sPoint[0].y = 100;
    P1.sPoint[0].direction = r;
    P1.sPoint[1].x = 1080;
    P1.sPoint[1].y = 600;
    P1.sPoint[1].direction = l;
    P1.sPoint[2].x = 1080;
    P1.sPoint[2].y = 100;
    P1.sPoint[2].direction = l;
    P1.sPoint[3].x = 100;
    P1.sPoint[3].y = 600;
    P1.sPoint[3].direction = r;
    
    P2.sPoint[0].x = 100;
    P2.sPoint[0].y = 100;
    P2.sPoint[0].direction = r;
    P2.sPoint[1].x = 1080;
    P2.sPoint[1].y = 600;
    P2.sPoint[1].direction = l;
    P2.sPoint[2].x = 1080;
    P2.sPoint[2].y = 100;
    P2.sPoint[2].direction = l;
    P2.sPoint[3].x = 100;
    P2.sPoint[3].y = 600;
    P2.sPoint[3].direction = r;
    
    P1.setTexture(bg);
    P1.spawn(P1.sPoint[P1.sCount].x, P1.sPoint[P1.sCount].y, P1.sPoint[P1.sCount].direction);
    P2.setTexture(bg);
    P2.sCount = rand()%4;
    while (P1.sCount == P2.sCount) {
        P2.sCount = rand()%4;
    }
    P2.spawn(P2.sPoint[P2.sCount].x, P2.sPoint[P2.sCount].y, P2.sPoint[P2.sCount].direction);

};
void D_ShotObj::Init(float x, float y, float spd, float angle, int graphic, int delay)
{
	PatternList.reserve(10);
	Position.x = x;
	Position.y = y;
	Speed = spd;
	Angle = angle;

	UpdateMoveDirection();

	LoadTextureFromFile(L"UltimaShot_HD.png", Texture);
	AdjustSourceRect(&SourceRect, 0,32, 32, 32);
	
	Origin.x = (SourceRect.right - SourceRect.left) / 2.00f;
	Origin.y = (SourceRect.bottom - SourceRect.top) / 2.00f;

}
示例#12
0
bool CSpriteAnimated::GetFrameDataFromXml( const std::string& aPathToTexture)
{
	bool retValue = false;
	std::string PathToImage;
	std::vector<glm::vec4> FrameData;

	std::size_t found = aPathToTexture.find(".xml");
	if (found!=std::string::npos)
	{
		CXMLParserPUGI Parser( aPathToTexture );
		if (!Parser.Ready())
		{
			CCoreEngine::Instance().GetLogManager().LogOutput( LOG_ERROR, LOGSUB_RESOURCES, "FAILED LOADING %s", aPathToTexture.c_str() );
			return retValue;
		}
		std::size_t founddir = aPathToTexture.rfind("/");
		if (founddir!=std::string::npos)
		{
			PathToImage = aPathToTexture.substr(0,(founddir+1));
		}
		std::string l_File = Parser.GetStringAttributeValue( "TextureAtlas", "imagePath");
		PathToImage += l_File;

		u32 FramesCount = Parser.GetNodeNameCount("TextureAtlas/sprite");
		for ( u32 c = 0; c < FramesCount; c++ )
		{
			std::string XmlNode("TextureAtlas/sprite#");
			XmlNode += to_string( c );

			s32 l_Xi = Parser.GetIntAttributeValue( XmlNode, "x");
			s32 l_Yi = Parser.GetIntAttributeValue( XmlNode, "y");
			s32 l_Xf = l_Xi + Parser.GetIntAttributeValue( XmlNode, "w");
			s32 l_Yf = l_Yi + Parser.GetIntAttributeValue( XmlNode, "h");

			FrameData.push_back( glm::vec4(l_Xi,l_Yi,l_Xf,l_Yf) );
		}

		LoadTextureFromFile(PathToImage, FrameData.size(), FrameData );
		retValue = true;
	}

	return retValue;
}
示例#13
0
void Mesh::RestoreGFX()
{
	HRESULT result;
	VOID* pVoid;

	if (TextureFilePath)
		LoadTextureFromFile(TextureFilePath);

	result = gfx.GetDevice()->CreateVertexBuffer(vb_size*sizeof(CUSTOMVERTEX), 0, CUSTOMFVF,
		D3DPOOL_MANAGED, &vb, NULL);
	assert(!FAILED(result));

	vb->Lock(NULL, NULL, (void**)&pVoid, 0);
	memcpy(pVoid, vertexBuffer, vb_size*sizeof(CUSTOMVERTEX));
	vb->Unlock();

	result = gfx.GetDevice()->CreateIndexBuffer(ib_size*sizeof(short), 0, D3DFMT_INDEX16,
		D3DPOOL_MANAGED, &ib, 0);
	assert(!FAILED(result));

	ib->Lock(0, 0, (void**)&pVoid, 0);
	memcpy(pVoid, indexBuffer, ib_size*sizeof(short));
	ib->Unlock();
}
示例#14
0
CTexture::CTexture(LPCSTR pathName, D3DCOLOR color)
{
	this->_texture = NULL;
	this->_namePath = pathName;
	LoadTextureFromFile(this->_namePath,color);
}
示例#15
0
void Mesh::LoadFromFile(const char* filename)
{

	//GETTING THE NAME OF THE MATERIAL (MTL) FILE AND STORING IT IN A SEPERATE STRING
	int nameLen = 0;
	int matExtensionStart = 0;
	int dirLen = 0;
	for (; filename[nameLen] != '\0'; nameLen++);
	dirLen = nameLen;
	char* matFilepath = new char[nameLen + 1];

	for (; filename[dirLen] != '\\'; dirLen--);
	dirLen += 2;
	char* curDirectory = new char[dirLen];

	for (int i = 0; i < dirLen-1; i++)
	{
		curDirectory[i] = filename[i];
	}
	curDirectory[dirLen - 1] = '\0';

	for (int i = 0; i < nameLen; i++)
	{
		matFilepath[i] = filename[i]; 
		if (filename[i] == '.')
		{
			matExtensionStart = i;
			break;
		}
	}

	matFilepath[matExtensionStart + 1] = 'm';
	matFilepath[matExtensionStart + 2] = 't';
	matFilepath[matExtensionStart + 3] = 'l';
	matFilepath[matExtensionStart + 4] = '\0';
	//******************************************************************************

	//*********************************************************
	//INITIALIZATION OF TEMPORARY BUFFERS
	short*			TempIb			= NULL;
	vector3*		TempVb			= NULL;
	vector3*		TempNb			= NULL;
	UV*				TempTb			= NULL;
	faceInfo*		faces			= NULL;
	CUSTOMVERTEX*	FMTINDEXBUFFER	= NULL;

	UINT nFaces		= 0;
	UINT nVertices	= 0;
	UINT nNormals	= 0;
	UINT nIndices	= 0;
	UINT nTexCoord	= 0;

	bool isVtParse	= false;
	//*********************************************************
	//LOADING THE INFO FROM THE FILE
	nVerts = 0;
	nTris = 0;

	FILE* pFile;
	pFile = fopen(filename, "r");
	do
	{
		char buffer[32];
		if (!feof(pFile))
		{
			fscanf(pFile, "%s", buffer);
			//***********************
			//LOADING VERTEX INFO//***********************************
			if (!strcmp(buffer, "v"))
			{
				float x = 0, y = 0, z = 0;
				fscanf(pFile, "%f%f%f", &x, &y, &z);

				vector3* temp = new vector3[nVertices + 1];
				for (int i = 0; i < nVertices; i++)
				{
					temp[i] = TempVb[i];
				}
				
				if (TempVb)
					delete[] TempVb;
				TempVb = new vector3[nVertices + 1];
				
				temp[nVertices].x = x;
				temp[nVertices].y = y;
				temp[nVertices].z = z;

				for (int i = 0; i < nVertices + 1; i++)
				{
					TempVb[i] = temp[i];
				}

				delete[] temp;
				nVertices++;
			}//LOADING NORMAL INFO//**********************************
			else if (!strcmp(buffer, "vn"))
			{
				float x = 0, y = 0, z = 0;
				fscanf(pFile, "%f%f%f", &x, &y, &z);

				vector3* temp = new vector3[nNormals + 1];
				for (int i = 0; i < nNormals; i++)
				{
					temp[i] = TempNb[i];
				}

				if (TempNb)
					delete[] TempNb;
				TempNb = new vector3[nNormals + 1];

				temp[nNormals].x = x;
				temp[nNormals].y = y;
				temp[nNormals].z = z;

				for (int i = 0; i < nNormals + 1; i++)
				{
					TempNb[i] = temp[i];
				}

				delete[] temp;
				nNormals++;
			}//LOADING FACE INFO//************************************
			else if (!strcmp(buffer, "vt"))
			{
				UV* temp = new UV[nTexCoord + 1];
				for (int i = 0; i < nTexCoord; i++){ temp[i] = TempTb[i]; }
				float tu = -1, tv = -1;
				fscanf(pFile, "%f%f", &tu, &tv);

				temp[nTexCoord].U = tu;
				temp[nTexCoord].V = tv;

				nTexCoord++;

				if (TempTb)
					delete[] TempTb;
				TempTb = new UV[nTexCoord];

				for (int i = 0; i < nTexCoord; i++){ TempTb[i] = temp[i]; }
				delete[] temp;
			}
			else if (!strcmp(buffer, "f"))
			{
				faceInfo* temp = new faceInfo[nFaces+1];
				temp[nFaces].nPoints = 0;
				temp[nFaces].point = NULL;

				for (int i = 0; i < nFaces; i++)
				{
					temp[i] = faces[i];
				}

				if (faces)
					delete faces;
				faces = new faceInfo[nFaces + 1];

				do
				{
					UINT v = -1, vt = -1, vn = -1;
					fscanf(pFile, "%d%s", &v, buffer);

					if (buffer[0] == '/' && buffer[1] == '/')
					{
						vt = -1;
						vn = atoi(&buffer[2]);
					}
					else
					{
						int i_vt = 1, i_vn = 2;
						for (int i = 1; i < 32; i++, i_vn++)
						{
							if (buffer[i_vn - 1] == '/')
								break;
						}
						vt = atoi(&buffer[i_vt]);
						vn = atoi(&buffer[i_vn]);
					}
					faceVertex* tempPoint = new faceVertex[temp[nFaces].nPoints + 1];

					v  -= 1;
					vn -= 1;
					vt -= 1;

					for (int i = 0; i < temp[nFaces].nPoints; i++)
					{
						tempPoint[i] = temp[nFaces].point[i];
					}

					if (temp[nFaces].point)
						delete[] temp[nFaces].point;
					temp[nFaces].point = new faceVertex[temp[nFaces].nPoints + 1];

					for (int i = 0; i < temp[nFaces].nPoints; i++)
					{
						temp[nFaces].point[i] = tempPoint[i];
					}

					temp[nFaces].point[temp[nFaces].nPoints].vertexIndex = v;
					temp[nFaces].point[temp[nFaces].nPoints].textureIndex = vt;
					temp[nFaces].point[temp[nFaces].nPoints].normalIndex = vn;

					temp[nFaces].nPoints++;

					delete[] tempPoint;
				} while (pFile->_ptr[0] != '\n');
				nFaces++;

				for (int i = 0; i < nFaces; i++)
				{
					faces[i] = temp[i];
				}

				delete[] temp;
			}
		}
	} while (!feof(pFile));

	fclose(pFile);

	pFile = fopen(matFilepath, "r");
	do
	{
		char buffer[128] = { 0 };
		if (!feof(pFile))
		{
			fscanf(pFile, "%s", buffer);
			if (!strcmp(buffer,"map_Kd") )
			{
				fscanf(pFile, "%s", buffer);
				if (buffer)
				{
					int filepathLen = 0;
					int texLen = 0;
					for (; buffer[texLen] != '\0'; texLen++);
					filepathLen = dirLen + texLen;

					TextureFilePath = new char[filepathLen];

					for (int i = 0; i < dirLen - 1; i++)
					{
						TextureFilePath[i] = curDirectory[i];
					}

					for (int i = 0; i < texLen; i++)
					{
						TextureFilePath[i + dirLen - 1] = buffer[i];
					}
					TextureFilePath[filepathLen - 1] = '\0';
				}
				else
				{
					TextureFilePath = { 0 };
				}
			}
		}
	} while (!feof(pFile));

	//**************************
	//FORMATTING THE INFORMATION
	//**************************
	int BufIndex = 0;
	short* t_pSortedIb = NULL;
	CUSTOMVERTEX* t_pSortedVb = new CUSTOMVERTEX[nFaces * 3];

	//Counting the number of vertex indices needed
	int nFaceVerts = 0;
	for (int i = 0; i < nFaces; i++)
	{
		nFaceVerts += faces[i].nPoints;
	}

	t_pSortedIb = new short[nFaceVerts];

	faces = TriangulateFaces(faces,&nFaces);

	//Looping through all face definitions and creating the neccesary Vertices
	for (int i = 0; i < nFaces; i++)
	{
		faceInfo* face = &faces[i];
		
		for (int p_i = 0; p_i < 3; p_i++)
		{
			int v_i = face->point[p_i].vertexIndex;
			int vn_i = face->point[p_i].normalIndex;
			int vt_i = face->point[p_i].textureIndex;

			vector3* t_norm = NULL;
			vector3* t_vert = NULL;
			UV*		 t_uv = NULL;
			if (TempNb)
				t_norm = new vector3;
				*t_norm = TempNb[vn_i];
			if (TempVb)
				t_vert = new vector3;
				*t_vert = TempVb[v_i];
			if (TempTb)
			{
				t_uv = new UV; 
				*t_uv = TempTb[vt_i];
			}

			bool vertExists = false;
			for (int i_v = 0; i_v < BufIndex; i_v++)
			{
				if (t_pSortedVb[i_v].NORMAL.x == -t_norm->x &&
					t_pSortedVb[i_v].NORMAL.y == -t_norm->y &&
					t_pSortedVb[i_v].NORMAL.z == -t_norm->z &&
					t_pSortedVb[i_v].x == -t_vert->x &&
					t_pSortedVb[i_v].y == -t_vert->y &&
					t_pSortedVb[i_v].z == -t_vert->z &&
					t_pSortedVb[i_v].tu == t_uv->U &&
					t_pSortedVb[i_v].tv == 1 - t_uv->V)
				{
					t_pSortedIb[p_i + i * 3] = i_v;
				}
			}

			if (!vertExists)
			{
				if (t_norm)
				{
					t_pSortedVb[BufIndex].NORMAL.x = -t_norm->x;
					t_pSortedVb[BufIndex].NORMAL.y = -t_norm->y;
					t_pSortedVb[BufIndex].NORMAL.z = -t_norm->z;
				}
				
				if (t_vert)
				{
					t_pSortedVb[BufIndex].x = -t_vert->x;
					t_pSortedVb[BufIndex].y = -t_vert->y;
					t_pSortedVb[BufIndex].z = -t_vert->z;
				}

				if (t_uv)
				{
					t_pSortedVb[BufIndex].tu = t_uv->U;
					t_pSortedVb[BufIndex].tv = 1 - t_uv->V;
				}

				t_pSortedIb[p_i + i * 3] = BufIndex;
				BufIndex++;

				if (t_norm)
					delete t_norm;
				if (t_vert)
					delete t_vert;
				if (t_uv)
					delete t_uv;
			}
		}
	}


	for (int i = 0; i < nFaces; i++)
	{
		int i_1 = 0, i_2 = 0, i_3 = 0;
		i_1 = t_pSortedIb[i * 3];
		i_2 = t_pSortedIb[i * 3 + 1];
		i_3 = t_pSortedIb[i * 3 + 2];

		t_pSortedIb[i * 3] = i_1;
		t_pSortedIb[i * 3 + 1] = i_3;
		t_pSortedIb[i * 3 + 2] = i_2;
	}

	//LOADING SORTED INFORMATION INTO THE BUFFERS USED FOR DRAWING
	if (vertexBuffer)
		delete [] vertexBuffer;
	vertexBuffer = new CUSTOMVERTEX[BufIndex];

	if (indexBuffer)
		delete [] indexBuffer;
	indexBuffer = new short[nFaceVerts];

	for (int i = 0; i < BufIndex; i++)
	{
		vertexBuffer[i] = t_pSortedVb[i];
	}

	for (int i = 0; i < nFaceVerts; i++)
	{
		indexBuffer[i] = t_pSortedIb[i];
	}

	nVerts = BufIndex;
	nIndices = nFaceVerts;

	nTris = nFaces;

	vb_size = nVerts;
	ib_size = nIndices;

	pFile = fopen("primitive.txt", "w");

	fprintf(pFile, "static const CUSTOMVERTEX INSERTNAME[] =\n{\n");
	for (int i = 0; i < nVerts; i++)
	{
		fprintf(pFile, "\t{%ff,%ff,%ff,%ff,%ff,%ff,\t%ff,%ff,},\n",vertexBuffer[i].x,
			vertexBuffer[i].y,
			vertexBuffer[i].z,
			vertexBuffer[i].NORMAL.x,
			vertexBuffer[i].NORMAL.y,
			vertexBuffer[i].NORMAL.z,
			vertexBuffer[i].tu,
			vertexBuffer[i].tv);
	}
	fprintf(pFile, "};\n\n");
	fprintf(pFile, "static const short INSERTNAME[] =\n{");
	for (int i = 0; i < nFaces; i++)
	{
		fprintf(pFile, "\t%d,%d,%d,\n", indexBuffer[i * 3],
			indexBuffer[i * 3 + 1],
			indexBuffer[i * 3 + 2]);
	}
	fprintf(pFile, "};\n");

	fclose(pFile);

	//CREATING DIRECTX STUFF

	if (TextureFilePath)
		LoadTextureFromFile(TextureFilePath);

	HRESULT result;
	VOID* pVoid;

	result = gfx.GetDevice()->CreateVertexBuffer(nVerts*sizeof(CUSTOMVERTEX), 0, CUSTOMFVF,
		D3DPOOL_MANAGED, &vb, NULL);
	assert(!FAILED(result));

	vb->Lock(NULL, NULL, (void**)&pVoid, 0);
	memcpy(pVoid, vertexBuffer, nVerts*sizeof(CUSTOMVERTEX));
	vb->Unlock();

	result = gfx.GetDevice()->CreateIndexBuffer(nIndices*sizeof(short), 0, D3DFMT_INDEX16,
		D3DPOOL_MANAGED, &ib, 0);
	assert(!FAILED(result));

	ib->Lock(0, 0, (void**)&pVoid, 0);
	memcpy(pVoid, indexBuffer, nIndices*sizeof(short));
	ib->Unlock();
}