moved background tiles into class
This commit is contained in:
parent
5374b7f76a
commit
a41dbfd3b1
|
@ -138,3 +138,18 @@ Model::operator glm::mat4() const
|
|||
{
|
||||
return model_transformation;
|
||||
}
|
||||
|
||||
/* Increment offset that indicates which tile texture is active. If offset reaches the end of the container,
|
||||
* start over from the beginning. */
|
||||
void Background::next()
|
||||
{
|
||||
offset = ++offset % model_texture.size();
|
||||
}
|
||||
|
||||
/* Return the currently active tile texture. */
|
||||
const sb::Texture& Background::tile() const
|
||||
{
|
||||
auto position = model_texture.begin();
|
||||
std::advance(position, offset);
|
||||
return position->second;
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
#include <string>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <iterator>
|
||||
#include "glm/glm.hpp"
|
||||
#include "Attributes.hpp"
|
||||
#include "Texture.hpp"
|
||||
|
@ -28,7 +29,7 @@
|
|||
class Model
|
||||
{
|
||||
|
||||
private:
|
||||
protected:
|
||||
|
||||
std::map<std::string, std::shared_ptr<sb::Attributes>> model_attributes;
|
||||
std::map<std::string, sb::Texture> model_texture;
|
||||
|
@ -69,10 +70,24 @@ public:
|
|||
{1.0f, 1.0f}, {1.0f, 0.0f}, {0.0f, 0.0f}
|
||||
});
|
||||
|
||||
public:
|
||||
|
||||
Plane() : Model(std::map<std::string, std::shared_ptr<sb::Attributes>>({{"position", position}, {"uv", uv}})) {}
|
||||
|
||||
};
|
||||
|
||||
/* Plane that stores multiple textures which can be cycled through and looped. Only one texture is
|
||||
* active at a time, returned by Background::current. Cycle only goes forward, using Background::next. */
|
||||
class Background : public Plane
|
||||
{
|
||||
|
||||
private:
|
||||
|
||||
std::uint8_t offset = 0;
|
||||
|
||||
public:
|
||||
|
||||
void next();
|
||||
const sb::Texture& tile() const;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -38,11 +38,21 @@ Pudding::Pudding()
|
|||
/* use gl context so we can draw 3D */
|
||||
load_gl_context();
|
||||
load_tiles();
|
||||
Model boom;
|
||||
Model boom, kaboom;
|
||||
boom["hello world"] = std::make_shared<sb::Attributes>(sb::Attributes{1, 2, 3, 4, 5});
|
||||
std::cout << *boom["hello world"] << std::endl;
|
||||
boom.attributes("bam", {{4.2f, 42.0f, 420.0f}, {.69f, 6.9f, 69.0f}});
|
||||
std::cout << *boom["bam"] << std::endl;
|
||||
kaboom = boom;
|
||||
std::cout << *kaboom.attributes("hello world") << std::endl;
|
||||
background_copy = background;
|
||||
background_copy.next();
|
||||
background = background_copy;
|
||||
background_copy_2 = background_copy;
|
||||
background_copy_2.next();
|
||||
background = background_copy_2;
|
||||
background_copy = background_copy_2;
|
||||
background = background_copy;
|
||||
}
|
||||
|
||||
/* Assign vertices, colors and texture UV coordinates to the pudding model */
|
||||
|
@ -225,7 +235,7 @@ void Pudding::load_tiles()
|
|||
{
|
||||
sb::Texture texture = sb::Texture(path);
|
||||
texture.load();
|
||||
tiles.push_back(texture);
|
||||
background.texture(path, texture);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -307,7 +317,7 @@ void Pudding::respond(SDL_Event& event)
|
|||
}
|
||||
else if (get_delegate().compare(event, "tile"))
|
||||
{
|
||||
current_tile_index = ++current_tile_index % tiles.size();
|
||||
background_copy.next();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -751,7 +761,7 @@ void Pudding::update()
|
|||
plane.enable();
|
||||
glUniform1i(uniform["flat"]["texture"], 0);
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
tiles[current_tile_index].bind();
|
||||
background_copy.tile().bind();
|
||||
/* set blend to modify white part of background, color passed is in HSV format */
|
||||
glUniform3f(uniform["flat"]["blend"], 0.0f, 0.0f, 1.0f);
|
||||
glUniform1i(uniform["flat"]["scroll"], true);
|
||||
|
|
|
@ -78,8 +78,7 @@ private:
|
|||
const glm::vec3 PUDDING_YELLOW = glm::vec3(0.878f, 0.859f, 0.122f);
|
||||
std::string current_barcode, previous_barcode, current_config_barcode, current_camera_barcode;
|
||||
std::vector<Item> items;
|
||||
int current_item_index = 0, effect_id = EFFECT_NONE, pudding_triangle_vertex_count = 0, pudding_fan_vertex_count = 0,
|
||||
current_tile_index = 0;
|
||||
int current_item_index = 0, effect_id = EFFECT_NONE, pudding_triangle_vertex_count = 0, pudding_fan_vertex_count = 0;
|
||||
cv::VideoCapture capture;
|
||||
zbar::ImageScanner image_scanner;
|
||||
std::map<std::string, std::map<std::string, GLuint>> uniform;
|
||||
|
@ -87,10 +86,10 @@ private:
|
|||
glm::mat4 projection, model = glm::mat4(1.0f), mvp;
|
||||
Model pudding_model;
|
||||
Plane plane;
|
||||
Background background, background_copy, background_copy_2;
|
||||
// Plane background, camera_frame;
|
||||
bool show_item = false, reading_capture_frame = false;
|
||||
SDL_GLContext capture_frame_thread_context = nullptr;
|
||||
std::vector<sb::Texture> tiles;
|
||||
sb::Texture capture_texture_front_buffer, capture_texture_back_buffer;
|
||||
sb::Texture& capture_texture = capture_texture_front_buffer;
|
||||
sb::VAO vao;
|
||||
|
|
Loading…
Reference in New Issue