SpaceshipModelTest.cpp 2.94 KB
#include "SpaceshipModelTest.h"
#include "include/OBJ_Loader.h"

SpaceshipModelTest::SpaceshipModelTest()
{
	

}

SpaceshipModelTest::~SpaceshipModelTest()
{
}

void SpaceshipModelTest::privateInit()
{
	spaceshipShader.initShaders("assets/shaders/spaceship");

	_texture = SOIL_load_OGL_texture
	(
		"assets/models/Spaceship/Textures/shipA.bmp",
		SOIL_LOAD_AUTO,
		SOIL_CREATE_NEW_ID,
		SOIL_FLAG_MIPMAPS | SOIL_FLAG_INVERT_Y | SOIL_FLAG_NTSC_SAFE_RGB | SOIL_FLAG_COMPRESS_TO_DXT
	);

	if (0 == _texture)
	{
		printf("SOIL loading error: '%s'\n", SOIL_last_result());
	}

	
	objl::Loader Loader;
	bool loadout = Loader.LoadFile("assets/models/Spaceship/shipA_OBJ/shipA_OBJ.obj");

	if (loadout)
	{
		for (int i = 0; i < Loader.LoadedMeshes.size(); i++)
		{
			objl::Mesh curMesh = Loader.LoadedMeshes[i];
			for (int j = 0; j < curMesh.Vertices.size(); j++)
			{
				_VERT.push_back(glm::vec3(curMesh.Vertices[j].Position.X, curMesh.Vertices[j].Position.Y, curMesh.Vertices[j].Position.Z));
				_NORM.push_back(glm::vec3(curMesh.Vertices[j].Normal.X, curMesh.Vertices[j].Normal.Y, curMesh.Vertices[j].Normal.Z));
				_TEXC.push_back(glm::vec2(curMesh.Vertices[j].TextureCoordinate.X, curMesh.Vertices[j].TextureCoordinate.Y));
			}

			for (int j = 0; j < curMesh.Indices.size(); j += 3)
			{
				_INDI.push_back(curMesh.Indices[j]);
				_INDI.push_back(curMesh.Indices[j+1]);
				_INDI.push_back(curMesh.Indices[j+2]);
			}
			
		}
	} else {
		std::cout << "Could not load file!" << std::endl;
	}
	
	spaceshipShader.enable();
	_texColormapSampler = glGetUniformLocation(spaceshipShader.getProg(), "tex_colormap");
	glUniform1i(_texColormapSampler, 0);
	spaceshipShader.disable();

}

void SpaceshipModelTest::privateRender()
{
	spaceshipShader.enable();

	glDisable(GL_COLOR_MATERIAL);
	
	glClearColor(0.0, 0.0, 0.0, 0.0);
	
	glActiveTexture(GL_TEXTURE0);
	glEnable(GL_TEXTURE_2D);
	glBindTexture(GL_TEXTURE_2D, _texture);
	
	glEnableClientState(GL_VERTEX_ARRAY);
	glEnableClientState(GL_TEXTURE_COORD_ARRAY);

	glEnable(GL_PRIMITIVE_RESTART);

	//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
	//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
	//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
	//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
	//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
	//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

	glVertexPointer(3, GL_FLOAT, 0, &_VERT[0]);
	glTexCoordPointer(2, GL_FLOAT, 0, &_TEXC[0]);


	glDrawElements(GL_TRIANGLES,
		_INDI.size(),
		GL_UNSIGNED_INT,
		&_INDI[0]);
	
	glDisable(GL_PRIMITIVE_RESTART);
	
	glClearColor(0.0, 0.0, 0.0, 0.0);
	
	glActiveTexture(GL_TEXTURE0);
	glDisable(GL_TEXTURE_2D);
	glDisableClientState(GL_TEXTURE_COORD_ARRAY);
	glDisableClientState(GL_VERTEX_ARRAY);
	spaceshipShader.disable();
}

void SpaceshipModelTest::privateUpdate()
{
}

bool SpaceshipModelTest::markedForDeletion()
{
	return _markDelete;
}