view Samples/Qt/BasicScene.cpp @ 885:56e4e9281076 am-dev

sharing code between Qt/SDL BasiceScene sample
author Alain Mazy <alain@mazy.be>
date Tue, 09 Jul 2019 16:44:25 +0200
parents 30268a0cafca
children 6073c980323a
line wrap: on
line source

/**
 * Stone of Orthanc
 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
 * Department, University Hospital of Liege, Belgium
 * Copyright (C) 2017-2019 Osimis S.A., Belgium
 *
 * This program is free software: you can redistribute it and/or
 * modify it under the terms of the GNU Affero General Public License
 * as published by the Free Software Foundation, either version 3 of
 * the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 **/

#define GLEW_STATIC 1
// From Stone
#include "../../Framework/OpenGL/OpenGLIncludes.h"
#include "../../Applications/Sdl/SdlOpenGLWindow.h"
#include "../../Framework/Scene2D/CairoCompositor.h"
#include "../../Framework/Scene2D/ColorTextureSceneLayer.h"
#include "../../Framework/Scene2D/OpenGLCompositor.h"
#include "../../Framework/Scene2D/PanSceneTracker.h"
#include "../../Framework/Scene2D/RotateSceneTracker.h"
#include "../../Framework/Scene2D/Scene2D.h"
#include "../../Framework/Scene2D/ZoomSceneTracker.h"
#include "../../Framework/Scene2DViewport/ViewportController.h"
#include "../../Framework/Scene2DViewport/UndoStack.h"

#include "../../Framework/StoneInitialization.h"
#include "../../Framework/Messages/MessageBroker.h"

// From Orthanc framework
#include <Core/Logging.h>
#include <Core/OrthancException.h>
#include <Core/Images/Image.h>
#include <Core/Images/ImageProcessing.h>
#include <Core/Images/PngWriter.h>

#include <boost/make_shared.hpp>
#include <boost/ref.hpp>
#include "EmbeddedResources.h"

//#include <SDL.h>
#include <stdio.h>
#include <QDebug>
#include <QWindow>

#include "../Shared/SharedBasicScene.h"


using namespace OrthancStone;



static void GLAPIENTRY OpenGLMessageCallback(GLenum source,
                                             GLenum type,
                                             GLuint id,
                                             GLenum severity,
                                             GLsizei length,
                                             const GLchar* message,
                                             const void* userParam )
{
  if (severity != GL_DEBUG_SEVERITY_NOTIFICATION)
  {
    fprintf(stderr, "GL CALLBACK: %s type = 0x%x, severity = 0x%x, message = %s\n",
            ( type == GL_DEBUG_TYPE_ERROR ? "** GL ERROR **" : "" ),
            type, severity, message );
  }
}

extern void InitGL();

#include <QApplication>
#include "BasicSceneWindow.h"

int main(int argc, char* argv[])
{
  {
    QApplication a(argc, argv);

    QSurfaceFormat requestedFormat;
    requestedFormat.setVersion( 2, 0 );

    OrthancStone::Samples::BasicSceneWindow window;
    window.show();

    MessageBroker broker;
    boost::shared_ptr<UndoStack> undoStack(new UndoStack);
    boost::shared_ptr<ViewportController> controller = boost::make_shared<ViewportController>(
      undoStack, boost::ref(broker));
    PrepareScene(controller);

    boost::shared_ptr<OrthancStone::Scene2DInteractor> interactor(new BasicScene2DInteractor(controller));
    window.GetOpenGlWidget().SetInteractor(interactor);

    QOpenGLContext * context = new QOpenGLContext;
    context->setFormat( requestedFormat );
    context->create();
    context->makeCurrent(window.GetOpenGlWidget().context()->surface());

    boost::shared_ptr<OpenGLCompositor> compositor = boost::make_shared<OpenGLCompositor>(window.GetOpenGlWidget(), *controller->GetScene());
    compositor->SetFont(0, Orthanc::EmbeddedResources::UBUNTU_FONT,
                       BASIC_SCENE_FONT_SIZE, Orthanc::Encoding_Latin1);

    interactor->SetCompositor(compositor);
    window.GetOpenGlWidget().SetCompositor(compositor);

    return a.exec();
  }
}