fixing rendering issue on real PS2

This commit is contained in:
Sandro Sobczyński
2020-11-08 21:50:06 +01:00
parent b11df0262e
commit 3b5fb1b670
14 changed files with 110 additions and 77 deletions
+14 -18
View File
@@ -32,10 +32,12 @@ BmpLoader::~BmpLoader() {}
*/
void BmpLoader::load(MeshTexture &o_texture, char *t_subfolder, char *t_name, char *t_extension)
{
char *t_path_part = String::createConcatenated(t_subfolder, t_name);
char *t_path = String::createConcatenated(t_path_part, t_extension);
delete[] t_path_part;
FILE *file = fopen(t_path, "rb");
char *path_part1 = String::createConcatenated(t_subfolder, t_name);
char *path_part2 = String::createConcatenated("host:", path_part1);
char *path = String::createConcatenated(path_part2, t_extension);
delete[] path_part1;
delete[] path_part2;
FILE *file = fopen(path, "rb");
if (file == NULL)
{
@@ -46,8 +48,8 @@ void BmpLoader::load(MeshTexture &o_texture, char *t_subfolder, char *t_name, ch
unsigned char header[54];
fread(header, sizeof(unsigned char), 54, file);
u32 width = *(u32 *)&header[18];
u32 height = *(u32 *)&header[22];
u32 width = (u32)header[18];
u32 height = (u32)header[22];
o_texture.setSize(width, height);
printf("BMPLoader - width: %d | height: %d\n", width, height);
if (width > 128 || height > 128)
@@ -55,27 +57,21 @@ void BmpLoader::load(MeshTexture &o_texture, char *t_subfolder, char *t_name, ch
u64 rowPadded = (width * 3 + 3) & (~3);
unsigned char *data = new unsigned char[rowPadded];
unsigned char tmp;
unsigned char row[rowPadded];
u32 x = 0;
for (u32 i = 0; i < height; i++)
{
fread(data, sizeof(unsigned char), rowPadded, file);
fread(&row, sizeof(unsigned char), rowPadded, file);
for (u32 j = 0; j < width * 3; j += 3)
{
// Convert (B, G, R) to (R, G, B)
tmp = data[j];
data[j] = data[j + 2];
data[j + 2] = tmp;
o_texture.setData(x, data[j]);
o_texture.setData(x + 1, data[j + 1]);
o_texture.setData(x + 2, data[j + 2]);
o_texture.setData(x, row[j + 2]);
o_texture.setData(x + 1, row[j + 1]);
o_texture.setData(x + 2, row[j]);
x += 3;
}
}
delete[] t_path;
delete[] data;
delete[] path;
fclose(file);
}
+22 -1
View File
@@ -37,7 +37,8 @@ DffLoader::~DffLoader() {}
void DffLoader::load(MeshFrame *o_result, char *t_filename, float t_scale, u8 t_invertT)
{
PRINT_LOG("Loading dff file");
FILE *file = fopen(t_filename, "rb");
char *path = String::createConcatenated("host:", t_filename);
FILE *file = fopen(path, "rb");
if (file == NULL)
PRINT_ERR("Failed to load .dff file!");
fseek(file, 0L, SEEK_END);
@@ -48,9 +49,29 @@ void DffLoader::load(MeshFrame *o_result, char *t_filename, float t_scale, u8 t_
fclose(file);
serialize(o_result, t_invertT, data, t_scale);
o_result->calculateBoundingBoxes();
delete[] path;
PRINT_LOG("Dff file loaded!");
}
// void DffLoader::im_not_used_anywhere(MeshFrame *o_result, char *t_filename, float t_scale, u8 t_invertT)
// {
// PRINT_LOG("Loading dff file");
// char *path = String::createConcatenated("host:", t_filename);
// FILE *file = fopen(path, "rb");
// if (file == NULL)
// PRINT_ERR("Failed to load .dff file!");
// fseek(file, 0L, SEEK_END);
// long fileSize = ftell(file);
// u8 data[fileSize];
// rewind(file);
// fread(&data, sizeof(u8), fileSize, file);
// fclose(file);
// serialize(o_result, t_invertT, data, t_scale);
// o_result->calculateBoundingBoxes();
// delete[] path;
// PRINT_LOG("Dff file loaded!");
// }
void DffLoader::serialize(MeshFrame *o_result, u8 t_invertT, u8 *t_data, float t_scale)
{
u32 ptrPos = 0;
+3 -1
View File
@@ -46,8 +46,10 @@ MeshFrame *MD2Loader::load(u32 &o_framesCount, char *t_subpath, char *t_nameWith
{
PRINT_LOG("Loading new MD2 file");
char *part1 = String::createConcatenated(t_subpath, t_nameWithoutExtension);
char *finalPath = String::createConcatenated(part1, ".md2"); // "folder/object.md2"
char *part2 = String::createConcatenated("host:", part1);
char *finalPath = String::createConcatenated(part2, ".md2"); // "folder/object.md2"
delete[] part1;
delete[] part2;
md2_t header;
FILE *file = fopen(finalPath, "rb");
+3 -1
View File
@@ -28,7 +28,8 @@ ObjLoader::~ObjLoader() {}
void ObjLoader::load(MeshFrame *o_result, char *t_filename, float t_scale, u8 t_invertT)
{
FILE *file = fopen(t_filename, "rb");
char *path = String::createConcatenated("host:", t_filename);
FILE *file = fopen(path, "rb");
if (file == NULL)
PRINT_ERR("Failed to load .obj file!");
allocateObjMemory(file, o_result);
@@ -98,6 +99,7 @@ void ObjLoader::load(MeshFrame *o_result, char *t_filename, float t_scale, u8 t_
}
o_result->calculateBoundingBoxes();
fclose(file);
delete[] path;
}
/** Calculate how many vertices(v), coordinates(vt), normals(vn) and faces(f) have .obj file */