Example #1
0
	void Renderer::init(GLSLProgram & shader)
	{
		setProjectionMatrix(30,1, 1, -100, projection);

		shader.use();
		shader.setUniformMatrix4fv("projectionMatrix", projection);
		shader.unuse();
	}
Example #2
0
	void Renderer::render(Entity& entity,GLSLProgram& shader)
	{
		mat4 rotMatrix;
		mat4 translationMatrix;
		mat4 transformMatrix;

		prepare();
		time += 0.0001f;
		entity.increaseRotation(0.0, 0.0, 0.0);
		entity.increasePosition(0, 0, 0);

		translationMatrix = calcTranslationMatrix(entity.getPosition().x, entity.getPosition().y, entity.getPosition().z);
		rotMatrix = calcRotationMatrix(entity.getRotX(), entity.getRotY(), entity.getRotZ());
		transformMatrix = rotMatrix * translationMatrix;
		
		
		shader.setUniformMatrix4fv("transformMatrix", transformMatrix);

		TexturedModel texturedModel = entity.getTexturedModel();
		RawModel model = texturedModel.getRawModel();
		glBindBuffer(GL_ARRAY_BUFFER, model.getVboID());
		glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,model.getIndices());
		glActiveTexture(GL_TEXTURE0);
		texturedModel.getModelTexture().bind();
		glEnableVertexAttribArray(0);
		glEnableVertexAttribArray(1);
		glEnableVertexAttribArray(2);
		glVertexAttribPointer(0, 3, GL_FLOAT, false, sizeof(Vertex), (void*)offsetof(Vertex, position));
		glVertexAttribPointer(1, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(Vertex), (void*)offsetof(Vertex, color));
		glVertexAttribPointer(2, 2, GL_FLOAT, false, sizeof(Vertex), (void*)offsetof(Vertex, uv));
		//glDrawArrays(GL_TRIANGLES, 0, model.getVertexCount());
		//glDrawElements(GL_LINES, model.getVertexCount(), GL_UNSIGNED_INT, 0);
		glDrawElements(GL_TRIANGLES,model.getVertexCount(), GL_UNSIGNED_INT,0);
		glDisableVertexAttribArray(0);
		glDisableVertexAttribArray(1);
		glDisableVertexAttribArray(2);

		glBindBuffer(GL_ARRAY_BUFFER, 0);
		glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,0);
		texturedModel.getModelTexture().unbind();

	}