Skip to content

Commit

Permalink
try to fix cmake :')
Browse files Browse the repository at this point in the history
  • Loading branch information
JulioJPinto committed May 21, 2024
1 parent dfe7f93 commit 9b76cb6
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 23 deletions.
25 changes: 13 additions & 12 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ set_property(GLOBAL PROPERTY USE_FOLDERS ON)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED True)

# Specify build type if not set
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Debug CACHE STRING "Build type" FORCE)
endif()
# # Specify build type if not set
# if(NOT CMAKE_BUILD_TYPE)
# set(CMAKE_BUILD_TYPE Debug CACHE STRING "Build type" FORCE)
# endif()

# Set debug-specific flags
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
set(CMAKE_CXX_FLAGS_DEBUG "-g")
set(CMAKE_EXE_LINKER_FLAGS_DEBUG "-g")
endif()
# # Set debug-specific flags
# if(CMAKE_BUILD_TYPE STREQUAL "Debug")
# set(CMAKE_CXX_FLAGS_DEBUG "-g")
# set(CMAKE_EXE_LINKER_FLAGS_DEBUG "-g")
# endif()

# Dependencies
include(FetchContent)
Expand All @@ -38,8 +38,9 @@ FetchContent_Declare(glm
FetchContent_MakeAvailable(glm)

# - Devil
find_package(DevIL REQUIRED)

FetchContent_Declare(DevIL
GIT_REPOSITORY "https://github.com/DentonW/DevIL/")
FetchContent_MakeAvailable(DevIL)

# - Imgui with docking
FetchContent_Declare(imgui
Expand Down Expand Up @@ -93,5 +94,5 @@ target_link_libraries(cg-engine PUBLIC
CustomImgui
glm
fmt
DevIL::IL
DevIL
)
12 changes: 12 additions & 0 deletions engine/include/texture.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#ifndef TEXTURE_HPP
#define TEXTURE_HPP

#include "utils.hpp"
#include <GL/glew.h>
#include <IL/il.h>
#include <IL/ilu.h>

void loadTeture(const char* filepath, GLuint& textureInt);


#endif // TEXTURE_HPP
12 changes: 12 additions & 0 deletions engine/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,16 @@ void processNormalKeys(unsigned char key, int x, int y) {
}
}

void initModels(Group& group) {
for (Model& model : group.models) {
model.setupModel();
}

for (Group& g : group.subgroups) {
initModels(g);
}
}

void setupConfig(char* arg) {
filename.assign(arg);

Expand Down Expand Up @@ -251,6 +261,8 @@ int main(int argc, char** argv) {
glEnable(GL_CULL_FACE);
setupLights(c.lights);

initModels(c.group);

// enter GLUT�s main cycle
glutMainLoop();

Expand Down
1 change: 1 addition & 0 deletions engine/src/model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ void Model::setupModel() {

void Model::drawModel() {
if (!this->initialized) {
std::cout << "Wassup" << std::endl;
this->initialized = true;
setupModel();
}
Expand Down
18 changes: 7 additions & 11 deletions engine/src/parse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,18 +207,14 @@ void parseModels(rapidxml::xml_node<>* modelsNode, Group& group) {
std::cerr << "Error reading model file: " << file << std::endl;
return;
}
// <texture file="earth.jpg" />
// rapidxml::xml_node<>* texture = modelNode->first_node("texture");
// if (texture) {
// const std::string& textureFile = texture->first_attribute("file")->value();
// model.texture = loadTexture(textureFile);
// }

rapidxml::xml_node<>* color = modelNode->first_node("color");
/*
<color>
<diffuse R="200" G="200" B="200" />
<ambient R="50" G="50" B="50" />
<specular R="0" G="0" B="0" />
<emissive R="0" G="0" B="0" />
<shininess value="0" />
</color>
*/
// Set the vector for diffuse, ambient, specular and emissive based on the
// above example
glm::vec4 diffuse_vec = glm::vec4(0.8f, 0.8f, 0.8f, 1.0f);
glm::vec4 ambient_vec = glm::vec4(0.2f, 0.2f, 0.2f, 1.0f);
glm::vec4 specular_vec = glm::vec4(0.0f, 0.0f, 0.0f, 1.0f);
Expand Down
34 changes: 34 additions & 0 deletions engine/src/texture.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#include "texture.hpp"

void loadTexture(std::string filepath, GLuint& textureInt) {
ILuint imageID;
ilGenImages(1, &imageID);
ilBindImage(imageID);
ILboolean success = ilLoadImage(filepath.c_str());
if (success == IL_FALSE) {
ILenum error = ilGetError();
std::cerr << "Error loading image: " << iluErrorString(error) << std::endl;
ilDeleteImages(1, &imageID);
return;
}
success = ilConvertImage(IL_RGBA, IL_UNSIGNED_BYTE);
if (success == IL_FALSE) {
ILenum error = ilGetError();
std::cerr << "Error converting image: " << iluErrorString(error) << std::endl;
ilDeleteImages(1, &imageID);
return;
}
ILint width = ilGetInteger(IL_IMAGE_WIDTH);
ILint height = ilGetInteger(IL_IMAGE_HEIGHT);
ILint bpp = ilGetInteger(IL_IMAGE_BYTES_PER_PIXEL);
ILubyte* data = ilGetData();
GLuint textureID;
glGenTextures(1, &textureID);
glBindTexture(GL_TEXTURE_2D, textureID);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
glGenerateMipmap(GL_TEXTURE_2D);
ilDeleteImages(1, &imageID);
glBindTexture(GL_TEXTURE_2D, 0);
textureInt = textureID;

}

0 comments on commit 9b76cb6

Please sign in to comment.