diff options
author | Dominick Allen <djallen@librehumanitas.org> | 2024-09-28 17:39:03 -0500 |
---|---|---|
committer | Dominick Allen <djallen@librehumanitas.org> | 2024-09-28 17:39:03 -0500 |
commit | 876c829512301e3f20161f05d7c193540e6d1710 (patch) | |
tree | 17cb3f1956d88ce87e1bcd980ea67f0592b0bed4 /src/demo.cpp | |
parent | dac2e7507d0172e2a87ed5b2df9c320bc9717da6 (diff) |
Working through file picker.
Diffstat (limited to 'src/demo.cpp')
-rw-r--r-- | src/demo.cpp | 62 |
1 files changed, 47 insertions, 15 deletions
diff --git a/src/demo.cpp b/src/demo.cpp index 433dd5d..14bd8d5 100644 --- a/src/demo.cpp +++ b/src/demo.cpp @@ -20,20 +20,34 @@ namespace bookmouse { // Simple helper function to load an image into a OpenGL texture with common settings -bool LoadTextureFromMemory(const void* data, size_t data_size, GLuint* out_texture, int* out_width, int* out_height) +bool LoadTextureFromMemory( // force newline + const void* data, + size_t data_size, + GLuint* out_texture, + int* out_width, + int* out_height) { // Load from file int width = 0; int height = 0; int channelsInFile = 4; - unsigned char* - image_data = stbi_load_from_memory((const unsigned char*)data, (int)data_size, &width, &height, nullptr, 4); + unsigned char* image_data = stbi_load_from_memory( // force + (const unsigned char*)data, + (int)data_size, + &width, + &height, + nullptr, + 4); if (image_data == nullptr) { spdlog::error("Failed to get data from"); return false; } - spdlog::info("Got result: {} pixels per row of {} scanlines with {} channels", width, height, channelsInFile); + spdlog::info( // force + "Got result: {} pixels per row of {} scanlines with {} channels", + width, + height, + channelsInFile); // Create a OpenGL texture identifier GLuint imageTexture; @@ -46,7 +60,16 @@ bool LoadTextureFromMemory(const void* data, size_t data_size, GLuint* out_textu // Upload pixels into texture glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, image_data); + glTexImage2D( // force + GL_TEXTURE_2D, + 0, + GL_RGBA, + width, + height, + 0, + GL_RGBA, + GL_UNSIGNED_BYTE, + image_data); stbi_image_free(image_data); *out_texture = imageTexture; @@ -57,12 +80,16 @@ bool LoadTextureFromMemory(const void* data, size_t data_size, GLuint* out_textu } // Open and read a file, then forward to LoadTextureFromMemory() -bool LoadTextureFromFile(const fud::String& filename, GLuint* out_texture, int* out_width, int* out_height) +bool LoadTextureFromFile( // force + const fud::String& filename, + GLuint* out_texture, + int* out_width, + int* out_height) { fud::CBinaryFile inFile{filename, fud::CFileMode::ReadOnly}; auto fileResult = inFile.open(); - using fud::FileStatus; - if (fileResult == FileStatus::Error) { + using fud::FudStatus; + if (fileResult == FudStatus::Failure) { spdlog::error("can't open {}", filename.c_str()); // return err(ImageError::FileError); return false; @@ -70,7 +97,10 @@ bool LoadTextureFromFile(const fud::String& filename, GLuint* out_texture, int* auto fileSizeResult = inFile.size(); if (fileSizeResult.isError()) { - spdlog::error("bad file size {} {}", filename.c_str(), FileStatusToString(fileSizeResult.getError())); + spdlog::error( // force + "bad file size {} {}", + filename.c_str(), + FudStatusToString(fileSizeResult.getError())); return false; } auto fileSize = fileSizeResult.getOkay(); @@ -86,12 +116,14 @@ bool LoadTextureFromFile(const fud::String& filename, GLuint* out_texture, int* fileData.resize(fileSize); auto readResult = inFile.read(fileData.data(), fileSize, fileSize); - if (readResult.status != FileStatus::Success) { - spdlog::error("bad read {} {}", filename.c_str(), FileStatusToString(readResult.status)); + if (readResult.status != FudStatus::Success) { + spdlog::error( // force + "bad read {} {}", filename.c_str(), FudStatusToString(readResult.status)); return false; } - bool ret = LoadTextureFromMemory(fileData.data(), fileSize, out_texture, out_width, out_height); + bool ret = LoadTextureFromMemory( // force + fileData.data(), fileSize, out_texture, out_width, out_height); return ret; } @@ -109,7 +141,8 @@ int demo(const fud::String& m_filename) int my_image_width = 0; int my_image_height = 0; GLuint my_image_texture = 0; - bool ret = LoadTextureFromFile(m_filename, &my_image_texture, &my_image_width, &my_image_height); + bool ret = LoadTextureFromFile( // force + m_filename, &my_image_texture, &my_image_width, &my_image_height); IM_ASSERT(ret); // Our state @@ -119,8 +152,7 @@ int demo(const fud::String& m_filename) // Main loop bool done = false; - while (!done) - { + while (!done) { // Poll and handle events (inputs, window resize, etc.) // You can read the io.WantCaptureMouse, io.WantCaptureKeyboard flags to tell if dear imgui wants to use your // inputs. |