Compare commits
8 Commits
Version_0.
...
Version_0.
Author | SHA1 | Date | |
---|---|---|---|
![]() |
15743e11fa | ||
![]() |
6107b648f9 | ||
![]() |
ee8989b098 | ||
![]() |
2f83d37e12 | ||
![]() |
b4b2538ea6 | ||
![]() |
e5490b9451 | ||
![]() |
9c7691df85 | ||
![]() |
0fd3a7f9c8 |
@@ -27,17 +27,6 @@ struct Modl {
|
|||||||
Mtyp type;
|
Mtyp type;
|
||||||
std::uint32_t renderFlags;
|
std::uint32_t renderFlags;
|
||||||
glm::mat4 m4x4Translation;
|
glm::mat4 m4x4Translation;
|
||||||
struct {
|
|
||||||
float scale[3];
|
|
||||||
float rotation[4];
|
|
||||||
float translation[3];
|
|
||||||
} tran;
|
|
||||||
struct {
|
|
||||||
std::uint32_t type;
|
|
||||||
float data1;
|
|
||||||
float data2;
|
|
||||||
float data3;
|
|
||||||
} swci;
|
|
||||||
std::string texture;
|
std::string texture;
|
||||||
float* vertex;
|
float* vertex;
|
||||||
float* uv;
|
float* uv;
|
||||||
|
@@ -5,6 +5,7 @@
|
|||||||
#include <glm\glm.hpp>
|
#include <glm\glm.hpp>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include "Object.h"
|
#include "Object.h"
|
||||||
|
#include "Texture.h"
|
||||||
|
|
||||||
#define VERTEX_INDEX_XYZ 0
|
#define VERTEX_INDEX_XYZ 0
|
||||||
#define VERTEX_INDEX_UV 1
|
#define VERTEX_INDEX_UV 1
|
||||||
@@ -23,6 +24,13 @@ struct Vertex {
|
|||||||
GLfloat uv[2];
|
GLfloat uv[2];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct textureData {
|
||||||
|
bool alpha;
|
||||||
|
std::uint32_t width;
|
||||||
|
std::uint32_t height;
|
||||||
|
std::vector<std::uint8_t>* data;
|
||||||
|
};
|
||||||
|
|
||||||
class OpenGLController
|
class OpenGLController
|
||||||
{
|
{
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
@@ -65,6 +73,7 @@ private:
|
|||||||
|
|
||||||
// data
|
// data
|
||||||
std::vector<Modl*> vModels;
|
std::vector<Modl*> vModels;
|
||||||
|
std::vector<textureData*> vTextures;
|
||||||
|
|
||||||
// transformation =========================
|
// transformation =========================
|
||||||
//values
|
//values
|
||||||
|
@@ -79,20 +79,6 @@ void Object::setModlDefault(Modl * model)
|
|||||||
model->type = null;
|
model->type = null;
|
||||||
model->renderFlags = -1;
|
model->renderFlags = -1;
|
||||||
model->m4x4Translation = glm::mat4(1.0f);
|
model->m4x4Translation = glm::mat4(1.0f);
|
||||||
model->tran.scale[0] = 0;
|
|
||||||
model->tran.scale[1] = 0;
|
|
||||||
model->tran.scale[2] = 0;
|
|
||||||
model->tran.rotation[0] = 0;
|
|
||||||
model->tran.rotation[1] = 0;
|
|
||||||
model->tran.rotation[2] = 0;
|
|
||||||
model->tran.rotation[3] = 0;
|
|
||||||
model->tran.translation[0] = 0;
|
|
||||||
model->tran.translation[1] = 0;
|
|
||||||
model->tran.translation[2] = 0;
|
|
||||||
model->swci.type = -1;
|
|
||||||
model->swci.data1 = -1;
|
|
||||||
model->swci.data2 = -1;
|
|
||||||
model->swci.data3 = -1;
|
|
||||||
model->texture = "";
|
model->texture = "";
|
||||||
model->vertex = NULL;
|
model->vertex = NULL;
|
||||||
model->uv = NULL;
|
model->uv = NULL;
|
||||||
@@ -347,16 +333,6 @@ void Object::analyseModlChunks(Modl* dataDestination, std::list<ChunkHeader*>& c
|
|||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!strcmp("SWCI", (*it)->name))
|
|
||||||
{
|
|
||||||
fsMesh.seekg((*it)->position);
|
|
||||||
fsMesh.read(reinterpret_cast<char*>(&dataDestination->swci.type), sizeof(dataDestination->swci.type));
|
|
||||||
fsMesh.read(reinterpret_cast<char*>(&dataDestination->swci.data1), sizeof(dataDestination->swci.data1));
|
|
||||||
fsMesh.read(reinterpret_cast<char*>(&dataDestination->swci.data2), sizeof(dataDestination->swci.data2));
|
|
||||||
fsMesh.read(reinterpret_cast<char*>(&dataDestination->swci.data3), sizeof(dataDestination->swci.data3));
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -41,6 +41,14 @@ OpenGLController::~OpenGLController()
|
|||||||
delete cursor->vertex;
|
delete cursor->vertex;
|
||||||
delete cursor;
|
delete cursor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
while (!vTextures.empty())
|
||||||
|
{
|
||||||
|
textureData* cursor = vTextures.back();
|
||||||
|
vTextures.pop_back();
|
||||||
|
delete cursor->data;
|
||||||
|
delete cursor;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -104,8 +112,19 @@ void OpenGLController::processInit()
|
|||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// get some shader IDs
|
||||||
gluiMatrixID = glGetUniformLocation(gluiShaderPrgmID, "MVP");
|
gluiMatrixID = glGetUniformLocation(gluiShaderPrgmID, "MVP");
|
||||||
gluiSamplerID = glGetUniformLocation(gluiShaderPrgmID, "textureSampler");
|
gluiSamplerID = glGetUniformLocation(gluiShaderPrgmID, "textureSampler");
|
||||||
|
|
||||||
|
// generate texture
|
||||||
|
glGenTextures(1, &gluiTextureID);
|
||||||
|
glBindTexture(GL_TEXTURE_2D, gluiTextureID);
|
||||||
|
|
||||||
|
// set some texture parameters
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
|
||||||
}
|
}
|
||||||
|
|
||||||
void OpenGLController::startGLFW()
|
void OpenGLController::startGLFW()
|
||||||
@@ -253,6 +272,21 @@ void OpenGLController::updateScene()
|
|||||||
|
|
||||||
for (int modelIndex = 0; modelIndex < vModels.size(); modelIndex++)
|
for (int modelIndex = 0; modelIndex < vModels.size(); modelIndex++)
|
||||||
{
|
{
|
||||||
|
// give texture to the shader
|
||||||
|
glTexImage2D(GL_TEXTURE_2D,
|
||||||
|
0,
|
||||||
|
vTextures[modelIndex]->alpha ? GL_RGBA : GL_RGB,
|
||||||
|
vTextures[modelIndex]->width,
|
||||||
|
vTextures[modelIndex]->height,
|
||||||
|
0,
|
||||||
|
vTextures[modelIndex]->alpha ? GL_BGRA : GL_BGR,
|
||||||
|
GL_UNSIGNED_BYTE,
|
||||||
|
vTextures[modelIndex]->data->data()
|
||||||
|
);
|
||||||
|
|
||||||
|
glGenerateMipmap(GL_TEXTURE_2D);
|
||||||
|
|
||||||
|
// give the MVP to the shader
|
||||||
glUniformMatrix4fv(gluiMatrixID, 1, GL_FALSE, &getMVPMatrix(modelIndex)[0][0]);
|
glUniformMatrix4fv(gluiMatrixID, 1, GL_FALSE, &getMVPMatrix(modelIndex)[0][0]);
|
||||||
|
|
||||||
glDrawArrays(GL_TRIANGLES, instanceOffset, vModels[modelIndex]->meshSize);
|
glDrawArrays(GL_TRIANGLES, instanceOffset, vModels[modelIndex]->meshSize);
|
||||||
@@ -266,7 +300,7 @@ void OpenGLController::updateScene()
|
|||||||
|
|
||||||
void OpenGLController::loadMsh(const char * path)
|
void OpenGLController::loadMsh(const char * path)
|
||||||
{
|
{
|
||||||
// get data
|
// get all models
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Object obj(path);
|
Object obj(path);
|
||||||
@@ -278,55 +312,9 @@ void OpenGLController::loadMsh(const char * path)
|
|||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
glGenTextures(1, &gluiTextureID);
|
// collect vertex data of all models
|
||||||
glBindTexture(GL_TEXTURE_2D, gluiTextureID);
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
////TODO: for all
|
|
||||||
if (vModels.front()->texture == "")
|
|
||||||
throw std::invalid_argument("no texture name");
|
|
||||||
|
|
||||||
std::string tempPath = path;
|
|
||||||
|
|
||||||
while (tempPath.back() != '/' && tempPath.back() != '\\')
|
|
||||||
tempPath.pop_back();
|
|
||||||
|
|
||||||
TextureTGA tempTex(std::string(tempPath + vModels.front()->texture).c_str());
|
|
||||||
glTexImage2D(GL_TEXTURE_2D,
|
|
||||||
0,
|
|
||||||
tempTex.hasAlpha() ? GL_RGBA : GL_RGB,
|
|
||||||
tempTex.getWidth(),
|
|
||||||
tempTex.getHeight(),
|
|
||||||
0, tempTex.hasAlpha() ? GL_BGRA : GL_BGR,
|
|
||||||
GL_UNSIGNED_BYTE,
|
|
||||||
tempTex.getData().data()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
catch (std::invalid_argument e)
|
|
||||||
{
|
|
||||||
GLubyte solidColor[4] = { 255, 0, 0, 255};
|
|
||||||
glTexImage2D(GL_TEXTURE_2D,
|
|
||||||
0,
|
|
||||||
GL_RGBA,
|
|
||||||
1,
|
|
||||||
1,
|
|
||||||
0,
|
|
||||||
GL_RGBA,
|
|
||||||
GL_UNSIGNED_BYTE,
|
|
||||||
(const GLvoid*)solidColor
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
|
|
||||||
glGenerateMipmap(GL_TEXTURE_2D);
|
|
||||||
|
|
||||||
////TODO: for all
|
|
||||||
std::vector<Vertex> tempBufferData;
|
std::vector<Vertex> tempBufferData;
|
||||||
|
|
||||||
for (auto& it : vModels)
|
for (auto& it : vModels)
|
||||||
{
|
{
|
||||||
for (unsigned int i = 0; i < it->meshSize; i++)
|
for (unsigned int i = 0; i < it->meshSize; i++)
|
||||||
@@ -351,6 +339,7 @@ void OpenGLController::loadMsh(const char * path)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// fill the buffer
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, gluiVertexBufferID);
|
glBindBuffer(GL_ARRAY_BUFFER, gluiVertexBufferID);
|
||||||
glBufferData(
|
glBufferData(
|
||||||
GL_ARRAY_BUFFER,
|
GL_ARRAY_BUFFER,
|
||||||
@@ -360,4 +349,37 @@ void OpenGLController::loadMsh(const char * path)
|
|||||||
);
|
);
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||||
|
|
||||||
|
|
||||||
|
// get textures
|
||||||
|
for (auto& it : vModels)
|
||||||
|
{
|
||||||
|
textureData* tempData = new textureData;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (it->texture == "")
|
||||||
|
throw std::invalid_argument("no texture name");
|
||||||
|
|
||||||
|
std::string tempPath = path;
|
||||||
|
|
||||||
|
while (tempPath.back() != '/' && tempPath.back() != '\\')
|
||||||
|
tempPath.pop_back();
|
||||||
|
|
||||||
|
TextureTGA tempTex(std::string(tempPath + it->texture).c_str());
|
||||||
|
|
||||||
|
tempData->alpha = tempTex.hasAlpha();
|
||||||
|
tempData->width = tempTex.getWidth();
|
||||||
|
tempData->height = tempTex.getHeight();
|
||||||
|
tempData->data = new std::vector<std::uint8_t>(tempTex.getData());
|
||||||
|
}
|
||||||
|
catch (std::invalid_argument e)
|
||||||
|
{
|
||||||
|
GLubyte solidColor[4] = { 0, 0, 255, 255 };
|
||||||
|
tempData->alpha = true;
|
||||||
|
tempData->width = 1;
|
||||||
|
tempData->height = 1;
|
||||||
|
tempData->data = new std::vector<std::uint8_t>({ 0, 0, 255, 255 });
|
||||||
|
}
|
||||||
|
|
||||||
|
vTextures.push_back(tempData);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -20,25 +20,8 @@ int main(int argc, char** argv)
|
|||||||
else
|
else
|
||||||
scene = OpenGLController::getInstance();
|
scene = OpenGLController::getInstance();
|
||||||
|
|
||||||
|
scene->loadMsh("..\\Release\\Msh\\multiModTex.msh");
|
||||||
goto openGL;
|
//scene->loadMsh("..\\Release\\Msh\\cubeTex.msh");
|
||||||
|
|
||||||
try {
|
|
||||||
Object obj("..\\Release\\Msh\\cubeTex.msh");
|
|
||||||
}
|
|
||||||
catch (std::invalid_argument e)
|
|
||||||
{
|
|
||||||
std::cout << e.what() << std::endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
system("pause");
|
|
||||||
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
openGL:
|
|
||||||
|
|
||||||
scene->loadMsh("..\\Release\\Msh\\multipleModels.msh");
|
|
||||||
|
|
||||||
do {
|
do {
|
||||||
scene->updateScene();
|
scene->updateScene();
|
||||||
|
@@ -13,7 +13,6 @@ Feel free to use my code the way you like. But remember i used some public libra
|
|||||||
licence, too.
|
licence, too.
|
||||||
|
|
||||||
### To Do
|
### To Do
|
||||||
- draw multiple models of one mesh,
|
|
||||||
- crashing sometimes - no idea why,
|
- crashing sometimes - no idea why,
|
||||||
- bones are not triangulated,
|
- bones are not triangulated,
|
||||||
- nulls are not triangulated,
|
- nulls are not triangulated,
|
||||||
|
BIN
Release/Msh/128x128Braun.tga
Normal file
BIN
Release/Msh/128x128Braun.tga
Normal file
Binary file not shown.
After Width: | Height: | Size: 48 KiB |
BIN
Release/Msh/128x128Grau.tga
Normal file
BIN
Release/Msh/128x128Grau.tga
Normal file
Binary file not shown.
After Width: | Height: | Size: 48 KiB |
BIN
Release/Msh/128x128Gruen.tga
Normal file
BIN
Release/Msh/128x128Gruen.tga
Normal file
Binary file not shown.
After Width: | Height: | Size: 48 KiB |
BIN
Release/Msh/128x128Rot.tga
Normal file
BIN
Release/Msh/128x128Rot.tga
Normal file
Binary file not shown.
After Width: | Height: | Size: 48 KiB |
BIN
Release/Msh/multiModTex.msh
Normal file
BIN
Release/Msh/multiModTex.msh
Normal file
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user