mirror of
https://github.com/wheremyfoodat/Panda3DS.git
synced 2025-04-17 19:21:30 +12:00
Better GL screen widget, initialize it to red as a test
This commit is contained in:
parent
b8032c8286
commit
45a80c9e39
3 changed files with 36 additions and 19 deletions
|
@ -10,20 +10,7 @@ class ScreenWidget : public QWidget {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ScreenWidget(QWidget* parent = nullptr) : QWidget(parent) {
|
ScreenWidget(QWidget* parent = nullptr);
|
||||||
// Create a native window for use with our graphics API of choice
|
|
||||||
setAutoFillBackground(false);
|
|
||||||
setAttribute(Qt::WA_NativeWindow, true);
|
|
||||||
setAttribute(Qt::WA_NoSystemBackground, true);
|
|
||||||
setAttribute(Qt::WA_PaintOnScreen, true);
|
|
||||||
setAttribute(Qt::WA_KeyCompression, false);
|
|
||||||
setFocusPolicy(Qt::StrongFocus);
|
|
||||||
setMouseTracking(true);
|
|
||||||
|
|
||||||
if (!createGLContext()) {
|
|
||||||
Helpers::panic("Failed to create GL context for display");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::unique_ptr<GL::Context> glContext = nullptr;
|
std::unique_ptr<GL::Context> glContext = nullptr;
|
||||||
|
|
|
@ -12,6 +12,7 @@ int main(int argc, char *argv[]) {
|
||||||
window.setWindowTitle("Alber");
|
window.setWindowTitle("Alber");
|
||||||
ScreenWidget screen(&window);
|
ScreenWidget screen(&window);
|
||||||
screen.show();
|
screen.show();
|
||||||
|
screen.resize(320, 240);
|
||||||
|
|
||||||
return app.exec();
|
return app.exec();
|
||||||
}
|
}
|
|
@ -1,16 +1,45 @@
|
||||||
#include "panda_qt/screen.hpp"
|
#include "opengl.hpp"
|
||||||
|
// opengl.hpp must be included at the very top. This comment exists to make clang-format not reorder it :p
|
||||||
|
#include <QGuiApplication>
|
||||||
|
#include <QScreen>
|
||||||
|
#include <QWindow>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <array>
|
#include <array>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
#include <QGuiApplication>
|
|
||||||
#include <QScreen>
|
#include "panda_qt/screen.hpp"
|
||||||
#include <QWindow>
|
|
||||||
|
|
||||||
// OpenGL screen widget, based on https://github.com/melonDS-emu/melonDS/blob/master/src/frontend/qt_sdl/main.cpp
|
// OpenGL screen widget, based on https://github.com/melonDS-emu/melonDS/blob/master/src/frontend/qt_sdl/main.cpp
|
||||||
|
|
||||||
#ifdef PANDA3DS_ENABLE_OPENGL
|
#ifdef PANDA3DS_ENABLE_OPENGL
|
||||||
|
ScreenWidget::ScreenWidget(QWidget* parent) : QWidget(parent) {
|
||||||
|
// Create a native window for use with our graphics API of choice
|
||||||
|
setAutoFillBackground(false);
|
||||||
|
setAttribute(Qt::WA_NativeWindow, true);
|
||||||
|
setAttribute(Qt::WA_NoSystemBackground, true);
|
||||||
|
setAttribute(Qt::WA_PaintOnScreen, true);
|
||||||
|
setAttribute(Qt::WA_KeyCompression, false);
|
||||||
|
setFocusPolicy(Qt::StrongFocus);
|
||||||
|
setMouseTracking(true);
|
||||||
|
|
||||||
|
if (!createGLContext()) {
|
||||||
|
Helpers::panic("Failed to create GL context for display");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Make our context current to use it
|
||||||
|
glContext->MakeCurrent();
|
||||||
|
// Enable VSync for now
|
||||||
|
glContext->SetSwapInterval(1);
|
||||||
|
|
||||||
|
OpenGL::setViewport(320, 240);
|
||||||
|
OpenGL::setClearColor(1.0, 0.0, 0.0, 1.0);
|
||||||
|
OpenGL::clearColor();
|
||||||
|
|
||||||
|
// Swap buffers to display our red as a test
|
||||||
|
glContext->SwapBuffers();
|
||||||
|
}
|
||||||
|
|
||||||
bool ScreenWidget::createGLContext() {
|
bool ScreenWidget::createGLContext() {
|
||||||
// List of GL context versions we will try. Anything 4.1+ is good
|
// List of GL context versions we will try. Anything 4.1+ is good
|
||||||
static constexpr std::array<GL::Context::Version, 6> versionsToTry = {
|
static constexpr std::array<GL::Context::Version, 6> versionsToTry = {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue