Graphics owo?

This commit is contained in:
maelstrom 2024-12-01 12:26:14 +01:00
parent da26fdae53
commit c75291a757
6 changed files with 116 additions and 5 deletions

View file

@ -1,3 +1,8 @@
CompileFlags: # Tweak the parse settings, example directory given to show format CompileFlags: # Tweak the parse settings, example directory given to show format
Add: Add:
- "--include-directory=../../src" - "--include-directory=../../src"
- "--include-directory=../src"
- "--include-directory=/usr/include/qt6/QtWidgets"
- "--include-directory=/usr/include/qt6/QtOpenGLWidgets"
- "--include-directory=/usr/include/qt6"
- "--include-directory=/usr/include/qt6/QtGui"

View file

@ -9,9 +9,13 @@ set(CMAKE_AUTORCC ON)
set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets LinguistTools) find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets LinguistTools)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets LinguistTools) find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets LinguistTools)
include_directories("../src")
set(TS_FILES editor_en_US.ts) set(TS_FILES editor_en_US.ts)
set(PROJECT_SOURCES set(PROJECT_SOURCES
@ -19,6 +23,8 @@ set(PROJECT_SOURCES
mainwindow.cpp mainwindow.cpp
mainwindow.h mainwindow.h
mainwindow.ui mainwindow.ui
mainglwidget.h
mainglwidget.cpp
${TS_FILES} ${TS_FILES}
) )
@ -26,6 +32,7 @@ if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
qt_add_executable(editor qt_add_executable(editor
MANUAL_FINALIZATION MANUAL_FINALIZATION
${PROJECT_SOURCES} ${PROJECT_SOURCES}
$<TARGET_OBJECTS:openblocks>
) )
# Define target properties for Android with Qt 6 as: # Define target properties for Android with Qt 6 as:
# set_property(TARGET editor APPEND PROPERTY QT_ANDROID_PACKAGE_SOURCE_DIR # set_property(TARGET editor APPEND PROPERTY QT_ANDROID_PACKAGE_SOURCE_DIR
@ -43,13 +50,15 @@ else()
else() else()
add_executable(editor add_executable(editor
${PROJECT_SOURCES} ${PROJECT_SOURCES}
mainglwidget.h mainglwidget.cpp
$<TARGET_OBJECTS:openblocks>
) )
endif() endif()
qt5_create_translation(QM_FILES ${CMAKE_SOURCE_DIR} ${TS_FILES}) qt5_create_translation(QM_FILES ${CMAKE_SOURCE_DIR} ${TS_FILES})
endif() endif()
target_link_libraries(editor PRIVATE Qt${QT_VERSION_MAJOR}::Widgets) target_link_libraries(editor PRIVATE Qt${QT_VERSION_MAJOR}::Widgets ${SDL2_LIBRARIES} ${GLEW_LIBRARIES} ${GLUT_LIBRARIES} OpenGL::GL OpenGL::GLU glfw glm::glm assimp ReactPhysics3D::ReactPhysics3D)
# Qt for iOS sets MACOSX_BUNDLE_GUI_IDENTIFIER automatically since Qt 6.1. # Qt for iOS sets MACOSX_BUNDLE_GUI_IDENTIFIER automatically since Qt 6.1.
# If you are developing for iOS or macOS you should consider setting an # If you are developing for iOS or macOS you should consider setting an
@ -74,4 +83,4 @@ install(TARGETS editor
if(QT_VERSION_MAJOR EQUAL 6) if(QT_VERSION_MAJOR EQUAL 6)
qt_finalize_executable(editor) qt_finalize_executable(editor)
endif() endif()

66
editor/mainglwidget.cpp Normal file
View file

@ -0,0 +1,66 @@
#include "GL/glew.h"
#include "part.h"
#include "rendering/renderer.h"
#include "physics/simulation.h"
#include "camera.h"
#include "common.h"
#include "mainglwidget.h"
MainGLWidget::MainGLWidget(QWidget* parent): QOpenGLWidget(parent) {}
void MainGLWidget::initializeGL() {
// Set up the rendering context, load shaders and other resources, etc.:
// QOpenGLFunctions *f = QOpenGLContext::currentContext()->functions();
// f->glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
glewInit();
simulationInit();
renderInit(NULL);
// Baseplate
parts.push_back(Part {
.position = glm::vec3(0, -5, 0),
.rotation = glm::vec3(0),
.scale = glm::vec3(512, 1.2, 512),
.material = Material {
.diffuse = glm::vec3(0.388235, 0.372549, 0.384314),
.specular = glm::vec3(0.5f, 0.5f, 0.5f),
.shininess = 32.0f,
},
.anchored = true,
});
syncPartPhysics(parts.back());
parts.push_back(Part {
.position = glm::vec3(0),
.rotation = glm::vec3(0),
.scale = glm::vec3(4, 1.2, 2),
.material = Material {
.diffuse = glm::vec3(0.639216f, 0.635294f, 0.647059f),
.specular = glm::vec3(0.5f, 0.5f, 0.5f),
.shininess = 32.0f,
}
});
syncPartPhysics(parts.back());
}
void MainGLWidget::resizeGL(int w, int h) {
// Update projection matrix and other size related settings:
// m_projection.setToIdentity();
// m_projection.perspective(45.0f, w / float(h), 0.01f, 100.0f);
// ...
}
float lastTime = glfwGetTime();
void MainGLWidget::paintGL() {
float deltaTime = glfwGetTime() - lastTime;
lastTime = glfwGetTime();
// processInput(NULL);
physicsStep(deltaTime);
::render(NULL);
}

17
editor/mainglwidget.h Normal file
View file

@ -0,0 +1,17 @@
#ifndef MAINGLWIDGET_H
#define MAINGLWIDGET_H
#include <QOpenGLWidget>
#include <QWidget>
class MainGLWidget : public QOpenGLWidget {
public:
MainGLWidget(QWidget *parent = nullptr);
protected:
void initializeGL() override;
void resizeGL(int w, int h) override;
void paintGL() override;
};
#endif // MAINGLWIDGET_H

View file

@ -5,6 +5,7 @@
#include <QMessageBox> #include <QMessageBox>
#include <QProcess> #include <QProcess>
#include <QThread> #include <QThread>
#include "mainglwidget.h"
MainWindow::MainWindow(QWidget *parent) MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent) : QMainWindow(parent)
@ -16,4 +17,4 @@ MainWindow::MainWindow(QWidget *parent)
MainWindow::~MainWindow() MainWindow::~MainWindow()
{ {
delete ui; delete ui;
} }

View file

@ -13,7 +13,13 @@
<property name="windowTitle"> <property name="windowTitle">
<string>MainWindow</string> <string>MainWindow</string>
</property> </property>
<widget class="QWidget" name="centralwidget"/> <widget class="QWidget" name="centralwidget">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="MainGLWidget" name="openGLWidget"/>
</item>
</layout>
</widget>
<widget class="QMenuBar" name="menubar"> <widget class="QMenuBar" name="menubar">
<property name="geometry"> <property name="geometry">
<rect> <rect>
@ -26,6 +32,13 @@
</widget> </widget>
<widget class="QStatusBar" name="statusbar"/> <widget class="QStatusBar" name="statusbar"/>
</widget> </widget>
<customwidgets>
<customwidget>
<class>MainGLWidget</class>
<extends>QOpenGLWidget</extends>
<header>mainglwidget.h</header>
</customwidget>
</customwidgets>
<resources/> <resources/>
<connections/> <connections/>
</ui> </ui>