mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-05-03 09:20:26 -05:00
Start adding loading screen code
This commit is contained in:
@@ -0,0 +1,59 @@
|
|||||||
|
/*****************************************************************************************
|
||||||
|
* *
|
||||||
|
* OpenSpace *
|
||||||
|
* *
|
||||||
|
* Copyright (c) 2014-2017 *
|
||||||
|
* *
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
|
||||||
|
* software and associated documentation files (the "Software"), to deal in the Software *
|
||||||
|
* without restriction, including without limitation the rights to use, copy, modify, *
|
||||||
|
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to the following *
|
||||||
|
* conditions: *
|
||||||
|
* *
|
||||||
|
* The above copyright notice and this permission notice shall be included in all copies *
|
||||||
|
* or substantial portions of the Software. *
|
||||||
|
* *
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
|
||||||
|
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
|
||||||
|
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
|
||||||
|
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
|
||||||
|
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
|
||||||
|
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||||
|
****************************************************************************************/
|
||||||
|
|
||||||
|
#ifndef __OPENSPACE_CORE___LOADINGSCREEN___H__
|
||||||
|
#define __OPENSPACE_CORE___LOADINGSCREEN___H__
|
||||||
|
|
||||||
|
#include <ghoul/glm.h>
|
||||||
|
#include <ghoul/opengl/ghoul_gl.h>
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
namespace ghoul::opengl {
|
||||||
|
class ProgramObject;
|
||||||
|
class Texture;
|
||||||
|
} // namespace ghoul::opengl
|
||||||
|
|
||||||
|
namespace openspace {
|
||||||
|
|
||||||
|
class LoadingScreen {
|
||||||
|
public:
|
||||||
|
LoadingScreen(glm::vec2 windowSize);
|
||||||
|
~LoadingScreen();
|
||||||
|
|
||||||
|
void render();
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::unique_ptr<ghoul::opengl::ProgramObject> _program;
|
||||||
|
std::unique_ptr<ghoul::opengl::Texture> _logoTexture;
|
||||||
|
|
||||||
|
glm::vec2 _windowSize;
|
||||||
|
|
||||||
|
GLuint _vao;
|
||||||
|
GLuint _vbo;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace openspace
|
||||||
|
|
||||||
|
#endif // __OPENSPACE_CORE___LOADINGSCREEN___H__
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
/*****************************************************************************************
|
||||||
|
* *
|
||||||
|
* OpenSpace *
|
||||||
|
* *
|
||||||
|
* Copyright (c) 2014 - 2017 *
|
||||||
|
* *
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
|
||||||
|
* software and associated documentation files (the "Software"), to deal in the Software *
|
||||||
|
* without restriction, including without limitation the rights to use, copy, modify, *
|
||||||
|
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to the following *
|
||||||
|
* conditions: *
|
||||||
|
* *
|
||||||
|
* The above copyright notice and this permission notice shall be included in all copies *
|
||||||
|
* or substantial portions of the Software. *
|
||||||
|
* *
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
|
||||||
|
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
|
||||||
|
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
|
||||||
|
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
|
||||||
|
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
|
||||||
|
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||||
|
****************************************************************************************/
|
||||||
|
|
||||||
|
#version __CONTEXT__
|
||||||
|
|
||||||
|
out vec4 FragColor;
|
||||||
|
|
||||||
|
uniform vec4 color;
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
FragColor = color;
|
||||||
|
}
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
/*****************************************************************************************
|
||||||
|
* *
|
||||||
|
* OpenSpace *
|
||||||
|
* *
|
||||||
|
* Copyright (c) 2014 - 2017 *
|
||||||
|
* *
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
|
||||||
|
* software and associated documentation files (the "Software"), to deal in the Software *
|
||||||
|
* without restriction, including without limitation the rights to use, copy, modify, *
|
||||||
|
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to the following *
|
||||||
|
* conditions: *
|
||||||
|
* *
|
||||||
|
* The above copyright notice and this permission notice shall be included in all copies *
|
||||||
|
* or substantial portions of the Software. *
|
||||||
|
* *
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
|
||||||
|
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
|
||||||
|
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
|
||||||
|
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
|
||||||
|
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
|
||||||
|
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||||
|
****************************************************************************************/
|
||||||
|
|
||||||
|
#version __CONTEXT__
|
||||||
|
|
||||||
|
in vec2 in_position;
|
||||||
|
|
||||||
|
uniform mat4 ortho;
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
gl_Position = ortho * vec4(in_position, 0.0, 1.0);
|
||||||
|
}
|
||||||
@@ -120,6 +120,7 @@ set(OPENSPACE_SOURCE
|
|||||||
${OPENSPACE_BASE_DIR}/src/query/query.cpp
|
${OPENSPACE_BASE_DIR}/src/query/query.cpp
|
||||||
${OPENSPACE_BASE_DIR}/src/rendering/abufferrenderer.cpp
|
${OPENSPACE_BASE_DIR}/src/rendering/abufferrenderer.cpp
|
||||||
${OPENSPACE_BASE_DIR}/src/rendering/framebufferrenderer.cpp
|
${OPENSPACE_BASE_DIR}/src/rendering/framebufferrenderer.cpp
|
||||||
|
${OPENSPACE_BASE_DIR}/src/rendering/loadingscreen.cpp
|
||||||
${OPENSPACE_BASE_DIR}/src/rendering/raycastermanager.cpp
|
${OPENSPACE_BASE_DIR}/src/rendering/raycastermanager.cpp
|
||||||
${OPENSPACE_BASE_DIR}/src/rendering/renderable.cpp
|
${OPENSPACE_BASE_DIR}/src/rendering/renderable.cpp
|
||||||
${OPENSPACE_BASE_DIR}/src/rendering/renderengine.cpp
|
${OPENSPACE_BASE_DIR}/src/rendering/renderengine.cpp
|
||||||
@@ -275,6 +276,7 @@ set(OPENSPACE_HEADER
|
|||||||
${OPENSPACE_BASE_DIR}/include/openspace/query/query.h
|
${OPENSPACE_BASE_DIR}/include/openspace/query/query.h
|
||||||
${OPENSPACE_BASE_DIR}/include/openspace/rendering/abufferrenderer.h
|
${OPENSPACE_BASE_DIR}/include/openspace/rendering/abufferrenderer.h
|
||||||
${OPENSPACE_BASE_DIR}/include/openspace/rendering/framebufferrenderer.h
|
${OPENSPACE_BASE_DIR}/include/openspace/rendering/framebufferrenderer.h
|
||||||
|
${OPENSPACE_BASE_DIR}/include/openspace/rendering/loadingscreen.h
|
||||||
${OPENSPACE_BASE_DIR}/include/openspace/rendering/raycasterlistener.h
|
${OPENSPACE_BASE_DIR}/include/openspace/rendering/raycasterlistener.h
|
||||||
${OPENSPACE_BASE_DIR}/include/openspace/rendering/raycastermanager.h
|
${OPENSPACE_BASE_DIR}/include/openspace/rendering/raycastermanager.h
|
||||||
${OPENSPACE_BASE_DIR}/include/openspace/rendering/renderable.h
|
${OPENSPACE_BASE_DIR}/include/openspace/rendering/renderable.h
|
||||||
|
|||||||
@@ -41,6 +41,7 @@
|
|||||||
#include <openspace/interaction/luaconsole.h>
|
#include <openspace/interaction/luaconsole.h>
|
||||||
#include <openspace/network/networkengine.h>
|
#include <openspace/network/networkengine.h>
|
||||||
#include <openspace/network/parallelconnection.h>
|
#include <openspace/network/parallelconnection.h>
|
||||||
|
#include <openspace/rendering/loadingscreen.h>
|
||||||
#include <openspace/rendering/renderable.h>
|
#include <openspace/rendering/renderable.h>
|
||||||
#include <openspace/scripting/scriptscheduler.h>
|
#include <openspace/scripting/scriptscheduler.h>
|
||||||
#include <openspace/scripting/scriptengine.h>
|
#include <openspace/scripting/scriptengine.h>
|
||||||
@@ -75,8 +76,6 @@
|
|||||||
|
|
||||||
#include <glbinding/callbacks.h>
|
#include <glbinding/callbacks.h>
|
||||||
|
|
||||||
#include <random>
|
|
||||||
|
|
||||||
#if defined(_MSC_VER) && defined(OPENSPACE_ENABLE_VLD)
|
#if defined(_MSC_VER) && defined(OPENSPACE_ENABLE_VLD)
|
||||||
#include <vld.h>
|
#include <vld.h>
|
||||||
#endif
|
#endif
|
||||||
@@ -615,22 +614,24 @@ void OpenSpaceEngine::loadScene(const std::string& scenePath) {
|
|||||||
_renderEngine->setGlobalBlackOutFactor(0.0);
|
_renderEngine->setGlobalBlackOutFactor(0.0);
|
||||||
_renderEngine->startFading(1, 3.0);
|
_renderEngine->startFading(1, 3.0);
|
||||||
|
|
||||||
// TODO remove after moving OpenGL out of initialize
|
// We can initialize all SceneGraphNodes in a separate thread since none of them use
|
||||||
|
// an OpenGL context
|
||||||
std::atomic_bool initializeFinished = false;
|
std::atomic_bool initializeFinished = false;
|
||||||
std::thread t([scene, &initializeFinished]() {
|
std::thread t([scene, &initializeFinished]() {
|
||||||
scene->initialize();
|
scene->initialize();
|
||||||
initializeFinished = true;
|
initializeFinished = true;
|
||||||
});
|
});
|
||||||
|
|
||||||
std::random_device rd;
|
|
||||||
std::mt19937 gen(rd());
|
|
||||||
std::uniform_real_distribution<> dis(0.0, 1.0);
|
LoadingScreen loadingScreen(_windowWrapper->currentWindowResolution());
|
||||||
|
// While the SceneGraphNodes initialize themselves, we can hand over control to the
|
||||||
|
// Loading screen rendering
|
||||||
while (!initializeFinished) {
|
while (!initializeFinished) {
|
||||||
glClearColor(dis(gen), dis(gen), dis(gen), 1.0);
|
loadingScreen.render();
|
||||||
glClear(ClearBufferMask::GL_COLOR_BUFFER_BIT);
|
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(250));
|
|
||||||
_windowWrapper->swapBuffer();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
t.join();
|
||||||
|
|
||||||
scene->initializeGL();
|
scene->initializeGL();
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,120 @@
|
|||||||
|
/*****************************************************************************************
|
||||||
|
* *
|
||||||
|
* OpenSpace *
|
||||||
|
* *
|
||||||
|
* Copyright (c) 2014-2017 *
|
||||||
|
* *
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
|
||||||
|
* software and associated documentation files (the "Software"), to deal in the Software *
|
||||||
|
* without restriction, including without limitation the rights to use, copy, modify, *
|
||||||
|
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to the following *
|
||||||
|
* conditions: *
|
||||||
|
* *
|
||||||
|
* The above copyright notice and this permission notice shall be included in all copies *
|
||||||
|
* or substantial portions of the Software. *
|
||||||
|
* *
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
|
||||||
|
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
|
||||||
|
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
|
||||||
|
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
|
||||||
|
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
|
||||||
|
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||||
|
****************************************************************************************/
|
||||||
|
|
||||||
|
#include <openspace/rendering/loadingscreen.h>
|
||||||
|
|
||||||
|
#include <openspace/engine/openspaceengine.h>
|
||||||
|
#include <openspace/engine/wrapper/windowwrapper.h>
|
||||||
|
|
||||||
|
#include <ghoul/filesystem/filesystem.h>
|
||||||
|
#include <ghoul/io/texture/texturereader.h>
|
||||||
|
#include <ghoul/opengl/programobject.h>
|
||||||
|
#include <ghoul/opengl/texture.h>
|
||||||
|
|
||||||
|
#include <random>
|
||||||
|
|
||||||
|
namespace openspace {
|
||||||
|
|
||||||
|
LoadingScreen::LoadingScreen(glm::vec2 windowSize)
|
||||||
|
: _windowSize(std::move(windowSize))
|
||||||
|
{
|
||||||
|
_program = ghoul::opengl::ProgramObject::Build(
|
||||||
|
"Loading Screen",
|
||||||
|
"${SHADERS}/loadingscreen.vert",
|
||||||
|
"${SHADERS}/loadingscreen.frag"
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
_logoTexture = ghoul::io::TextureReader::ref().loadTexture(absPath("${OPENSPACE_DATA}/openspace-logo.png"));
|
||||||
|
|
||||||
|
GLfloat data[] = {
|
||||||
|
0.f, 0.f,
|
||||||
|
1.f, 1.f,
|
||||||
|
0.f, 1.f,
|
||||||
|
|
||||||
|
0.f, 0.f,
|
||||||
|
1.f, 0.f,
|
||||||
|
1.f, 1.f
|
||||||
|
};
|
||||||
|
|
||||||
|
glGenVertexArrays(1, &_vao);
|
||||||
|
glBindVertexArray(_vao);
|
||||||
|
glGenBuffers(1, &_vbo);
|
||||||
|
glBindBuffer(GL_ARRAY_BUFFER, _vbo);
|
||||||
|
glBufferData(GL_ARRAY_BUFFER, sizeof(data), data, GL_STATIC_DRAW);
|
||||||
|
|
||||||
|
glEnableVertexAttribArray(0);
|
||||||
|
glVertexAttribPointer(
|
||||||
|
0,
|
||||||
|
2,
|
||||||
|
GL_FLOAT,
|
||||||
|
GL_FALSE,
|
||||||
|
2 * sizeof(GLfloat),
|
||||||
|
nullptr
|
||||||
|
);
|
||||||
|
|
||||||
|
glBindVertexArray(0);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
LoadingScreen::~LoadingScreen() {
|
||||||
|
_logoTexture = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
void LoadingScreen::render() {
|
||||||
|
// Clear background
|
||||||
|
glClearColor(0.8f, 0.8f, 0.8f, 1.f);
|
||||||
|
glClear(ClearBufferMask::GL_COLOR_BUFFER_BIT);
|
||||||
|
|
||||||
|
_program->activate();
|
||||||
|
|
||||||
|
_program->setUniform(
|
||||||
|
"ortho",
|
||||||
|
glm::ortho(
|
||||||
|
0.f, static_cast<float>(_windowSize.x), 0.f, static_cast<float>(_windowSize.y)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
std::random_device rd; //Will be used to obtain a seed for the random number engine
|
||||||
|
std::mt19937 gen(rd()); //Standard mersenne_twister_engine seeded with rd()
|
||||||
|
std::uniform_real_distribution<> dis(0.0, 1.0);
|
||||||
|
|
||||||
|
_program->setUniform(
|
||||||
|
"color",
|
||||||
|
glm::vec4(dis(gen), dis(gen), dis(gen), 1.f)
|
||||||
|
);
|
||||||
|
|
||||||
|
// Draw the background color
|
||||||
|
glBindVertexArray(_vao);
|
||||||
|
glDrawArrays(GL_TRIANGLES, 0, 6);
|
||||||
|
|
||||||
|
|
||||||
|
_program->deactivate();
|
||||||
|
|
||||||
|
|
||||||
|
std::this_thread::sleep_for(std::chrono::milliseconds(16));
|
||||||
|
OsEng.windowWrapper().swapBuffer();
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace openspace
|
||||||
Reference in New Issue
Block a user