Compare commits
13 Commits
Version_0.
...
Version_0.
Author | SHA1 | Date | |
---|---|---|---|
![]() |
1ab385475b | ||
![]() |
9298d88260 | ||
![]() |
91b65bf6e3 | ||
![]() |
b4bd314450 | ||
![]() |
2524971d19 | ||
![]() |
15743e11fa | ||
![]() |
6107b648f9 | ||
![]() |
ee8989b098 | ||
![]() |
2f83d37e12 | ||
![]() |
b4b2538ea6 | ||
![]() |
e5490b9451 | ||
![]() |
9c7691df85 | ||
![]() |
0fd3a7f9c8 |
@@ -3,7 +3,6 @@
|
|||||||
#include <list>
|
#include <list>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <gl\glew.h>
|
|
||||||
#include <glm\gtc\matrix_transform.hpp>
|
#include <glm\gtc\matrix_transform.hpp>
|
||||||
|
|
||||||
enum Mtyp {
|
enum Mtyp {
|
||||||
@@ -22,27 +21,16 @@ struct ChunkHeader {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct Modl {
|
struct Modl {
|
||||||
std::string name;
|
std::string name = "";
|
||||||
std::string parent;
|
std::string parent = "";
|
||||||
Mtyp type;
|
Mtyp type = null;
|
||||||
std::uint32_t renderFlags;
|
std::int32_t renderFlags = -1;
|
||||||
glm::mat4 m4x4Translation;
|
glm::mat4 m4x4Translation = glm::mat4(1.0f);
|
||||||
struct {
|
std::string texture = "";
|
||||||
float scale[3];
|
float* vertex = nullptr;
|
||||||
float rotation[4];
|
float* uv = nullptr;
|
||||||
float translation[3];
|
std::uint32_t* mesh = nullptr;
|
||||||
} tran;
|
std::uint32_t meshSize = 0;
|
||||||
struct {
|
|
||||||
std::uint32_t type;
|
|
||||||
float data1;
|
|
||||||
float data2;
|
|
||||||
float data3;
|
|
||||||
} swci;
|
|
||||||
std::string texture;
|
|
||||||
float* vertex;
|
|
||||||
float* uv;
|
|
||||||
std::uint32_t* mesh;
|
|
||||||
std::uint32_t meshSize;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -60,7 +48,6 @@ private:
|
|||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void setModlDefault(Modl* model);
|
|
||||||
void loadChunks(std::list<ChunkHeader*> &destination, std::streampos start, const std::uint32_t end);
|
void loadChunks(std::list<ChunkHeader*> &destination, std::streampos start, const std::uint32_t end);
|
||||||
void analyseMsh2Chunks(std::list<ChunkHeader*> &chunkList);
|
void analyseMsh2Chunks(std::list<ChunkHeader*> &chunkList);
|
||||||
void analyseMatdChunks(std::list<ChunkHeader*> &chunkList);
|
void analyseMatdChunks(std::list<ChunkHeader*> &chunkList);
|
||||||
|
@@ -1,10 +1,9 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <string>
|
|
||||||
#include <gl\glew.h>
|
#include <gl\glew.h>
|
||||||
#include <gl\glfw3.h>
|
#include <gl\glfw3.h>
|
||||||
#include <glm\glm.hpp>
|
|
||||||
#include <vector>
|
|
||||||
#include "Object.h"
|
#include "Object.h"
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
|
||||||
#define VERTEX_INDEX_XYZ 0
|
#define VERTEX_INDEX_XYZ 0
|
||||||
#define VERTEX_INDEX_UV 1
|
#define VERTEX_INDEX_UV 1
|
||||||
@@ -23,6 +22,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 +71,7 @@ private:
|
|||||||
|
|
||||||
// data
|
// data
|
||||||
std::vector<Modl*> vModels;
|
std::vector<Modl*> vModels;
|
||||||
|
std::vector<textureData*> vTextures;
|
||||||
|
|
||||||
// transformation =========================
|
// transformation =========================
|
||||||
//values
|
//values
|
||||||
@@ -87,12 +94,14 @@ private:
|
|||||||
// private functions
|
// private functions
|
||||||
private:
|
private:
|
||||||
void processInit();
|
void processInit();
|
||||||
|
void deleteVectors();
|
||||||
|
|
||||||
void startGLFW();
|
void startGLFW();
|
||||||
void createWindow();
|
void createWindow();
|
||||||
void startGLEW();
|
void startGLEW();
|
||||||
void setCallbackFunctions();
|
void setCallbackFunctions();
|
||||||
|
|
||||||
|
glm::mat4 getModelMatrix(unsigned int index);
|
||||||
glm::mat4 getMVPMatrix(unsigned int index);
|
glm::mat4 getMVPMatrix(unsigned int index);
|
||||||
|
|
||||||
|
|
||||||
|
@@ -8,4 +8,6 @@ extern void mouseMove(GLFWwindow *window, double xpos, double ypos);
|
|||||||
|
|
||||||
extern void mouseWheel(GLFWwindow *window, double xoffset, double yoffset);
|
extern void mouseWheel(GLFWwindow *window, double xoffset, double yoffset);
|
||||||
|
|
||||||
extern void keyPress(GLFWwindow *window, int key, int scancode, int action, int mods);
|
extern void keyPress(GLFWwindow *window, int key, int scancode, int action, int mods);
|
||||||
|
|
||||||
|
extern void dragNdrop(GLFWwindow* window, int count, const char** paths);
|
@@ -1,5 +1,7 @@
|
|||||||
#include "Object.h"
|
#include "Object.h"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
|
|
||||||
#define PI (4.0*atan(1.0))
|
#define PI (4.0*atan(1.0))
|
||||||
|
|
||||||
|
|
||||||
@@ -72,34 +74,6 @@ Object::~Object()
|
|||||||
/////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////
|
||||||
// private functions
|
// private functions
|
||||||
|
|
||||||
void Object::setModlDefault(Modl * model)
|
|
||||||
{
|
|
||||||
model->name = "";
|
|
||||||
model->parent = "";
|
|
||||||
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;
|
|
||||||
model->mesh = NULL;
|
|
||||||
model->meshSize = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Object::loadChunks(std::list<ChunkHeader*>& destination, std::streampos start, const std::uint32_t end)
|
void Object::loadChunks(std::list<ChunkHeader*>& destination, std::streampos start, const std::uint32_t end)
|
||||||
{
|
{
|
||||||
// jump to first chunk
|
// jump to first chunk
|
||||||
@@ -184,7 +158,6 @@ void Object::analyseMsh2Chunks(std::list<ChunkHeader*>& chunkList)
|
|||||||
if (!strcmp("MODL", (*it)->name))
|
if (!strcmp("MODL", (*it)->name))
|
||||||
{
|
{
|
||||||
Modl* tempModl = new Modl;
|
Modl* tempModl = new Modl;
|
||||||
setModlDefault(tempModl);
|
|
||||||
|
|
||||||
// get all subchunks
|
// get all subchunks
|
||||||
std::list<ChunkHeader*> tempChunks;
|
std::list<ChunkHeader*> tempChunks;
|
||||||
@@ -347,16 +320,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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,17 +1,14 @@
|
|||||||
#include <gl\glew.h>
|
|
||||||
#include <gl\glfw3.h>
|
|
||||||
#include <Windows.h>
|
|
||||||
#include "OpenGLController.h"
|
#include "OpenGLController.h"
|
||||||
#include "callback.h"
|
#include "callback.h"
|
||||||
|
|
||||||
#include <glm\gtc\matrix_transform.hpp>
|
|
||||||
#include "shader.hpp"
|
#include "shader.hpp"
|
||||||
#include "Texture.h"
|
#include "Texture.h"
|
||||||
#include <iostream>
|
#include <Windows.h>
|
||||||
|
#include <string>
|
||||||
|
#include <glm\gtc\matrix_transform.hpp>
|
||||||
|
|
||||||
|
|
||||||
#define VERTEX_SHADER "Shader/TextureShader.vert"
|
#define VERTEX_SHADER "Shader/TextureShader.vert"
|
||||||
#define FRAGMENT_SHADER "Shader/TextureShader.frag"
|
#define FRAGMENT_SHADER "Shader/TextureShader.frag"
|
||||||
#define MAX_MODEL_COUNT 1000
|
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////
|
||||||
// public constructor/destructor
|
// public constructor/destructor
|
||||||
@@ -31,16 +28,7 @@ OpenGLController::~OpenGLController()
|
|||||||
glDeleteTextures(1, &gluiSamplerID);
|
glDeleteTextures(1, &gluiSamplerID);
|
||||||
glfwTerminate();
|
glfwTerminate();
|
||||||
|
|
||||||
while (!vModels.empty())
|
deleteVectors();
|
||||||
{
|
|
||||||
Modl* cursor = vModels.back();
|
|
||||||
vModels.pop_back();
|
|
||||||
|
|
||||||
delete cursor->uv;
|
|
||||||
delete cursor->mesh;
|
|
||||||
delete cursor->vertex;
|
|
||||||
delete cursor;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -104,8 +92,41 @@ 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::deleteVectors()
|
||||||
|
{
|
||||||
|
while (!vModels.empty())
|
||||||
|
{
|
||||||
|
Modl* cursor = vModels.back();
|
||||||
|
vModels.pop_back();
|
||||||
|
|
||||||
|
delete cursor->uv;
|
||||||
|
delete cursor->mesh;
|
||||||
|
delete cursor->vertex;
|
||||||
|
delete cursor;
|
||||||
|
}
|
||||||
|
|
||||||
|
while (!vTextures.empty())
|
||||||
|
{
|
||||||
|
textureData* cursor = vTextures.back();
|
||||||
|
vTextures.pop_back();
|
||||||
|
delete cursor->data;
|
||||||
|
delete cursor;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void OpenGLController::startGLFW()
|
void OpenGLController::startGLFW()
|
||||||
@@ -163,6 +184,23 @@ void OpenGLController::setCallbackFunctions()
|
|||||||
glfwSetWindowSizeCallback(pWindow, windowResize);
|
glfwSetWindowSizeCallback(pWindow, windowResize);
|
||||||
glfwSetScrollCallback(pWindow, mouseWheel);
|
glfwSetScrollCallback(pWindow, mouseWheel);
|
||||||
glfwSetKeyCallback(pWindow, keyPress);
|
glfwSetKeyCallback(pWindow, keyPress);
|
||||||
|
glfwSetDropCallback(pWindow, dragNdrop);
|
||||||
|
}
|
||||||
|
|
||||||
|
glm::mat4 OpenGLController::getModelMatrix(unsigned int index)
|
||||||
|
{
|
||||||
|
glm::mat4 tempParentMatrix = glm::mat4(1.0f);
|
||||||
|
|
||||||
|
for (unsigned int loop = 0; loop < vModels.size(); loop++)
|
||||||
|
{
|
||||||
|
if (!strcmp(vModels[index]->parent.c_str(), vModels[loop]->name.c_str()))
|
||||||
|
{
|
||||||
|
tempParentMatrix = getModelMatrix(loop);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return tempParentMatrix * vModels[index]->m4x4Translation;
|
||||||
}
|
}
|
||||||
|
|
||||||
glm::mat4 OpenGLController::getMVPMatrix(unsigned int index)
|
glm::mat4 OpenGLController::getMVPMatrix(unsigned int index)
|
||||||
@@ -177,10 +215,6 @@ glm::mat4 OpenGLController::getMVPMatrix(unsigned int index)
|
|||||||
glm::vec3(0, 1, 0)
|
glm::vec3(0, 1, 0)
|
||||||
);
|
);
|
||||||
|
|
||||||
// Model
|
|
||||||
//TODO for all
|
|
||||||
glm::mat4 m4x4Model = vModels[index]->m4x4Translation;
|
|
||||||
|
|
||||||
// User controlled rotation
|
// User controlled rotation
|
||||||
glm::mat4 m4x4ModelRot = glm::mat4(1.0f);
|
glm::mat4 m4x4ModelRot = glm::mat4(1.0f);
|
||||||
m4x4ModelRot = glm::rotate(m4x4ModelRot, fRotationX, glm::vec3(1, 0, 0));
|
m4x4ModelRot = glm::rotate(m4x4ModelRot, fRotationX, glm::vec3(1, 0, 0));
|
||||||
@@ -188,7 +222,7 @@ glm::mat4 OpenGLController::getMVPMatrix(unsigned int index)
|
|||||||
m4x4ModelRot = glm::rotate(m4x4ModelRot, fRotationZ, glm::vec3(0, 0, 1));
|
m4x4ModelRot = glm::rotate(m4x4ModelRot, fRotationZ, glm::vec3(0, 0, 1));
|
||||||
|
|
||||||
// Return MVP
|
// Return MVP
|
||||||
return m4x4Projection * m4x4View * m4x4ModelRot * m4x4Model;
|
return m4x4Projection * m4x4View * m4x4ModelRot * getModelMatrix(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -251,8 +285,23 @@ void OpenGLController::updateScene()
|
|||||||
|
|
||||||
int instanceOffset(0);
|
int instanceOffset(0);
|
||||||
|
|
||||||
for (int modelIndex = 0; modelIndex < vModels.size(); modelIndex++)
|
for (unsigned 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 +315,10 @@ void OpenGLController::updateScene()
|
|||||||
|
|
||||||
void OpenGLController::loadMsh(const char * path)
|
void OpenGLController::loadMsh(const char * path)
|
||||||
{
|
{
|
||||||
// get data
|
// clean up old stuff first
|
||||||
|
deleteVectors();
|
||||||
|
|
||||||
|
// get all models
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Object obj(path);
|
Object obj(path);
|
||||||
@@ -278,55 +330,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 +357,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 +367,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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,7 +1,5 @@
|
|||||||
#include "Texture.h"
|
#include "Texture.h"
|
||||||
#include <iostream>
|
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <Windows.h>
|
|
||||||
|
|
||||||
TextureTGA::TextureTGA(const char * filePath)
|
TextureTGA::TextureTGA(const char * filePath)
|
||||||
{
|
{
|
||||||
|
@@ -1,6 +1,3 @@
|
|||||||
//#include "callback.h"
|
|
||||||
#include <gl\glew.h>
|
|
||||||
#include <gl\glfw3.h>
|
|
||||||
#include "OpenGLController.h"
|
#include "OpenGLController.h"
|
||||||
|
|
||||||
|
|
||||||
@@ -101,3 +98,10 @@ void keyPress(GLFWwindow *window, int key, int scancode, int action, int mods)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void dragNdrop(GLFWwindow* window, int count, const char** paths)
|
||||||
|
{
|
||||||
|
OpenGLController* controller = reinterpret_cast<OpenGLController*>(glfwGetWindowUserPointer(window));
|
||||||
|
if(count > 0)
|
||||||
|
controller->loadMsh(paths[0]);
|
||||||
|
}
|
||||||
|
@@ -3,9 +3,6 @@
|
|||||||
#endif // DEBUG
|
#endif // DEBUG
|
||||||
|
|
||||||
#include "OpenGLController.h"
|
#include "OpenGLController.h"
|
||||||
#include "Object.h"
|
|
||||||
#include <iostream>
|
|
||||||
#include <Windows.h>
|
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
@@ -20,25 +17,7 @@ int main(int argc, char** argv)
|
|||||||
else
|
else
|
||||||
scene = OpenGLController::getInstance();
|
scene = OpenGLController::getInstance();
|
||||||
|
|
||||||
|
scene->loadMsh("..\\Release\\Msh\\structured.msh");
|
||||||
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");
|
|
||||||
|
|
||||||
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.
BIN
Release/Msh/structured.msh
Normal file
BIN
Release/Msh/structured.msh
Normal file
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user