forked from Hartmut/paradiso
sync
This commit is contained in:
parent
0eebe25ea9
commit
b6691561e8
7 changed files with 58 additions and 51 deletions
|
@ -21,3 +21,4 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
|||
set(CMAKE_CXX_EXTENSIONS OFF)
|
||||
|
||||
add_subdirectory(src)
|
||||
add_subdirectory(examples/simple)
|
16
examples/simple/CMakeLists.txt
Normal file
16
examples/simple/CMakeLists.txt
Normal file
|
@ -0,0 +1,16 @@
|
|||
set(paradiso_src
|
||||
main.cpp
|
||||
)
|
||||
|
||||
add_executable(
|
||||
paradiso
|
||||
${paradiso_src}
|
||||
)
|
||||
|
||||
target_link_libraries(paradiso
|
||||
paradiso_core
|
||||
)
|
||||
|
||||
target_include_directories(paradiso
|
||||
PRIVATE
|
||||
lib)
|
|
@ -62,10 +62,11 @@ auto main() -> int {
|
|||
auto checker_board = paradiso::Bitmap::empty(paradiso::Size{4, 4});
|
||||
|
||||
auto checker_board_2 = paradiso::Bitmap::from_data(
|
||||
paradiso::Size{2, 2}, paradiso::RGBA::from_rgb(0x00, 0xFF, 0x00),
|
||||
paradiso::RGBA::from_rgb(0x00, 0xFF, 0x00),
|
||||
paradiso::RGBA::from_rgb(0x00, 0xFF, 0x00),
|
||||
paradiso::RGBA::from_rgb(0x00, 0xFF, 0x00));
|
||||
paradiso::Size{2, 2},
|
||||
paradiso::RGBA::from_rgb(0x00, 0xFF, 0x00), // G
|
||||
paradiso::RGBA::from_rgb(0xFF, 0x00, 0x00), // R
|
||||
paradiso::RGBA::from_rgb(0x00, 0x00, 0xFF), // B
|
||||
paradiso::RGBA::from_rgb(0xFF, 0x00, 0xFF));// C
|
||||
|
||||
auto window = paradiso::Window();
|
||||
|
||||
|
@ -102,9 +103,9 @@ auto main() -> int {
|
|||
while (window.update([&](auto& w) -> bool {
|
||||
|
||||
ctx.set_clearcolor(paradiso::RGBA::from_rgb(0xFF, green_slider, 0x00));
|
||||
// ctx.set_viewport(paradiso::Rectangle{
|
||||
// .size = w.client_size()
|
||||
// });
|
||||
ctx.set_viewport(paradiso::Rectangle{
|
||||
.size = w.client_size()
|
||||
});
|
||||
ctx.clear();
|
||||
|
||||
renderer.draw(sprite, shader);
|
|
@ -1,18 +1,2 @@
|
|||
add_subdirectory(lib)
|
||||
|
||||
set(paradiso_src
|
||||
main.cpp
|
||||
)
|
||||
|
||||
add_executable(
|
||||
paradiso
|
||||
${paradiso_src}
|
||||
)
|
||||
|
||||
target_link_libraries(paradiso
|
||||
paradiso_core
|
||||
)
|
||||
|
||||
target_include_directories(paradiso
|
||||
PRIVATE
|
||||
lib)
|
|
@ -38,8 +38,8 @@ struct RGBA final {
|
|||
static constexpr RGBA from_rgba(uint8_t red, uint8_t green, uint8_t blue,
|
||||
uint8_t alpha) noexcept {
|
||||
return {.pixel =
|
||||
(value_type)(((((red << 8) | green) << 8) | blue) << 8) |
|
||||
alpha};
|
||||
(value_type)(((((alpha << 8) | blue) << 8) | green) << 8) |
|
||||
red};
|
||||
}
|
||||
|
||||
constexpr void to_float(float rgba_f[4]) const noexcept {
|
||||
|
@ -58,7 +58,10 @@ struct RGBA final {
|
|||
constexpr uint8_t blue() const noexcept {
|
||||
return uint8_t((pixel & 0xFF00) >> 8);
|
||||
}
|
||||
constexpr uint8_t alpha() const noexcept { return uint8_t(pixel & 0xFF); }
|
||||
constexpr uint8_t alpha() const noexcept {
|
||||
return uint8_t(pixel & 0xFF);
|
||||
}
|
||||
|
||||
|
||||
constexpr RGBA& set_red(uint8_t v) noexcept {
|
||||
pixel = (pixel & 0x00FFFFFF) | (v << 24);
|
||||
|
|
|
@ -30,6 +30,13 @@
|
|||
|
||||
namespace paradiso {
|
||||
|
||||
// 0 3 | y
|
||||
// +------+ | ^
|
||||
// | \ | | -- + - > x
|
||||
// | \ | | / |
|
||||
// +------+ | z
|
||||
// 1 2 |
|
||||
|
||||
struct Sprite final {
|
||||
using ChangeCountType = std::uint64_t;
|
||||
|
||||
|
@ -39,7 +46,7 @@ struct Sprite final {
|
|||
|
||||
Vector2<float> pivot{Vector2<float>::zero()};
|
||||
|
||||
std::array<std::uint32_t, 6> indices{0, 3, 2, 2, 1, 0};
|
||||
std::array<std::uint32_t, 6> indices{0, 2, 1, 0, 3, 2};
|
||||
|
||||
std::array<Vector3<float>, 4> vertices{
|
||||
Vector3<float>::make(-1.0f, -1.0f, 0.0f),
|
||||
|
@ -52,10 +59,10 @@ struct Sprite final {
|
|||
Vector3<float>::z_axis(), Vector3<float>::z_axis()};
|
||||
|
||||
std::array<Vector2<float>, 4> texture_coordinates{
|
||||
Vector2<float>::make(0.0f, 0.0f), /// 0
|
||||
Vector2<float>::make(0.0f, 1.0f), /// 1
|
||||
Vector2<float>::make(1.0f, 1.0f), /// 2
|
||||
Vector2<float>::make(1.0f, 0.0f) /// 3
|
||||
Vector2<float>::make(0.0f, 0.0f),
|
||||
Vector2<float>::make(1.0f, 0.0f),
|
||||
Vector2<float>::make(1.0f, 1.0f),
|
||||
Vector2<float>::make(0.0f, 1.0f)
|
||||
};
|
||||
|
||||
ChangeCountType change_count{};
|
||||
|
|
|
@ -22,8 +22,8 @@
|
|||
*/
|
||||
#include "paradiso/renderer.hpp"
|
||||
#include "paradiso/bitmap.hpp"
|
||||
#include "paradiso/sprite.hpp"
|
||||
#include "paradiso/shader.hpp"
|
||||
#include "paradiso/sprite.hpp"
|
||||
|
||||
#include "glad/glad.h"
|
||||
|
||||
|
@ -53,7 +53,6 @@ struct Renderer::impl {
|
|||
GL_TRUE == glIsVertexArray(vertex_array_obj);
|
||||
}
|
||||
|
||||
|
||||
bool build(const Sprite& sprite) {
|
||||
// reset if the Renderer already in use
|
||||
if (ready())
|
||||
|
@ -114,7 +113,6 @@ struct Renderer::impl {
|
|||
return ready();
|
||||
}
|
||||
|
||||
|
||||
void texture_bind() {
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D, texture_id);
|
||||
|
@ -124,6 +122,9 @@ struct Renderer::impl {
|
|||
|
||||
void texture_update(const Bitmap& image) {
|
||||
if (GL_FALSE == glIsTexture(texture_id)) {
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
|
||||
glGenTextures(1, &texture_id);
|
||||
|
||||
glActiveTexture(GL_TEXTURE0 + 0);
|
||||
|
@ -139,21 +140,19 @@ struct Renderer::impl {
|
|||
// setup new texture
|
||||
glTexImage2D(GL_TEXTURE_2D, // target
|
||||
0, // level
|
||||
GL_RGB, // internal format
|
||||
GL_RGBA, // internal format
|
||||
image.size.width, // width
|
||||
image.size.height, // height
|
||||
0, // border
|
||||
GL_RGBA, // format
|
||||
GL_BGRA, // format
|
||||
GL_UNSIGNED_BYTE, // type
|
||||
image.data.data() // pointer to data
|
||||
);
|
||||
|
||||
#if 0
|
||||
|
||||
// generate MipMaps
|
||||
glGenerateMipmap(GL_TEXTURE_2D);
|
||||
glGenerateTextureMipmap(_textureId);
|
||||
#endif
|
||||
glGenerateTextureMipmap(texture_id);
|
||||
|
||||
} else {
|
||||
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
|
@ -167,18 +166,15 @@ struct Renderer::impl {
|
|||
0, // y-offset
|
||||
image.size.width, // width
|
||||
image.size.height, // height
|
||||
GL_RGBA, // format
|
||||
GL_BGRA, // format
|
||||
GL_UNSIGNED_BYTE, // type
|
||||
image.data.data()); // pointer
|
||||
}
|
||||
|
||||
// glBindTexture(GL_TEXTURE_2D, 0);
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
}
|
||||
|
||||
void texture_release()
|
||||
{
|
||||
glDeleteTextures(1, &texture_id);
|
||||
}
|
||||
void texture_release() { glDeleteTextures(1, &texture_id); }
|
||||
|
||||
void release() {
|
||||
|
||||
|
@ -189,7 +185,6 @@ struct Renderer::impl {
|
|||
glDeleteVertexArrays(1, &vertex_array_obj);
|
||||
|
||||
texture_release();
|
||||
|
||||
}
|
||||
|
||||
void just_draw(const Sprite& sprite) {
|
||||
|
@ -239,7 +234,7 @@ bool Renderer::draw(const Sprite& sprite, const Shader& shader) {
|
|||
|
||||
// Renderer::impl::fetch_errors(__PRETTY_FUNCTION__);
|
||||
|
||||
// impl_->texture_unbind();
|
||||
impl_->texture_unbind(); // overkill but some cards are finicky
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue