mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-01-05 19:19:39 -06:00
render TouchMarkers, currently causes crash on runtime
This commit is contained in:
@@ -25,7 +25,7 @@
|
||||
include(${OPENSPACE_CMAKE_EXT_DIR}/module_definition.cmake)
|
||||
|
||||
set(HEADER_FILES
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/ext/levmarq.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/ext/levmarq.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/include/TuioEar.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/include/TouchInteraction.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/include/TouchMarker.h
|
||||
@@ -33,17 +33,23 @@ set(HEADER_FILES
|
||||
source_group("Header Files" FILES ${HEADER_FILES})
|
||||
|
||||
set(SOURCE_FILES
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/ext/levmarq.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/ext/levmarq.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/TuioEar.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/TouchInteraction.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/TouchMarker.cpp
|
||||
)
|
||||
source_group("Source Files" FILES ${SOURCE_FILES})
|
||||
|
||||
set(SHADER_FILES
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/shaders/marker_fs.glsl
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/shaders/marker_vs.glsl
|
||||
)
|
||||
source_group("Shader Files" FILES ${SHADER_FILES})
|
||||
|
||||
create_new_module(
|
||||
"Touch"
|
||||
touch_module
|
||||
${HEADER_FILES} ${SOURCE_FILES}
|
||||
${HEADER_FILES} ${SOURCE_FILES} ${SHADER_FILES}
|
||||
)
|
||||
|
||||
include_external_library(${touch_module} libTUIO ${CMAKE_CURRENT_SOURCE_DIR}/ext/libTUIO)
|
||||
@@ -25,29 +25,64 @@
|
||||
#ifndef __OPENSPACE_TOUCH___MARKER___H__
|
||||
#define __OPENSPACE_TOUCH___MARKER___H__
|
||||
|
||||
#include <modules/touch/include/TuioEar.h>
|
||||
|
||||
#include <ghoul/opengl/ghoul_gl.h>
|
||||
#include <openspace/rendering/renderable.h>
|
||||
#include <openspace/properties/propertyowner.h>
|
||||
#include <openspace/properties/vectorproperty.h>
|
||||
#include <openspace/properties/stringproperty.h>
|
||||
#include <openspace/properties/scalar/boolproperty.h>
|
||||
#include <openspace/properties/scalar/floatproperty.h>
|
||||
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
|
||||
#include <math.h>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
#include <mutex>
|
||||
#include <numeric>
|
||||
#include <algorithm>
|
||||
|
||||
namespace ghoul {
|
||||
namespace opengl {
|
||||
class ProgramObject;
|
||||
class Texture;
|
||||
} // namespace opengl
|
||||
} // namespace ghoul
|
||||
|
||||
namespace openspace {
|
||||
|
||||
struct RenderData;
|
||||
struct UpdateData;
|
||||
|
||||
class TouchMarker : public properties::PropertyOwner
|
||||
{
|
||||
public:
|
||||
TouchMarker();
|
||||
|
||||
private:
|
||||
bool initialize(const std::vector<TUIO::TuioCursor> list);
|
||||
bool deinitialize();
|
||||
|
||||
bool isReady() const;
|
||||
|
||||
void render(const std::vector<TUIO::TuioCursor> list);
|
||||
void update();
|
||||
|
||||
|
||||
private:
|
||||
void loadTexture();
|
||||
void createVertexList(const std::vector<TUIO::TuioCursor> list);
|
||||
|
||||
properties::StringProperty _texturePath;
|
||||
properties::BoolProperty _visible;
|
||||
properties::FloatProperty _radiusSize;
|
||||
|
||||
std::unique_ptr<ghoul::opengl::ProgramObject> _shader;
|
||||
std::unique_ptr<ghoul::opengl::Texture> _texture;
|
||||
|
||||
GLuint _quad;
|
||||
GLuint _vertexPositionBuffer;
|
||||
int _numFingers;
|
||||
|
||||
bool _listIsDirty;
|
||||
bool _textureIsDirty;
|
||||
};
|
||||
|
||||
} // openspace namespace
|
||||
|
||||
66
modules/touch/shaders/marker_fs.glsl
Normal file
66
modules/touch/shaders/marker_fs.glsl
Normal file
@@ -0,0 +1,66 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* 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. *
|
||||
****************************************************************************************/
|
||||
|
||||
in vec2 out_position;
|
||||
in float pointRadius;
|
||||
|
||||
out vec4 FragColor;
|
||||
|
||||
void main () {
|
||||
|
||||
// calculate normal from texture coordinates
|
||||
//vec3 n;
|
||||
//n.xy = gl_PointCoord.st*vec2(2.0, -2.0) + vec2(-1.0, 1.0);
|
||||
//float mag = dot(n.xy, n.xy);
|
||||
//if (mag > 1.0) discard; // kill pixels outside circle
|
||||
//n.z = sqrt(1.0-mag);
|
||||
|
||||
//vec3 eye = mvPosition + vec3(0.0, 0.0, pointRadius * n.z);
|
||||
//float depth = (P[2][2] * eye.z + P[3][2]) / (P[2][3] * eye.z + P[3][3]);
|
||||
|
||||
//gl_FragDepth = (depth + 1.0) / 2.0;
|
||||
|
||||
|
||||
// calculate lighting
|
||||
//const vec3 light_dir = vec3(0.0, 0.0, 1.0);
|
||||
//float diffuse = max(0.0, dot(light_dir, n));
|
||||
|
||||
//vec3 halfVector = normalize( eye + light_dir);
|
||||
//float spec = pow(max(0.0, dot(n,halfVector)), 100.0);
|
||||
|
||||
// modify color according to the velocity
|
||||
//vec3 color = vec3(0.3, 0.3, 0.9);
|
||||
//vec3 hsv = rgb2hsv(color);
|
||||
//float v = length(outVelocity);
|
||||
//v = min((1.0/maxVelocity)*v*v, 1.0);
|
||||
//vec3 fluidColor = hsv2rgb(vec3(hsv.x, max(1.0 - v, 0.0), 1.0));
|
||||
|
||||
// compute final color
|
||||
//vec3 outColor = 0.25 * fluidColor;
|
||||
//outColor += 0.7 * diffuse * fluidColor;
|
||||
//outColor += 0.05 * spec * vec3(1.0);
|
||||
//outColor = clamp(outColor, 0.0, 1.0);
|
||||
|
||||
FragColor = vec4(1.0, 1.0, 1.0, 1.0);
|
||||
}
|
||||
43
modules/touch/shaders/marker_vs.glsl
Normal file
43
modules/touch/shaders/marker_vs.glsl
Normal file
@@ -0,0 +1,43 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* 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__
|
||||
|
||||
// Vertex attributes
|
||||
layout(location = 0) in vec2 in_position;
|
||||
|
||||
// Uniforms
|
||||
uniform float radius;
|
||||
|
||||
// Outputs
|
||||
out vec2 out_position;
|
||||
out float pointRadius;
|
||||
|
||||
void main() {
|
||||
out_position = in_position;
|
||||
pointRadius = 0.05; //radius;
|
||||
|
||||
gl_PointSize = 0.05; //radius;
|
||||
gl_Position = in_position;
|
||||
}
|
||||
@@ -25,11 +25,12 @@
|
||||
#include <modules/touch/include/TouchMarker.h>
|
||||
|
||||
#include <openspace/engine/openspaceengine.h>
|
||||
#include <openspace/engine/settingsengine.h>
|
||||
#include <openspace/engine/wrapper/windowwrapper.h>
|
||||
#include <openspace/interaction/interactionhandler.h>
|
||||
#include <openspace/rendering/renderengine.h>
|
||||
#include <openspace/rendering/screenspacerenderable.h>
|
||||
#include <ghoul/filesystem/filesystem.h>
|
||||
#include <ghoul/io/texture/texturereader.h>
|
||||
#include <ghoul/opengl/programobject.h>
|
||||
#include <ghoul/opengl/texture.h>
|
||||
#include <ghoul/opengl/textureunit.h>
|
||||
|
||||
#include <ghoul/logging/logmanager.h>
|
||||
|
||||
@@ -38,7 +39,141 @@ namespace {
|
||||
}
|
||||
namespace openspace {
|
||||
|
||||
TouchMarker::TouchMarker()
|
||||
: properties::PropertyOwner("TouchMarker") { }
|
||||
TouchMarker::TouchMarker()
|
||||
: properties::PropertyOwner("TouchMarker")
|
||||
, _visible("TouchMarkers visible", "Toggle visibility of markers", false)
|
||||
, _radiusSize("Marker size", "Set marker size in radius", 0.5, 0, 1)
|
||||
, _texturePath("texturePath", "Color Texture")
|
||||
, _shader(nullptr)
|
||||
, _texture(nullptr)
|
||||
, _listIsDirty(false)
|
||||
, _textureIsDirty(false)
|
||||
, _numFingers(0)
|
||||
{
|
||||
addProperty(_visible);
|
||||
addProperty(_radiusSize);
|
||||
addProperty(_texturePath);
|
||||
_texturePath.onChange(std::bind(&TouchMarker::loadTexture, this));
|
||||
|
||||
|
||||
}
|
||||
|
||||
bool TouchMarker::isReady() const {
|
||||
if (_shader == nullptr) {
|
||||
std::cout << "something went wrong\n";
|
||||
}
|
||||
return (_shader != nullptr); // && _texture;
|
||||
}
|
||||
|
||||
bool TouchMarker::initialize(const std::vector<TUIO::TuioCursor> list) {
|
||||
glGenVertexArrays(1, &_quad); // generate array
|
||||
glGenBuffers(1, &_vertexPositionBuffer); // generate buffer
|
||||
createVertexList(list);
|
||||
|
||||
_shader = OsEng.renderEngine().buildRenderProgram("MarkerProgram",
|
||||
"${MODULE_TOUCH}/shaders/marker_vs.glsl",
|
||||
"${MODULE_TOUCH}/shaders/marker_fs.glsl"
|
||||
);
|
||||
|
||||
//loadTexture();
|
||||
|
||||
return isReady();
|
||||
}
|
||||
|
||||
bool TouchMarker::deinitialize() {
|
||||
glDeleteVertexArrays(1, &_quad);
|
||||
_quad = 0;
|
||||
|
||||
glDeleteBuffers(1, &_vertexPositionBuffer);
|
||||
_vertexPositionBuffer = 0;
|
||||
|
||||
_texture = nullptr;
|
||||
|
||||
RenderEngine& renderEngine = OsEng.renderEngine();
|
||||
if (_shader) {
|
||||
renderEngine.removeRenderProgram(_shader);
|
||||
_shader = nullptr;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void TouchMarker::render(const std::vector<TUIO::TuioCursor> list) {
|
||||
if (_visible) {
|
||||
createVertexList(list);
|
||||
_shader->activate();
|
||||
|
||||
// Bind texture
|
||||
/*ghoul::opengl::TextureUnit unit;
|
||||
unit.activate();
|
||||
_texture->bind();
|
||||
_shader->setUniform("texture1", unit);*/
|
||||
_shader->setUniform("radius", _radiusSize);
|
||||
|
||||
glEnable(GL_PROGRAM_POINT_SIZE); // Enable gl_PointSize in vertex shader
|
||||
glPolygonMode(GL_FRONT_AND_BACK, GL_POINT);
|
||||
glBindVertexArray(_quad);
|
||||
glDrawArrays(GL_POINTS, 0, _numFingers);
|
||||
|
||||
_shader->deactivate();
|
||||
}
|
||||
}
|
||||
|
||||
void TouchMarker::update() {
|
||||
if (_shader->isDirty())
|
||||
_shader->rebuildFromFile();
|
||||
|
||||
if (_listIsDirty)
|
||||
//createFingerList();
|
||||
|
||||
if (_textureIsDirty) {
|
||||
loadTexture();
|
||||
_textureIsDirty = false;
|
||||
}
|
||||
}
|
||||
|
||||
void TouchMarker::loadTexture() {
|
||||
if (_texturePath.value() != "") {
|
||||
std::unique_ptr<ghoul::opengl::Texture> texture =
|
||||
ghoul::io::TextureReader::ref().loadTexture(absPath(_texturePath));
|
||||
|
||||
if (texture) {
|
||||
LDEBUGC(
|
||||
"TouchMarker",
|
||||
"Loaded texture from '" << absPath(_texturePath) << "'"
|
||||
);
|
||||
texture->uploadTexture();
|
||||
|
||||
// Textures of planets looks much smoother with AnisotropicMipMap rather than linear
|
||||
texture->setFilter(ghoul::opengl::Texture::FilterMode::AnisotropicMipMap);
|
||||
|
||||
_texture = std::move(texture);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void TouchMarker::createVertexList(const std::vector<TUIO::TuioCursor> list) {
|
||||
_numFingers = list.size();
|
||||
std::vector<GLfloat> vertexData(_numFingers * 2, 0);
|
||||
int i = 0;
|
||||
for (const TUIO::TuioCursor& c : list) {
|
||||
vertexData.at(i) = 2 * (c.getX() - 0.5);
|
||||
vertexData.at(i + 1) = -2 * (c.getY() - 0.5);
|
||||
i += 2;
|
||||
}
|
||||
|
||||
glBindVertexArray(_quad);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, _vertexPositionBuffer);
|
||||
glBufferData(GL_ARRAY_BUFFER, sizeof(vertexData.data()), vertexData.data(), GL_STATIC_DRAW);
|
||||
glEnableVertexAttribArray(0);
|
||||
glVertexAttribPointer(
|
||||
0,
|
||||
2,
|
||||
GL_FLOAT,
|
||||
GL_FALSE,
|
||||
0,
|
||||
reinterpret_cast<void*>(0)
|
||||
);
|
||||
}
|
||||
|
||||
} // openspace namespace
|
||||
@@ -23,7 +23,6 @@
|
||||
****************************************************************************************/
|
||||
|
||||
#include <modules/touch/include/TuioEar.h>
|
||||
#include <vector>
|
||||
|
||||
#include <openspace/engine/openspaceengine.h>
|
||||
#include <openspace/engine/settingsengine.h>
|
||||
|
||||
@@ -102,7 +102,24 @@ TouchModule::TouchModule()
|
||||
: OpenSpaceModule("Touch")
|
||||
{
|
||||
addPropertySubOwner(touch);
|
||||
|
||||
addPropertySubOwner(markers);
|
||||
|
||||
OsEng.registerModuleCallback(
|
||||
OpenSpaceEngine::CallbackOption::InitializeGL,
|
||||
[&]() {
|
||||
LDEBUGC("TouchModule", "Initializing TouchMarker OpenGL");
|
||||
markers.initialize(listOfContactPoints);
|
||||
}
|
||||
);
|
||||
|
||||
OsEng.registerModuleCallback(
|
||||
OpenSpaceEngine::CallbackOption::DeinitializeGL,
|
||||
[&]() {
|
||||
LDEBUGC("TouchMarker", "Deinitialize TouchMarker OpenGL");
|
||||
markers.deinitialize();
|
||||
}
|
||||
);
|
||||
|
||||
OsEng.registerModuleCallback(
|
||||
OpenSpaceEngine::CallbackOption::PreSync,
|
||||
[&]() {
|
||||
@@ -128,7 +145,8 @@ TouchModule::TouchModule()
|
||||
|
||||
OsEng.registerModuleCallback(
|
||||
OpenSpaceEngine::CallbackOption::PostDraw,
|
||||
[]() {
|
||||
[&]() {
|
||||
markers.render(listOfContactPoints);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@@ -26,9 +26,9 @@
|
||||
#define __OPENSPACE_MODULE_TOUCH___TOUCHMODULE___H__
|
||||
|
||||
#include <openspace/util/openspacemodule.h>
|
||||
#include <modules/touch/include/TuioEar.h>
|
||||
#include <modules/touch/include/TouchInteraction.h>
|
||||
#include <modules/touch/include/TouchMarker.h>
|
||||
#include <modules/touch/include/TouchInteraction.h>
|
||||
|
||||
|
||||
namespace openspace {
|
||||
|
||||
@@ -42,6 +42,7 @@ namespace openspace {
|
||||
|
||||
TuioEar ear;
|
||||
TouchInteraction touch;
|
||||
TouchMarker markers;
|
||||
std::vector<TUIO::TuioCursor> listOfContactPoints;
|
||||
std::vector<Point> lastProcessed; // contains an id and the TuioPoint that was processed last frame
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user