forked from Hartmut/paradiso
Now lets build a small demo game!
This commit is contained in:
parent
be6832cd24
commit
d21f526290
4 changed files with 22 additions and 34 deletions
|
@ -24,16 +24,13 @@ layout (location = 0) in vec3 vertices;
|
||||||
layout (location = 1) in vec3 normals;
|
layout (location = 1) in vec3 normals;
|
||||||
layout (location = 2) in vec2 texture_coords;
|
layout (location = 2) in vec2 texture_coords;
|
||||||
|
|
||||||
// uniform mat4 model;
|
uniform vec4 pivot = vec4( 0.5, 0.5, 0.0, 1.0 );
|
||||||
// uniform mat4 view;
|
|
||||||
// uniform mat4 projection;
|
|
||||||
|
|
||||||
out vec2 tex_c;
|
out vec2 tex_c;
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
tex_c = texture_coords;
|
tex_c = texture_coords;
|
||||||
// gl_Position = projection * view * model * vec4(vertices, 1.0);
|
gl_Position = vec4(vertices, 1.0) + pivot;
|
||||||
gl_Position = vec4(vertices, 1.0);
|
|
||||||
}
|
}
|
||||||
)";
|
)";
|
||||||
|
|
||||||
|
@ -59,15 +56,6 @@ void main() {
|
||||||
|
|
||||||
auto main() -> int {
|
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), // 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();
|
auto window = paradiso::Window();
|
||||||
|
|
||||||
window.set_size(paradiso::Size{.width = 1280, .height = 720})
|
window.set_size(paradiso::Size{.width = 1280, .height = 720})
|
||||||
|
@ -78,7 +66,12 @@ auto main() -> int {
|
||||||
auto ctx = paradiso::Context{};
|
auto ctx = paradiso::Context{};
|
||||||
|
|
||||||
auto sprite = paradiso::Sprite {
|
auto sprite = paradiso::Sprite {
|
||||||
.bitmap = checker_board_2
|
.bitmap = paradiso::Bitmap::from_data(
|
||||||
|
paradiso::Size{2, 2},
|
||||||
|
paradiso::RGBA::from_rgba(0x00, 0xFF, 0x00, 0x80), // G
|
||||||
|
paradiso::RGBA::from_rgba(0xFF, 0x00, 0x00, 0x80), // R
|
||||||
|
paradiso::RGBA::from_rgba(0x00, 0x00, 0xFF, 0x80), // B
|
||||||
|
paradiso::RGBA::from_rgba(0xFF, 0x00, 0xFF, 0x80)) // C
|
||||||
};
|
};
|
||||||
|
|
||||||
auto renderer = paradiso::Renderer{};
|
auto renderer = paradiso::Renderer{};
|
||||||
|
@ -87,7 +80,7 @@ auto main() -> int {
|
||||||
|
|
||||||
setup_shaders(shader);
|
setup_shaders(shader);
|
||||||
|
|
||||||
uint8_t green_slider = 0x00;
|
uint8_t slider_value = 0xFF;
|
||||||
bool want_close{false};
|
bool want_close{false};
|
||||||
int frame_counter = 10;
|
int frame_counter = 10;
|
||||||
|
|
||||||
|
@ -96,13 +89,13 @@ auto main() -> int {
|
||||||
if (key == 'Q' || key == 256)
|
if (key == 'Q' || key == 256)
|
||||||
want_close = true;
|
want_close = true;
|
||||||
else if (key == 'A' ) {
|
else if (key == 'A' ) {
|
||||||
green_slider += 10;
|
slider_value += 10;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
while (window.update([&](auto& w) -> bool {
|
while (window.update([&](auto& w) -> bool {
|
||||||
|
|
||||||
ctx.set_clearcolor(paradiso::RGBA::from_rgb(0xFF, green_slider, 0x00));
|
ctx.set_clearcolor(paradiso::RGBA::from_rgb(slider_value, slider_value, slider_value));
|
||||||
ctx.set_viewport(paradiso::Rectangle{
|
ctx.set_viewport(paradiso::Rectangle{
|
||||||
.size = w.client_size()
|
.size = w.client_size()
|
||||||
});
|
});
|
||||||
|
|
|
@ -23,17 +23,18 @@
|
||||||
#ifndef PARADISO_CONTEXT_HPP
|
#ifndef PARADISO_CONTEXT_HPP
|
||||||
#define PARADISO_CONTEXT_HPP
|
#define PARADISO_CONTEXT_HPP
|
||||||
|
|
||||||
#include <paradiso/globals.hpp>
|
|
||||||
#include <paradiso/geometry.hpp>
|
#include <paradiso/geometry.hpp>
|
||||||
|
#include <paradiso/globals.hpp>
|
||||||
#include <paradiso/rgba.hpp>
|
#include <paradiso/rgba.hpp>
|
||||||
|
|
||||||
|
|
||||||
namespace paradiso {
|
namespace paradiso {
|
||||||
|
|
||||||
struct Context final {
|
struct Context final {
|
||||||
|
|
||||||
Context();
|
Context();
|
||||||
~Context();
|
~Context();
|
||||||
|
Context(const Context&) = delete;
|
||||||
|
Context(Context&&) = default;
|
||||||
|
|
||||||
Context& set_blend();
|
Context& set_blend();
|
||||||
Context& set_depth();
|
Context& set_depth();
|
||||||
|
@ -51,9 +52,8 @@ struct Context final {
|
||||||
|
|
||||||
uint32_t get_error() const;
|
uint32_t get_error() const;
|
||||||
|
|
||||||
struct impl;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
struct impl;
|
||||||
std::unique_ptr<impl> impl_;
|
std::unique_ptr<impl> impl_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -49,19 +49,16 @@ struct RGBA final {
|
||||||
rgba_f[3] = static_cast<float>(this->alpha()) / 0xFF;
|
rgba_f[3] = static_cast<float>(this->alpha()) / 0xFF;
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr uint8_t red() const noexcept {
|
constexpr uint8_t red() const noexcept { return uint8_t(pixel & 0xFF); }
|
||||||
return (pixel & 0xFF000000) >> 24;
|
|
||||||
}
|
|
||||||
constexpr uint8_t green() const noexcept {
|
constexpr uint8_t green() const noexcept {
|
||||||
return uint8_t((pixel & 0xFF0000) >> 16);
|
|
||||||
}
|
|
||||||
constexpr uint8_t blue() const noexcept {
|
|
||||||
return uint8_t((pixel & 0xFF00) >> 8);
|
return uint8_t((pixel & 0xFF00) >> 8);
|
||||||
}
|
}
|
||||||
constexpr uint8_t alpha() const noexcept {
|
constexpr uint8_t blue() const noexcept {
|
||||||
return uint8_t(pixel & 0xFF);
|
return uint8_t((pixel & 0xFF0000) >> 16);
|
||||||
|
}
|
||||||
|
constexpr uint8_t alpha() const noexcept {
|
||||||
|
return (pixel & 0xFF000000) >> 24;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
constexpr RGBA& set_red(uint8_t v) noexcept {
|
constexpr RGBA& set_red(uint8_t v) noexcept {
|
||||||
pixel = (pixel & 0x00FFFFFF) | (v << 24);
|
pixel = (pixel & 0x00FFFFFF) | (v << 24);
|
||||||
|
|
|
@ -246,8 +246,6 @@ struct Window::impl {
|
||||||
|
|
||||||
glfwSetWindowMonitor(window_, nullptr, x, y, w, h, 0);
|
glfwSetWindowMonitor(window_, nullptr, x, y, w, h, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// glfwSetWindow
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool fullscreen() const { return glfwGetWindowMonitor(window_) != nullptr; }
|
bool fullscreen() const { return glfwGetWindowMonitor(window_) != nullptr; }
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue