8 Commits

Author SHA1 Message Date
Anakin
15743e11fa new release version 2016-11-09 17:49:02 +01:00
Anakin
6107b648f9 now every model is painted with it's own texture 2016-11-09 17:48:28 +01:00
Anakin
ee8989b098 update README.md,
Cip hat nur OpenGl 2.1 -.-
2016-11-09 14:02:57 +01:00
Anakin
2f83d37e12 fixed the problem,
next solve texture name is taken only from the first element,
move some code around
2016-11-08 21:28:24 +01:00
Anakin
b4b2538ea6 fixed problem 2016-11-08 17:06:50 +01:00
Anakin
e5490b9451 collect all texture data and give it to the shader later,
solid color works,
texture crash
2016-11-08 16:42:05 +01:00
Anakin
9c7691df85 removed unused variables 2016-11-08 10:31:34 +01:00
Anakin
0fd3a7f9c8 next step: draw each model with it's own texture,
added new example mesh
2016-11-08 10:25:10 +01:00
12 changed files with 82 additions and 104 deletions

View File

@@ -27,17 +27,6 @@ struct Modl {
Mtyp type;
std::uint32_t renderFlags;
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;
float* vertex;
float* uv;

View File

@@ -5,6 +5,7 @@
#include <glm\glm.hpp>
#include <vector>
#include "Object.h"
#include "Texture.h"
#define VERTEX_INDEX_XYZ 0
#define VERTEX_INDEX_UV 1
@@ -23,6 +24,13 @@ struct Vertex {
GLfloat uv[2];
};
struct textureData {
bool alpha;
std::uint32_t width;
std::uint32_t height;
std::vector<std::uint8_t>* data;
};
class OpenGLController
{
////////////////////////////////////////////////////////////////////////////////////////////
@@ -65,6 +73,7 @@ private:
// data
std::vector<Modl*> vModels;
std::vector<textureData*> vTextures;
// transformation =========================
//values

View File

@@ -79,20 +79,6 @@ void Object::setModlDefault(Modl * model)
model->type = null;
model->renderFlags = -1;
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->vertex = NULL;
model->uv = NULL;
@@ -347,16 +333,6 @@ void Object::analyseModlChunks(Modl* dataDestination, std::list<ChunkHeader*>& c
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;
}
}
}

View File

@@ -41,6 +41,14 @@ OpenGLController::~OpenGLController()
delete cursor->vertex;
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);
}
// get some shader IDs
gluiMatrixID = glGetUniformLocation(gluiShaderPrgmID, "MVP");
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()
@@ -253,6 +272,21 @@ void OpenGLController::updateScene()
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]);
glDrawArrays(GL_TRIANGLES, instanceOffset, vModels[modelIndex]->meshSize);
@@ -266,7 +300,7 @@ void OpenGLController::updateScene()
void OpenGLController::loadMsh(const char * path)
{
// get data
// get all models
try
{
Object obj(path);
@@ -278,55 +312,9 @@ void OpenGLController::loadMsh(const char * path)
exit(1);
}
glGenTextures(1, &gluiTextureID);
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
// collect vertex data of all models
std::vector<Vertex> tempBufferData;
for (auto& it : vModels)
{
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);
glBufferData(
GL_ARRAY_BUFFER,
@@ -360,4 +349,37 @@ void OpenGLController::loadMsh(const char * path)
);
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);
}
}

View File

@@ -20,25 +20,8 @@ int main(int argc, char** argv)
else
scene = OpenGLController::getInstance();
goto openGL;
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");
scene->loadMsh("..\\Release\\Msh\\multiModTex.msh");
//scene->loadMsh("..\\Release\\Msh\\cubeTex.msh");
do {
scene->updateScene();

View File

@@ -13,7 +13,6 @@ Feel free to use my code the way you like. But remember i used some public libra
licence, too.
### To Do
- draw multiple models of one mesh,
- crashing sometimes - no idea why,
- bones are not triangulated,
- nulls are not triangulated,

Binary file not shown.

After

Width:  |  Height:  |  Size: 48 KiB

BIN
Release/Msh/128x128Grau.tga Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 48 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 48 KiB

BIN
Release/Msh/128x128Rot.tga Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 48 KiB

BIN
Release/Msh/multiModTex.msh Normal file

Binary file not shown.

Binary file not shown.