GRIM/EMI: synced OpenGL and TinyGL a bit more
This commit is contained in:
parent
8a1e63abeb
commit
2bf63a5f52
2 changed files with 42 additions and 27 deletions
|
@ -573,19 +573,23 @@ void GfxOpenGL::finishActorDraw() {
|
||||||
glMatrixMode(GL_PROJECTION);
|
glMatrixMode(GL_PROJECTION);
|
||||||
glPopMatrix();
|
glPopMatrix();
|
||||||
glMatrixMode(GL_MODELVIEW);
|
glMatrixMode(GL_MODELVIEW);
|
||||||
|
|
||||||
|
glDisable(GL_TEXTURE_2D);
|
||||||
if (_alpha < 1.f) {
|
if (_alpha < 1.f) {
|
||||||
glDisable(GL_BLEND);
|
glDisable(GL_BLEND);
|
||||||
_alpha = 1.f;
|
_alpha = 1.f;
|
||||||
}
|
}
|
||||||
glDisable(GL_TEXTURE_2D);
|
|
||||||
if (_currentShadowArray) {
|
if (_currentShadowArray) {
|
||||||
glEnable(GL_LIGHTING);
|
glEnable(GL_LIGHTING);
|
||||||
glColor3f(1.0f, 1.0f, 1.0f);
|
glColor3f(1.0f, 1.0f, 1.0f);
|
||||||
glDisable(GL_POLYGON_OFFSET_FILL);
|
glDisable(GL_POLYGON_OFFSET_FILL);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (g_grim->getGameType() == GType_MONKEY4) {
|
if (g_grim->getGameType() == GType_MONKEY4) {
|
||||||
glDisable(GL_CULL_FACE);
|
glDisable(GL_CULL_FACE);
|
||||||
}
|
}
|
||||||
|
|
||||||
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
|
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
|
||||||
_currentActor = nullptr;
|
_currentActor = nullptr;
|
||||||
}
|
}
|
||||||
|
@ -671,8 +675,8 @@ void GfxOpenGL::drawEMIModelFace(const EMIModel *model, const EMIMeshFace *face)
|
||||||
else
|
else
|
||||||
glDisable(GL_TEXTURE_2D);
|
glDisable(GL_TEXTURE_2D);
|
||||||
|
|
||||||
float dim = 1.0f - _dimLevel;
|
|
||||||
glBegin(GL_TRIANGLES);
|
glBegin(GL_TRIANGLES);
|
||||||
|
float dim = 1.0f - _dimLevel;
|
||||||
for (uint j = 0; j < face->_faceLength * 3; j++) {
|
for (uint j = 0; j < face->_faceLength * 3; j++) {
|
||||||
int index = indices[j];
|
int index = indices[j];
|
||||||
if (face->_hasTexture) {
|
if (face->_hasTexture) {
|
||||||
|
@ -693,6 +697,7 @@ void GfxOpenGL::drawEMIModelFace(const EMIModel *model, const EMIMeshFace *face)
|
||||||
glVertex3fv(vertex.getData());
|
glVertex3fv(vertex.getData());
|
||||||
}
|
}
|
||||||
glEnd();
|
glEnd();
|
||||||
|
|
||||||
glEnable(GL_TEXTURE_2D);
|
glEnable(GL_TEXTURE_2D);
|
||||||
glEnable(GL_DEPTH_TEST);
|
glEnable(GL_DEPTH_TEST);
|
||||||
glEnable(GL_ALPHA_TEST);
|
glEnable(GL_ALPHA_TEST);
|
||||||
|
@ -833,6 +838,7 @@ void GfxOpenGL::drawSprite(const Sprite *sprite) {
|
||||||
glDisable(GL_ALPHA_TEST);
|
glDisable(GL_ALPHA_TEST);
|
||||||
glDepthMask(GL_TRUE);
|
glDepthMask(GL_TRUE);
|
||||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||||
|
glDisable(GL_BLEND);
|
||||||
glEnable(GL_DEPTH_TEST);
|
glEnable(GL_DEPTH_TEST);
|
||||||
|
|
||||||
glPopMatrix();
|
glPopMatrix();
|
||||||
|
|
|
@ -626,15 +626,14 @@ void GfxTinyGL::startActorDraw(const Actor *actor) {
|
||||||
tglBlendFunc(TGL_SRC_ALPHA, TGL_ONE_MINUS_SRC_ALPHA);
|
tglBlendFunc(TGL_SRC_ALPHA, TGL_ONE_MINUS_SRC_ALPHA);
|
||||||
}
|
}
|
||||||
|
|
||||||
const Math::Quaternion &quat = actor->getRotationQuat();
|
|
||||||
const float &scale = actor->getScale();
|
|
||||||
|
|
||||||
if (g_grim->getGameType() == GType_MONKEY4) {
|
if (g_grim->getGameType() == GType_MONKEY4) {
|
||||||
tglEnable(TGL_CULL_FACE);
|
tglEnable(TGL_CULL_FACE);
|
||||||
tglFrontFace(TGL_CW);
|
tglFrontFace(TGL_CW);
|
||||||
|
|
||||||
if (actor->isInOverworld()) {
|
if (actor->isInOverworld()) {
|
||||||
const Math::Vector3d &pos = actor->getWorldPos();
|
const Math::Vector3d &pos = actor->getWorldPos();
|
||||||
|
const Math::Quaternion &quat = actor->getRotationQuat();
|
||||||
|
// At distance 3.2, a 6.4x4.8 actor fills the screen.
|
||||||
tglMatrixMode(TGL_PROJECTION);
|
tglMatrixMode(TGL_PROJECTION);
|
||||||
tglLoadIdentity();
|
tglLoadIdentity();
|
||||||
float right = 1;
|
float right = 1;
|
||||||
|
@ -658,6 +657,9 @@ void GfxTinyGL::startActorDraw(const Actor *actor) {
|
||||||
} else {
|
} else {
|
||||||
// Grim
|
// Grim
|
||||||
Math::Vector3d pos = actor->getWorldPos();
|
Math::Vector3d pos = actor->getWorldPos();
|
||||||
|
const Math::Quaternion &quat = actor->getRotationQuat();
|
||||||
|
const float &scale = actor->getScale();
|
||||||
|
|
||||||
Math::Matrix4 worldRot = _currentQuat.toMatrix();
|
Math::Matrix4 worldRot = _currentQuat.toMatrix();
|
||||||
worldRot.inverseRotate(&pos);
|
worldRot.inverseRotate(&pos);
|
||||||
tglTranslatef(pos.x(), pos.y(), pos.z());
|
tglTranslatef(pos.x(), pos.y(), pos.z());
|
||||||
|
@ -669,6 +671,7 @@ void GfxTinyGL::startActorDraw(const Actor *actor) {
|
||||||
|
|
||||||
if (actor->getSortOrder() >= 100) {
|
if (actor->getSortOrder() >= 100) {
|
||||||
tglColorMask(TGL_FALSE, TGL_FALSE, TGL_FALSE, TGL_FALSE);
|
tglColorMask(TGL_FALSE, TGL_FALSE, TGL_FALSE, TGL_FALSE);
|
||||||
|
tglDepthMask(TGL_TRUE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -678,8 +681,8 @@ void GfxTinyGL::finishActorDraw() {
|
||||||
tglMatrixMode(TGL_PROJECTION);
|
tglMatrixMode(TGL_PROJECTION);
|
||||||
tglPopMatrix();
|
tglPopMatrix();
|
||||||
tglMatrixMode(TGL_MODELVIEW);
|
tglMatrixMode(TGL_MODELVIEW);
|
||||||
tglDisable(TGL_TEXTURE_2D);
|
|
||||||
|
|
||||||
|
tglDisable(TGL_TEXTURE_2D);
|
||||||
if (_alpha < 1.f) {
|
if (_alpha < 1.f) {
|
||||||
tglDisable(TGL_BLEND);
|
tglDisable(TGL_BLEND);
|
||||||
_alpha = 1.f;
|
_alpha = 1.f;
|
||||||
|
@ -756,14 +759,16 @@ void GfxTinyGL::getShadowColor(byte *r, byte *g, byte *b) {
|
||||||
|
|
||||||
void GfxTinyGL::drawEMIModelFace(const EMIModel *model, const EMIMeshFace *face) {
|
void GfxTinyGL::drawEMIModelFace(const EMIModel *model, const EMIMeshFace *face) {
|
||||||
int *indices = (int *)face->_indexes;
|
int *indices = (int *)face->_indexes;
|
||||||
|
|
||||||
tglEnable(TGL_DEPTH_TEST);
|
tglEnable(TGL_DEPTH_TEST);
|
||||||
tglDisable(TGL_ALPHA_TEST);
|
tglDisable(TGL_ALPHA_TEST);
|
||||||
|
//tglDisable(TGL_LIGHTING); // not apply here in TinyGL
|
||||||
if (face->_hasTexture)
|
if (face->_hasTexture)
|
||||||
tglEnable(TGL_TEXTURE_2D);
|
tglEnable(TGL_TEXTURE_2D);
|
||||||
else
|
else
|
||||||
tglDisable(TGL_TEXTURE_2D);
|
tglDisable(TGL_TEXTURE_2D);
|
||||||
tglBegin(TGL_TRIANGLES);
|
|
||||||
|
|
||||||
|
tglBegin(TGL_TRIANGLES);
|
||||||
float dim = 1.0f - _dimLevel;
|
float dim = 1.0f - _dimLevel;
|
||||||
for (uint j = 0; j < face->_faceLength * 3; j++) {
|
for (uint j = 0; j < face->_faceLength * 3; j++) {
|
||||||
int index = indices[j];
|
int index = indices[j];
|
||||||
|
@ -784,12 +789,14 @@ void GfxTinyGL::drawEMIModelFace(const EMIModel *model, const EMIMeshFace *face)
|
||||||
tglNormal3fv(normal.getData());
|
tglNormal3fv(normal.getData());
|
||||||
tglVertex3fv(vertex.getData());
|
tglVertex3fv(vertex.getData());
|
||||||
}
|
}
|
||||||
|
|
||||||
tglEnd();
|
tglEnd();
|
||||||
|
|
||||||
tglEnable(TGL_TEXTURE_2D);
|
tglEnable(TGL_TEXTURE_2D);
|
||||||
tglEnable(TGL_DEPTH_TEST);
|
tglEnable(TGL_DEPTH_TEST);
|
||||||
tglEnable(TGL_ALPHA_TEST);
|
tglEnable(TGL_ALPHA_TEST);
|
||||||
|
//tglEnable(GL_LIGHTING); // not apply here in TinyGL
|
||||||
tglDisable(TGL_BLEND);
|
tglDisable(TGL_BLEND);
|
||||||
|
tglDepthMask(TGL_TRUE);
|
||||||
tglColor3f(1.0f, 1.0f, 1.0f);
|
tglColor3f(1.0f, 1.0f, 1.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -816,23 +823,23 @@ void GfxTinyGL::drawSprite(const Sprite *sprite) {
|
||||||
tglLoadIdentity();
|
tglLoadIdentity();
|
||||||
tglMatrixMode(TGL_MODELVIEW);
|
tglMatrixMode(TGL_MODELVIEW);
|
||||||
tglPushMatrix();
|
tglPushMatrix();
|
||||||
tglTranslatef(sprite->_pos.x(), sprite->_pos.y(), sprite->_pos.z());
|
|
||||||
|
|
||||||
TGLfloat modelview[16];
|
|
||||||
tglGetFloatv(TGL_MODELVIEW_MATRIX, modelview);
|
|
||||||
|
|
||||||
if (g_grim->getGameType() == GType_MONKEY4) {
|
if (g_grim->getGameType() == GType_MONKEY4) {
|
||||||
|
TGLfloat modelview[16];
|
||||||
|
tglGetFloatv(TGL_MODELVIEW_MATRIX, modelview);
|
||||||
Math::Matrix4 act;
|
Math::Matrix4 act;
|
||||||
if (_currentActor->isInOverworld())
|
|
||||||
act.buildAroundZ(_currentActor->getYaw());
|
act.buildAroundZ(_currentActor->getYaw());
|
||||||
else
|
|
||||||
act.buildAroundZ(_currentActor->getRoll());
|
|
||||||
act.transpose();
|
act.transpose();
|
||||||
act(3, 0) = modelview[12];
|
act(3, 0) = modelview[12];
|
||||||
act(3, 1) = modelview[13];
|
act(3, 1) = modelview[13];
|
||||||
act(3, 2) = modelview[14];
|
act(3, 2) = modelview[14];
|
||||||
tglLoadMatrixf(act.getData());
|
tglLoadMatrixf(act.getData());
|
||||||
|
tglTranslatef(sprite->_pos.x(), sprite->_pos.y(), sprite->_pos.z());
|
||||||
} else {
|
} else {
|
||||||
|
tglTranslatef(sprite->_pos.x(), sprite->_pos.y(), sprite->_pos.z());
|
||||||
|
TGLfloat modelview[16];
|
||||||
|
tglGetFloatv(TGL_MODELVIEW_MATRIX, modelview);
|
||||||
|
|
||||||
// We want screen-aligned sprites so reset the rotation part of the matrix.
|
// We want screen-aligned sprites so reset the rotation part of the matrix.
|
||||||
for (int i = 0; i < 3; i++) {
|
for (int i = 0; i < 3; i++) {
|
||||||
for (int j = 0; j < 3; j++) {
|
for (int j = 0; j < 3; j++) {
|
||||||
|
@ -875,6 +882,7 @@ void GfxTinyGL::drawSprite(const Sprite *sprite) {
|
||||||
} else {
|
} else {
|
||||||
tglDepthMask(TGL_FALSE);
|
tglDepthMask(TGL_FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
float halfWidth = sprite->_width / 2;
|
float halfWidth = sprite->_width / 2;
|
||||||
float halfHeight = sprite->_height / 2;
|
float halfHeight = sprite->_height / 2;
|
||||||
float dim = 1.0f - _dimLevel;
|
float dim = 1.0f - _dimLevel;
|
||||||
|
@ -938,6 +946,7 @@ void GfxTinyGL::rotateViewpoint(const Math::Angle &angle, const Math::Vector3d &
|
||||||
}
|
}
|
||||||
|
|
||||||
void GfxTinyGL::translateViewpointFinish() {
|
void GfxTinyGL::translateViewpointFinish() {
|
||||||
|
//glMatrixMode(GL_MODELVIEW); // exist in opengl but doesn't work properly here
|
||||||
tglPopMatrix();
|
tglPopMatrix();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1453,12 +1462,12 @@ void GfxTinyGL::selectTexture(const Texture *texture) {
|
||||||
|
|
||||||
// Grim has inverted tex-coords, EMI doesn't
|
// Grim has inverted tex-coords, EMI doesn't
|
||||||
if (g_grim->getGameType() != GType_MONKEY4) {
|
if (g_grim->getGameType() != GType_MONKEY4) {
|
||||||
tglPushMatrix();
|
tglPushMatrix(); // removed in opengl but here doesn't work properly after remove
|
||||||
tglMatrixMode(TGL_TEXTURE);
|
tglMatrixMode(TGL_TEXTURE);
|
||||||
tglLoadIdentity();
|
tglLoadIdentity();
|
||||||
tglScalef(1.0f / texture->_width, 1.0f / texture->_height, 1);
|
tglScalef(1.0f / texture->_width, 1.0f / texture->_height, 1);
|
||||||
tglMatrixMode(TGL_MODELVIEW);
|
tglMatrixMode(TGL_MODELVIEW); // removed in opengl but here doesn't work properly after remove
|
||||||
tglPopMatrix();
|
tglPopMatrix(); // removed in opengl but here doesn't work properly after remove
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue