Ogre
This commit is contained in:
parent
d28634dc1c
commit
46ac0e2be1
|
|
@ -14,5 +14,6 @@ set(CMAKE_AUTOMOC ON) # Enable Qt's automatic meta-object compiler
|
|||
|
||||
find_package(Boost REQUIRED)
|
||||
find_package(cglm REQUIRED CONFIG)
|
||||
find_package(OGRE REQUIRED COMPONENTS Bites CONFIG)
|
||||
|
||||
add_subdirectory(Projects)
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
material sky/null_plainsky512
|
||||
{
|
||||
technique
|
||||
{
|
||||
pass
|
||||
{
|
||||
lighting off
|
||||
depth_write off
|
||||
|
||||
texture_unit
|
||||
{
|
||||
cubic_texture sky/null_plainsky512_bk.jpg sky/null_plainsky512_ft.jpg sky/null_plainsky512_lf.jpg sky/null_plainsky512_rt.jpg sky/null_plainsky512_up.jpg sky/null_plainsky512_dn.jpg separateUV
|
||||
tex_address_mode clamp
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 10 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 5.3 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 12 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 11 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 11 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 6.4 KiB |
|
|
@ -1,7 +1,11 @@
|
|||
include_directories(${CMAKE_BINARY_DIR})
|
||||
|
||||
if(COMPILE_PLAYER OR COMPILE_STUDIO)
|
||||
if(LINUX)
|
||||
include(/usr/share/cmake/Modules/FindX11.cmake)
|
||||
endif()
|
||||
find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets OpenGLWidgets)
|
||||
set(QT6_LIBRARIES_INCL Qt6::Core Qt6::Gui Qt6::Widgets Qt6::OpenGLWidgets Qt6::GuiPrivate GLAD ${X11_X11_LIB})
|
||||
add_subdirectory(Common)
|
||||
|
||||
if(COMPILE_PLAYER)
|
||||
|
|
|
|||
|
|
@ -2,8 +2,6 @@ add_subdirectory(${DEPENDENCIES_DIR}/GLAD ${CMAKE_BINARY_DIR}/Dependencies/GLAD)
|
|||
|
||||
project(Common)
|
||||
|
||||
set(QT6_LIBRARIES_INCL Qt6::Core Qt6::Gui Qt6::Widgets Qt6::OpenGLWidgets GLAD)
|
||||
|
||||
qt_standard_project_setup()
|
||||
qt_add_library(Common STATIC
|
||||
Header/GL/Adorn.hpp
|
||||
|
|
|
|||
|
|
@ -2,29 +2,45 @@
|
|||
|
||||
#include <glad/glad.h>
|
||||
|
||||
#include <QWidget>
|
||||
#include <QOpenGLWidget>
|
||||
#include <QOpenGLContext>
|
||||
#include <QElapsedTimer>
|
||||
#include <QResizeEvent>
|
||||
#include <OGRE/Ogre.h>
|
||||
|
||||
#include <GL/Adorn.hpp>
|
||||
|
||||
namespace GL
|
||||
{
|
||||
class Widget : public QOpenGLWidget
|
||||
class Widget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
Widget(QWidget* parent = nullptr);
|
||||
Widget(Ogre::Root *root, QWidget* parent = nullptr);
|
||||
|
||||
double delta;
|
||||
double render_time;
|
||||
|
||||
Adorn* adorn;
|
||||
|
||||
Ogre::Root* ogreRoot;
|
||||
Ogre::RenderWindow* ogreWindow;
|
||||
Ogre::SceneManager* ogreSceneManager;
|
||||
Ogre::Camera* ogreCamera;
|
||||
|
||||
void render();
|
||||
void initializeOgre();
|
||||
|
||||
Ogre::NameValuePairList getRenderOptions();
|
||||
Ogre::String getWindowHandle();
|
||||
|
||||
protected:
|
||||
virtual void initialize();
|
||||
virtual void paint();
|
||||
virtual void resize(int x, int y);
|
||||
|
||||
virtual void paintEvent(QPaintEvent* pEvent);
|
||||
virtual void resizeEvent(QResizeEvent* rEvent);
|
||||
virtual void mouseMoveEvent(QMouseEvent *event);
|
||||
virtual QPaintEngine* paintEngine() const;
|
||||
private:
|
||||
QElapsedTimer timer;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,30 +1,121 @@
|
|||
#include <GL/Widget.hpp>
|
||||
#include <QApplication>
|
||||
|
||||
#ifdef __unix__
|
||||
#include <qpa/qplatformnativeinterface.h>
|
||||
#include <X11/Xlib.h>
|
||||
#endif
|
||||
|
||||
// credits to https://github.com/Ekman/Qt-Ogre-Widget
|
||||
namespace GL
|
||||
{
|
||||
Widget::Widget(QWidget* parent) : QOpenGLWidget(parent)
|
||||
Widget::Widget(Ogre::Root *root, QWidget *parent) : QWidget(parent)
|
||||
{
|
||||
this->adorn = new GL::Adorn();
|
||||
this->ogreRoot = root;
|
||||
this->setMinimumSize(640, 480);
|
||||
this->ogreWindow = NULL;
|
||||
|
||||
this->setAttribute(Qt::WA_OpaquePaintEvent);
|
||||
this->setAttribute(Qt::WA_PaintOnScreen);
|
||||
this->setMouseTracking(true);
|
||||
this->setCursor(QCursor(Qt::BlankCursor));
|
||||
this->setFocusPolicy(Qt::StrongFocus);
|
||||
}
|
||||
|
||||
void Widget::initialize()
|
||||
void Widget::initializeOgre()
|
||||
{
|
||||
printf("RNR::GLWidget::initialize: initializing\n");
|
||||
Ogre::NameValuePairList options = this->getRenderOptions();
|
||||
|
||||
if (gladLoadGL())
|
||||
printf("Widget::initializeOgre: initializing render window\n");
|
||||
ogreWindow = ogreRoot->createRenderWindow("GLWidget-RenderWindow", width(), height(), false, &options);
|
||||
ogreWindow->setActive(true);
|
||||
ogreWindow->setVisible(true);
|
||||
ogreWindow->setAutoUpdated(true);
|
||||
|
||||
Ogre::ResourceGroupManager::getSingletonPtr()->addResourceLocation("content", "FileSystem", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, true);
|
||||
Ogre::ResourceGroupManager::getSingletonPtr()->addResourceLocation("../Content", "FileSystem", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, true);
|
||||
|
||||
Ogre::ResourceGroupManager::getSingletonPtr()->initialiseAllResourceGroups();
|
||||
Ogre::MaterialManager::getSingletonPtr()->load("sky", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
|
||||
|
||||
ogreSceneManager = ogreRoot->createSceneManager();
|
||||
ogreSceneManager->setSkyBox(true, "sky/null_plainsky512", 5.f);
|
||||
ogreSceneManager->setAmbientLight(Ogre::ColourValue::White);
|
||||
|
||||
//Ogre::RTShader::ShaderGenerator* shadergen = Ogre::RTShader::ShaderGenerator::getSingletonPtr();
|
||||
//shadergen->addSceneManager(ogreSceneManager);
|
||||
|
||||
Ogre::Light* light = ogreSceneManager->createLight("MainLight");
|
||||
Ogre::SceneNode* lightNode = ogreSceneManager->getRootSceneNode()->createChildSceneNode();
|
||||
lightNode->setPosition(0, 10, 15);
|
||||
lightNode->attachObject(light);
|
||||
|
||||
Ogre::SceneNode* camNode = ogreSceneManager->getRootSceneNode()->createChildSceneNode();
|
||||
camNode->setPosition(0, 0, 5);
|
||||
camNode->lookAt(Ogre::Vector3(0, sinf(render_time), cosf(render_time)), Ogre::Node::TS_PARENT);
|
||||
|
||||
ogreCamera = ogreSceneManager->createCamera("myCam");
|
||||
ogreCamera->setNearClipDistance(0.1); // specific to this sample
|
||||
ogreCamera->setFarClipDistance(1000.f);
|
||||
ogreCamera->setAutoAspectRatio(true);
|
||||
camNode->attachObject(ogreCamera);
|
||||
|
||||
ogreWindow->addViewport(ogreCamera);
|
||||
this->render_time = 0.0;
|
||||
}
|
||||
|
||||
void Widget::render()
|
||||
{
|
||||
this->delta = ogreRoot->getTimer()->getMicroseconds() / 1000000.0;
|
||||
this->render_time += ogreRoot->getTimer()->getMilliseconds() / 1000.0;
|
||||
ogreRoot->getTimer()->reset();
|
||||
|
||||
ogreCamera->getParentSceneNode()->lookAt(Ogre::Vector3(sinf(render_time)*5.f, cosf(render_time)*5.f, 0.f), Ogre::Node::TS_PARENT);
|
||||
|
||||
ogreRoot->renderOneFrame(this->delta);
|
||||
}
|
||||
|
||||
Ogre::NameValuePairList Widget::getRenderOptions()
|
||||
{
|
||||
Ogre::NameValuePairList options;
|
||||
|
||||
options["externalWindowHandle"] = getWindowHandle();
|
||||
#if OGRE_PLATFORM == OGRE_PLATFORM_APPLE
|
||||
options["macAPI"] = "cocoa";
|
||||
options["macAPICocoaUseNSView"] = "true";
|
||||
#endif
|
||||
|
||||
return options;
|
||||
}
|
||||
|
||||
Ogre::String Widget::getWindowHandle()
|
||||
{
|
||||
Ogre::String windowHandle;
|
||||
windowHandle = Ogre::StringConverter::toString((unsigned long)window()->winId());
|
||||
printf("Widget::getWindowHandle(): %s\n", windowHandle.c_str());
|
||||
return windowHandle;
|
||||
}
|
||||
|
||||
void Widget::resizeEvent(QResizeEvent *rEvent)
|
||||
{
|
||||
QWidget::resizeEvent(rEvent);
|
||||
if(ogreWindow)
|
||||
{
|
||||
printf("RNR::GLWidget::initialize: initialized\n");
|
||||
QSize size = rEvent->size();
|
||||
ogreWindow->resize(size.width(), size.height());
|
||||
}
|
||||
}
|
||||
|
||||
void Widget::paint()
|
||||
void Widget::paintEvent(QPaintEvent *pEvent)
|
||||
{
|
||||
this->delta = ((double)this->timer.elapsed()) / 1000.0;
|
||||
this->timer.start();
|
||||
}
|
||||
|
||||
void Widget::resize(int x, int y)
|
||||
void Widget::mouseMoveEvent(QMouseEvent *mEvent)
|
||||
{
|
||||
printf("RNR::GLWidget::resize: resizing to (%i, %i)\n", x, y);
|
||||
}
|
||||
|
||||
QPaintEngine *Widget::paintEngine() const
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
|
@ -13,9 +13,9 @@ class MainWindow : public QMainWindow
|
|||
public:
|
||||
MainWindow();
|
||||
|
||||
Ogre::Root* ogreRoot;
|
||||
GL::Widget* widget;
|
||||
QTreeWidget* explorer;
|
||||
|
||||
protected:
|
||||
void closeEvent(QCloseEvent* event);
|
||||
};
|
||||
|
|
@ -1,5 +1,7 @@
|
|||
#include <MainWindow.hpp>
|
||||
#include <QGridLayout>
|
||||
#include <QTreeView>
|
||||
#include <QToolBar>
|
||||
|
||||
#include "Resources/StudioResources.hpp"
|
||||
|
||||
|
|
@ -11,16 +13,27 @@ MainWindow::MainWindow()
|
|||
QWidget* content_widget = new QWidget();
|
||||
QGridLayout* grid = new QGridLayout();
|
||||
|
||||
this->widget = new GL::Widget();
|
||||
grid->addWidget(this->widget, 0, 0, 1, 1);
|
||||
ogreRoot = new Ogre::Root();
|
||||
ogreRoot->showConfigDialog(NULL);
|
||||
ogreRoot->initialise(false);
|
||||
this->widget = new GL::Widget(ogreRoot);
|
||||
grid->addWidget(this->widget, 0, 0, 1, 2);
|
||||
QTreeView* instance_tree = new QTreeView();
|
||||
grid->addWidget(instance_tree, 0, 2, 1, 1);
|
||||
|
||||
content_widget->setLayout(grid);
|
||||
|
||||
grid->setContentsMargins(0,0,0,0);
|
||||
grid->setSpacing(0);
|
||||
|
||||
setWindowTitle(QString("RNR Studio"));
|
||||
setWindowIcon(QIcon(pixmap));
|
||||
setCentralWidget(content_widget);
|
||||
|
||||
QToolBar* tool_bar = new QToolBar(this);
|
||||
}
|
||||
|
||||
void MainWindow::closeEvent(QCloseEvent* event)
|
||||
{
|
||||
//
|
||||
|
||||
}
|
||||
|
|
@ -1,6 +1,8 @@
|
|||
#include <stdio.h>
|
||||
|
||||
#include <QApplication>
|
||||
#include <QSurfaceFormat>
|
||||
#include <QStatusBar>
|
||||
|
||||
#include <MainWindow.hpp>
|
||||
|
||||
|
|
@ -11,16 +13,17 @@ int main(int argc, char** argv)
|
|||
format.setSwapInterval(0);
|
||||
|
||||
QSurfaceFormat::setDefaultFormat(format);
|
||||
|
||||
QApplication app(argc, argv);
|
||||
MainWindow window = MainWindow();
|
||||
|
||||
window.show();
|
||||
window.widget->initializeOgre();
|
||||
|
||||
bool running = true;
|
||||
while (running)
|
||||
while (window.isVisible())
|
||||
{
|
||||
window.statusBar()->showMessage(QString::asprintf("Dt=%f, Rt=%f", window.widget->delta, window.widget->render_time));
|
||||
|
||||
app.processEvents();
|
||||
window.widget->update();
|
||||
window.widget->render();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +1,5 @@
|
|||
project(Engine)
|
||||
|
||||
include_directories(Engine/Header)
|
||||
|
||||
add_library(Engine STATIC
|
||||
Header/Helpers/Name.hpp
|
||||
|
|
@ -20,5 +19,8 @@ add_library(Engine STATIC
|
|||
Source/Rendering/Adorn.cpp
|
||||
)
|
||||
|
||||
target_include_directories(Engine PUBLIC Header)
|
||||
target_link_libraries(Engine PUBLIC ${BOOST_LIBRARIES} cglm Luau.Analysis Luau.Ast Luau.Compiler Luau.VM)
|
||||
target_include_directories(Engine PUBLIC ${BOOST_INCLUDE_DIRS} Header/)
|
||||
target_link_libraries(Engine PUBLIC ${BOOST_LIBRARIES} OgreBites cglm Luau.Analysis Luau.Ast Luau.Compiler Luau.VM)
|
||||
|
||||
file(COPY ${OGRE_CONFIG_DIR}/plugins.cfg ${OGRE_CONFIG_DIR}/resources.cfg
|
||||
DESTINATION ${CMAKE_BINARY_DIR})
|
||||
|
|
|
|||
Loading…
Reference in New Issue