@@ -45,7 +45,7 @@ public: | |||
m_ready(false) | |||
{ | |||
m_camera = new Camera(); | |||
m_camera->SetProjection(mat4::perspective(radians(30.f), 960.f, 600.f, .1f, 1000.f)); | |||
m_camera->SetProjection(mat4::perspective(radians(30.f), 640.f, 480.f, .1f, 1000.f)); | |||
m_camera->SetView(mat4::lookat(vec3(-15.f, 5.f, 0.f), | |||
vec3(0.f, -1.f, 0.f), | |||
vec3(0.f, 1.f, 0.f))); | |||
@@ -1,7 +1,7 @@ | |||
// | |||
// Lol Engine | |||
// | |||
// Copyright © 2010—2016 Sam Hocevar <sam@hocevar.net> | |||
// Copyright © 2010—2019 Sam Hocevar <sam@hocevar.net> | |||
// | |||
// Lol Engine is free software. It comes without any warranty, to | |||
// the extent permitted by applicable law. You can redistribute it | |||
@@ -69,7 +69,7 @@ SdlAppDisplay::SdlAppDisplay(char const *title, ivec2 res) | |||
* However, perfs warning have been may occur. */ | |||
SDL_GL_SetAttribute(SDL_GL_SHARE_WITH_CURRENT_CONTEXT, 1); | |||
int flags = SDL_WINDOW_OPENGL; | |||
int flags = SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE; | |||
if (window_size == ivec2(0)) | |||
flags |= SDL_WINDOW_FULLSCREEN_DESKTOP; | |||
data->m_window = SDL_CreateWindow(title, | |||
@@ -1,7 +1,7 @@ | |||
// | |||
// Lol Engine | |||
// | |||
// Copyright © 2010—2017 Sam Hocevar <sam@hocevar.net> | |||
// Copyright © 2010—2019 Sam Hocevar <sam@hocevar.net> | |||
// | |||
// Lol Engine is free software. It comes without any warranty, to | |||
// the extent permitted by applicable law. You can redistribute it | |||
@@ -332,6 +332,9 @@ void SdlInputData::Tick(float seconds) | |||
case SDL_WINDOWEVENT_FOCUS_LOST: | |||
m_mouse->SetKey(3, false); | |||
break; | |||
case SDL_WINDOWEVENT_RESIZED: | |||
Video::Resize(ivec2(event.window.data1, event.window.data2)); | |||
break; | |||
} | |||
break; | |||
} | |||
@@ -204,14 +204,15 @@ mutex SceneData::m_prim_mutex; | |||
* Public Scene class | |||
*/ | |||
Scene::Scene(ivec2 size) | |||
: data(new SceneData()) | |||
{ | |||
m_renderer = new Renderer(size); | |||
data->m_renderbuffer[0] = new Framebuffer(size); | |||
data->m_renderbuffer[1] = new Framebuffer(size); | |||
data->m_renderbuffer[2] = new Framebuffer(size); | |||
data->m_renderbuffer[3] = new Framebuffer(size); | |||
: m_size(size), | |||
m_wanted_size(size), | |||
data(new SceneData()), | |||
m_renderer(new Renderer(size)) | |||
{ | |||
data->m_renderbuffer[0] = new Framebuffer(m_size); | |||
data->m_renderbuffer[1] = new Framebuffer(m_size); | |||
data->m_renderbuffer[2] = new Framebuffer(m_size); | |||
data->m_renderbuffer[3] = new Framebuffer(m_size); | |||
data->m_pp.m_shader[0] = Shader::Create(LOLFX_RESOURCE_NAME(gpu_blit)); | |||
data->m_pp.m_shader[1] = Shader::Create(LOLFX_RESOURCE_NAME(gpu_postprocess)); | |||
data->m_pp.m_coord[0] = data->m_pp.m_shader[0]->GetAttribLocation(VertexUsage::Position, 0); | |||
@@ -232,7 +233,7 @@ Scene::Scene(ivec2 size) | |||
/* Create a default orthographic camera, in case the user doesn’t. */ | |||
data->m_default_cam = new Camera(); | |||
mat4 proj = mat4::ortho(0.f, (float)size.x, 0.f, (float)size.y, -1000.f, 1000.f); | |||
mat4 proj = mat4::ortho(0.f, (float)m_size.x, 0.f, (float)m_size.y, -1000.f, 1000.f); | |||
data->m_default_cam->SetProjection(proj); | |||
PushCamera(data->m_default_cam); | |||
@@ -248,6 +249,11 @@ Scene::Scene(ivec2 size) | |||
data->m_line_api.m_debug_mask = 1; | |||
} | |||
void Scene::resize(ivec2 size) | |||
{ | |||
m_wanted_size = size; | |||
} | |||
//----------------------------------------------------------------------------- | |||
Scene::~Scene() | |||
{ | |||
@@ -591,6 +597,23 @@ void Scene::pre_render(float) | |||
{ | |||
gpu_marker("Pre Render"); | |||
// Handle resize event | |||
if (m_size != m_wanted_size) | |||
{ | |||
m_size = m_wanted_size; | |||
delete data->m_renderbuffer[0]; | |||
delete data->m_renderbuffer[1]; | |||
delete data->m_renderbuffer[2]; | |||
delete data->m_renderbuffer[3]; | |||
data->m_renderbuffer[0] = new Framebuffer(m_size); | |||
data->m_renderbuffer[1] = new Framebuffer(m_size); | |||
data->m_renderbuffer[2] = new Framebuffer(m_size); | |||
data->m_renderbuffer[3] = new Framebuffer(m_size); | |||
mat4 proj = mat4::ortho(0.f, (float)m_size.x, 0.f, (float)m_size.y, -1000.f, 1000.f); | |||
data->m_default_cam->SetProjection(proj); | |||
} | |||
/* First render into the offline buffer */ | |||
if (do_pp) | |||
{ | |||
@@ -250,6 +250,8 @@ public: | |||
void EnableDisplay(); | |||
void DisableDisplay(); | |||
void resize(ivec2 size); | |||
void pre_render(float seconds); | |||
void render(float seconds); | |||
void post_render(float seconds); | |||
@@ -259,6 +261,8 @@ private: | |||
void render_tiles(); | |||
void render_lines(float seconds); | |||
ivec2 m_size, m_wanted_size; | |||
SceneData *data; | |||
Renderer *m_renderer; | |||
}; | |||
@@ -120,6 +120,11 @@ void Video::Capture(uint32_t *buffer) | |||
#endif | |||
} | |||
void Video::Resize(ivec2 size) | |||
{ | |||
Scene::GetScene(0).resize(size); | |||
} | |||
ivec2 Video::GetSize() | |||
{ | |||
return Scene::GetScene(0).get_renderer()->GetViewport().extent(); | |||
@@ -1,11 +1,13 @@ | |||
// | |||
// Lol Engine | |||
// Lol Engine | |||
// | |||
// Copyright: (c) 2010-2011 Sam Hocevar <sam@hocevar.net> | |||
// This program is free software; you can redistribute it and/or | |||
// modify it under the terms of the Do What The Fuck You Want To | |||
// Public License, Version 2, as published by Sam Hocevar. See | |||
// http://www.wtfpl.net/ for more details. | |||
// Copyright © 2010—2019 Sam Hocevar <sam@hocevar.net> | |||
// | |||
// Lol Engine is free software. It comes without any warranty, to | |||
// the extent permitted by applicable law. You can redistribute it | |||
// and/or modify it under the terms of the Do What the Fuck You Want | |||
// to Public License, Version 2, as published by the WTFPL Task Force. | |||
// See http://www.wtfpl.net/ for more details. | |||
// | |||
#pragma once | |||
@@ -49,6 +51,7 @@ public: | |||
static void Setup(ivec2 size); | |||
static void Destroy(); | |||
static void Resize(ivec2 size); | |||
static ivec2 GetSize(); | |||
static void SetDebugRenderMode(DebugRenderMode d); | |||