Can now render textures but not correctly

This commit is contained in:
theclub654 2023-12-06 22:36:55 -05:00
parent 02dcf3cbe9
commit 236860e13e
11 changed files with 295 additions and 22 deletions

View File

@ -1,5 +1,5 @@
#include "alo.h"
std::vector <GEOM> allcollisionModels;
std::vector <GEOM*> allcollisionModels;
void* NewAlo()
{
@ -273,15 +273,8 @@ void DeleteModel(ALO *palo)
glDeleteBuffers(1, &palo->globset.aglob[i].asubglob[a].VCB);
glDeleteBuffers(1, &palo->globset.aglob[i].asubglob[a].TCB);
glDeleteBuffers(1, &palo->globset.aglob[i].asubglob[a].EBO);
glDeleteTextures(1, &palo->globset.aglob[i].asubglob[a].gl_texture);
}
}
for (int i = 0; i < allcollisionModels.size(); i++)
{
glDeleteVertexArrays(1, &allcollisionModels[i].VAO);
glDeleteBuffers(1, &allcollisionModels[i].VBO);
}
}
void DeleteAlo(LO* palo)

View File

@ -1,6 +1,6 @@
#include "bis.h"
std::vector <GEOM*> allcollisionModels;
extern std::vector <GEOM*> allcollisionModels;
CBinaryInputStream::CBinaryInputStream(std::string filePath)
{

View File

@ -159,7 +159,7 @@ void LoadGlobsetFromBrx(GLOBSET* pglobset, CBinaryInputStream* pbis, ALO* palo)
// Loading texture property info from vector
pglobset->aglob[i].asubglob[a].pshd = &g_ashd[pbis->U16Read()];
pglobset->aglob[i].asubglob[a].unSelfIllum = pbis->U8Read();
pglobset->aglob[i].asubglob[a].cibnd = pbis->U8Read();
@ -346,6 +346,9 @@ void DrawGlob(GLOBSET* pglobset, glm::vec3 pos)
int modelUniformLocation = glGetUniformLocation(glShader.ID, "model");
glUniformMatrix4fv(modelUniformLocation, 1, GL_FALSE, glm::value_ptr(model));
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, pglobset->aglob[i].asubglob[a].pshd->glTexture);
glBindVertexArray(pglobset->aglob[i].asubglob[a].VAO);
glDrawElements(GL_TRIANGLES, pglobset->aglob[i].asubglob[a].indices.size(), GL_UNSIGNED_SHORT, (void*)0);
glBindVertexArray(0);

View File

@ -4,8 +4,11 @@ out vec4 FragColor;
in vec4 color;
in vec3 aNormal;
in vec2 TEXCOORD;
uniform sampler2D Texture;
void main()
{
FragColor = vec4(aNormal, 1.0);
FragColor = texture(Texture, TEXCOORD);
}

View File

@ -33,7 +33,6 @@ struct SUBGLOB // NOT DONE
GLuint VCB;
GLuint TCB;
GLuint EBO;
GLuint gl_texture;
glm::vec3 posCenter; // Submodel orgin
float sRadius;

View File

@ -7,6 +7,7 @@ layout (location = 3) in vec2 texCoord;
out vec4 color;
out vec3 aNormal;
out vec2 TEXCOORD;
uniform mat4 proj;
uniform mat4 view;
@ -17,4 +18,5 @@ void main()
gl_Position = proj * view * model * vec4(pos.y, pos.x, pos.z, 1.0);
color = vertexColor / 255.0;
aNormal = normal;
TEXCOORD = texCoord;
}

View File

@ -1668,3 +1668,99 @@ Column 0 Sort=0v
RefScale=13
Column 0 Sort=0v
[Table][0x7447640B,4]
RefScale=13
Column 0 Sort=0v
[Table][0xDABA3DAD,4]
RefScale=13
Column 0 Sort=0v
[Table][0x1AA5A642,4]
RefScale=13
Column 0 Sort=0v
[Table][0xA542EA78,4]
RefScale=13
Column 0 Sort=0v
[Table][0x582AC5C6,4]
RefScale=13
Column 0 Sort=0v
[Table][0x1149C658,4]
RefScale=13
Column 0 Sort=0v
[Table][0x6E4BFA18,4]
RefScale=13
Column 0 Sort=0v
[Table][0x391C30F5,4]
RefScale=13
Column 0 Sort=0v
[Table][0x4E78894F,4]
RefScale=13
Column 0 Sort=0v
[Table][0xBFD46161,4]
RefScale=13
Column 0 Sort=0v
[Table][0x26A59285,4]
RefScale=13
Column 0 Sort=0v
[Table][0xC18A668A,4]
RefScale=13
Column 0 Sort=0v
[Table][0x8EF02033,4]
RefScale=13
Column 0 Sort=0v
[Table][0xB03CBB83,4]
RefScale=13
Column 0 Sort=0v
[Table][0xA5692912,4]
RefScale=13
Column 0 Sort=0v
[Table][0xD7D70615,4]
RefScale=13
Column 0 Sort=0v
[Table][0x7F4CE530,4]
RefScale=13
Column 0 Sort=0v
[Table][0x874F12C4,4]
RefScale=13
Column 0 Sort=0v
[Table][0xF089B0FD,4]
RefScale=13
Column 0 Sort=0v
[Table][0x5574E97C,4]
RefScale=13
Column 0 Sort=0v
[Table][0xA6620D9E,4]
RefScale=13
Column 0 Sort=0v
[Table][0xD7358156,4]
RefScale=13
Column 0 Sort=0v
[Table][0x7AE10AE7,4]
RefScale=13
Column 0 Sort=0v
[Table][0xD22DF52B,4]
RefScale=13
Column 0 Sort=0v

View File

@ -8,7 +8,7 @@ GLSHADER glShaderCollision;
std::string file;
CTransition g_transition;
FREECAMERA g_freecamera(glm::vec3{0.0});
bool firstClick = true;
float deltaTime = 0.0f;
float lastFrame = 0.0f;
@ -51,9 +51,7 @@ int main(int cphzArgs, char* aphzArgs[])
DrawSwAll();
if (fRenderCollision != 0)
{
DrawSwCollisionAll();
}
}
ImGui::Render();

View File

@ -56,7 +56,7 @@ void LoadBitmapsFromBrx(CBinaryInputStream *pbis)
for (int i = 0; i < g_cbmp; i++)
{
g_abmp[i].bmpWidth = pbis->U16Read();
g_abmp[i].bmpheight = pbis->U16Read();
g_abmp[i].bmpHeight = pbis->U16Read();
g_abmp[i].grfzon = pbis->U32Read();
g_abmp[i].psm = pbis->S8Read();
g_abmp[i].cgsRow = pbis->S8Read();
@ -136,3 +136,162 @@ void LoadShadersFromBrx(CBinaryInputStream *pbis)
LoadFontsFromBrx(pbis);
}
void ParseTextures(CBinaryInputStream* pbis)
{
for (uint16_t i = 0; i < 0x100; i += 0x20) {
for (uint16_t j = i; j < i + 8; j++) {
csm1ClutIndices[j] = static_cast<uint8_t>(j);
csm1ClutIndices[j + 8] = static_cast<uint8_t>(j) + 0x10;
csm1ClutIndices[j + 0x10] = static_cast<uint8_t>(j) + 0x8;
csm1ClutIndices[j + 0x18] = static_cast<uint8_t>(j) + 0x18;
}
}
textureDataStart = pbis->file.tellg();
for (int i = 0; i < g_ashd.size(); i++)
{
for (int a = 0; a < g_ashd[i].atex.size(); a++)
{
bool is1Img1Pal = ((g_ashd[i].atex[a].bmpIndex.size() == 1) && (g_ashd[i].atex[a].clutIndex.size() == 1));
bool is1ImgManyPal = ((g_ashd[i].atex[a].bmpIndex.size() == 1) && (g_ashd[i].atex[a].clutIndex.size() > 1));
bool isManyImgManyPal = ((g_ashd[i].atex[a].bmpIndex.size() > 1) && (g_ashd[i].atex[a].clutIndex.size() > 1));
if (is1Img1Pal)
MakeTexture(pbis, i, g_ashd[i].atex[a].clutIndex[0], g_ashd[i].atex[a].bmpIndex[0]);
else if (is1ImgManyPal)
{
if (g_ashd[i].atex[a].clutIndex.size() == 3)
{
MakeTexture(pbis, i, g_ashd[i].atex[a].clutIndex[1], g_ashd[i].atex[a].bmpIndex[0]);
MakeTexture(pbis, i, g_ashd[i].atex[a].clutIndex[1], g_ashd[i].atex[a].bmpIndex[0]);
MakeTexture(pbis, i, g_ashd[i].atex[a].clutIndex[1], g_ashd[i].atex[a].bmpIndex[0]);
}
else
MakeTexture(pbis, i, g_ashd[i].atex[a].clutIndex[1], g_ashd[i].atex[a].bmpIndex[0]);
}
else if (isManyImgManyPal)
MakeTexture(pbis, i, g_ashd[i].atex[a].clutIndex[1], g_ashd[i].atex[a].bmpIndex[1]);
}
}
}
std::vector<byte> MakeBmp(CBinaryInputStream* pbis, uint32_t bmpIndex)
{
std::vector <byte> buffer;
std::vector <byte> test;
size_t bufferOff = textureDataStart + g_abmp[bmpIndex].baseOffset;
int width = g_abmp[bmpIndex].bmpWidth;
int height = g_abmp[bmpIndex].bmpHeight;
buffer.resize(width * height);
pbis->file.seekg(bufferOff, SEEK_SET);
for (int i = 0; i < width * height; i++)
buffer[i] = pbis->U8Read();
return buffer;
}
std::vector<byte> MakePallete(CBinaryInputStream* pbis, uint32_t clutIndex)
{
std::vector <byte> buffer;
size_t paletteBuffer = textureDataStart + g_aclut[clutIndex].baseOffset;
int numColors = g_aclut[clutIndex].numColors;
int colorSize = g_aclut[clutIndex].colorSize;
buffer.resize(numColors * colorSize * 4);
pbis->file.seekg(paletteBuffer, SEEK_SET);
for (int i = 0; i < numColors * colorSize * 4; i++)
buffer[i] = pbis->U8Read();
return buffer;
}
void MakeTexture(CBinaryInputStream* pbis, uint32_t textureTableIndex, int16_t clutIndex, int16_t bmpIndex)
{
if (clutIndex >= g_aclut.size() || bmpIndex >= g_abmp.size())
return;
std::vector <byte> image;
std::vector <byte> pallete;
std::vector <byte> texture;
image = MakeBmp(pbis, bmpIndex);
pallete = MakePallete(pbis, clutIndex);
short width = g_abmp[bmpIndex].bmpWidth;
short height = g_abmp[bmpIndex].bmpHeight;
texture.resize(width * height * 4);
byte alpha;
if (g_aclut[clutIndex].numColors > 16)
{
for (int i = 0; i < width * height; i++)
{
int index = csm1ClutIndices[image[i]] * 4;
texture[4 * i + 0] = pallete[index + 0];
texture[4 * i + 1] = pallete[index + 1];
texture[4 * i + 2] = pallete[index + 2];
alpha = pallete[index + 3];
if (alpha == 0x80)
texture[4 * i + 3] = 0xFF;
else
texture[4 * i + 3] = pallete[index + 3];
}
}
else
{
for (int i = 0; i < width * height / 2; i++)
{
byte index1 = image[i] >> 4;
byte index2 = image[i] & 0x0F;
texture[8 * i + 0] = pallete[4 * index1 + 0];
texture[8 * i + 1] = pallete[4 * index1 + 1];
texture[8 * i + 2] = pallete[4 * index1 + 2];
alpha = pallete[4 * index1 + 3];
if (alpha == 0x80)
texture[8 * i + 3] = 0xFF;
else
texture[8 * i + 3] = pallete[4 * index1 + 3];
texture[8 * i + 4] = pallete[4 * index2 + 0];
texture[8 * i + 5] = pallete[4 * index2 + 1];
texture[8 * i + 6] = pallete[4 * index2 + 2];
alpha = pallete[4 * index2 + 3];
if (alpha == 0x80)
texture[8 * i + 7] = 0xFF;
else
texture[8 * i + 7] = pallete[4 * index2 + 3];
}
}
glGenTextures(1, &g_ashd[textureTableIndex].glTexture);
glBindTexture(GL_TEXTURE_2D, g_ashd[textureTableIndex].glTexture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, texture.data());
glBindTexture(GL_TEXTURE_2D, 0);
texture.clear();
texture.shrink_to_fit();
}

View File

@ -25,7 +25,7 @@ struct CLUT
short numColors;
// Color size of the CLUT
short colorSize;
// Ptr to CLUT
// Ptr to CLUT in memory
uint32_t baseOffset;
};
@ -35,14 +35,14 @@ struct BMP
// BMP width
short bmpWidth;
// BMP height
short bmpheight;
short bmpHeight;
uint32_t grfzon;
byte psm;
byte cgsRow;
short cgsPixels;
// BMP size
uint32_t cbPixels;
// Offset to BMP in memory MIGHT NOT BE NEEDED
// Offset to BMP in memory
uint32_t baseOffset;
};
@ -58,6 +58,7 @@ struct TEXF
struct SHDF
{
GLuint glTexture;
byte shdk;
byte grfshd;
uint16_t oid;
@ -98,6 +99,10 @@ void LoadFontsFromBrx(CBinaryInputStream *pbis); // GOTTA COME BACK TO THIS
void LoadTexFromBrx(CBinaryInputStream* pbis, TEX* ptex);
// Loads texture and shader data from binary file
void LoadShadersFromBrx(CBinaryInputStream *pbis);
void ParseTextures(CBinaryInputStream* pbis);
std::vector <byte> MakeBmp(CBinaryInputStream* pbis, uint32_t bmpIndex);
std::vector <byte> MakePallete(CBinaryInputStream* pbis, uint32_t clutIndex);
void MakeTexture(CBinaryInputStream* pbis, uint32_t textureTableIndex, int16_t clutIndex, int16_t bmpIndex);
// Global variable which holds the number of CLUT's in a binary file
static int g_cclut;
@ -117,4 +122,8 @@ static int g_cpsaa;
// Global vector for shader animation property's
static std::vector <SAA> g_apsaa;
// Table for texture property's
static std::vector<TEX> g_atex;
static std::vector<TEX> g_atex;
// Unswizzled CLUT indices
static uint8_t csm1ClutIndices[256];
// Start of texture data
static size_t textureDataStart;

View File

@ -4,7 +4,7 @@
std::vector<LO*> allWorldObjs;
std::vector<ALO*> allSWAloObjs;
extern std::vector<void*> allSwLights;
extern std::vector <GEOM> allcollisionModels;
extern std::vector <GEOM*> allcollisionModels;
void* NewSw()
{
@ -80,6 +80,8 @@ void LoadSwFromBrx(SW* psw, CBinaryInputStream* pbis)
// Loads all the static world objects from the binary file
LoadSwObjectsFromBrx(psw, 0x0, pbis);
pbis->Align(0x10);
std::cout << "Loading Textures\n";
ParseTextures(pbis);
std::cout << "World Loaded Successfully\n";
}
@ -110,12 +112,21 @@ void DeleteSw(SW* psw)
void DeleteWorld(SW* psw)
{
for (int i = 0; i < allcollisionModels.size(); i++)
{
glDeleteVertexArrays(1, &allcollisionModels[i]->VAO);
glDeleteBuffers(1, &allcollisionModels[i]->VBO);
}
for (int i = 0; i < allSWAloObjs.size(); i++)
DeleteModel(allSWAloObjs[i]);
for (int i = 0; i < allWorldObjs.size(); i++)
allWorldObjs[i]->pvtlo->pfnDeleteLo(allWorldObjs[i]);
for (int i = 0; i < g_ashd.size(); i++)
glDeleteTextures(1, &g_ashd[i].glTexture);
allSWAloObjs.clear();
allSWAloObjs.shrink_to_fit();
allWorldObjs.clear();