[Scummvm-cvs-logs] CVS: residual bitmap.cpp,1.19,1.20 bitmap.h,1.6,1.7

Daniel Schepler dschepler at users.sourceforge.net
Mon Mar 22 13:59:19 CET 2004


Update of /cvsroot/scummvm/residual
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4590

Modified Files:
	bitmap.cpp bitmap.h 
Log Message:
Implement transparent bitmaps.


Index: bitmap.cpp
===================================================================
RCS file: /cvsroot/scummvm/residual/bitmap.cpp,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -d -r1.19 -r1.20
--- bitmap.cpp	22 Mar 2004 11:23:36 -0000	1.19
+++ bitmap.cpp	22 Mar 2004 21:48:30 -0000	1.20
@@ -64,6 +64,29 @@
 	}	
 	
 	if (format_ == 1) {
+		hasTransparency_ = false;
+
+		// Convert data to 32-bit RGBA format
+		char *texData = new char[4 * width_ * height_];
+		char *texDataPtr = texData;
+		uint16 *bitmapData = reinterpret_cast<uint16 *>(data_[0]);
+		for (int i = 0; i < width_ * height_;
+		     i++, texDataPtr += 4, bitmapData++) {
+			uint16 pixel = *bitmapData;
+			int r = pixel >> 11;
+			texDataPtr[0] = (r << 3) | (r >> 2);
+			int g = (pixel >> 5) & 0x3f;
+			texDataPtr[1] = (g << 2) | (g >> 4);
+			int b = pixel & 0x1f;
+			texDataPtr[2] = (b << 3) | (b >> 2);
+			if (pixel == 0xf81f) { // transparent
+				texDataPtr[3] = 0;
+				hasTransparency_ = true;
+			}
+			else
+				texDataPtr[3] = 255;
+		}
+
 		num_tex_ = ((width_ + (BITMAP_TEXTURE_SIZE - 1)) / BITMAP_TEXTURE_SIZE) *
 			((height_ + (BITMAP_TEXTURE_SIZE - 1)) / BITMAP_TEXTURE_SIZE);
 		tex_ids_ = new GLuint[num_tex_];
@@ -74,9 +97,9 @@
 			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
 			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
 			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
-			glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB,
+			glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA,
 				BITMAP_TEXTURE_SIZE, BITMAP_TEXTURE_SIZE, 0,
-				GL_RGB, GL_UNSIGNED_SHORT_5_6_5, NULL);
+				GL_RGBA, GL_UNSIGNED_BYTE, NULL);
 		}
 
 		glPixelStorei(GL_UNPACK_ALIGNMENT, 2);
@@ -92,14 +115,15 @@
 					0,
 					0, 0,
 					width, height,
-					GL_RGB,
-					GL_UNSIGNED_SHORT_5_6_5,
-					data_[curr_image_] + (y * 2 * width_) + (2 * x));
+					GL_RGBA,
+					GL_UNSIGNED_BYTE,
+					texData + (y * 4 * width_) + (4 * x));
 				cur_tex_idx++;
 			}
 		}
 		glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
 		glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
+		delete [] texData;
 	} else {
 		for (int i = 0; i < (width_ * height_); i++) {
 			uint16 val = READ_LE_UINT16(data_[curr_image_] + 2 * i);
@@ -120,6 +144,12 @@
 	glLoadIdentity();
 	// A lot more may need to be put there : disabling Alpha test, blending, ...
 	// For now, just keep this here :-)
+	if (hasTransparency_) {
+		glEnable(GL_BLEND);
+		glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+	}
+	else
+		glDisable(GL_BLEND);
 	glDisable(GL_LIGHTING);
 	glEnable(GL_TEXTURE_2D);
 	if (format_ == 1) {		// Normal image
@@ -152,6 +182,7 @@
 
 		glDisable(GL_SCISSOR_TEST);
 		glDisable(GL_TEXTURE_2D);
+		glDisable(GL_BLEND);
 		glDepthMask(GL_TRUE);
 		glEnable(GL_DEPTH_TEST);
 	} else if (format_ == 5) {	// ZBuffer image

Index: bitmap.h
===================================================================
RCS file: /cvsroot/scummvm/residual/bitmap.h,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- bitmap.h	22 Mar 2004 11:23:36 -0000	1.6
+++ bitmap.h	22 Mar 2004 21:48:30 -0000	1.7
@@ -51,6 +51,7 @@
 	int format_;
 	int num_tex_;
 	GLuint *tex_ids_;
+	bool hasTransparency_;
 };
 
 #endif





More information about the Scummvm-git-logs mailing list