<iframe src="https://duddel.github.io/yourgamelib/yg_examples/template" style="width: 700px; height: 400px; border: 1px solid black" name="Yourgame Example Template"></iframe>
2#include "mygame_version.h"
8 yg::util::AssetManager g_assets;
9 yg::math::Camera g_camera;
10 yg::math::Trafo g_modelTrafo;
11 yg::gl::Lightsource g_light;
13 void init(
int argc,
char *argv[])
15 yg::log::info(
"project: %v (%v)", mygame::version::PROJECT_NAME, mygame::version::git_commit);
16 yg::log::info(
"based on: %v (%v)", yg::version::PROJECT_NAME, yg::version::git_commit);
18 g_camera.trafo()->lookAt(glm::vec3(7.35889f, 4.95831f, 6.92579f),
19 glm::vec3(0.0f, 0.0f, 0.0f),
20 glm::vec3(0.0f, 1.0f, 0.0f));
21 g_camera.setPerspective(40.0f, yg::input::get(yg::input::WINDOW_ASPECT_RATIO), 1.0f, 100.0f);
23 g_light.setPosition({4.07625f, 5.90386f, -1.00545f});
24 g_light.setDiffuse({1.0f, 1.0f, 1.0f});
26 g_assets.insert(
"geoCube", yg::gl::loadGeometry(
"a//yg_cube_outside.obj"));
27 g_assets.insert(
"geoGrid", yg::gl::loadGeometry(
"a//yg_grid.obj"));
29 g_assets.insert(
"shaderDiffuseColor",
30 yg::gl::loadShader({{GL_VERTEX_SHADER,
"a//yg_default.vert"},
31 {GL_FRAGMENT_SHADER,
"a//yg_diffusecolor.frag"}}));
33 g_assets.insert(
"shaderSimpleColor",
34 yg::gl::loadShader({{GL_VERTEX_SHADER,
"a//yg_default.vert"},
35 {GL_FRAGMENT_SHADER,
"a//yg_simplecolor.frag"}}));
37 glClearColor(0.275f, 0.275f, 0.275f, 1.0f);
38 glEnable(GL_DEPTH_TEST);
43 g_camera.setAspect(yg::input::get(yg::input::WINDOW_ASPECT_RATIO));
46 yg::input::geti(yg::input::WINDOW_WIDTH),
47 yg::input::geti(yg::input::WINDOW_HEIGHT));
48 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
50 if (yg::input::get(yg::input::KEY_ESCAPE))
56 g_camera.trafo()->rotateGlobal(
static_cast<float>(yg::time::getDelta()) * 0.75f * yg::input::get(yg::input::KEY_LEFT), yg::math::Axis::Y);
57 g_camera.trafo()->rotateGlobal(
static_cast<float>(yg::time::getDelta()) * -0.75f * yg::input::get(yg::input::KEY_RIGHT), yg::math::Axis::Y);
58 g_camera.trafo()->rotateLocal(
static_cast<float>(yg::time::getDelta()) * 0.75f * yg::input::get(yg::input::KEY_UP), yg::math::Axis::X);
59 g_camera.trafo()->rotateLocal(
static_cast<float>(yg::time::getDelta()) * -0.75f * yg::input::get(yg::input::KEY_DOWN), yg::math::Axis::X);
60 g_camera.trafo()->translateLocal(
static_cast<float>(yg::time::getDelta()) * -5.0f * yg::input::get(yg::input::KEY_W), yg::math::Axis::Z);
61 g_camera.trafo()->translateLocal(
static_cast<float>(yg::time::getDelta()) * 5.0f * yg::input::get(yg::input::KEY_S), yg::math::Axis::Z);
62 g_camera.trafo()->translateLocal(
static_cast<float>(yg::time::getDelta()) * 5.0f * yg::input::get(yg::input::KEY_D), yg::math::Axis::X);
63 g_camera.trafo()->translateLocal(
static_cast<float>(yg::time::getDelta()) * -5.0f * yg::input::get(yg::input::KEY_A), yg::math::Axis::X);
66 static float lightT = 0.0f;
67 float light = std::cos(lightT) * 0.5f + 0.5f;
68 g_light.setDiffuse({light, light, light});
69 lightT += (
static_cast<float>(yg::time::getDelta()) * 0.65f);
73 auto shdrDiffCol = g_assets.get<yg::gl::Shader>(
"shaderDiffuseColor");
74 shdrDiffCol->useProgram(&g_light, &g_camera);
75 yg::gl::DrawConfig cfg;
76 cfg.camera = &g_camera;
77 cfg.modelMat = g_modelTrafo.mat();
78 cfg.shader = shdrDiffCol;
79 yg::gl::drawGeo(g_assets.get<yg::gl::Geometry>(
"geoCube"), cfg);
84 auto shdrSimpCol = g_assets.get<yg::gl::Shader>(
"shaderSimpleColor");
85 shdrSimpCol->useProgram(
nullptr, &g_camera);
86 yg::gl::DrawConfig cfg;
87 cfg.camera = &g_camera;
88 cfg.shader = shdrSimpCol;
89 yg::gl::drawGeo(g_assets.get<yg::gl::Geometry>(
"geoGrid"), cfg);
User functions that are linked to and called by the yourgame library framework.
Definition mygame_external.h:33
int shutdown()
user project clean-up
void init(int argc, char *argv[])
user project initialization
void tick()
user project update/draw (once pre frame)