void ModelMaterial::Save(std::ofstream& file)
	{
		uint32_t nameSize = Name().size();
		ModelExporter::WriteInteger(nameSize, file);
		file.write(mName.c_str(), nameSize*sizeof(char));

		uint32_t nTextures = Textures().size();
		ModelExporter::WriteInteger(nTextures, file);
		for (auto& texture : Textures())
		{
			uint32_t textureType = texture.first;
			ModelExporter::WriteInteger(textureType, file);

			uint32_t textureCount = texture.second->size();
			ModelExporter::WriteInteger(textureCount, file);
			if (textureCount > 0)
			{
				for (auto& wideString : *texture.second)
				{
					uint32_t textureNameSize = wideString.size();
					ModelExporter::WriteInteger(textureNameSize, file);

					if (textureNameSize > 0)
					{
						for (uint32_t i = 0; i < textureNameSize; ++i)
						{
							file.write((char*)&wideString.at(i), sizeof(wchar_t));
						}

						//file.write(reinterpret_cast<char*>(&wideString), wideString.size()*sizeof(char));
					}
				}
			}
		}
	}
Beispiel #2
0
//-------------------- FUNCOES: GERAIS --------------------//
GLvoid Init() { //Preparacao da cena
    glClearColor(0.0f, 0.0f, 0.0f, 1.0f); //cor de fundo preta
    glEnable(GL_DEPTH_TEST); //ativa teste de prfundidade
    glDepthFunc(GL_LESS); //especifica a comparação de profundidade: mostra se for menor
    glEnable(GL_COLOR_MATERIAL);
    glEnable(GL_RESCALE_NORMAL); //normalização dos vetores
    glShadeModel(GL_SMOOTH); //Rendering de Gourard

    //inicia valores para câmera
    obsX = width/2;
    obsY = height/2;
    obsZ = width/3;
    centerX = width/2;
    centerY = height/2;
    centerZ = -width;

    glViewport(0.0, 0.0, width, height); //define tamanho e localização da viewport

    glMatrixMode(GL_PROJECTION);  //define que matriz é de projecao
    glLoadIdentity();
    glOrtho(0, width, 0, height, -1, width*3); //Define projecao ortogonal para mapear coordenadas do mundo para coordenadas da tela

    CreateRoom(); //cria vertices/poligonos do cenario base
    LoadObjects(); //carrega objetos

    Lighting(); //ilumina cena
    Textures(); //aplica textura à cena
}
Beispiel #3
0
void Graphics::init(){
	this->initGLFW();
	this->initGLEW();
	this->initGL();
	//_time = glfwGetTime();

	_camera = Camera(0,0);


	_textures = Textures(_shaderProgram);
	_textures.init();
}
Beispiel #4
0
	int main(std::size_t Iterations)
	{
		int Error = 0;

		std::vector<std::shared_ptr<gli::texture2d> > Textures(gli::FORMAT_COUNT);
		for(std::size_t FormatIndex = gli::FORMAT_FIRST, FormatCount = gli::FORMAT_COUNT; FormatIndex < FormatCount; ++FormatIndex)
		{
			Textures[FormatIndex].reset(new gli::texture2d(static_cast<gli::format>(FormatIndex), gli::texture2d::extent_type(4), 9));
			Error += Textures[FormatIndex]->empty() ? 1 : 0;
		}

		{
			std::clock_t TimeBegin = std::clock();

			for(gli::size_t Index = 0, Count = Iterations; Index < Count; ++Index)
			for(std::size_t FormatIndex = gli::FORMAT_FIRST, FormatCount = gli::FORMAT_COUNT; FormatIndex < FormatCount; ++FormatIndex)
			{
				for(gli::size_t LayerIndex = 0, LayerCount = Textures[FormatIndex]->layers(); LayerIndex < LayerCount; ++LayerIndex)
				for(gli::size_t LevelIndex = 0, LevelCount = Textures[FormatIndex]->levels(); LevelIndex < LevelCount; ++LevelIndex)
				{
					void* BaseAddress = Textures[FormatIndex]->data(LayerIndex, 0, LevelIndex);
					Error += BaseAddress != nullptr ? 0 : 1;
				}
			}

			std::clock_t TimeEnd = std::clock();

			printf("2d texture data access performance test: %d\n", TimeEnd - TimeBegin);
		}

		{
			std::clock_t TimeBegin = std::clock();

			for(gli::size_t Index = 0, Count = Iterations; Index < Count; ++Index)
			for(std::size_t FormatIndex = gli::FORMAT_FIRST, FormatCount = gli::FORMAT_COUNT; FormatIndex < FormatCount; ++FormatIndex)
			{
				for(gli::size_t LayerIndex = 0, LayerCount = Textures[FormatIndex]->layers(); LayerIndex < LayerCount; ++LayerIndex)
				for(gli::size_t LevelIndex = 0, LevelCount = Textures[FormatIndex]->levels(); LevelIndex < LevelCount; ++LevelIndex)
				{
					gli::size_t Size = Textures[FormatIndex]->size(LevelIndex);
					Error += Size != 0 ? 0 : 1;
				}
			}

			std::clock_t TimeEnd = std::clock();

			printf("2d texture size performance test: %d\n", TimeEnd - TimeBegin);
		}

		{
			std::clock_t TimeBegin = std::clock();

			for(gli::size_t Index = 0, Count = Iterations; Index < Count; ++Index)
			for(std::size_t FormatIndex = gli::FORMAT_FIRST, FormatCount = gli::FORMAT_COUNT; FormatIndex < FormatCount; ++FormatIndex)
			{
				for(gli::size_t LayerIndex = 0, LayerCount = Textures[FormatIndex]->layers(); LayerIndex < LayerCount; ++LayerIndex)
				for(gli::size_t LevelIndex = 0, LevelCount = Textures[FormatIndex]->levels(); LevelIndex < LevelCount; ++LevelIndex)
				{
					gli::texture2d::extent_type Extent = Textures[FormatIndex]->extent(LevelIndex);
					Error += Extent.x != 0 ? 0 : 1;
					Error += Extent.y != 0 ? 0 : 1;
				}
			}

			std::clock_t TimeEnd = std::clock();

			printf("2d texture extent access performance test: %d\n", TimeEnd - TimeBegin);
		}

		{
			std::clock_t TimeBegin = std::clock();

			for(gli::size_t Index = 0, Count = Iterations; Index < Count; ++Index)
			for(std::size_t FormatIndex = gli::FORMAT_FIRST, FormatCount = gli::FORMAT_COUNT; FormatIndex < FormatCount; ++FormatIndex)
			{
				for(gli::size_t LayerIndex = 0, LayerCount = Textures[FormatIndex]->layers(); LayerIndex < LayerCount; ++LayerIndex)
				for(gli::size_t LevelIndex = 0, LevelCount = Textures[FormatIndex]->levels(); LevelIndex < LevelCount; ++LevelIndex)
				{
					gli::texture2d::extent_type Extent = Textures[FormatIndex]->extent(LevelIndex);
					gli::size_t Size = Textures[FormatIndex]->size(LevelIndex);

					Error += Extent.x != 0 ? 0 : 1;
					Error += Extent.y != 0 ? 0 : 1;
					Error += Size != 0 ? 0 : 1;
				}
			}

			std::clock_t TimeEnd = std::clock();

			printf("2d texture extent and size access performance test: %d\n", TimeEnd - TimeBegin);
		}

		{
			std::clock_t TimeBegin = std::clock();

			for(gli::size_t Index = 0, Count = Iterations; Index < Count; ++Index)
			for(std::size_t FormatIndex = gli::FORMAT_FIRST, FormatCount = gli::FORMAT_COUNT; FormatIndex < FormatCount; ++FormatIndex)
			{
				for(gli::size_t LayerIndex = 0, LayerCount = Textures[FormatIndex]->layers(); LayerIndex < LayerCount; ++LayerIndex)
				for(gli::size_t LevelIndex = 0, LevelCount = Textures[FormatIndex]->levels(); LevelIndex < LevelCount; ++LevelIndex)
				{
					gli::texture2d::extent_type Extent = Textures[FormatIndex]->extent(LevelIndex);
					gli::size_t Size = Textures[FormatIndex]->size(LevelIndex);
					void* BaseAddress = Textures[FormatIndex]->data(LayerIndex, 0, LevelIndex);

					Error += Extent.x != 0 ? 0 : 1;
					Error += Extent.y != 0 ? 0 : 1;
					Error += Size != 0 ? 0 : 1;
					Error += BaseAddress != nullptr ? 0 : 1;
				}
			}

			std::clock_t TimeEnd = std::clock();

			printf("2d texture all access performance test: %d\n", TimeEnd - TimeBegin);
		}

		return Error;
	}
Beispiel #5
0
void CreateResources(ResourceManager &resourceManager)
{
    std::vector<Textures> texVec;
    std::vector<Sounds> soundVec;

    if(!resourceManager.GetTexture("geoff.png"))
        texVec.push_back(Textures("geoff.png"));
    if(!resourceManager.GetTexture("wolf.png"))
        texVec.push_back(Textures("wolf.png"));
    if(!resourceManager.GetTexture("bear.png"))
        texVec.push_back(Textures("bear.png"));
    if(!resourceManager.GetTexture("scenery.png"))
        texVec.push_back(Textures("scenery.png"));
    if(!resourceManager.GetTexture("scenery2.png"))
        texVec.push_back(Textures("scenery2.png"));
    if(!resourceManager.GetTexture("text.png"))
        texVec.push_back(Textures("text.png"));
    if(!resourceManager.GetTexture("snake.png"))
        texVec.push_back(Textures("snake.png"));

    if(!resourceManager.GetSound("bear.ogg"))
        soundVec.push_back(Sounds("bear.ogg"));
    if(!resourceManager.GetSound("chainsaw.ogg"))
        soundVec.push_back(Sounds("chainsaw.ogg"));
    if(!resourceManager.GetSound("chop.ogg"))
        soundVec.push_back(Sounds("chop.ogg"));
    if(!resourceManager.GetSound("death.ogg"))
        soundVec.push_back(Sounds("death.ogg"));
    if(!resourceManager.GetSound("snake.ogg"))
        soundVec.push_back(Sounds("snake.ogg"));
    if(!resourceManager.GetSound("wolfhowl.ogg"))
        soundVec.push_back(Sounds("wolfhowl.ogg"));
    if(!resourceManager.GetSound("woodpile.ogg"))
        soundVec.push_back(Sounds("woodpile.ogg"));

    resourceManager.GetOrCreateProgram("textured.vs", "textured.fs");
    resourceManager.GetOrCreateProgram("character.vs", "textured.fs");
    resourceManager.GetOrCreateProgram("colouredsquare.vs", "colouredsquare.fs");

    std::shared_ptr<unsigned int> buffer(resourceManager.GetVao("buffer"));

    if(!buffer)
    {
        buffer = std::make_shared<unsigned int>(CreateBuffer());
        resourceManager.AddVao("buffer", buffer);
    }
    if(!resourceManager.GetVao("full vao"))
    {
        std::shared_ptr<unsigned int> vao(new unsigned int (CreateVAO(*buffer, 1)));
        resourceManager.AddVao("full vao", vao);
    }
    if(!resourceManager.GetVao("vao top left"))
    {
        std::shared_ptr<unsigned int> vaoTopLeft(new unsigned int (CreateVAO(*buffer, 2)));
        resourceManager.AddVao("vao top left", vaoTopLeft);
    }
    if(!resourceManager.GetVao("vao top right"))
    {
        std::shared_ptr<unsigned int> vaoTopRight(new unsigned int (CreateVAO(*buffer, 3)));
        resourceManager.AddVao("vao top right", vaoTopRight);
    }
    if(!resourceManager.GetVao("vao bottom left"))
    {
        std::shared_ptr<unsigned int> vaoBottomLeft(new unsigned int (CreateVAO(*buffer, 4)));
        resourceManager.AddVao("vao bottom left", vaoBottomLeft);
    }
    if(!resourceManager.GetVao("vao bottom right"))
    {
        std::shared_ptr<unsigned int> vaoBottomRight(new unsigned int (CreateVAO(*buffer, 5)));
        resourceManager.AddVao("vao bottom right", vaoBottomRight);
    }
    if(!resourceManager.GetVao("vao plain colour"))
    {
        std::shared_ptr<unsigned int> vaoPlainColour(new unsigned int (SetupStandardVAO(*buffer)));
        resourceManager.AddVao("vao plain colour", vaoPlainColour);
    }

    CreateTexturesAndSound(texVec, soundVec);
    for(auto object(texVec.begin()); object != texVec.end(); ++object)
    {
        std::shared_ptr<unsigned int> ptr(
                    new unsigned int(CreateOpenGLTexture((*object).texVec, (*object).width,
                                                         (*object).height)));
        resourceManager.AddTexture((*object).filename, ptr);
    }
    texVec.clear();
    for(auto object(soundVec.begin()); object != soundVec.end(); ++object)
    {
        std::shared_ptr<unsigned int> ptr(
                    new unsigned int(object->sound));
        resourceManager.AddSound((*object).filename, ptr);
    }
    soundVec.clear();
}