Now lets build a small demo game!

This commit is contained in:
Hartmut Seichter 2023-07-01 10:54:20 +02:00
parent be6832cd24
commit d21f526290
4 changed files with 22 additions and 34 deletions

View file

@ -24,16 +24,13 @@ layout (location = 0) in vec3 vertices;
layout (location = 1) in vec3 normals;
layout (location = 2) in vec2 texture_coords;
// uniform mat4 model;
// uniform mat4 view;
// uniform mat4 projection;
uniform vec4 pivot = vec4( 0.5, 0.5, 0.0, 1.0 );
out vec2 tex_c;
void main() {
tex_c = texture_coords;
// gl_Position = projection * view * model * vec4(vertices, 1.0);
gl_Position = vec4(vertices, 1.0);
gl_Position = vec4(vertices, 1.0) + pivot;
}
)";
@ -59,15 +56,6 @@ void main() {
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();
window.set_size(paradiso::Size{.width = 1280, .height = 720})
@ -77,8 +65,13 @@ auto main() -> int {
auto ctx = paradiso::Context{};
auto sprite = paradiso::Sprite{
.bitmap = checker_board_2
auto sprite = paradiso::Sprite {
.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{};
@ -87,7 +80,7 @@ auto main() -> int {
setup_shaders(shader);
uint8_t green_slider = 0x00;
uint8_t slider_value = 0xFF;
bool want_close{false};
int frame_counter = 10;
@ -96,13 +89,13 @@ auto main() -> int {
if (key == 'Q' || key == 256)
want_close = true;
else if (key == 'A' ) {
green_slider += 10;
slider_value += 10;
}
});
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{
.size = w.client_size()
});

View file

@ -23,17 +23,18 @@
#ifndef PARADISO_CONTEXT_HPP
#define PARADISO_CONTEXT_HPP
#include <paradiso/globals.hpp>
#include <paradiso/geometry.hpp>
#include <paradiso/globals.hpp>
#include <paradiso/rgba.hpp>
namespace paradiso {
struct Context final {
Context();
~Context();
Context(const Context&) = delete;
Context(Context&&) = default;
Context& set_blend();
Context& set_depth();
@ -51,9 +52,8 @@ struct Context final {
uint32_t get_error() const;
struct impl;
private:
struct impl;
std::unique_ptr<impl> impl_;
};

View file

@ -49,19 +49,16 @@ struct RGBA final {
rgba_f[3] = static_cast<float>(this->alpha()) / 0xFF;
}
constexpr uint8_t red() const noexcept {
return (pixel & 0xFF000000) >> 24;
}
constexpr uint8_t red() const noexcept { return uint8_t(pixel & 0xFF); }
constexpr uint8_t green() const noexcept {
return uint8_t((pixel & 0xFF0000) >> 16);
}
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 blue() const noexcept {
return uint8_t((pixel & 0xFF0000) >> 16);
}
constexpr uint8_t alpha() const noexcept {
return (pixel & 0xFF000000) >> 24;
}
constexpr RGBA& set_red(uint8_t v) noexcept {
pixel = (pixel & 0x00FFFFFF) | (v << 24);

View file

@ -246,8 +246,6 @@ struct Window::impl {
glfwSetWindowMonitor(window_, nullptr, x, y, w, h, 0);
}
// glfwSetWindow
}
bool fullscreen() const { return glfwGetWindowMonitor(window_) != nullptr; }