Better MT lighting.
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
#include <engine/collision.h>
|
||||
#include <sphere.h>
|
||||
void Cube::pre_render() {
|
||||
hVelocity = 1;
|
||||
//hVelocity = 1;
|
||||
hMove(velAngle, hVelocity);
|
||||
vMove(vVelocity);
|
||||
|
||||
@@ -18,9 +18,9 @@ void Cube::pre_render() {
|
||||
moby->velAngle = moby->lAngle();
|
||||
velAngle = rAngle();
|
||||
}
|
||||
angle.x = angle.x + 18*engine->frameDelta;
|
||||
angle.y = angle.y + 18*engine->frameDelta;
|
||||
angle.z = angle.z + 18*engine->frameDelta;
|
||||
angle.x = angle.x + 24*engine->frameDelta;
|
||||
angle.y = angle.y + 24*engine->frameDelta;
|
||||
angle.z = angle.z + 24*engine->frameDelta;
|
||||
}
|
||||
|
||||
void Cube::update(float elapsed) {
|
||||
|
@@ -52,15 +52,14 @@ void Engine::initGL()
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
glDepthMask(GL_TRUE);
|
||||
glClearDepth(1.0f);
|
||||
//glEnable(GL_BLEND);
|
||||
//glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
glEnable(GL_CULL_FACE);
|
||||
glEnable(GL_LIGHTING);
|
||||
glEnable(GL_LIGHT0);
|
||||
glEnable(GL_COLOR_MATERIAL);
|
||||
glEnable(GL_VERTEX_ARRAY);
|
||||
glEnable(GL_LIGHTING);
|
||||
glEnable(GL_ALPHA_TEST);
|
||||
glAlphaFunc(GL_GREATER, 0.1f);
|
||||
glAlphaFunc(GL_GREATER, 0.05f); //Anything with an opacity of less than 5% gets thrown out
|
||||
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
|
||||
//glEnable(GL_LIGHT0);
|
||||
//glEnable(GL_COLOR_MATERIAL);
|
||||
//glDepthRange(-0.5f,0.5f);
|
||||
}
|
||||
|
||||
@@ -71,11 +70,10 @@ void Engine::initGL()
|
||||
engine->window->setResizable(false);
|
||||
engine->initGL();
|
||||
engine->loadConfig();
|
||||
|
||||
engine->world->setAmbientLightColor(1.0f, 1.0f, 1.0f, 1.0f);
|
||||
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
||||
|
||||
//glDisable(GL_CULL_FACE);
|
||||
//glEnable(GL_BLEND);
|
||||
glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &maxTextureUnits);
|
||||
auto* camera = new Camera();
|
||||
camera->SetPos({0.0f, -2.0f, -5.0f});
|
||||
@@ -87,7 +85,6 @@ void Engine::initGL()
|
||||
skybox->draw = true;
|
||||
skybox->angle = {0,0,0};
|
||||
skybox->SetParent(engine->world);
|
||||
engine->world->setAmbientLightColor(0.6, 0.6, 0.6, 1);
|
||||
|
||||
Shader test;
|
||||
test.name = "test";
|
||||
@@ -118,11 +115,7 @@ void Engine::initGL()
|
||||
{
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
//TODO: *Always* render the camera first.
|
||||
glCullFace(GL_BACK);
|
||||
for (auto& e : engine->world->GetChildren()) {
|
||||
|
@@ -130,16 +130,13 @@ void Entity::render() {
|
||||
if (!multiTexture) {
|
||||
glPushMatrix();
|
||||
|
||||
//Allows transparency effects to work.
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
|
||||
//Set the single texture as the active texture.
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glClientActiveTexture(GL_TEXTURE0);
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
glEnableClientState(GL_VERTEX_ARRAY);
|
||||
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
glBindTexture(GL_TEXTURE_2D, getTexture()->id);
|
||||
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
|
||||
|
||||
glTranslatef(position.x, position.y, position.z);
|
||||
|
||||
@@ -171,16 +168,12 @@ void Entity::render() {
|
||||
if (getScale() != 1.0f)
|
||||
glScalef(getScale(), getScale(), getScale());
|
||||
|
||||
|
||||
//Allows transparency effects to work.
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
|
||||
//Set the single texture as the active texture.
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glClientActiveTexture(GL_TEXTURE0);
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
glEnableClientState(GL_VERTEX_ARRAY);
|
||||
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D, multi->id);
|
||||
|
||||
if (!engine->useVBO) {
|
||||
@@ -202,36 +195,59 @@ void Entity::render() {
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
glEnableClientState(GL_VERTEX_ARRAY);
|
||||
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, texture.id);
|
||||
|
||||
if (!engine->useVBO) {
|
||||
glVertexPointer(3, GL_FLOAT, sizeof(Vertex), &getGeometry()->vertices[0].x);
|
||||
glTexCoordPointer(2, GL_FLOAT, sizeof(TextureCoordinate), &getGeometry()->texCoords[0].x);
|
||||
}
|
||||
|
||||
if (engine->useVBO) {
|
||||
glBindBuffer(GL_ARRAY_BUFFER, getGeometry()->tbo);
|
||||
glTexCoordPointer(2, GL_FLOAT, 0, nullptr);
|
||||
}
|
||||
|
||||
|
||||
//Mode for every other unit. We basically "add" each subsequent texture to the previous one like a stack.
|
||||
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
|
||||
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
|
||||
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_REPLACE);
|
||||
|
||||
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_ADD); //RGB
|
||||
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB, GL_PREVIOUS);
|
||||
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB, GL_TEXTURE);
|
||||
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_SRC_COLOR);
|
||||
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB, GL_SRC_COLOR);
|
||||
|
||||
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_ADD); //ALPHA
|
||||
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA, GL_PREVIOUS);
|
||||
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_ALPHA, GL_TEXTURE);
|
||||
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA, GL_SRC_ALPHA);
|
||||
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_ALPHA, GL_SRC_ALPHA);
|
||||
i++;
|
||||
|
||||
}
|
||||
|
||||
//Put on the last one. Which is the ambient light.
|
||||
GLuint ambientLightTexture;
|
||||
glGenTextures(1, &ambientLightTexture);
|
||||
GLfloat ambientLight[4] = {
|
||||
1.0f - engine->world->getAmbientLightColor().x,
|
||||
1.0f - engine->world->getAmbientLightColor().y,
|
||||
1.0f - engine->world->getAmbientLightColor().z,
|
||||
engine->world->getAmbientLightColor().w
|
||||
};
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_FLOAT, &ambientLight);
|
||||
|
||||
glActiveTexture(GL_TEXTURE1 + i);
|
||||
glClientActiveTexture(GL_TEXTURE1 + i);
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
glEnableClientState(GL_VERTEX_ARRAY);
|
||||
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, ambientLightTexture);
|
||||
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
|
||||
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_REPLACE);
|
||||
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_REPLACE);
|
||||
|
||||
|
||||
if (!engine->useVBO) {
|
||||
glVertexPointer(3, GL_FLOAT, sizeof(Vertex), &getGeometry()->vertices[0].x);
|
||||
glTexCoordPointer(2, GL_FLOAT, sizeof(TextureCoordinate), &getGeometry()->texCoords[0].x);
|
||||
}
|
||||
|
||||
if (engine->useVBO) {
|
||||
glBindBuffer(GL_ARRAY_BUFFER, getGeometry()->tbo);
|
||||
glTexCoordPointer(2, GL_FLOAT, 0, nullptr);
|
||||
}
|
||||
i++;
|
||||
//Draw code
|
||||
if (!engine->useVBO)
|
||||
glDrawElements(GL_TRIANGLES, getGeometry()->indices.size(), GL_UNSIGNED_INT, &getGeometry()->indices[0]);
|
||||
@@ -249,6 +265,7 @@ void Entity::render() {
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
}
|
||||
|
||||
glDeleteTextures(1, &ambientLightTexture);
|
||||
for (int j = 0; j <= i; j++) {
|
||||
glActiveTexture(GL_TEXTURE1 + j);
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
@@ -256,14 +273,11 @@ void Entity::render() {
|
||||
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
}
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
glDisableClientState(GL_VERTEX_ARRAY);
|
||||
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
glDisable(GL_BLEND);
|
||||
|
||||
if (engine->useVBO) {
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
}
|
||||
}
|
||||
|
||||
if (engine->debug) {
|
||||
|
@@ -48,8 +48,9 @@ MultiTexture::MultiTexture(const std::string& name, const char* pathContainingTe
|
||||
if (storeOnTextureList)
|
||||
engine->world->textureList.push_back(new MultiTexture(*this));
|
||||
|
||||
//You cannot have more than 32 textures in one multi-texture.
|
||||
if (multi.size()+1 > engine->maxTextureUnits)
|
||||
//You cannot have more than 6 additional textures.
|
||||
//We reserve one for the multi-textured lighting, And the other is the base.
|
||||
if (multi.size() > 6)
|
||||
engine->setError(ENGINE_ERROR_CODE::TEXTURE_NOT_FOUND, true);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user