Adding OpenGL support to the Bitmap object
This commit is contained in:
@@ -1 +1,47 @@
|
|||||||
#include "Bitmap.h"
|
#include "Bitmap.h"
|
||||||
|
|
||||||
|
namespace yaze {
|
||||||
|
namespace Application {
|
||||||
|
namespace Graphics {
|
||||||
|
|
||||||
|
Bitmap::Bitmap() {}
|
||||||
|
|
||||||
|
// Simple helper function to load an image into a OpenGL texture with common
|
||||||
|
// settings
|
||||||
|
bool Bitmap::LoadBitmapFromROM(unsigned char* texture_data, GLuint* out_texture,
|
||||||
|
int* out_width, int* out_height) {
|
||||||
|
// Load from file
|
||||||
|
int image_width = 0;
|
||||||
|
int image_height = 0;
|
||||||
|
if (texture_data == NULL) return false;
|
||||||
|
|
||||||
|
// Create a OpenGL texture identifier
|
||||||
|
GLuint image_texture;
|
||||||
|
glGenTextures(1, &image_texture);
|
||||||
|
glBindTexture(GL_TEXTURE_2D, image_texture);
|
||||||
|
|
||||||
|
// Setup filtering parameters for display
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,
|
||||||
|
GL_CLAMP_TO_EDGE); // This is required on WebGL for non
|
||||||
|
// power-of-two textures
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); // Same
|
||||||
|
|
||||||
|
// Upload pixels into texture
|
||||||
|
#if defined(GL_UNPACK_ROW_LENGTH) && !defined(__EMSCRIPTEN__)
|
||||||
|
glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
|
||||||
|
#endif
|
||||||
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, image_width, image_height, 0, GL_RGBA,
|
||||||
|
GL_UNSIGNED_BYTE, texture_data);
|
||||||
|
|
||||||
|
*out_texture = image_texture;
|
||||||
|
*out_width = image_width;
|
||||||
|
*out_height = image_height;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace Graphics
|
||||||
|
} // namespace Application
|
||||||
|
} // namespace yaze
|
||||||
|
|||||||
@@ -1,14 +1,22 @@
|
|||||||
#ifndef YAZE_APPLICATION_UTILS_BITMAP_H
|
#ifndef YAZE_APPLICATION_UTILS_BITMAP_H
|
||||||
#define YAZE_APPLICATION_UTILS_BITMAP_H
|
#define YAZE_APPLICATION_UTILS_BITMAP_H
|
||||||
|
|
||||||
|
#include "GL/glew.h"
|
||||||
|
#include <SDL2/SDL_opengl.h>
|
||||||
|
|
||||||
|
#include "Utils/ROM.h"
|
||||||
|
|
||||||
namespace yaze {
|
namespace yaze {
|
||||||
namespace Application {
|
namespace Application {
|
||||||
namespace Utils {
|
namespace Graphics {
|
||||||
class Bitmap {
|
class Bitmap {
|
||||||
|
public:
|
||||||
|
Bitmap();
|
||||||
|
|
||||||
|
bool LoadBitmapFromROM(unsigned char* texture_data, GLuint* out_texture,
|
||||||
|
int* out_width, int* out_height);
|
||||||
};
|
};
|
||||||
} // namespace Utils
|
} // namespace Graphics
|
||||||
} // namespace Application
|
} // namespace Application
|
||||||
} // namespace yaze
|
} // namespace yaze
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
# SDL libraries --------------------------------------------------------------------------------------------------
|
# SDL libraries --------------------------------------------------------------------------------------------------
|
||||||
find_package(SDL2 REQUIRED)
|
find_package(SDL2 REQUIRED)
|
||||||
|
|
||||||
|
find_package(OpenGL REQUIRED)
|
||||||
|
find_package(GLEW REQUIRED)
|
||||||
|
|
||||||
# ImGui library --------------------------------------------------------------------------------------------------
|
# ImGui library --------------------------------------------------------------------------------------------------
|
||||||
set(IMGUI_PATH "Library/imgui") # Set where the ImGui files are stored
|
set(IMGUI_PATH "Library/imgui") # Set where the ImGui files are stored
|
||||||
file(GLOB IMGUI_SOURCES ${IMGUI_PATH}/*.cpp) # Compile as static library
|
file(GLOB IMGUI_SOURCES ${IMGUI_PATH}/*.cpp) # Compile as static library
|
||||||
@@ -26,10 +29,10 @@ add_executable(
|
|||||||
Application/Core/Window.cc
|
Application/Core/Window.cc
|
||||||
Application/Data/Overworld.cc
|
Application/Data/Overworld.cc
|
||||||
Application/Data/OverworldMap.cc
|
Application/Data/OverworldMap.cc
|
||||||
Application/Data/Tile.cc
|
Application/Graphics/Bitmap.cc
|
||||||
|
Application/Graphics/Tile.cc
|
||||||
Application/Editor/Editor.cc
|
Application/Editor/Editor.cc
|
||||||
Application/Events/Event.cc
|
Application/Events/Event.cc
|
||||||
Application/Graphics/Bitmap.cc
|
|
||||||
Application/Utils/Compression.cc
|
Application/Utils/Compression.cc
|
||||||
Application/Utils/ROM.cc
|
Application/Utils/ROM.cc
|
||||||
# GUI libraries
|
# GUI libraries
|
||||||
@@ -47,11 +50,14 @@ target_include_directories(
|
|||||||
yaze PUBLIC
|
yaze PUBLIC
|
||||||
Library/
|
Library/
|
||||||
Application/
|
Application/
|
||||||
|
${SDL2_INCLUDE_DIR}
|
||||||
|
${GLEW_INCLUDE_DIRS}
|
||||||
)
|
)
|
||||||
|
|
||||||
target_link_libraries(
|
target_link_libraries(
|
||||||
yaze
|
yaze
|
||||||
${SDL2_LIBRARIES}
|
${SDL2_LIBRARIES}
|
||||||
|
${GLEW_LIBRARIES}
|
||||||
${OPENGL_LIBRARIES}
|
${OPENGL_LIBRARIES}
|
||||||
ImGui
|
ImGui
|
||||||
)
|
)
|
||||||
Reference in New Issue
Block a user