diff --git a/MyGameMaker/MyGameEditor/main.cpp b/MyGameMaker/MyGameEditor/main.cpp index 902294e..3b8e6a0 100644 --- a/MyGameMaker/MyGameEditor/main.cpp +++ b/MyGameMaker/MyGameEditor/main.cpp @@ -1,9 +1,8 @@ #include -//assimp -#include -#include -#include +//devil +#include +#include //imgui and panels #include "MyGUI.h" @@ -30,6 +29,11 @@ using namespace std; int main(int argc, char* argv[]) { + + //init DevIL // we have to create a texture manager to initialize it and load textures + ilInit(); + iluInit(); + //start engine Engine& engine = Engine::Instance(); engine.Awake(); diff --git a/MyGameMaker/MyGameEngine/Input.cpp b/MyGameMaker/MyGameEngine/Input.cpp index b54dffc..58785ac 100644 --- a/MyGameMaker/MyGameEngine/Input.cpp +++ b/MyGameMaker/MyGameEngine/Input.cpp @@ -145,7 +145,7 @@ bool Input::PreUpdate() case SDL_DROPFILE: std::string filename = event.drop.file; - if (filename.ends_with(".png")) { + if (filename.ends_with(".png") || filename.ends_with(".dds")) { Engine::Instance().scene->loadTextureByPath(event.drop.file); } else if (filename.ends_with(".fbx")) { diff --git a/MyGameMaker/MyGameEngine/Scene.cpp b/MyGameMaker/MyGameEngine/Scene.cpp index 0d223c2..d6a49e3 100644 --- a/MyGameMaker/MyGameEngine/Scene.cpp +++ b/MyGameMaker/MyGameEngine/Scene.cpp @@ -44,7 +44,8 @@ void Scene::Start() go->GetComponent()->setModel(models[i]); go->GetComponent()->setFilePath("Assets/FBX/BakerHouse.fbx"); go->CreateComponent(ComponentType::Material, go.get()); - go->GetComponent()->m_Texture = std::make_unique("Assets/Textures/Baker_house.png"); + std::string path = "Assets/Textures/Baker_house.png"; + go->GetComponent()->m_Texture = std::make_unique(path); go->GetComponent()->m_Shader = std::make_unique("Assets/Shaders/Basic.shader"); go->GetComponent()->loadToOpenGL(); addChild(go); diff --git a/MyGameMaker/MyGameEngine/Texture.cpp b/MyGameMaker/MyGameEngine/Texture.cpp index 6012ff3..6e2988f 100644 --- a/MyGameMaker/MyGameEngine/Texture.cpp +++ b/MyGameMaker/MyGameEngine/Texture.cpp @@ -1,32 +1,15 @@ #include "Texture.h" -#include +#include +#include #include "Renderer.h" Texture::Texture(const string& path, unsigned int* valor) : m_RendererID(0), m_FilePath(path), m_LocalBuffer(nullptr), m_Width(0), m_Height(0), m_BPP(0) { - // Carga la imagen usando SDL_image - SDL_Surface* imageSurface = IMG_Load(path.c_str()); - if (!imageSurface) { - printf("Error al cargar imagen: %s\n", IMG_GetError()); - return; - } - - // Determina el formato de la imagen para OpenGL - GLenum format; - if (imageSurface->format->BytesPerPixel == 4) { // RGBA - format = (imageSurface->format->Rmask == 0x000000ff) ? GL_RGBA : GL_BGRA; - } - else if (imageSurface->format->BytesPerPixel == 3) { // RGB - format = (imageSurface->format->Rmask == 0x000000ff) ? GL_RGB : GL_BGR; - } - else { - printf("Formato de imagen no compatible\n"); - SDL_FreeSurface(imageSurface); - return; - } + auto il_img_id = ilGenImage(); + ilLoadImage((const wchar_t*)path.c_str()); GLCall(glGenTextures(1, &m_RendererID)); GLCall(glBindTexture(GL_TEXTURE_2D, m_RendererID)); @@ -40,11 +23,11 @@ m_Width(0), m_Height(0), m_BPP(0) GLCall(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE)); GLCall(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE)); - glTexImage2D(GL_TEXTURE_2D, 0, format, imageSurface->w, imageSurface->h, 0, format, GL_UNSIGNED_BYTE, imageSurface->pixels); + glTexImage2D(GL_TEXTURE_2D, 0, ilGetInteger(IL_IMAGE_BPP), ilGetInteger(IL_IMAGE_WIDTH), ilGetInteger(IL_IMAGE_HEIGHT), 0, ilGetInteger(IL_IMAGE_FORMAT), GL_UNSIGNED_BYTE, ilGetData()); GLCall(glBindTexture(GL_TEXTURE_2D, 0)); - // Liberar la superficie de SDL - SDL_FreeSurface(imageSurface); + // Free image + ilDeleteImage(il_img_id); if (valor != nullptr) { diff --git a/vcpkg.json b/vcpkg.json index 5b1562f..b40015e 100644 --- a/vcpkg.json +++ b/vcpkg.json @@ -9,6 +9,6 @@ "features": [ "sdl2-binding", "opengl3-binding" ] }, "glm", - "sdl2-image" + "devil" ] } \ No newline at end of file