KekEngine/src/kekgame/cpp/kekgame.cpp
2022-11-05 22:07:53 +01:00

77 lines
2.2 KiB
C++

#include <iostream>
#include "kekengine.h"
#include <GL/glew.h>
#include <GLFW/glfw3.h>
using namespace kek;
static ButtonElement *button;
void periodicCallback(GLFWwindow *window, void *data){
}
void keyCallback(GLFWwindow *window, int key, int scancode, int action, int mods, void *data){
}
void mouseButtonCallback(GLFWwindow *window, int button, int action, int mods, void *data){
}
void onButtonClick(void *data) {
Input::captureKeyboardInput(KeyCharCallback([](GLFWwindow *window, unsigned int codepoint, void *data) {
std::u32string str = Unicode::convertStdToU32(button->text->getText());
str.push_back(codepoint);
button->text->setText(Unicode::convertU32ToStd(str));
}, nullptr), Callable());
}
int main(int argc, char **argv) {
Engine::init();
MemoryBuffer *buf = Resource::loadResource("object/sphere/Sphere.obj");
Mesh *mesh = ObjParser::parseMesh(buf, "object/sphere/");
delete buf;
GameObject *test = new GameObject();
test->addMesh(mesh);
Scene *scene = new Scene();
scene->addObject(test);
for(int i = 0; i < 10; i++) {
GameObject *test2 = new GameObject();
test2->addMesh(ObjParser::loadMesh("object/cube_colored/Cube.obj"));
test2->moveTo(glm::vec3(0.0f, 5.0f, 3 * i));
scene->addObject(test2);
}
PointLight *light = new PointLight(glm::vec3(1), 1, 0, 1);
scene->lights->add(light);
//DirectionalLight *l = new DirectionalLight(glm::vec3(1), glm::vec3(1, -1, 1));
//scene->lights->add(l);
//SpotLight *spot = new SpotLight(glm::vec3(1), glm::vec3(0, 0, -1), 1, 0, 1, glm::radians(8.0f), glm::radians(15.0f));
//spot->moveTo(glm::vec3(0, 0, 5));
//scene->lights->add(spot);
Engine::setActiveScene(scene);
Input::addPeriodicCallback(PeriodicCallback(periodicCallback, nullptr));
Input::addKeyListener(KeyCallback(keyCallback, nullptr));
Input::addMouseButtonListener(MouseButtonCallback(mouseButtonCallback, nullptr));
button = new ButtonElement(px(10), px(100), px(200), px(50));
button->text->color = Colors::BLACK;
button->color = Colors::WHITE;
button->hoverColor = Colors::GRAY;
button->text->setText("Hello There!");
button->onClick = Callable(onButtonClick, nullptr);
UI::addElement(button);
Engine::start();
}