GRIM: Make a material transparent only if it asks to. Fix #298 Fix #254

This also fixes partially #31, making the hats visible.
This commit is contained in:
Giulio Camuffo 2011-07-28 21:36:03 +02:00
parent abfa56a336
commit c3470d9b16
4 changed files with 16 additions and 9 deletions

View file

@ -971,6 +971,9 @@ void GfxOpenGL::createMaterial(MaterialData *material, const char *data, const C
uint8 col = *(uint8 *)(data); uint8 col = *(uint8 *)(data);
if (col == 0) { if (col == 0) {
memset(texdatapos, 0, 4); // transparent memset(texdatapos, 0, 4); // transparent
if (!material->_hasAlpha) {
texdatapos[3] = '\xff'; // fully opaque
}
} else { } else {
memcpy(texdatapos, cmap->_colors + 3 * (col), 3); memcpy(texdatapos, cmap->_colors + 3 * (col), 3);
texdatapos[3] = '\xff'; // fully opaque texdatapos[3] = '\xff'; // fully opaque
@ -1273,7 +1276,7 @@ void GfxOpenGL::dimRegion(int x, int yReal, int w, int h, float level) {
delete[] data; delete[] data;
} }
void GfxOpenGL::irisAroundRegion(int x, int y) void GfxOpenGL::irisAroundRegion(int x, int y)
{ {
glMatrixMode(GL_PROJECTION); glMatrixMode(GL_PROJECTION);
@ -1281,13 +1284,13 @@ void GfxOpenGL::irisAroundRegion(int x, int y)
glOrtho(0.0, _screenWidth, _screenHeight, 0.0, 0.0, 1.0); glOrtho(0.0, _screenWidth, _screenHeight, 0.0, 0.0, 1.0);
glMatrixMode(GL_MODELVIEW); glMatrixMode(GL_MODELVIEW);
glLoadIdentity(); glLoadIdentity();
glDisable(GL_DEPTH_TEST); glDisable(GL_DEPTH_TEST);
glDisable(GL_TEXTURE_2D); glDisable(GL_TEXTURE_2D);
glDisable(GL_BLEND); glDisable(GL_BLEND);
glDisable(GL_LIGHTING); glDisable(GL_LIGHTING);
glDepthMask(GL_FALSE); glDepthMask(GL_FALSE);
glColor3f(0.0f, 0.0f, 0.0f); glColor3f(0.0f, 0.0f, 0.0f);
float points[20] = { float points[20] = {
@ -1314,13 +1317,13 @@ void GfxOpenGL::irisAroundRegion(int x, int y)
glDrawArrays(GL_TRIANGLE_STRIP, 0, 10); glDrawArrays(GL_TRIANGLE_STRIP, 0, 10);
glDisableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_VERTEX_ARRAY);
#endif #endif
glColor3f(1.0f, 1.0f, 1.0f); glColor3f(1.0f, 1.0f, 1.0f);
glEnable(GL_DEPTH_TEST); glEnable(GL_DEPTH_TEST);
glEnable(GL_LIGHTING); glEnable(GL_LIGHTING);
glDepthMask(GL_TRUE); glDepthMask(GL_TRUE);
} }
void GfxOpenGL::drawRectangle(PrimitiveObject *primitive) { void GfxOpenGL::drawRectangle(PrimitiveObject *primitive) {
int x1 = primitive->getP1().x; int x1 = primitive->getP1().x;
int y1 = primitive->getP1().y; int y1 = primitive->getP1().y;

View file

@ -812,9 +812,12 @@ void GfxTinyGL::createMaterial(MaterialData *material, const char *data, const C
for (int y = 0; y < material->_height; y++) { for (int y = 0; y < material->_height; y++) {
for (int x = 0; x < material->_width; x++) { for (int x = 0; x < material->_width; x++) {
uint8 col = *(uint8 *)(data); uint8 col = *(uint8 *)(data);
if (col == 0) if (col == 0) {
memset(texdatapos, 0, 4); // transparent memset(texdatapos, 0, 4); // transparent
else { if (!material->_hasAlpha) {
texdatapos[3] = '\xff'; // fully opaque
}
} else {
memcpy(texdatapos, cmap->_colors + 3 * (col), 3); memcpy(texdatapos, cmap->_colors + 3 * (col), 3);
texdatapos[3] = '\xff'; // fully opaque texdatapos[3] = '\xff'; // fully opaque
} }
@ -959,7 +962,7 @@ void GfxTinyGL::dimRegion(int x, int y, int w, int h, float level) {
} }
} }
} }
void GfxTinyGL::irisAroundRegion(int x, int y) void GfxTinyGL::irisAroundRegion(int x, int y)
{ {
uint16 *data = (uint16 *)_zb->pbuf; uint16 *data = (uint16 *)_zb->pbuf;

View file

@ -50,6 +50,7 @@ MaterialData::MaterialData(const Common::String &filename, const char *data, int
error("Unknown offset: %d", offset); error("Unknown offset: %d", offset);
_width = READ_LE_UINT32(data + 60 + _numImages * 40); _width = READ_LE_UINT32(data + 60 + _numImages * 40);
_height = READ_LE_UINT32(data + 64 + _numImages * 40); _height = READ_LE_UINT32(data + 64 + _numImages * 40);
_hasAlpha = READ_LE_UINT32(data + 68 + _numImages * 40);
if (_width == 0 || _height == 0) { if (_width == 0 || _height == 0) {
if (gDebugLevel == DEBUG_WARN || gDebugLevel == DEBUG_ALL) if (gDebugLevel == DEBUG_WARN || gDebugLevel == DEBUG_ALL)

View file

@ -40,7 +40,7 @@ public:
const ObjectPtr<CMap> _cmap; const ObjectPtr<CMap> _cmap;
int _numImages; int _numImages;
int _width, _height; int _width, _height;
int _alpha; bool _hasAlpha;
void *_textures; void *_textures;
int _refCount; int _refCount;
}; };