-OBJS = main.o stb_image.o helpers.o tiny_obj_loader.o baseclass.o old_objects.o
+OBJS = main.o stb_image.o helpers.o tiny_obj_loader.o baseclass.o old_objects.o geometric_objects.o
CXXFLAGS = -g -Wall
LDFLAGS = -lGL -lglfw -lGLEW -pthread -g
./a.out
${OBJS} : game.h
-main.o : projectiles.h activation_area.h turret.h tile_floor.h old_objects.h moving_platform.h
+main.o : projectiles.h activation_area.h turret.h tile_floor.h old_objects.h moving_platform.h geometric_objects.h
#include "game.h"
+std::vector<glm::mat4> gameobject::create_models(){
+ std::vector<glm::mat4> models;
+ data_mutex.lock();
+ models.reserve(locations.size());
+ for(glm::vec3 l : locations){
+ glm::mat4 new_model = glm::mat4(1.0f);
+ new_model = translate(new_model, l);
+ models.push_back(new_model);
+ }
+ data_mutex.unlock();
+ return models;
+}
+
int loaded_object::init() {
// Initialization part
std::vector<vertex> vertices;
return 0;
}
-std::vector<glm::mat4> loaded_object::create_models(glm::mat4 vp){
- std::vector<glm::mat4> models;
- data_mutex.lock();
- models.reserve(locations.size());
- for(glm::vec3 l : locations){
- glm::mat4 new_model = glm::mat4(1.0f);
- new_model = translate(new_model, l);
- models.push_back(new_model);
- }
- data_mutex.unlock();
- return models;
-}
-
void loaded_object::draw(glm::mat4 vp) {
glUseProgram(program);
- std::vector<glm::mat4> models = create_models(vp);
+ std::vector<glm::mat4> models = create_models();
glBindBuffer(GL_SHADER_STORAGE_BUFFER, models_buffer);
glBufferData(GL_SHADER_STORAGE_BUFFER, models.size() * sizeof(glm::mat4), models.data(), GL_STATIC_DRAW);
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 0, models_buffer);
virtual int init() { return 0; }
virtual void deinit() {};
virtual void draw(glm::mat4) {}
+ virtual std::vector<glm::mat4> create_models();
virtual void move() {}
virtual void animate() {}
virtual bool is_on_idx(glm::vec3 position, size_t index, float height) {return false;}
loaded_object(const char* of, const char* tf, glm::vec3 s) : objectfile(of), texturefile(tf) { size = s; }
int init() override ;
- virtual std::vector<glm::mat4> create_models(glm::mat4 vp);
void draw(glm::mat4 vp) override;
};
--- /dev/null
+#include "game.h"
+#include "geometric_objects.h"
+
+int flat_panel::init() {
+ // Initialization part
+ float vertices[] = {
+ -1.0, 0, 1.0,
+ 1.0, 0, 1.0,
+ 1.0, 0, -1.0,
+ -1.0, 0, 1.0,
+ 1.0, 0, -1.0,
+ -1.0, 0, -1.0,
+ };
+ glGenBuffers(1, &vbuf);
+ glBindBuffer(GL_SHADER_STORAGE_BUFFER, vbuf);
+ glBufferData(GL_SHADER_STORAGE_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
+
+ program = make_program("panel_vertex_shader.glsl",0, 0, 0, "loaded_object_fragment_shader.glsl");
+ if (!program)
+ return 1;
+
+ tex = load_texture(texturefile);
+
+ glGenBuffers(1, &models_buffer);
+ glGenBuffers(1, &scales_buffer);
+
+ v_attrib = glGetAttribLocation(program, "in_vertex");
+ mvp_uniform = glGetUniformLocation(program, "vp");
+ return 0;
+}
+
+void flat_panel::addpanel(glm::vec3 location, glm::vec2 object_scale, glm::vec2 texture_scale){
+ locations.push_back(location);
+ object_scales.push_back(object_scale);
+ texture_scales.push_back(texture_scale);
+
+}
+
+std::vector<glm::mat4> flat_panel::create_models(){
+ std::vector<glm::mat4> models;
+ models.reserve(locations.size());
+ for(size_t i = 0; i < locations.size(); i++){
+ glm::mat4 new_model = glm::mat4(1.0f);
+ new_model = glm::translate(new_model, locations[i]);
+ new_model = glm::scale(new_model, glm::vec3(object_scales[i].x, 1.0f, object_scales[i].y));
+ models.push_back(new_model);
+ }
+ return models;
+}
+
+void flat_panel::draw(glm::mat4 vp) {
+ glUseProgram(program);
+ data_mutex.lock();
+ std::vector<glm::mat4> models = create_models();
+ glBindBuffer(GL_SHADER_STORAGE_BUFFER, models_buffer);
+ glBufferData(GL_SHADER_STORAGE_BUFFER, models.size() * sizeof(glm::mat4), models.data(), GL_STATIC_DRAW);
+ glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 0, models_buffer);
+
+ glBindBuffer(GL_SHADER_STORAGE_BUFFER, scales_buffer);
+ glBufferData(GL_SHADER_STORAGE_BUFFER, texture_scales.size() * sizeof(glm::vec2), texture_scales.data(), GL_STATIC_DRAW);
+ glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1, scales_buffer);
+ data_mutex.unlock();
+
+ glEnableVertexAttribArray(v_attrib);
+ glBindBuffer(GL_ARRAY_BUFFER, vbuf);
+ glVertexAttribPointer(v_attrib, 3, GL_FLOAT, GL_FALSE, 0, 0);
+
+ glActiveTexture(GL_TEXTURE0);
+ glBindTexture(GL_TEXTURE_2D, tex);
+
+ glUniformMatrix4fv(mvp_uniform, 1, 0, glm::value_ptr(vp));
+
+ glDrawArraysInstanced(GL_TRIANGLES, 0, 6, models.size());
+}
--- /dev/null
+#pragma once
+
+class flat_panel : public gameobject {
+public:
+ std::vector<glm::vec2> object_scales, texture_scales;
+ unsigned scales_buffer;
+ const char *texturefile;
+ flat_panel(const char* tf) : texturefile(tf) {}
+ int init() override;
+ void draw(glm::mat4 vp) override;
+ std::vector<glm::mat4> create_models();
+ void addpanel(glm::vec3 location, glm::vec2 object_scale, glm::vec2 texture_scale);
+};
+
#include "tile_floor.h"
#include "moving_platform.h"
#include "turret.h"
+#include "geometric_objects.h"
std::mutex grand_mutex;
int cpu_time = std::chrono::duration_cast<std::chrono::microseconds>(end_time - start_time).count();
last_call = start_time;
int sleep_time = 1000 - cpu_time;
- printf("Loop time: %d Sleep time: %d CPU time: %d\n", loop_time, sleep_time, cpu_time);
+// printf("Loop time: %d Sleep time: %d CPU time: %d\n", loop_time, sleep_time, cpu_time);
if(sleep_time > 100 )
std::this_thread::sleep_for(std::chrono::microseconds(sleep_time));
}
/* Level Loading (hardcoded at the moment) */
+ /*
tile_floor fl;
objects.push_back(&ice_balls);
objects.push_back(&fl);
target_spawning.add_area(glm::vec3(10, 0, 10), bob, 1);
target_spawning.add_area(glm::vec3(100, 5, 300), activate_turret, 2);
objects.push_back(&target_spawning);
-
- /*
+*/
+
wall_block monster_box("cube.obj", "monster1.png", glm::vec3(10, 10, 10));
monster_box.scale = 5.0;
- monster_box.locations.push_back(glm::vec3(90, -5, 300 ));
+ monster_box.locations.push_back(glm::vec3(53, -10, 50));
objects.push_back(&monster_box);
- */
-
+
+/*
// What if it wasn't a cube?
wall_block bwb("cube.obj", "brick.jpg", glm::vec3(20, 20, 20));
bwb.scale = 10;
t.current_target = &targets;
t.current_projectile = &ice_balls;
objects.push_back(&t);
-
+*/
+ flat_panel p("nutsandbolts.jpg");
+ p.addpanel(glm::vec3(63, 0, 50), glm::vec2(2, 2), glm::vec2(2.0, 2.0));
+ p.addpanel(glm::vec3(58, 0, 50), glm::vec2(2, 2), glm::vec2(0.5, 0.5));
+ p.addpanel(glm::vec3(53, 0, 50), glm::vec2(2, 2), glm::vec2(1, 1));
+ objects.push_back(&p);
/* Initialize game objects */
for(gameobject* o : objects){
rotation += 0.01;
}
- std::vector<glm::mat4> create_models(glm::mat4 vp) override {
+ std::vector<glm::mat4> create_models() override {
std::vector<glm::mat4> models;
data_mutex.lock();
models.reserve(locations.size());
for(glm::vec3 l : locations){
- printf("create_models loop in turret\n");
glm::mat4 new_model = glm::mat4(1.0f);
new_model = translate(new_model, l);
new_model = rotate(new_model, rotation, glm::vec3(0, 1, 0));