paradiso-win/src/main.cpp

122 lines
2.7 KiB
C++
Raw Normal View History

/**
* paradiso - Paradigmen der Softwareentwicklung
*
* (c) Copyright 2023 Hartmut Seichter
*
*/
#include "bitmap.hpp"
#include "context.hpp"
#include "geometry.hpp"
2023-06-30 22:05:23 +02:00
#include "renderer.hpp"
#include "shader.hpp"
#include "sprite.hpp"
#include "window.hpp"
#include <iomanip>
#include <iostream>
2023-06-30 22:05:23 +02:00
void setup_shaders(paradiso::Shader& shader) {
const auto unlit_v = R"(
#version 330 core
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;
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);
}
)";
const auto unlit_f = R"(
#version 330 core
uniform vec4 color = vec4(1.0, 0.0, 0.0, 1.0);
uniform sampler2D tex_color;
in vec2 tex_c;
out vec4 frag_color;
void main() {
frag_color = texture(tex_color,tex_c); // * color;
})";
shader.set_source(paradiso::Shader::Type::Vertex, unlit_v);
shader.set_source(paradiso::Shader::Type::Fragment, unlit_f);
shader.build();
}
2023-06-30 22:05:23 +02:00
auto main() -> int {
2023-06-30 22:05:23 +02:00
auto checker_board = paradiso::Bitmap::empty(paradiso::Size{4, 4});
2023-06-30 22:05:23 +02:00
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));
auto window = paradiso::Window();
window.set_size(paradiso::Size{.width = 1280, .height = 720})
.set_position(paradiso::Point{.x = 100, .y = 100})
.set_title("PardiSO")
.set_visible(true);
auto ctx = paradiso::Context{};
2023-06-30 22:05:23 +02:00
auto sprite = paradiso::Sprite{
//
};
2023-06-30 22:05:23 +02:00
auto renderer = paradiso::Renderer{};
auto shader = paradiso::Shader{};
setup_shaders(shader);
uint8_t green_slider = 0x00;
bool want_close{false};
2023-06-30 22:05:23 +02:00
int frame_counter = 10;
window.set_keyboardcallback(
[&](auto& w, int key, int scancode, int action, int mods) {
if (key == 'Q' || key == 256)
want_close = true;
2023-06-30 22:05:23 +02:00
else if (key == 'A' ) {
green_slider += 10;
}
});
while (window.update([&](auto& w) -> bool {
2023-06-30 22:05:23 +02:00
ctx.set_clearcolor(paradiso::RGBA::from_rgb(0xFF, green_slider, 0x00));
ctx.set_viewport(paradiso::Rectangle{
.size = w.client_size()
});
ctx.clear();
2023-06-30 22:05:23 +02:00
shader.use();
renderer.draw(sprite);
2023-06-30 22:05:23 +02:00
// if (frame_counter-- == 0) want_close = true;
return !want_close;
})) {
};
return 0;
}