Commits

Anonymous committed 660ed36

pvr support

  • Participants
  • Parent commits 2fe217a
  • Branches gles

Comments (0)

Files changed (2)

code/payload/Lobster.cpp

 		dy = 0.0f;
 
 		this->sprite1 = new Sprite();
-		this->sprite1->texture  = banana::loadTexture("data/textures/huita.tga");
-		this->sprite1->position = float3(0.0f, -0.6f, 0.0f);
-		this->sprite1->width    = 1.5f;
-		this->sprite1->height   = 0.5f;
-		this->sprite1->scale    = 1.0f;
+		this->sprite1->texture  = banana::loadTexture("data/textures/sun.pvr");
+		this->sprite1->position = float3(0.5f, -0.6f, 0.0f);
+		this->sprite1->width    = 1.0f;
+		this->sprite1->height   = 1.0f;
+		this->sprite1->scale    = 0.5f;
 		this->sprite1->angle    = 0.0f;
 
-		//this->scene.objects.push_back(this->sprite1);
+		this->scene.objects.push_back(this->sprite1);
 
 		this->sprite2 = new Sprite();
 		this->sprite2->texture  = banana::loadTexture("data/textures/ebala.png");
-		this->sprite2->position = float3(0.0f, -0.6f, 0.0f);
+		this->sprite2->position = float3(-0.5f, -0.6f, 0.0f);
 		this->sprite2->width    = 1.0f;
 		this->sprite2->height   = 1.0f;
-		this->sprite2->scale    = 1.0f;
+		this->sprite2->scale    = 0.5f;
 		this->sprite2->angle    = 0.0f;
 
 		this->scene.objects.push_back(this->sprite2);

code/payload/banana/BananaTexture.cpp

 
 }
 
+/**
+ * PVR texture header
+ */
+struct PVRTextureHeader 
+{
+	uint32_t headerLength;
+	uint32_t height;
+	uint32_t width;
+	uint32_t numMipmaps;
+	uint32_t flags;
+	uint32_t dataLength;
+	uint32_t bpp;
+	uint32_t bitmaskRed;
+	uint32_t bitmaskGreen;
+	uint32_t bitmaskBlue;
+	uint32_t bitmaskAlpha;
+	uint32_t pvrTag;
+	uint32_t numSurfs;
+};
+
+/**
+ * TGA texture header
+ */
 #pragma pack(1)
 struct TGATextureHeader
 {
 
 GLuint loadTextureFromPng(const char* filename)
 {
-	char fullpath[1024];
-	sprintf(fullpath, "%s", filename);
-
-	VFSFILE* file = vfs_fopen(fullpath, "rb");
+	VFSFILE* file = vfs_fopen(filename, "rb");
 	if (file == NULL)
 		return 0;
 
 
 GLuint loadTextureFromTga(const char* filename)
 {
-	char fullpath[1024];
-	sprintf(fullpath, "%s", filename);
-	
-	VFSFILE* file = vfs_fopen(fullpath, "rb");
+	VFSFILE* file = vfs_fopen(filename, "rb");
 	if (file == NULL)
 		return 0;
 	
 	vfs_fclose(file);
 	
 	return result;
-} 
+}
+
+GLuint loadTextureFromPvr(const char* filename)
+{
+	int sizeInBytes = vfs_fsize(filename);
+	if (sizeInBytes == -1)
+		return 0;
+
+	VFSFILE* file = vfs_fopen(filename, "rb");
+	if (file == NULL)
+		return 0;
+
+	uint8_t* buffer = new uint8_t[sizeInBytes];
+	
+	vfs_fread(buffer, 1, sizeInBytes, file);
+	
+	PVRTextureHeader* header = (PVRTextureHeader*)buffer;
+	uint8_t* imageData = (uint8_t*)buffer + header->headerLength;
+	
+	// Create OpenGL texture
+	GLuint result = 0;
+	
+	glGenTextures(1, &result);
+	glBindTexture(GL_TEXTURE_2D, result);
+	glCompressedTexImage2D(GL_TEXTURE_2D, 0, 
+						   header->bpp == 4 ? GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG : GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG, 
+						   header->width, header->height, 0, header->dataLength, imageData);
+	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+	
+	delete [] buffer;
+	vfs_fclose(file);
+	
+	return result; 
+}
 
 /**
  * A very useful function in OpenGL
 	if (strcmp(ext, ".tga") == 0)
 		return loadTextureFromTga(filename);
 
+	if (strcmp(ext, ".pvr") == 0)
+		return loadTextureFromPvr(filename);
+
 	assert(false);
 	return 0;
 }