2018-09-04 19:25:54 +00:00
|
|
|
#include "MyApplication.h"
|
|
|
|
|
2018-09-08 04:06:10 +00:00
|
|
|
MyApplication::MyApplication(int width, int height)
|
2018-09-13 04:51:47 +00:00
|
|
|
: Application(width, height),
|
|
|
|
m_basic_scene(*this),
|
|
|
|
m_simple_2d_scene(*this),
|
|
|
|
m_simple_3d_scene(*this),
|
|
|
|
m_simple_cube_scene(*this),
|
2018-10-15 01:19:38 +00:00
|
|
|
m_builtin_basic_cube_scene(*this),
|
2018-10-15 23:53:22 +00:00
|
|
|
m_builtin_textured_scene(*this),
|
2018-10-17 23:21:58 +00:00
|
|
|
m_builtin_lit_scene(*this),
|
|
|
|
m_pong_scene(*this)
|
2018-09-11 19:00:28 +00:00
|
|
|
{}
|
2018-09-08 04:06:10 +00:00
|
|
|
|
2018-09-05 15:47:09 +00:00
|
|
|
void MyApplication::init()
|
2018-09-04 19:25:54 +00:00
|
|
|
{
|
2018-09-11 05:18:17 +00:00
|
|
|
m_basic_scene.init();
|
|
|
|
m_simple_2d_scene.init();
|
|
|
|
m_simple_3d_scene.init();
|
2018-09-11 19:00:28 +00:00
|
|
|
m_simple_cube_scene.init();
|
2018-09-13 23:21:34 +00:00
|
|
|
m_builtin_basic_cube_scene.init();
|
2018-10-15 01:19:38 +00:00
|
|
|
m_builtin_textured_scene.init();
|
2018-10-15 23:53:22 +00:00
|
|
|
m_builtin_lit_scene.init();
|
2018-10-17 23:21:58 +00:00
|
|
|
m_pong_scene.init();
|
2018-09-05 23:10:38 +00:00
|
|
|
|
2018-09-11 05:18:17 +00:00
|
|
|
m_p_current_scene = &m_basic_scene;
|
2018-09-05 23:10:38 +00:00
|
|
|
m_p_current_scene->use();
|
2018-09-04 19:25:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MyApplication::update(float delta_time, clock_t clock)
|
|
|
|
{
|
2018-09-05 23:10:38 +00:00
|
|
|
if (m_glfw_input_manager.is_key_pressed(GLFW_KEY_1))
|
|
|
|
{
|
2018-09-11 05:18:17 +00:00
|
|
|
swap_scene(&m_basic_scene);
|
2018-09-05 23:10:38 +00:00
|
|
|
}
|
|
|
|
else if (m_glfw_input_manager.is_key_pressed(GLFW_KEY_2))
|
|
|
|
{
|
2018-09-11 05:18:17 +00:00
|
|
|
swap_scene(&m_simple_2d_scene);
|
2018-09-05 23:10:38 +00:00
|
|
|
}
|
2018-09-10 01:20:56 +00:00
|
|
|
else if (m_glfw_input_manager.is_key_pressed(GLFW_KEY_3))
|
|
|
|
{
|
2018-09-11 05:18:17 +00:00
|
|
|
swap_scene(&m_simple_3d_scene);
|
2018-09-10 01:20:56 +00:00
|
|
|
}
|
2018-09-11 19:00:28 +00:00
|
|
|
else if (m_glfw_input_manager.is_key_pressed(GLFW_KEY_4))
|
|
|
|
{
|
|
|
|
swap_scene(&m_simple_cube_scene);
|
|
|
|
}
|
2018-09-13 04:51:47 +00:00
|
|
|
else if (m_glfw_input_manager.is_key_pressed(GLFW_KEY_5))
|
|
|
|
{
|
2018-09-13 23:21:34 +00:00
|
|
|
swap_scene(&m_builtin_basic_cube_scene);
|
2018-09-13 04:51:47 +00:00
|
|
|
}
|
2018-10-15 01:19:38 +00:00
|
|
|
else if (m_glfw_input_manager.is_key_pressed(GLFW_KEY_6))
|
|
|
|
{
|
|
|
|
swap_scene(&m_builtin_textured_scene);
|
|
|
|
}
|
2018-10-15 23:53:22 +00:00
|
|
|
else if (m_glfw_input_manager.is_key_pressed(GLFW_KEY_7))
|
|
|
|
{
|
|
|
|
swap_scene(&m_builtin_lit_scene);
|
|
|
|
}
|
2018-10-17 23:21:58 +00:00
|
|
|
else if (m_glfw_input_manager.is_key_pressed(GLFW_KEY_8))
|
|
|
|
{
|
|
|
|
swap_scene(&m_pong_scene);
|
|
|
|
}
|
2018-09-05 23:10:38 +00:00
|
|
|
m_p_current_scene->update(delta_time, clock);
|
2018-09-04 19:25:54 +00:00
|
|
|
}
|
|
|
|
|
2018-09-12 15:22:56 +00:00
|
|
|
void MyApplication::prerender()
|
|
|
|
{
|
|
|
|
m_p_current_scene->prerender();
|
|
|
|
}
|
|
|
|
|
2018-09-04 19:25:54 +00:00
|
|
|
void MyApplication::render()
|
|
|
|
{
|
2018-09-05 23:10:38 +00:00
|
|
|
m_p_current_scene->render();
|
2018-09-04 19:25:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MyApplication::close()
|
|
|
|
{
|
2018-09-05 23:10:38 +00:00
|
|
|
m_p_current_scene->unuse();
|
2018-09-04 19:25:54 +00:00
|
|
|
}
|
|
|
|
|
2018-09-05 23:10:38 +00:00
|
|
|
void MyApplication::swap_scene(Scene* scene)
|
|
|
|
{
|
|
|
|
if (m_p_current_scene != scene)
|
|
|
|
{
|
|
|
|
m_p_current_scene->unuse();
|
|
|
|
m_p_current_scene = scene;
|
|
|
|
m_p_current_scene->use();
|
|
|
|
}
|
|
|
|
}
|
2018-09-04 19:25:54 +00:00
|
|
|
|