Quick and dirty attempt at placing images inside cells.

master
Zed A. Shaw 7 days ago
parent d79d891691
commit 43bfba0d71
  1. 1
      TODO.md
  2. BIN
      assets/bone.png
  3. BIN
      assets/test.png
  4. BIN
      assets/test_bg_small.png
  5. 4
      lua/builder_test.lua
  6. 4
      shaders/image.vert.glsl
  7. 3
      src/document.cpp
  8. 7
      src/engine.cpp
  9. 25
      src/guecs/opengl/components.cpp
  10. 12
      src/image.cpp
  11. 6
      src/image.hpp

@ -4,3 +4,4 @@
* Checks for errors in analyzer
* Resource prep: images, fonts, font glyphs
* Images if images are first they don't render correctly, just black
* Images need a cleanup process/destructor

Binary file not shown.

After

Width:  |  Height:  |  Size: 34 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.3 KiB

@ -9,7 +9,7 @@ config{
slide{
image{
src="assets/test.jpg"
src="assets/test_bg_small.png"
},
h1 "Image Before café",
}
@ -17,7 +17,7 @@ slide{
slide{
h1 "Image After Test",
image{
src="assets/test.jpg"
src="assets/test.png"
},
}

@ -5,8 +5,10 @@ layout (location = 1) in vec2 aTexCoord;
out vec2 TexCoord;
uniform mat4 transform;
void main()
{
gl_Position = vec4(aPos, 0.0, 1.0);
gl_Position = transform * vec4(aPos, 0.0, 1.0);
TexCoord = aTexCoord;
}

@ -1,5 +1,6 @@
#include "document.hpp"
#include <fmt/core.h>
#include "config.hpp"
void Deck::analyze() {
for(auto& slide : slides) {
@ -10,6 +11,8 @@ void Deck::analyze() {
node.image = std::make_shared<Image>();
std::string src = std::any_cast<std::string>(node.config.at("src"));
node.image->load(src);
fmt::println("HACK! fix this");
node.image->position = {WINDOW_WIDTH / 2, WINDOW_HEIGHT / 2};
break;
}
default:

@ -49,7 +49,7 @@ void init_glfw() {
GLFWwindow* create_window() {
GLFWwindow* window = glfwCreateWindow(WINDOW_WIDTH, WINDOW_HEIGHT, "LearnOpenGL", NULL, NULL);
GLFWwindow* window = glfwCreateWindow(WINDOW_WIDTH, WINDOW_HEIGHT, "Bezos2", NULL, NULL);
dbc::check(window != NULL, "failed to open window");
glfwMakeContextCurrent(window);
@ -81,14 +81,14 @@ void setup() {
void Engine::init_ui() {
ui.position(0, 0, WINDOW_WIDTH, WINDOW_HEIGHT);
ui.layout(
"[=title|=*%(200,100)description|_|_|_]"
"[*%(100,700)slide]"
"[_]"
"[_]"
"[_]"
"[_]"
"[_]"
"[_]"
"[=title|=*%(200,100)description|_|_|_]");
"[_]");
ui.init();
auto click = ui.entity("slide");
@ -100,6 +100,7 @@ void Engine::init_ui() {
auto title = ui.entity("title");
ui.set<guecs::Text>(title, {L"The Text Test!" });
ui.set<guecs::Sprite>(title, {"assets/bone.png"});
ui.set<guecs::Clickable>(title, {
[&](auto mods){
auto& at_title = ui.get<guecs::Text>(ui.entity("title"));

@ -4,14 +4,11 @@
#include <iostream>
#include <fmt/core.h>
#include <GLFW/glfw3.h>
#include "config.hpp"
namespace guecs {
using std::make_shared;
inline SpriteTexture load_texture(const string& name, bool is_icon) {
return {};
}
void Text::init(lel::Cell &cell, const std::string& font_file) {
assert(text == nullptr && "Double init on text.");
@ -46,16 +43,18 @@ namespace guecs {
void Sprite::update(const string& new_name) {
if(new_name != name) {
name = new_name;
// CHANGE: get the image and save it
dbc::sentinel("Swapping Images Not Implemented yet!");
}
}
void Sprite::init(lel::Cell &cell) {
if(cell.center) stretch = false;
// handle is_icon
image = make_shared<::Image>();
image->load(name);
auto sprite_texture = load_texture(name, is_icon);
// setup the image size and such
glm::vec2 bounds{0.0, 0.0}; // get this from the image
glm::vec2 bounds{image->width, image->height}; // get this from the image
if(stretch) {
// handle stretch
@ -65,13 +64,23 @@ namespace guecs {
float scale = std::min(box_width / float(bounds.x), box_height / float(bounds.y));
// no stretch so scale it
image->scale.x = (bounds.x / float(WINDOW_WIDTH)) * scale;
image->scale.y = (bounds.y / float(WINDOW_HEIGHT)) * scale;
// find center point of cell since origin of image is center (for now)
image->position.x = (cell.x + box_width / 2);
image->position.y = (cell.y + box_height / 2);
fmt::println("pos: {},{} | bounds: {},{} | box: {},{} | scale: {}",
image->position.x, image->position.y, bounds.x, bounds.y, box_width, box_height, scale);
}
// used the center helper here
}
void Sprite::render() {
// apply position and scale....
image->render();
}
void Rectangle::init(lel::Cell& cell) {

@ -1,5 +1,7 @@
#include "image.hpp"
#include <stb_image.h>
#include <glm/gtc/matrix_transform.hpp>
#include "config.hpp"
// these never change so just put them here
float VERTICES[24] = {
@ -54,10 +56,20 @@ void Image::load(const std::string& filename) {
texture_id = image_to_texture(data, width, height, nrComponents);
stbi_image_free(data);
$name = filename;
}
void Image::render() {
shader.use();
auto transform = glm::mat4(1.0f);
float xpos = (2.0f * position.x) / WINDOW_WIDTH - 1.0f;
float ypos = 1.0f - (2.0f * position.y) / WINDOW_HEIGHT;
transform = glm::translate(transform, glm::vec3(xpos, ypos, 0.0f));
transform = glm::scale(transform, glm::vec3(scale.x, scale.y, 1.0f));
shader.setMat4("transform", transform);
// use the correct texture unit
glActiveTexture(GL_TEXTURE0 + texture_unit);

@ -4,6 +4,10 @@
struct Image {
Shader shader{{"shaders/image.vert.glsl", "shaders/image.frag.glsl", ""}};
glm::vec2 position{0.0f, 0.0f};
glm::vec2 scale{1.0f, 1.0f};
unsigned int image_vao = UINT_MAX;
unsigned int image_vbo = UINT_MAX;
unsigned int texture_id = UINT_MAX;
@ -12,6 +16,8 @@ struct Image {
int height = 0;
int nrComponents = 0;
// scale, rotate, position
std::string $name{"NOT SET"};
Image();
void load(const std::string& filename);

Loading…
Cancel
Save