diff --git a/CMakeLists.txt b/CMakeLists.txt index 96f53da..12b7838 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) \ No newline at end of file diff --git a/Content/sky/null_plainsky512.material b/Content/sky/null_plainsky512.material new file mode 100644 index 0000000..dcaca03 --- /dev/null +++ b/Content/sky/null_plainsky512.material @@ -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 + } + } + } +} \ No newline at end of file diff --git a/Content/sky/null_plainsky512_bk.jpg b/Content/sky/null_plainsky512_bk.jpg new file mode 100644 index 0000000..9e042e2 Binary files /dev/null and b/Content/sky/null_plainsky512_bk.jpg differ diff --git a/Content/sky/null_plainsky512_dn.jpg b/Content/sky/null_plainsky512_dn.jpg new file mode 100644 index 0000000..e9281a2 Binary files /dev/null and b/Content/sky/null_plainsky512_dn.jpg differ diff --git a/Content/sky/null_plainsky512_ft.jpg b/Content/sky/null_plainsky512_ft.jpg new file mode 100644 index 0000000..c20ed21 Binary files /dev/null and b/Content/sky/null_plainsky512_ft.jpg differ diff --git a/Content/sky/null_plainsky512_lf.jpg b/Content/sky/null_plainsky512_lf.jpg new file mode 100644 index 0000000..12a95c1 Binary files /dev/null and b/Content/sky/null_plainsky512_lf.jpg differ diff --git a/Content/sky/null_plainsky512_rt.jpg b/Content/sky/null_plainsky512_rt.jpg new file mode 100644 index 0000000..ef1c45d Binary files /dev/null and b/Content/sky/null_plainsky512_rt.jpg differ diff --git a/Content/sky/null_plainsky512_up.jpg b/Content/sky/null_plainsky512_up.jpg new file mode 100644 index 0000000..efff81e Binary files /dev/null and b/Content/sky/null_plainsky512_up.jpg differ diff --git a/Projects/Client/CMakeLists.txt b/Projects/Client/CMakeLists.txt index 85372ea..d4f1fe0 100644 --- a/Projects/Client/CMakeLists.txt +++ b/Projects/Client/CMakeLists.txt @@ -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) diff --git a/Projects/Client/Common/CMakeLists.txt b/Projects/Client/Common/CMakeLists.txt index 8680259..a27d0d0 100644 --- a/Projects/Client/Common/CMakeLists.txt +++ b/Projects/Client/Common/CMakeLists.txt @@ -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 diff --git a/Projects/Client/Common/Header/GL/Widget.hpp b/Projects/Client/Common/Header/GL/Widget.hpp index 0cff0cb..0c1b37c 100644 --- a/Projects/Client/Common/Header/GL/Widget.hpp +++ b/Projects/Client/Common/Header/GL/Widget.hpp @@ -2,29 +2,45 @@ #include +#include #include +#include #include +#include +#include #include 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; }; diff --git a/Projects/Client/Common/Source/GL/Widget.cpp b/Projects/Client/Common/Source/GL/Widget.cpp index f28098f..5485385 100644 --- a/Projects/Client/Common/Source/GL/Widget.cpp +++ b/Projects/Client/Common/Source/GL/Widget.cpp @@ -1,30 +1,121 @@ #include +#include +#ifdef __unix__ +#include +#include +#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; } } \ No newline at end of file diff --git a/Projects/Client/Studio/Header/MainWindow.hpp b/Projects/Client/Studio/Header/MainWindow.hpp index e5e6c30..82faa98 100644 --- a/Projects/Client/Studio/Header/MainWindow.hpp +++ b/Projects/Client/Studio/Header/MainWindow.hpp @@ -13,9 +13,9 @@ class MainWindow : public QMainWindow public: MainWindow(); + Ogre::Root* ogreRoot; GL::Widget* widget; QTreeWidget* explorer; - protected: void closeEvent(QCloseEvent* event); }; \ No newline at end of file diff --git a/Projects/Client/Studio/Source/MainWindow.cpp b/Projects/Client/Studio/Source/MainWindow.cpp index 85aa4d1..34d2545 100644 --- a/Projects/Client/Studio/Source/MainWindow.cpp +++ b/Projects/Client/Studio/Source/MainWindow.cpp @@ -1,5 +1,7 @@ #include #include +#include +#include #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) { - // + } \ No newline at end of file diff --git a/Projects/Client/Studio/Source/main.cpp b/Projects/Client/Studio/Source/main.cpp index fcb98b9..c48a6a6 100644 --- a/Projects/Client/Studio/Source/main.cpp +++ b/Projects/Client/Studio/Source/main.cpp @@ -1,6 +1,8 @@ #include #include +#include +#include #include @@ -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(); } } \ No newline at end of file diff --git a/Projects/Engine/CMakeLists.txt b/Projects/Engine/CMakeLists.txt index 6243128..c798499 100644 --- a/Projects/Engine/CMakeLists.txt +++ b/Projects/Engine/CMakeLists.txt @@ -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) \ No newline at end of file +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})