Mercurial > hg > orthanc-stone
changeset 611:e3f21a265be5
Added version directive to GLSL shader code + glew init function in sample code
AND commented-out glew init function in StoneInitialize
author | Benjamin Golinvaux <bgo@osimis.io> |
---|---|
date | Tue, 30 Apr 2019 16:07:48 +0200 |
parents | 0c4c0693b97c |
children | ba72bffceb7d |
files | Framework/Scene2D/Internals/OpenGLColorTextureProgram.cpp Framework/Scene2D/Internals/OpenGLFloatTextureProgram.cpp Framework/Scene2D/Internals/OpenGLLinesProgram.cpp Framework/Scene2D/Internals/OpenGLShaderVersionDirective.h Framework/Scene2D/Internals/OpenGLTextProgram.cpp Framework/Scene2D/Internals/OpenGLTextureProgram.cpp Framework/StoneInitialization.cpp README.md Samples/Sdl/BasicScene.cpp |
diffstat | 9 files changed, 59 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/Framework/Scene2D/Internals/OpenGLColorTextureProgram.cpp Tue Apr 30 09:17:45 2019 +0200 +++ b/Framework/Scene2D/Internals/OpenGLColorTextureProgram.cpp Tue Apr 30 16:07:48 2019 +0200 @@ -20,9 +20,10 @@ #include "OpenGLColorTextureProgram.h" - +#include "OpenGLShaderVersionDirective.h" static const char* FRAGMENT_SHADER = + ORTHANC_STONE_OPENGL_SHADER_VERSION_DIRECTIVE "uniform sampler2D u_texture; \n" "varying vec2 v_texcoord; \n" "void main() \n"
--- a/Framework/Scene2D/Internals/OpenGLFloatTextureProgram.cpp Tue Apr 30 09:17:45 2019 +0200 +++ b/Framework/Scene2D/Internals/OpenGLFloatTextureProgram.cpp Tue Apr 30 16:07:48 2019 +0200 @@ -20,6 +20,7 @@ #include "OpenGLFloatTextureProgram.h" +#include "OpenGLShaderVersionDirective.h" #include <Core/OrthancException.h> #include <Core/Images/Image.h> @@ -27,6 +28,7 @@ static const char* FRAGMENT_SHADER = + ORTHANC_STONE_OPENGL_SHADER_VERSION_DIRECTIVE "uniform float u_offset; \n" "uniform float u_slope; \n" "uniform float u_windowCenter; \n"
--- a/Framework/Scene2D/Internals/OpenGLLinesProgram.cpp Tue Apr 30 09:17:45 2019 +0200 +++ b/Framework/Scene2D/Internals/OpenGLLinesProgram.cpp Tue Apr 30 16:07:48 2019 +0200 @@ -20,6 +20,7 @@ #include "OpenGLLinesProgram.h" +#include "OpenGLShaderVersionDirective.h" #include <Core/OrthancException.h> @@ -29,6 +30,7 @@ static const char* VERTEX_SHADER = + ORTHANC_STONE_OPENGL_SHADER_VERSION_DIRECTIVE "attribute vec2 a_miter_direction; \n" "attribute vec4 a_position; \n" "uniform float u_thickness; \n" @@ -42,6 +44,7 @@ static const char* FRAGMENT_SHADER = + ORTHANC_STONE_OPENGL_SHADER_VERSION_DIRECTIVE "uniform bool u_antialiasing; \n" "uniform float u_antialiasing_start; \n" "uniform vec3 u_color; \n"
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Framework/Scene2D/Internals/OpenGLShaderVersionDirective.h Tue Apr 30 16:07:48 2019 +0200 @@ -0,0 +1,3 @@ +#pragma once + +#define ORTHANC_STONE_OPENGL_SHADER_VERSION_DIRECTIVE "#version 110 core \n" \ No newline at end of file
--- a/Framework/Scene2D/Internals/OpenGLTextProgram.cpp Tue Apr 30 09:17:45 2019 +0200 +++ b/Framework/Scene2D/Internals/OpenGLTextProgram.cpp Tue Apr 30 16:07:48 2019 +0200 @@ -20,6 +20,7 @@ #include "OpenGLTextProgram.h" +#include "OpenGLShaderVersionDirective.h" #include "../../Fonts/OpenGLTextCoordinates.h" @@ -29,6 +30,7 @@ static const unsigned int COMPONENTS = 2; static const char* VERTEX_SHADER = + ORTHANC_STONE_OPENGL_SHADER_VERSION_DIRECTIVE "attribute vec2 a_texcoord; \n" "attribute vec4 a_position; \n" "uniform mat4 u_matrix; \n" @@ -40,6 +42,7 @@ "}"; static const char* FRAGMENT_SHADER = + ORTHANC_STONE_OPENGL_SHADER_VERSION_DIRECTIVE "uniform sampler2D u_texture; \n" "uniform vec3 u_color; \n" "varying vec2 v_texcoord; \n"
--- a/Framework/Scene2D/Internals/OpenGLTextureProgram.cpp Tue Apr 30 09:17:45 2019 +0200 +++ b/Framework/Scene2D/Internals/OpenGLTextureProgram.cpp Tue Apr 30 16:07:48 2019 +0200 @@ -20,11 +20,13 @@ #include "OpenGLTextureProgram.h" +#include "OpenGLShaderVersionDirective.h" static const unsigned int COMPONENTS = 2; static const unsigned int COUNT = 6; // 2 triangles in 2D static const char* VERTEX_SHADER = + ORTHANC_STONE_OPENGL_SHADER_VERSION_DIRECTIVE "attribute vec2 a_texcoord; \n" "attribute vec4 a_position; \n" "uniform mat4 u_matrix; \n"
--- a/Framework/StoneInitialization.cpp Tue Apr 30 09:17:45 2019 +0200 +++ b/Framework/StoneInitialization.cpp Tue Apr 30 16:07:48 2019 +0200 @@ -21,6 +21,7 @@ #include "StoneInitialization.h" +#include <Core/OrthancException.h> #include <Core/Logging.h> #if !defined(ORTHANC_ENABLE_SDL) @@ -32,6 +33,9 @@ # include "../Applications/Sdl/SdlWindow.h" #endif +#if ORTHANC_ENABLE_OPENGL == 1 +# include "GL/glew.h" +#endif namespace OrthancStone { @@ -39,6 +43,31 @@ { Orthanc::Logging::Initialize(); +#if 0 +#if ORTHANC_ENABLE_OPENGL == 1 + glEnable(GL_DEBUG_OUTPUT); + GLenum err = glewInit(); + if (GLEW_OK != err) + { + const char* error = + reinterpret_cast<const char*>(glewGetErrorString(err)); + if (strcmp(error, "Missing GL version") != 0) + { + std::stringstream msg; + msg << "Error while initializing OpenGL through GLEW: " << error; + throw Orthanc::OrthancException( + Orthanc::ErrorCode_InternalError,msg.str()); + } + } + { + std::stringstream message; + message << "Using GLEW version " << reinterpret_cast<const char*>( + glewGetString(GLEW_VERSION)); + LOG(INFO) << "Using GLEW version " << message.str(); + } +#endif +#endif + #if ORTHANC_ENABLE_SDL == 1 OrthancStone::SdlWindow::GlobalInitialize(); #endif
--- a/README.md Tue Apr 30 09:17:45 2019 +0200 +++ b/README.md Tue Apr 30 16:07:48 2019 +0200 @@ -236,9 +236,11 @@ url="https://doi.org/10.1007/s10278-018-0082-y" } -Various notes to be deleted +Various notes to be sorted --------------------------- -class BaseCommand : public ICommand +How to build the newest (2019-04-29) SDL samples under Windows, *inside* a +folder that is sibling to the orthanc-stone folder: -RadiographySceneCommand -GenericNoArgCommand +``` +cmake -G "Visual Studio 15 2017 Win64" -DMSVC_MULTIPLE_PROCESSES=ON -DENABLE_OPENGL=ON -DSTATIC_BUILD=ON -DOPENSSL_NO_CAPIENG=ON -DORTHANC_FRAMEWORK_SOURCE=path -DORTHANC_FRAMEWORK_ROOT="$($pwd)\..\orthanc" -DALLOW_DOWNLOADS=ON -DENABLE_SDL=ON ../orthanc-stone/Samples/Sdl +```
--- a/Samples/Sdl/BasicScene.cpp Tue Apr 30 09:17:45 2019 +0200 +++ b/Samples/Sdl/BasicScene.cpp Tue Apr 30 16:07:48 2019 +0200 @@ -274,9 +274,18 @@ void Run(OrthancStone::Scene2D& scene) { + OrthancStone::SdlOpenGLWindow window("Hello", 1024, 768); + + GLenum err = glewInit(); + if (GLEW_OK != err) + { + throw std::runtime_error("GLEW_OK != err"); + } + scene.FitContent(window.GetCanvasWidth(), window.GetCanvasHeight()); + glEnable(GL_DEBUG_OUTPUT); glDebugMessageCallback(OpenGLMessageCallback, 0 );