Skip to content

Commit

Permalink
Fix OpenGL driver for Qt 6
Browse files Browse the repository at this point in the history
  • Loading branch information
kovzol committed Jan 20, 2024
1 parent 010d09e commit 30d3ffa
Show file tree
Hide file tree
Showing 18 changed files with 67 additions and 32 deletions.
21 changes: 12 additions & 9 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@ name: build
on: [push]

jobs:
linux:

linux-qmake:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v1
- name: prerequisites
Expand All @@ -17,9 +15,7 @@ jobs:
run: make

linux-cmake-deepzoom:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v1
- name: prerequisites
Expand All @@ -29,10 +25,19 @@ jobs:
- name: make
run: cd cbuild; make

mac:
linux-cmake-opengl:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: prerequisites
run: sudo apt update && sudo apt install build-essential qt6-base-dev qt6-tools-dev qt6-tools-dev-tools qt6-l10n-tools linguist-qt6 libgl1-mesa-dev freeglut3-dev
- name: cmake
run: mkdir cbuild; cd cbuild; cmake -DOPENGL=ON ..
- name: make
run: cd cbuild; make

mac-qmake:
runs-on: macos-latest

steps:
- uses: actions/checkout@v1
- name: install-qt
Expand All @@ -45,9 +50,7 @@ jobs:
run: make

mac-cmake:

runs-on: macos-latest

steps:
- uses: actions/checkout@v1
- name: install-qt
Expand Down
34 changes: 32 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,18 @@
# -DDEEPZOOM=ON
#
# on the cmake command line.
#
# * Alternatively, it is possible to build XaoS with the OpenGL driver. For this, you may need
# additional libraries:
#
# - freeglut3-dev
#
# Add
#
# -DOPENGL=ON
#
# on the cmake command line to enable the driver.


###########################################################################

Expand All @@ -66,17 +78,25 @@ cmake_minimum_required(VERSION 3.14.0)
project(XaoS)

option(DEEPZOOM "Use 128-bit float for deep zoom" OFF)
option(OPENGL "Use OpenGL" OFF)

if(DEEPZOOM)
add_definitions(-DUSE_FLOAT128) # may be unsupported on Mac, unless gcc/g++ is used
else(DEEPZOOM)
add_definitions(-DUSE_LONG_DOUBLE)
endif(DEEPZOOM)

if(OPENGL)
add_definitions(-DUSE_OPENGL)
endif(OPENGL)

# general definitions
add_definitions(-DUSE_SFFE -DSFFE_CMPLX_GSL)

# resolve symbolic links
set(CMAKE_FIND_PACKAGE_RESOLVE_SYMLINKS TRUE)

# by default, build a release (a non-debug executable)
if(NOT CMAKE_BUILD_TYPE)
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY VALUE Release)
endif(NOT CMAKE_BUILD_TYPE)
Expand All @@ -93,6 +113,13 @@ set(CMAKE_AUTORCC ON)
find_package(QT NAMES Qt6 COMPONENTS Widgets PrintSupport REQUIRED)
find_package(Qt6 COMPONENTS Widgets PrintSupport REQUIRED)

if(OPENGL)
find_package(QT NAMES Qt6 COMPONENTS OpenGL OpenGLWidgets REQUIRED)
find_package(Qt6 COMPONENTS OpenGL OpenGLWidgets REQUIRED)
find_package(GLUT REQUIRED)
find_package(OpenGL REQUIRED)
endif(OPENGL)

# OS specific stuff
# on macOS the QT libraries are usually not installed into the system library folders
if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
Expand Down Expand Up @@ -139,11 +166,14 @@ add_executable(XaoS MACOSX_BUNDLE
XaoS.qrc
)

# Link
# link libraries
target_link_libraries(XaoS Qt6::Widgets Qt6::PrintSupport)
if(DEEPZOOM)
target_link_libraries(XaoS quadmath)
target_link_libraries(XaoS quadmath)
endif(DEEPZOOM)
if(OPENGL)
target_link_libraries(XaoS Qt6::OpenGL Qt6::OpenGLWidgets)
endif(OPENGL)

# install bundle
install(TARGETS XaoS DESTINATION bin)
Expand Down
2 changes: 1 addition & 1 deletion src/engine/3d.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "config.h"
#include "config.h"
#include <cstdlib>
#include <cstdio> /*for NULL */
#include <cmath>
Expand Down
2 changes: 1 addition & 1 deletion src/ui-hlp/autod.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#ifndef UNSUPPORTED
#ifndef UNSUPPORTED
static inline int look1(uih_context *context, int x, int y, int range, int max)
{
cpixel_t *vbuff;
Expand Down
1 change: 0 additions & 1 deletion src/ui-hlp/autopilot.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

/*
* XaoS, a fast portable realtime fractal zoomer
* Copyright (C) 1996,1997 by
Expand Down
1 change: 0 additions & 1 deletion src/ui-hlp/autopilot.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

/*
* XaoS, a fast portable realtime fractal zoomer
* Copyright (C) 1996,1997 by
Expand Down
2 changes: 1 addition & 1 deletion src/ui-hlp/messg.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include <cstdlib>
#include <cstdlib>
#include <cstring>
#include "filter.h"
#include "fractal.h"
Expand Down
2 changes: 1 addition & 1 deletion src/ui-hlp/play.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include <climits>
#include <climits>
#include <cstdlib>
#include <cstring>
#include "config.h"
Expand Down
2 changes: 1 addition & 1 deletion src/ui-hlp/play.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#ifndef PLAY_H
#ifndef PLAY_H
#define PLAY_H
struct keyword {
char *name;
Expand Down
2 changes: 1 addition & 1 deletion src/ui-hlp/playtext.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include <cstdlib>
#include <cstdlib>

#include "config.h"
#include "filter.h"
Expand Down
1 change: 0 additions & 1 deletion src/ui-hlp/render.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

#include <cstring>
#include <cmath>
#include <cstdlib>
Expand Down
2 changes: 1 addition & 1 deletion src/ui-hlp/save.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#define __USE_MINGW_ANSI_STDIO 1 // for long double support on Windows
#define __USE_MINGW_ANSI_STDIO 1 // for long double support on Windows
#include <cstdio>
#include <climits>
#include <cstring>
Expand Down
2 changes: 1 addition & 1 deletion src/ui-hlp/wstack.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include <cstdlib>
#include <cstdlib>
#include <cstring>
#include <cassert>

Expand Down
13 changes: 9 additions & 4 deletions src/ui/fractalwidget.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "fractalwidget.h"
#include "fractalwidget.h"

#include <QtGui>
#ifdef USE_OPENGL
Expand Down Expand Up @@ -28,9 +28,14 @@ void FractalWidget::paintGL()
if (m_image) {
QImage *qimage =
reinterpret_cast<QImage **>(m_image->data)[m_image->currimage];
QImage glimage = QGLWidget::convertToGLFormat(*qimage);
glDrawPixels(glimage.width(), glimage.height(), GL_RGBA,
GL_UNSIGNED_BYTE, glimage.bits());
// QImage glimage = QGLWidget::convertToOpenGLFormat(*qimage);
// glDrawPixels(glimage.width(), glimage.height(), GL_RGBA,
// GL_UNSIGNED_BYTE, glimage.bits());
// For some reason, Qt 6 requires mirroring the image and using another color space.
// The old convertToOpenGLFormat is no longer supported in Qt 6.
QImage mirrored = qimage->mirrored(false, true);
glDrawPixels(qimage->width(), qimage->height(), GL_BGRA_EXT,
GL_UNSIGNED_BYTE, mirrored.bits());
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/ui/fractalwidget.h
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
#ifndef FRACTALWIDGET_H
#ifndef FRACTALWIDGET_H
#define FRACTALWIDGET_H

#include "config.h"
#include <QWidget>
#ifdef USE_OPENGL
#include <QGLWidget>
#include <QOpenGLWidget>
#endif
class QImage;
class QPoint;

#ifdef USE_OPENGL
class FractalWidget : public QGLWidget
class FractalWidget : public QOpenGLWidget
#else
class FractalWidget : public QWidget
#endif
Expand Down
2 changes: 1 addition & 1 deletion src/ui/image_qt.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include <QtWidgets>
#include <QtWidgets>
#include "config.h"
#include "filter.h"
#include "grlib.h"
Expand Down
2 changes: 1 addition & 1 deletion src/ui/mainwindow.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include <QtWidgets>
#include <QtWidgets>
#include <cassert>
#include <QTimer>
#include <iostream>
Expand Down
2 changes: 1 addition & 1 deletion src/ui/mainwindow.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#ifndef MAINWINDOW_H
#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
Expand Down

0 comments on commit 30d3ffa

Please sign in to comment.