Version initiale du logiciel. Développement commencé le 06/01/2026, en reprenant certaines parties/idées de miniDart, que j'ai écrit quelques années plus tôt
Cette révision appartient à :
+231
@@ -0,0 +1,231 @@
|
||||
Introduction
|
||||
|
||||
( English => This file contains "Modulations numériques" project history. )
|
||||
( Last changes are given in reverse order (as a stack : last changes at the top of the file), )
|
||||
( Please insert your changes on top, for readability reasons. )
|
||||
( Rule : every day is separated from the previous by a header : line + date + author )
|
||||
|
||||
French => Ce fichier contient l'historique du projet Modulations numériques.
|
||||
Les derniers ajouts sont donnés comme une pile (derniers ajouts en début de fichier)
|
||||
Merci d'insérer vos modifications en début de ce fichier, pour des raisons de lisibilité.
|
||||
Règle : chaque nouveau jour est séparé du précédent par une "en-tête" minimale : ligne de separation + date + auteur
|
||||
|
||||
Copyright ericb 2026/01/07
|
||||
Licence GPL v2 (see )
|
||||
|
||||
LAST CHANGES
|
||||
|
||||
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
||||
2026/01/25 ericb
|
||||
|
||||
Passage à OpenGL 3.3 (au lieu de 3.0)
|
||||
Remplacement de selectMenuTheme() par selectThemeMenu()
|
||||
Factorisation de code :
|
||||
- création de selectThemeMenu() // imgui_utils.cxx
|
||||
- création de selectFrameSize() // imgui_utils.cxx
|
||||
- tout le code SDL est maintenant encapsulé dans Engine
|
||||
Création de la classe Engine
|
||||
Implémentation de la classe Engine dans main.cxx (simplifications)
|
||||
Dans chaque onglet, ajout de app.set_current_tab() pour garantir l'état de l'onglet après redimensionnement
|
||||
Vérification des dimensionnements.
|
||||
Correction : suppression d'un ImGui::NewLine() pas très utile.
|
||||
Correction : ajout des fonctions manquantes dans imgui_utils (l'interface était incomplète)
|
||||
Correction : initialisation des dimensions de la fenêtre SDL dans la classe applications.
|
||||
|
||||
En test : les corrections de la modulation 16-QAM, proposées par vrst
|
||||
|
||||
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
||||
2026/01/18 ericb
|
||||
|
||||
Abstraction du nom de la fenêtre SDL3 principale
|
||||
Ajout de engine.h dans les sources pour tester la compilation
|
||||
(la classe engine est repris de miniDart, mais doit être simlifiée et rendue compatible avec SDL3)
|
||||
Implémentation de la modulation d'amplitude 16-QAM
|
||||
Description de la constellation 16-QAM (impossible faire tous les dessins, ce serait illissible)
|
||||
|
||||
En cours : Correction de engine.cxx en cours (passage SDL2 -> SDL3)
|
||||
|
||||
TODO :
|
||||
Inclusion progressive de la classe engine dans application.cxx et main.cxx (factorisation de code)
|
||||
Ajout de nouveaux événements (passage en plein écran via le menu)
|
||||
|
||||
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
||||
2026/01/17 ericb vrst tsbs
|
||||
|
||||
TODO :
|
||||
- implémentation de la modulation 16-QAM
|
||||
- essais de cross-compilation (version Windows)
|
||||
- documentation
|
||||
- tests unitaires à améliorer
|
||||
|
||||
Ajustement de l'écart pour les VToggleButtons, en fonction de la longueur de la Trame
|
||||
Ajout de l'entrée de menu "Longueur Trame"
|
||||
Déplacement de la modulation 4-QAM dans l'onglet ad hoc
|
||||
Ajout de l'onglet "Modulation numérique M-QAM"
|
||||
Tests de la trame avec 16 et 24 bits
|
||||
Implémentation de la classe Application
|
||||
Correction des coefficients 4-ASK qui étaient inversés
|
||||
Ajustement du rectangle de surbrillance
|
||||
Correction complète du layout
|
||||
Corrections variées : écartement entre les VToggleButtons correcte (pour 8 bits)
|
||||
|
||||
|
||||
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
||||
2026/01/16 ericb
|
||||
|
||||
TODO :
|
||||
- corriger le positionnement des boutons en plein écran (pas en face du bit modifié)
|
||||
- valider l'algorithme du DPSK, actuellement faux
|
||||
Améliorations possibles : pouvoir modifier la couleur du trait en runtime pour les tracés.
|
||||
Corrigé le trait lors du passage d'un bit à un autre lorsque la discontinuité est trop importante.
|
||||
Implémentation de la modulation umérique 4-QAM (principe de la TNT et du wifi 7)
|
||||
Utilisation de nouveaux contrôles pour modifier les bits du mot transmis
|
||||
Affichage de la signification d'un 1 ou d'un 0, sinon du symbole transmis sur 2 bits
|
||||
dans la fenêtre fille.
|
||||
Correction du nomnre de périodes affichées dans la fenêtre fille :
|
||||
- maintenant, le nombre de périodes affichées correspond au cas étudié.
|
||||
- la fréquence affichée coïncide avec le réglage
|
||||
|
||||
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
||||
2026/01/15 ericb
|
||||
|
||||
TODO : créer un layout proportionnel, et non avec des valeurs "magiques"
|
||||
Correction du redimensionnement : maintenant, quel que soit le thème, les couleurs sont respectées.
|
||||
Factorisation du code : mise en surbrillance, avec création de l'utilitaire highlightFrame()
|
||||
Création de imgui_utils.h (devrait devenir une classe d'objets utiles)
|
||||
Écriture du code qui permet d'écrire les bits autour des VToggleButtons
|
||||
Remerciements
|
||||
|
||||
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
||||
2026/01/14 ericb
|
||||
|
||||
Ajout de la modulation 4-QAM (qui ressemble à un cas particulier de 4-PSK)
|
||||
Création de imgui_utils.cxx
|
||||
Factorisation de code : ajout de drawVToggleButton()
|
||||
Ajout de drawVToggleButtons()
|
||||
Ajout de la partie documentation
|
||||
Ajout de la classe application
|
||||
|
||||
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
||||
2026/01/13 ericb
|
||||
|
||||
Bugfix : initialisation du thème corrigée. Tous les thèmes sont selectionables sans problème maintenant
|
||||
Ajout du CMakeList.txt, proposé par merx
|
||||
Essai de tests unitaires. À suivre demain avec les groupes 2 et 3
|
||||
|
||||
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
||||
2026/01/11 ericb
|
||||
|
||||
CODE : Partie 2 uniquement
|
||||
Correction partielle du layout :
|
||||
- identification de chaque paramètre utilisé ;
|
||||
- définition et choix de valeurs cohérentes ;
|
||||
- correction des alignements.
|
||||
|
||||
Simplification du code dans main + ajout de commentaires pour l'initialisation de dmod.
|
||||
Initialisation du constructeur de la classe modulation : les types de modulations doivent etre initialisés.
|
||||
Utiliser main(void) pour des raisons évidentes : on n'utilise pas d'arguments pour démarrer l'application.
|
||||
Correction du layout
|
||||
Utilisation d'un fichier pour la traduction. Exemple en français, mais qui pourra être facilement étendu à l'anglais.
|
||||
Ajout d'une entrée de menu : choix d'un thème de couleurs
|
||||
Implémentation des thèmes colorés : Light Green, Dark, Light Blue, Windows et Classic.
|
||||
|
||||
TODO : corriger le pb du layout qui perdure : la fenêtre n'est pas redimensionnable ...
|
||||
|
||||
DEBUT PARTIE2 : ajout d'une nouvelle arborescence appelée Code_final_partie2
|
||||
|
||||
|
||||
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
||||
PARTIE1
|
||||
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
||||
2026/01/10 ericb
|
||||
|
||||
Ajout d'un slider en mode DEBUG : permet de voir l'effet d'une modification de k x fbase (k entier, peut varier de 2 à 10)
|
||||
Correction des problèmes de compilation apportés par la modification du code.
|
||||
Modulation numérique de fréquence : 4 x fbase plutôt que 2 x fbase pour le signal modulé => meilleure visibilité
|
||||
Modulation numérique de Phase : modification de PSK en BPSK plus précis
|
||||
Corrections de fautes de frappes, orthographe variée sur la page de présentation.
|
||||
|
||||
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
||||
2026/01/09 ericb
|
||||
|
||||
Ajout d'un menu " Appliqation -> Quitter " à titre d'exemple (fonctionnel)
|
||||
TODO : améliorer l'algorithme pour le DPSK, qui n'a pas l'air d'être correct.
|
||||
Correction du bug de la fréquence qui ne variait pas en modulation numérique de phase.
|
||||
Mise à jour du README
|
||||
Ajout de la modulation numérique de fréquence. FSK et M-FSK sont opérationnels et fonctionnent comme attendu.
|
||||
Implémentation de la classe DignitalModulation. Fonctionne comme attendu pour la modulation d'amplitude numérique.
|
||||
Remplacement de bits[] par am_bits[] (am pour amplitude modulation), on utilisera aussi bm_bits, fm_bits[] et m_qam_bits[].
|
||||
Utilisation de M_PI (constante du système) au lieu de PI redéfinie maladroitement (nécessite des double).
|
||||
Test : pas de changement notable en utilisant M_PI à la place de PI.
|
||||
Ajouté : en mode DEBUG, un slider permet de voir ce qui se passe quand on modifie samples_per_bit
|
||||
|
||||
Bugfix : correction du Makefile qui n'ajoutait pas les symboles par défaut et qui compilait en double certains
|
||||
fichiers .cxx en mode debug
|
||||
|
||||
Ajout de la définition de DEFAULT_SAMPLES_PER_SYMBOL, défini à 100 par défaut (valeur optimale)
|
||||
Optimisation : calcul de l'amplitude remonté d'un niveau dans la boucle (ralentissait les calculs)
|
||||
Modification de l'initialisation de la longueur du mot avec DEFAULT_WORD_SIZE
|
||||
Suppression de BIT_COUNT, inapproprié.
|
||||
Correction de l'indentation, qui était chaotique.
|
||||
Cosmétique : variable de boucle définie à l'intérieur de la boucle, plutôt qu'à l'extérieur.
|
||||
Ajout de deux membres privés dans la classe modulation : le type et la taille du mot
|
||||
Création des assesseurs pour les membres privés
|
||||
Ajout de DEFAULT_WORD_SIZE (8 bits par défaut), en remplacement de BIT_COUNT, peu précis
|
||||
Compilation OK, pas de problème apparent.
|
||||
WARNING : Ne pas utiliser d'autre valeur que 8, sinon segfault (layout pose problème)
|
||||
|
||||
TODO : voir https://github.com/ocornut/imgui/issues/1537
|
||||
|
||||
Amélioration temporaire du layout (espacements, etc).
|
||||
Ajout du Changelog dans l'arborescence.
|
||||
Ajout de la définition des dimensions des sliders verticaux dans modulations.h
|
||||
Création de la classe modulations. Ajout dans l'arborescence.
|
||||
Commit : modification du makefile, et ajout de modulations.cxx.
|
||||
Test : compilation OK, mais la classe n'est pas encore utilisée (factorisation de code en cours)
|
||||
|
||||
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
||||
2026/01/08 ericb
|
||||
|
||||
Nettoyage de code, suppression de warnings, analyse de fonctionnement.
|
||||
Remplacement des "if" par un switch pour les 3 cas de modulation numérique d'amplitude.
|
||||
Factorisation de code : ajout de nouvelles entrées pour les modulations manquantes (typedef / modulations.h)
|
||||
Codage d'un caractère sur 2 bits avec l'utilisation de la parité
|
||||
Creation du fichier d'en-tête modulations.h et ajout dans le dépôt
|
||||
Correction du positionnement des sliders verticaux #HACK, car c'est le layout qui devrait décider
|
||||
Modification de la hauteur des sliders verticaux.
|
||||
Utilisation de la police (font) DroidSans en runtime. Le chemin est codé en dur et la fonte doit
|
||||
être placée dans le dossier fonts, au même niveau que build
|
||||
Correction de la prise en compte de nouveaux includes dans le makefile
|
||||
Tests du Makefile corrigé.
|
||||
TODO : penser à gérer la licence de la fonte DroidSans quelque part dans l'arborescence
|
||||
|
||||
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
||||
2026/01/07 ericb
|
||||
|
||||
Groups 2 and 3
|
||||
Ajout des boutons dont l'état est modiifiable (pas encore les sliders) dans la vue.
|
||||
Dessin d'une sinusoïde de fréquence variable (probablement généré avec chatGPT)
|
||||
|
||||
(à compléter avec ce qui a été fait)
|
||||
|
||||
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
||||
2026/01/06 ericb
|
||||
|
||||
Group 1 working, first tries (looks promising)
|
||||
|
||||
- starting with graphix3 code, to draw a window + an ImGui application inside an OpenGL context (orthogonal projection)
|
||||
- added some controls : silders, buttons
|
||||
- draw an SDL3 window + Dear ImGui (based on the example)
|
||||
- draw some controls inside and check (SliderFloat : 0 -> 9, draw sin 2Pi(f+af)t (a -> alpha, with alpha between 0 and 9)
|
||||
- Q : how to draw an sinusoid with IMGUI ? => cf demo widget
|
||||
|
||||
- Q : how to draw a vertical ON-OFF button ?
|
||||
- Q : how to draw and make radio buttons work ?
|
||||
- Q : how to add a text area ?
|
||||
- Q : how to add tabs ?
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
+125
@@ -0,0 +1,125 @@
|
||||
# Makefile pour illustrer la notion de surcharge d'opérateur en c++
|
||||
# incluant une nouvelle façon de créer un binaire exécutable
|
||||
# + une nouvelle façon de sécuriser ce binaire.
|
||||
|
||||
# Auteur : Eric Bachard
|
||||
# Ce document est sous Licence GPL v2 23 Septembre 2024
|
||||
# voir : http://www.gnu.org/licenses/gpl-2.0.html
|
||||
|
||||
UNAME_S = `uname -s`
|
||||
BUILD_DIR = build
|
||||
INCLUDE_DIR = inc
|
||||
APPLICATION_NAME = Modulations_Numeriques
|
||||
BINARY_NAME = ${BUILD_DIR}/${APPLICATION_NAME}
|
||||
|
||||
# please adapt the value to the gcc version
|
||||
# available on your machine
|
||||
#G++_VERSION = ...
|
||||
|
||||
CXX = g++${G++_VERSION}
|
||||
|
||||
SOURCES_DIR = src
|
||||
DEBUG_EXT = _debug
|
||||
CXX_STD=-std=c++20
|
||||
|
||||
INC_BACKEND = ${INCLUDE_DIR}/backend
|
||||
INC_FRONTEND = ${INCLUDE_DIR}/frontend
|
||||
LOCALIZATION_INC = localization
|
||||
|
||||
CXX_FLAGS += -I ${INCLUDE_DIR} -I ${LOCALIZATION_INC} -I ${INC_BACKEND} -I ${INC_FRONTEND} -I ${SOURCES_DIR}/gl3w/
|
||||
|
||||
CXX_FLAGS += -Wall -ansi -pedantic ${CXX_STD}
|
||||
|
||||
CXX_FLAGS += `pkg-config --cflags --libs sdl3`
|
||||
|
||||
LDD_CXX_FLAGS += `pkg-config --libs sdl3`
|
||||
|
||||
CXX_FLAGS_DEBUG = -g -DDEBUG -Wall -Wformat
|
||||
|
||||
|
||||
LIBS += -lm -lGL -dl ${LDD_CXX_FLAGS}
|
||||
|
||||
include secu.mk
|
||||
|
||||
# à modifier en fonction de vos besoins !!
|
||||
SRC_BACKEND = ${SOURCES_DIR}/backend
|
||||
SRC_FRONTEND = ${SOURCES_DIR}/frontend
|
||||
|
||||
SOURCES = \
|
||||
${SOURCES_DIR}/gl_helpers.cxx \
|
||||
${SOURCES_DIR}/modulations.cxx \
|
||||
${SOURCES_DIR}/imgui_utils.cxx \
|
||||
${SOURCES_DIR}/application.cxx \
|
||||
${SOURCES_DIR}/engine.cxx \
|
||||
${SOURCES_DIR}/main.cxx
|
||||
|
||||
SOURCES += \
|
||||
${SRC_FRONTEND}/imgui.cxx \
|
||||
${SRC_FRONTEND}/imgui_themes.cxx \
|
||||
${SRC_FRONTEND}/imgui_demo.cxx \
|
||||
${SRC_FRONTEND}/imgui_draw.cxx \
|
||||
${SRC_FRONTEND}/imgui_tables.cxx \
|
||||
${SRC_FRONTEND}/imgui_widgets.cxx
|
||||
|
||||
SOURCES += \
|
||||
${SRC_BACKEND}/imgui_impl_sdl3.cxx \
|
||||
${SRC_BACKEND}/imgui_impl_opengl3.cxx
|
||||
|
||||
|
||||
# todo : embed the DroidSans font
|
||||
# ${SOURCES_DIR}/${SRC_FRONTEND}/droidsans.cxx
|
||||
|
||||
|
||||
# works but looks buggy (only the first item of the list contains the right prefix)
|
||||
# that's the reason why the rule is slightly modified in the final collect
|
||||
OBJS = $(addsuffix .o, $(basename $(notdir $(SOURCES))))
|
||||
D_OBJS = $(addsuffix .do, $(basename $(notdir $(SOURCES))))
|
||||
|
||||
##---------------------------------------------------------------------
|
||||
## BUILD RULES
|
||||
##---------------------------------------------------------------------
|
||||
|
||||
#%.o:${SOURCES_DIR}/%.cxx
|
||||
# $(CXX) $(CXX_STD) ${EXTRA_CXX_FLAGS} ${CXX_FLAGS} -c -o ${BUILD_DIR}/$@ $<
|
||||
|
||||
#%.do:${SOURCES_DIR}/%.cxx
|
||||
# $(CXX) $(CXX_STD) ${CXX_FLAGS} ${CXX_FLAGS_DEBUG} ${EXTRA_CXX_FLAGS} ${CXX_FLAGS} ${CXX_FLAGS_DEBUG} -c -o ${BUILD_DIR}/$@ $<
|
||||
|
||||
%.o:${SOURCES_DIR}/%.cxx
|
||||
$(CXX) $(CXX_STD) ${CXX_FLAGS} ${EXTRA_CXX_FLAGS} $(CXXFLAGS) -c -o ${BUILD_DIR}/$@ $<
|
||||
|
||||
%.o:${SRC_BACKEND}/%.cxx
|
||||
$(CXX) $(CXX_STD) ${CXX_FLAGS} ${EXTRA_CXX_FLAGS} $(CXXFLAGS) -c -o ${BUILD_DIR}/$@ $<
|
||||
|
||||
%.o:${SRC_FRONTEND}/%.cxx
|
||||
$(CXX) $(CXX_STD) ${CXX_FLAGS} ${EXTRA_CXX_FLAGS} $(CXXFLAGS) -c -o ${BUILD_DIR}/$@ $<
|
||||
|
||||
%.do:${SOURCES_DIR}/%.cxx
|
||||
$(CXX) $(CXX_STD) ${CXX_FLAGS} ${CXX_FLAGS_DEBUG} ${EXTRA_CXX_FLAGS} $(CXXFLAGS) -c -o ${BUILD_DIR}/$@ $<
|
||||
|
||||
%.do:${SRC_BACKEND}/%.cxx
|
||||
$(CXX) $(CXX_STD) ${CXX_FLAGS} ${CXX_FLAGS_DEBUG} ${EXTRA_CXX_FLAGS} $(CXXFLAGS) -c -o ${BUILD_DIR}/$@ $<
|
||||
|
||||
%.do:${SRC_FRONTEND}/%.cxx
|
||||
$(CXX) $(CXX_STD) ${CXX_FLAGS} ${CXX_FLAGS_DEBUG} ${EXTRA_CXX_FLAGS} $(CXXFLAGS) -c -o ${BUILD_DIR}/$@ $<
|
||||
|
||||
%.do:${SOURCES_DIR}/gl3w/GL/%.c
|
||||
$(CC) $(CFLAGS) -c -o ${BUILD_DIR}/$@ $<
|
||||
|
||||
all: ${BINARY_NAME} ${BINARY_NAME}${DEBUG_EXT}
|
||||
@echo Build complete for ${UNAME_S}
|
||||
|
||||
${BINARY_NAME}: ${OBJS}
|
||||
$(CXX) $(CXX_STD) ${CXX_FLAGS} ${EXTRA_CXX_FLAGS} -DNDEBUG -o $@ ${BUILD_DIR}/*.o ${LIBS}
|
||||
strip $@
|
||||
rm -f ${BUILD_DIR}/*.o
|
||||
|
||||
${BINARY_NAME}_debug: ${D_OBJS}
|
||||
$(CXX) $(CXX_STD) ${CXX_FLAGS} ${CXX_FLAGS_DEBUG} ${EXTRA_CXX_FLAGS} -o $@ ${BUILD_DIR}/*.do ${LIBS}
|
||||
rm -f ${BUILD_DIR}/*.do
|
||||
|
||||
clean:
|
||||
echo Effacement de : ${BINARY_NAME}*
|
||||
rm -f ${BINARY_NAME}* ${BUILD_DIR}/*.o ${BUILD_DIR}/*.do
|
||||
|
||||
|
||||
+139
-1
@@ -1,3 +1,141 @@
|
||||
# Modulations numériques
|
||||
|
||||
Logiciel permettant de comprendre et de s'amuser avec les différentes modulations numériques. Les valeurs ne sont pas celles utilisées dans la réalité, mais permettent de bien visualiser le fonctionnement et les principes utilisés.
|
||||
Logiciel permettant de comprendre et de s'amuser avec les différentes modulations numériques. Les valeurs ne sont pas celles utilisées dans la réalité, mais permettent de bien visualiser le fonctionnement et les principes utilisés. # Découvrir le principe des Modulations Numériques (partie 2)
|
||||
|
||||
Constellation_modulation_numerique_16_QAM.png
|
||||
|
||||
<img style="text-align: center;" src="./images/Constellation_modulation_numerique_16_QAM.png" alt="Modulations numériques : constellation de la modulation 16-QAM (même technologie quele wifi)" width="400"/>
|
||||
|
||||
**Ci-dessus, la constellation de la modulation numérique avec 2 porteuses en quadrature, type 16-QAM (Le wifi 7 fontionne en 256-QAM)**.
|
||||
|
||||
## Objectif :
|
||||
|
||||
**Ajouter des fonctionnalités à un logiciel en C++ permettant de visualiser et comprendre les différents cas de modulations numériques (Amplitude, fréquence, phase et combo)**
|
||||
|
||||
Le travail est fait par 4 groupes de 16 élèves, successivement. *Dans chaque groupe*, **chaque tâche** sera réalisée par un **groupe de 4 élèves**. **30 min seront réservées en fin de séance pour préparer la transmission au groupe suivant**
|
||||
|
||||
**Thème : transporter l'information**
|
||||
|
||||
<img style="text-align: center;" src="./images/modulation_4-ASK_avec_application_quitter.png" alt="Modulations numériques : exemple avec la modulation 4-ASK avec explication du principe de codage" width="400"/>
|
||||
|
||||
**Modulation numérique 4-ASK + le menu "Application -> Quitter"**
|
||||
|
||||
|
||||
## Contraintes et attentes
|
||||
|
||||
- Utiliser Dear ImGui + SDL3 (imposé) ;
|
||||
- Logiciel écrit et testé sous Linux uniquement (toutefois, la cross-compilation est possible pour Windows) ;
|
||||
- dépendances : libSDL3 + mesa (OpenGL nécéssaire). N.B. : sans OpenGL fonctionnel, il faut compiler l'exemple d'implémentation dite "software rendering" ;
|
||||
- Travail par itérations : on travaille pour le prochain groupe ;
|
||||
- Documenter au maximum.
|
||||
|
||||
**Copyright : Eric Bachard 2026/01/07**
|
||||
|
||||
[**=> voir le Changelog**](./Changelog)
|
||||
|
||||
# Étude et validation des modulations numériques possibles avec le logiciel
|
||||
|
||||
Actuellement fonctionnel (2026/01/26) :
|
||||
|
||||
- [X] Longueur Trame de 8, 16 ou 24 bits, modifiable en temps réel
|
||||
- [X] OOK : On-Off Keying
|
||||
- [X] ASK : Amplitude Shift Keying
|
||||
- [X] M-ASK (ici 4-ASK) : 4 niveaux Amplitude Shift Keying
|
||||
- [X] 4-QAM : Quadrature Amplitude Modulation
|
||||
- [X] 16-QAM : Quadrature Amplitude Modulation
|
||||
- [X] FSK : Frequency Shift Keying
|
||||
- [X] M-FSK : Multiple Frequency Shift Keying
|
||||
- [X] BPSK : Binary Phase Shift Keying
|
||||
- [X] DPSK : Differential-PSK (à vérifier, sous réserves)
|
||||
- [X] Ajout des signification d'un 1 ou d'un 0 (dessin compris, sous forme d'un nouveau canvas, ainsi que des 4 combinaisons possibles lorqu'un symbole est codé sur 2 bits.
|
||||
- [X] Ajout d'un menu "Application -> Quitter" fonctionnel
|
||||
- [X] Layout amélioré : tout ce qui doit apparaître est correctement affiché, au bon endroit et avec les bonnes dimensions
|
||||
- [X] Fenêtre en plein écran avec les bonnes couleurs.
|
||||
- [X] Utilisation de CMake (automatisation de la génération du Makefile)
|
||||
- [X] Utilisation de nouveaux contrôles pour modifier les bits du mot transmis
|
||||
- [X] Sélection de thème parmi Dark, Clair, Windows, Classic et Traditionnal Green
|
||||
- [X] Utilisation de la classe application, qui permettra de gérer le layout et le thème.
|
||||
- [X] Utilisation de nouveaux contrôles pour modifier les bits du mot transmis
|
||||
- [X] Écriture d'une classe application, qui permettra de gérer le layout et le thème.
|
||||
|
||||
<img style="text-align: center;" src="./images/modulation_4-FSK.png" alt="Modulations numériques : exemple avec la modulation 4-FSK" class="center" width="400"/>
|
||||
|
||||
Problèmes ou bugs connus :
|
||||
|
||||
- flickering quand on passe du mode plein écran au mode réduit, à corriger.
|
||||
|
||||
**Modulation Numérique 4-FSK avec description de l'encodage**
|
||||
|
||||
|
||||
|
||||
<img style="text-align: center;" src="./images/modulation_BPSK_theme_DARK.png" alt="Modulations numériques : exemple avec la modulation BPSK + description de l'encodage" class="center" width="400"/>
|
||||
|
||||
**Modulation Numérique BPSK (Binary Phase Shift Keying) avec description de l'encodage, et le thème Dark**
|
||||
|
||||
|
||||
## Tâches prévues pour cette partie
|
||||
|
||||
À intégrer (le code est en cours de test) :
|
||||
|
||||
- [ ] Utiliser CTest (tests unitaires)
|
||||
- [ ] Rédaction de la documentation
|
||||
- [X] (en cours) Revisiter le placement des contrôles, en utilisant un dimensionnement proportionnel
|
||||
|
||||
|
||||
## Compilation du programme (Linux seulement pour le moment)
|
||||
|
||||
### Dépendances
|
||||
|
||||
Il faut installer :
|
||||
- build-essential ;
|
||||
- libSDL3 ;
|
||||
- carte graphique INTEL : Il faut OpenGL fonctionnel. Pour cela, installer mesa-utils (glxgears), devrait installer toutes les dépendances ;
|
||||
- carte graphique NVidia : OpenGL fonctionnel (pilote propriétaire avec bibliothèques ad-hoc, ou mesa-utils si driver nouveau).
|
||||
|
||||
Pour compiler l'application :
|
||||
|
||||
Dans un terminal, se placer à la racine de Partie2
|
||||
|
||||
````
|
||||
make -j $(nproc)
|
||||
````
|
||||
## Installation sous Linux
|
||||
|
||||
Si les dépendances sont installées (libSDL3 et OpenGL + un environnement graphique), le fonctionnement ne devrait pas poser de problèmes.
|
||||
|
||||
Le logiciel s'appelle Modulations_Numeriques, et peut s'exécutr de plusieurs façons : en mode console et en mode "graphique".
|
||||
### Utilisation en mode console
|
||||
|
||||
N.B. : ce qui suit permet une installation en mode graphique.
|
||||
|
||||
Dans le terminal, l'exécution est déjà possible avec la commande ./Modulations_Numeriques depuis le dossier build.
|
||||
|
||||
**TODO :** ajouter la règle du make install avec cmake
|
||||
|
||||
### En mode graphique
|
||||
|
||||
Pour l'instant, l'installation est manuelle. Testée sous Linux Mint 22.2
|
||||
|
||||
1. copier le fichier Modulations_Numeriques.desktop (il se trouve dans ressources), dans le dossier .local/share/applications
|
||||
|
||||
2. créer le dossier $HOME/bin/build et y copier le binaire compilé appelé Modulations_Numeriques qui se trouve dans build
|
||||
|
||||
3. copier le script Modulations_Numeriques (il se trouve dans ressources), dans le dossier $HOME/bin
|
||||
|
||||
4. rendre ce script exécutable
|
||||
|
||||
5. créer le dossier fonts dans $HOME/bin et y placer le fichier DroidSans.ttf qui se trouve dans le dossier fonts.
|
||||
|
||||
L'application devrait maintenant être utilisable en mode graphique.
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<img style="text-align: center;" src="./images/modulation_DPSK_avec_le_theme_LightGreen.png" alt="**Illustration du fonctionnement du menu : Application -> Quitter**" width="400"/>
|
||||
|
||||
**Modulation numérique DPSK (Differential Phase Shift Keying) avec le thème LightGreen.**
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Application.cxx Projet Modulations Numériques
|
||||
* Création : 2026/01/17 17h
|
||||
* Licence GPL v2
|
||||
* Copyright Eric Bachard 2026/01/13
|
||||
*/
|
||||
|
||||
#include "application.h"
|
||||
#include "imgui_themes.h"
|
||||
|
||||
Application::Application()
|
||||
: current_theme(DEFAULT_THEME), current_tab(Amplitude_TAB),
|
||||
windowWidth(DEFAULT_SDL_WINDOW_WIDTH),
|
||||
windowHeight(DEFAULT_SDL_WINDOW_HEIGHT)
|
||||
{
|
||||
}
|
||||
|
||||
Application::~Application()
|
||||
{
|
||||
}
|
||||
|
||||
void Application::set_current_tab(TAB_name aTab)
|
||||
{
|
||||
if (current_tab == aTab)
|
||||
return;
|
||||
|
||||
current_tab = aTab;
|
||||
}
|
||||
|
||||
|
||||
void Application::setTheme(THEME aTheme)
|
||||
{
|
||||
if (current_theme == aTheme)
|
||||
return;
|
||||
|
||||
switch(aTheme)
|
||||
{
|
||||
case LIGHT_GREEN_THEME:
|
||||
ImGui::StyleColorsLightGreen();
|
||||
break;
|
||||
|
||||
case DARK_THEME:
|
||||
ImGui::StyleColorsDark();
|
||||
break;
|
||||
|
||||
case CLASSIC_THEME:
|
||||
ImGui::StyleColorsClassic();
|
||||
break;
|
||||
|
||||
case LIGHT_BLUE_THEME:
|
||||
ImGui::StyleColorsLight();
|
||||
break;
|
||||
|
||||
case WINDOWS_THEME: ImGui::StyleColorsWindows();
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
current_theme = aTheme;
|
||||
}
|
||||
Fichier diff supprimé car celui-ci est trop grand
Voir la Diff
@@ -0,0 +1,830 @@
|
||||
// dear imgui: Platform Backend for SDL3
|
||||
// This needs to be used along with a Renderer (e.g. SDL_GPU, DirectX11, OpenGL3, Vulkan..)
|
||||
// (Info: SDL3 is a cross-platform general purpose library for handling windows, inputs, graphics context creation, etc.)
|
||||
|
||||
// Implemented features:
|
||||
// [X] Platform: Clipboard support.
|
||||
// [X] Platform: Mouse support. Can discriminate Mouse/TouchScreen.
|
||||
// [X] Platform: Keyboard support. Since 1.87 we are using the io.AddKeyEvent() function. Pass ImGuiKey values to all key functions e.g. ImGui::IsKeyPressed(ImGuiKey_Space). [Legacy SDL_SCANCODE_* values are obsolete since 1.87 and not supported since 1.91.5]
|
||||
// [X] Platform: Gamepad support.
|
||||
// [X] Platform: Mouse cursor shape and visibility (ImGuiBackendFlags_HasMouseCursors). Disable with 'io.ConfigFlags |= ImGuiConfigFlags_NoMouseCursorChange'.
|
||||
// [X] Platform: IME support.
|
||||
|
||||
// You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this.
|
||||
// Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need.
|
||||
// Learn about Dear ImGui:
|
||||
// - FAQ https://dearimgui.com/faq
|
||||
// - Getting Started https://dearimgui.com/getting-started
|
||||
// - Documentation https://dearimgui.com/docs (same as your local docs/ folder).
|
||||
// - Introduction, links and more at the top of imgui.cpp
|
||||
|
||||
// CHANGELOG
|
||||
// (minor and older changes stripped away, please see git history for details)
|
||||
// 2025-06-27: IME: avoid calling SDL_StartTextInput() again if already active. (#8727)
|
||||
// 2025-04-22: IME: honor ImGuiPlatformImeData->WantTextInput as an alternative way to call SDL_StartTextInput(), without IME being necessarily visible.
|
||||
// 2025-04-09: Don't attempt to call SDL_CaptureMouse() on drivers where we don't call SDL_GetGlobalMouseState(). (#8561)
|
||||
// 2025-03-30: Update for SDL3 api changes: Revert SDL_GetClipboardText() memory ownership change. (#8530, #7801)
|
||||
// 2025-03-21: Fill gamepad inputs and set ImGuiBackendFlags_HasGamepad regardless of ImGuiConfigFlags_NavEnableGamepad being set.
|
||||
// 2025-03-10: When dealing with OEM keys, use scancodes instead of translated keycodes to choose ImGuiKey values. (#7136, #7201, #7206, #7306, #7670, #7672, #8468)
|
||||
// 2025-02-26: Only start SDL_CaptureMouse() when mouse is being dragged, to mitigate issues with e.g.Linux debuggers not claiming capture back. (#6410, #3650)
|
||||
// 2025-02-24: Avoid calling SDL_GetGlobalMouseState() when mouse is in relative mode.
|
||||
// 2025-02-18: Added ImGuiMouseCursor_Wait and ImGuiMouseCursor_Progress mouse cursor support.
|
||||
// 2025-02-10: Using SDL_OpenURL() in platform_io.Platform_OpenInShellFn handler.
|
||||
// 2025-01-20: Made ImGui_ImplSDL3_SetGamepadMode(ImGui_ImplSDL3_GamepadMode_Manual) accept an empty array.
|
||||
// 2024-10-24: Emscripten: SDL_EVENT_MOUSE_WHEEL event doesn't require dividing by 100.0f on Emscripten.
|
||||
// 2024-09-03: Update for SDL3 api changes: SDL_GetGamepads() memory ownership revert. (#7918, #7898, #7807)
|
||||
// 2024-08-22: moved some OS/backend related function pointers from ImGuiIO to ImGuiPlatformIO:
|
||||
// - io.GetClipboardTextFn -> platform_io.Platform_GetClipboardTextFn
|
||||
// - io.SetClipboardTextFn -> platform_io.Platform_SetClipboardTextFn
|
||||
// - io.PlatformSetImeDataFn -> platform_io.Platform_SetImeDataFn
|
||||
// 2024-08-19: Storing SDL_WindowID inside ImGuiViewport::PlatformHandle instead of SDL_Window*.
|
||||
// 2024-08-19: ImGui_ImplSDL3_ProcessEvent() now ignores events intended for other SDL windows. (#7853)
|
||||
// 2024-07-22: Update for SDL3 api changes: SDL_GetGamepads() memory ownership change. (#7807)
|
||||
// 2024-07-18: Update for SDL3 api changes: SDL_GetClipboardText() memory ownership change. (#7801)
|
||||
// 2024-07-15: Update for SDL3 api changes: SDL_GetProperty() change to SDL_GetPointerProperty(). (#7794)
|
||||
// 2024-07-02: Update for SDL3 api changes: SDLK_x renames and SDLK_KP_x removals (#7761, #7762).
|
||||
// 2024-07-01: Update for SDL3 api changes: SDL_SetTextInputRect() changed to SDL_SetTextInputArea().
|
||||
// 2024-06-26: Update for SDL3 api changes: SDL_StartTextInput()/SDL_StopTextInput()/SDL_SetTextInputRect() functions signatures.
|
||||
// 2024-06-24: Update for SDL3 api changes: SDL_EVENT_KEY_DOWN/SDL_EVENT_KEY_UP contents.
|
||||
// 2024-06-03; Update for SDL3 api changes: SDL_SYSTEM_CURSOR_ renames.
|
||||
// 2024-05-15: Update for SDL3 api changes: SDLK_ renames.
|
||||
// 2024-04-15: Inputs: Re-enable calling SDL_StartTextInput()/SDL_StopTextInput() as SDL3 no longer enables it by default and should play nicer with IME.
|
||||
// 2024-02-13: Inputs: Fixed gamepad support. Handle gamepad disconnection. Added ImGui_ImplSDL3_SetGamepadMode().
|
||||
// 2023-11-13: Updated for recent SDL3 API changes.
|
||||
// 2023-10-05: Inputs: Added support for extra ImGuiKey values: F13 to F24 function keys, app back/forward keys.
|
||||
// 2023-05-04: Fixed build on Emscripten/iOS/Android. (#6391)
|
||||
// 2023-04-06: Inputs: Avoid calling SDL_StartTextInput()/SDL_StopTextInput() as they don't only pertain to IME. It's unclear exactly what their relation is to IME. (#6306)
|
||||
// 2023-04-04: Inputs: Added support for io.AddMouseSourceEvent() to discriminate ImGuiMouseSource_Mouse/ImGuiMouseSource_TouchScreen. (#2702)
|
||||
// 2023-02-23: Accept SDL_GetPerformanceCounter() not returning a monotonically increasing value. (#6189, #6114, #3644)
|
||||
// 2023-02-07: Forked "imgui_impl_sdl2" into "imgui_impl_sdl3". Removed version checks for old feature. Refer to imgui_impl_sdl2.cpp for older changelog.
|
||||
|
||||
#include "imgui.h"
|
||||
#ifndef IMGUI_DISABLE
|
||||
#include "imgui_impl_sdl3.h"
|
||||
|
||||
// Clang warnings with -Weverything
|
||||
#if defined(__clang__)
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wold-style-cast" // warning: use of old-style cast
|
||||
#pragma clang diagnostic ignored "-Wimplicit-int-float-conversion" // warning: implicit conversion from 'xxx' to 'float' may lose precision
|
||||
#endif
|
||||
|
||||
// SDL
|
||||
#include <SDL3/SDL.h>
|
||||
#include <stdio.h> // for snprintf()
|
||||
#if defined(__APPLE__)
|
||||
#include <TargetConditionals.h>
|
||||
#endif
|
||||
#ifdef _WIN32
|
||||
#ifndef WIN32_LEAN_AND_MEAN
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#endif
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
#if !defined(__EMSCRIPTEN__) && !defined(__ANDROID__) && !(defined(__APPLE__) && TARGET_OS_IOS) && !defined(__amigaos4__)
|
||||
#define SDL_HAS_CAPTURE_AND_GLOBAL_MOUSE 1
|
||||
#else
|
||||
#define SDL_HAS_CAPTURE_AND_GLOBAL_MOUSE 0
|
||||
#endif
|
||||
|
||||
// FIXME-LEGACY: remove when SDL 3.1.3 preview is released.
|
||||
#ifndef SDLK_APOSTROPHE
|
||||
#define SDLK_APOSTROPHE SDLK_QUOTE
|
||||
#endif
|
||||
#ifndef SDLK_GRAVE
|
||||
#define SDLK_GRAVE SDLK_BACKQUOTE
|
||||
#endif
|
||||
|
||||
// SDL Data
|
||||
struct ImGui_ImplSDL3_Data
|
||||
{
|
||||
SDL_Window* Window;
|
||||
SDL_WindowID WindowID;
|
||||
SDL_Renderer* Renderer;
|
||||
Uint64 Time;
|
||||
char* ClipboardTextData;
|
||||
char BackendPlatformName[48];
|
||||
|
||||
// IME handling
|
||||
SDL_Window* ImeWindow;
|
||||
|
||||
// Mouse handling
|
||||
Uint32 MouseWindowID;
|
||||
int MouseButtonsDown;
|
||||
SDL_Cursor* MouseCursors[ImGuiMouseCursor_COUNT];
|
||||
SDL_Cursor* MouseLastCursor;
|
||||
int MousePendingLeaveFrame;
|
||||
bool MouseCanUseGlobalState;
|
||||
bool MouseCanUseCapture;
|
||||
|
||||
// Gamepad handling
|
||||
ImVector<SDL_Gamepad*> Gamepads;
|
||||
ImGui_ImplSDL3_GamepadMode GamepadMode;
|
||||
bool WantUpdateGamepadsList;
|
||||
|
||||
ImGui_ImplSDL3_Data() { memset((void*)this, 0, sizeof(*this)); }
|
||||
};
|
||||
|
||||
// Backend data stored in io.BackendPlatformUserData to allow support for multiple Dear ImGui contexts
|
||||
// It is STRONGLY preferred that you use docking branch with multi-viewports (== single Dear ImGui context + multiple windows) instead of multiple Dear ImGui contexts.
|
||||
// FIXME: multi-context support is not well tested and probably dysfunctional in this backend.
|
||||
// FIXME: some shared resources (mouse cursor shape, gamepad) are mishandled when using multi-context.
|
||||
static ImGui_ImplSDL3_Data* ImGui_ImplSDL3_GetBackendData()
|
||||
{
|
||||
return ImGui::GetCurrentContext() ? (ImGui_ImplSDL3_Data*)ImGui::GetIO().BackendPlatformUserData : nullptr;
|
||||
}
|
||||
|
||||
// Functions
|
||||
static const char* ImGui_ImplSDL3_GetClipboardText(ImGuiContext*)
|
||||
{
|
||||
ImGui_ImplSDL3_Data* bd = ImGui_ImplSDL3_GetBackendData();
|
||||
if (bd->ClipboardTextData)
|
||||
SDL_free(bd->ClipboardTextData);
|
||||
bd->ClipboardTextData = SDL_GetClipboardText();
|
||||
return bd->ClipboardTextData;
|
||||
}
|
||||
|
||||
static void ImGui_ImplSDL3_SetClipboardText(ImGuiContext*, const char* text)
|
||||
{
|
||||
SDL_SetClipboardText(text);
|
||||
}
|
||||
|
||||
static void ImGui_ImplSDL3_PlatformSetImeData(ImGuiContext*, ImGuiViewport* viewport, ImGuiPlatformImeData* data)
|
||||
{
|
||||
ImGui_ImplSDL3_Data* bd = ImGui_ImplSDL3_GetBackendData();
|
||||
SDL_WindowID window_id = (SDL_WindowID)(intptr_t)viewport->PlatformHandle;
|
||||
SDL_Window* window = SDL_GetWindowFromID(window_id);
|
||||
if ((!(data->WantVisible || data->WantTextInput) || bd->ImeWindow != window) && bd->ImeWindow != nullptr)
|
||||
{
|
||||
SDL_StopTextInput(bd->ImeWindow);
|
||||
bd->ImeWindow = nullptr;
|
||||
}
|
||||
if (data->WantVisible)
|
||||
{
|
||||
SDL_Rect r;
|
||||
r.x = (int)data->InputPos.x;
|
||||
r.y = (int)data->InputPos.y;
|
||||
r.w = 1;
|
||||
r.h = (int)data->InputLineHeight;
|
||||
SDL_SetTextInputArea(window, &r, 0);
|
||||
bd->ImeWindow = window;
|
||||
}
|
||||
if (!SDL_TextInputActive(window) && (data->WantVisible || data->WantTextInput))
|
||||
SDL_StartTextInput(window);
|
||||
}
|
||||
|
||||
// Not static to allow third-party code to use that if they want to (but undocumented)
|
||||
ImGuiKey ImGui_ImplSDL3_KeyEventToImGuiKey(SDL_Keycode keycode, SDL_Scancode scancode);
|
||||
ImGuiKey ImGui_ImplSDL3_KeyEventToImGuiKey(SDL_Keycode keycode, SDL_Scancode scancode)
|
||||
{
|
||||
// Keypad doesn't have individual key values in SDL3
|
||||
switch (scancode)
|
||||
{
|
||||
case SDL_SCANCODE_KP_0: return ImGuiKey_Keypad0;
|
||||
case SDL_SCANCODE_KP_1: return ImGuiKey_Keypad1;
|
||||
case SDL_SCANCODE_KP_2: return ImGuiKey_Keypad2;
|
||||
case SDL_SCANCODE_KP_3: return ImGuiKey_Keypad3;
|
||||
case SDL_SCANCODE_KP_4: return ImGuiKey_Keypad4;
|
||||
case SDL_SCANCODE_KP_5: return ImGuiKey_Keypad5;
|
||||
case SDL_SCANCODE_KP_6: return ImGuiKey_Keypad6;
|
||||
case SDL_SCANCODE_KP_7: return ImGuiKey_Keypad7;
|
||||
case SDL_SCANCODE_KP_8: return ImGuiKey_Keypad8;
|
||||
case SDL_SCANCODE_KP_9: return ImGuiKey_Keypad9;
|
||||
case SDL_SCANCODE_KP_PERIOD: return ImGuiKey_KeypadDecimal;
|
||||
case SDL_SCANCODE_KP_DIVIDE: return ImGuiKey_KeypadDivide;
|
||||
case SDL_SCANCODE_KP_MULTIPLY: return ImGuiKey_KeypadMultiply;
|
||||
case SDL_SCANCODE_KP_MINUS: return ImGuiKey_KeypadSubtract;
|
||||
case SDL_SCANCODE_KP_PLUS: return ImGuiKey_KeypadAdd;
|
||||
case SDL_SCANCODE_KP_ENTER: return ImGuiKey_KeypadEnter;
|
||||
case SDL_SCANCODE_KP_EQUALS: return ImGuiKey_KeypadEqual;
|
||||
default: break;
|
||||
}
|
||||
switch (keycode)
|
||||
{
|
||||
case SDLK_TAB: return ImGuiKey_Tab;
|
||||
case SDLK_LEFT: return ImGuiKey_LeftArrow;
|
||||
case SDLK_RIGHT: return ImGuiKey_RightArrow;
|
||||
case SDLK_UP: return ImGuiKey_UpArrow;
|
||||
case SDLK_DOWN: return ImGuiKey_DownArrow;
|
||||
case SDLK_PAGEUP: return ImGuiKey_PageUp;
|
||||
case SDLK_PAGEDOWN: return ImGuiKey_PageDown;
|
||||
case SDLK_HOME: return ImGuiKey_Home;
|
||||
case SDLK_END: return ImGuiKey_End;
|
||||
case SDLK_INSERT: return ImGuiKey_Insert;
|
||||
case SDLK_DELETE: return ImGuiKey_Delete;
|
||||
case SDLK_BACKSPACE: return ImGuiKey_Backspace;
|
||||
case SDLK_SPACE: return ImGuiKey_Space;
|
||||
case SDLK_RETURN: return ImGuiKey_Enter;
|
||||
case SDLK_ESCAPE: return ImGuiKey_Escape;
|
||||
//case SDLK_APOSTROPHE: return ImGuiKey_Apostrophe;
|
||||
case SDLK_COMMA: return ImGuiKey_Comma;
|
||||
//case SDLK_MINUS: return ImGuiKey_Minus;
|
||||
case SDLK_PERIOD: return ImGuiKey_Period;
|
||||
//case SDLK_SLASH: return ImGuiKey_Slash;
|
||||
case SDLK_SEMICOLON: return ImGuiKey_Semicolon;
|
||||
//case SDLK_EQUALS: return ImGuiKey_Equal;
|
||||
//case SDLK_LEFTBRACKET: return ImGuiKey_LeftBracket;
|
||||
//case SDLK_BACKSLASH: return ImGuiKey_Backslash;
|
||||
//case SDLK_RIGHTBRACKET: return ImGuiKey_RightBracket;
|
||||
//case SDLK_GRAVE: return ImGuiKey_GraveAccent;
|
||||
case SDLK_CAPSLOCK: return ImGuiKey_CapsLock;
|
||||
case SDLK_SCROLLLOCK: return ImGuiKey_ScrollLock;
|
||||
case SDLK_NUMLOCKCLEAR: return ImGuiKey_NumLock;
|
||||
case SDLK_PRINTSCREEN: return ImGuiKey_PrintScreen;
|
||||
case SDLK_PAUSE: return ImGuiKey_Pause;
|
||||
case SDLK_LCTRL: return ImGuiKey_LeftCtrl;
|
||||
case SDLK_LSHIFT: return ImGuiKey_LeftShift;
|
||||
case SDLK_LALT: return ImGuiKey_LeftAlt;
|
||||
case SDLK_LGUI: return ImGuiKey_LeftSuper;
|
||||
case SDLK_RCTRL: return ImGuiKey_RightCtrl;
|
||||
case SDLK_RSHIFT: return ImGuiKey_RightShift;
|
||||
case SDLK_RALT: return ImGuiKey_RightAlt;
|
||||
case SDLK_RGUI: return ImGuiKey_RightSuper;
|
||||
case SDLK_APPLICATION: return ImGuiKey_Menu;
|
||||
case SDLK_0: return ImGuiKey_0;
|
||||
case SDLK_1: return ImGuiKey_1;
|
||||
case SDLK_2: return ImGuiKey_2;
|
||||
case SDLK_3: return ImGuiKey_3;
|
||||
case SDLK_4: return ImGuiKey_4;
|
||||
case SDLK_5: return ImGuiKey_5;
|
||||
case SDLK_6: return ImGuiKey_6;
|
||||
case SDLK_7: return ImGuiKey_7;
|
||||
case SDLK_8: return ImGuiKey_8;
|
||||
case SDLK_9: return ImGuiKey_9;
|
||||
case SDLK_A: return ImGuiKey_A;
|
||||
case SDLK_B: return ImGuiKey_B;
|
||||
case SDLK_C: return ImGuiKey_C;
|
||||
case SDLK_D: return ImGuiKey_D;
|
||||
case SDLK_E: return ImGuiKey_E;
|
||||
case SDLK_F: return ImGuiKey_F;
|
||||
case SDLK_G: return ImGuiKey_G;
|
||||
case SDLK_H: return ImGuiKey_H;
|
||||
case SDLK_I: return ImGuiKey_I;
|
||||
case SDLK_J: return ImGuiKey_J;
|
||||
case SDLK_K: return ImGuiKey_K;
|
||||
case SDLK_L: return ImGuiKey_L;
|
||||
case SDLK_M: return ImGuiKey_M;
|
||||
case SDLK_N: return ImGuiKey_N;
|
||||
case SDLK_O: return ImGuiKey_O;
|
||||
case SDLK_P: return ImGuiKey_P;
|
||||
case SDLK_Q: return ImGuiKey_Q;
|
||||
case SDLK_R: return ImGuiKey_R;
|
||||
case SDLK_S: return ImGuiKey_S;
|
||||
case SDLK_T: return ImGuiKey_T;
|
||||
case SDLK_U: return ImGuiKey_U;
|
||||
case SDLK_V: return ImGuiKey_V;
|
||||
case SDLK_W: return ImGuiKey_W;
|
||||
case SDLK_X: return ImGuiKey_X;
|
||||
case SDLK_Y: return ImGuiKey_Y;
|
||||
case SDLK_Z: return ImGuiKey_Z;
|
||||
case SDLK_F1: return ImGuiKey_F1;
|
||||
case SDLK_F2: return ImGuiKey_F2;
|
||||
case SDLK_F3: return ImGuiKey_F3;
|
||||
case SDLK_F4: return ImGuiKey_F4;
|
||||
case SDLK_F5: return ImGuiKey_F5;
|
||||
case SDLK_F6: return ImGuiKey_F6;
|
||||
case SDLK_F7: return ImGuiKey_F7;
|
||||
case SDLK_F8: return ImGuiKey_F8;
|
||||
case SDLK_F9: return ImGuiKey_F9;
|
||||
case SDLK_F10: return ImGuiKey_F10;
|
||||
case SDLK_F11: return ImGuiKey_F11;
|
||||
case SDLK_F12: return ImGuiKey_F12;
|
||||
case SDLK_F13: return ImGuiKey_F13;
|
||||
case SDLK_F14: return ImGuiKey_F14;
|
||||
case SDLK_F15: return ImGuiKey_F15;
|
||||
case SDLK_F16: return ImGuiKey_F16;
|
||||
case SDLK_F17: return ImGuiKey_F17;
|
||||
case SDLK_F18: return ImGuiKey_F18;
|
||||
case SDLK_F19: return ImGuiKey_F19;
|
||||
case SDLK_F20: return ImGuiKey_F20;
|
||||
case SDLK_F21: return ImGuiKey_F21;
|
||||
case SDLK_F22: return ImGuiKey_F22;
|
||||
case SDLK_F23: return ImGuiKey_F23;
|
||||
case SDLK_F24: return ImGuiKey_F24;
|
||||
case SDLK_AC_BACK: return ImGuiKey_AppBack;
|
||||
case SDLK_AC_FORWARD: return ImGuiKey_AppForward;
|
||||
default: break;
|
||||
}
|
||||
|
||||
// Fallback to scancode
|
||||
switch (scancode)
|
||||
{
|
||||
case SDL_SCANCODE_GRAVE: return ImGuiKey_GraveAccent;
|
||||
case SDL_SCANCODE_MINUS: return ImGuiKey_Minus;
|
||||
case SDL_SCANCODE_EQUALS: return ImGuiKey_Equal;
|
||||
case SDL_SCANCODE_LEFTBRACKET: return ImGuiKey_LeftBracket;
|
||||
case SDL_SCANCODE_RIGHTBRACKET: return ImGuiKey_RightBracket;
|
||||
case SDL_SCANCODE_NONUSBACKSLASH: return ImGuiKey_Oem102;
|
||||
case SDL_SCANCODE_BACKSLASH: return ImGuiKey_Backslash;
|
||||
case SDL_SCANCODE_SEMICOLON: return ImGuiKey_Semicolon;
|
||||
case SDL_SCANCODE_APOSTROPHE: return ImGuiKey_Apostrophe;
|
||||
case SDL_SCANCODE_COMMA: return ImGuiKey_Comma;
|
||||
case SDL_SCANCODE_PERIOD: return ImGuiKey_Period;
|
||||
case SDL_SCANCODE_SLASH: return ImGuiKey_Slash;
|
||||
default: break;
|
||||
}
|
||||
return ImGuiKey_None;
|
||||
}
|
||||
|
||||
static void ImGui_ImplSDL3_UpdateKeyModifiers(SDL_Keymod sdl_key_mods)
|
||||
{
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
io.AddKeyEvent(ImGuiMod_Ctrl, (sdl_key_mods & SDL_KMOD_CTRL) != 0);
|
||||
io.AddKeyEvent(ImGuiMod_Shift, (sdl_key_mods & SDL_KMOD_SHIFT) != 0);
|
||||
io.AddKeyEvent(ImGuiMod_Alt, (sdl_key_mods & SDL_KMOD_ALT) != 0);
|
||||
io.AddKeyEvent(ImGuiMod_Super, (sdl_key_mods & SDL_KMOD_GUI) != 0);
|
||||
}
|
||||
|
||||
|
||||
static ImGuiViewport* ImGui_ImplSDL3_GetViewportForWindowID(SDL_WindowID window_id)
|
||||
{
|
||||
ImGui_ImplSDL3_Data* bd = ImGui_ImplSDL3_GetBackendData();
|
||||
return (window_id == bd->WindowID) ? ImGui::GetMainViewport() : nullptr;
|
||||
}
|
||||
|
||||
// You can read the io.WantCaptureMouse, io.WantCaptureKeyboard flags to tell if dear imgui wants to use your inputs.
|
||||
// - When io.WantCaptureMouse is true, do not dispatch mouse input data to your main application, or clear/overwrite your copy of the mouse data.
|
||||
// - When io.WantCaptureKeyboard is true, do not dispatch keyboard input data to your main application, or clear/overwrite your copy of the keyboard data.
|
||||
// Generally you may always pass all inputs to dear imgui, and hide them from your application based on those two flags.
|
||||
// If you have multiple SDL events and some of them are not meant to be used by dear imgui, you may need to filter events based on their windowID field.
|
||||
bool ImGui_ImplSDL3_ProcessEvent(const SDL_Event* event)
|
||||
{
|
||||
ImGui_ImplSDL3_Data* bd = ImGui_ImplSDL3_GetBackendData();
|
||||
IM_ASSERT(bd != nullptr && "Context or backend not initialized! Did you call ImGui_ImplSDL3_Init()?");
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
|
||||
switch (event->type)
|
||||
{
|
||||
case SDL_EVENT_MOUSE_MOTION:
|
||||
{
|
||||
if (ImGui_ImplSDL3_GetViewportForWindowID(event->motion.windowID) == nullptr)
|
||||
return false;
|
||||
ImVec2 mouse_pos((float)event->motion.x, (float)event->motion.y);
|
||||
io.AddMouseSourceEvent(event->motion.which == SDL_TOUCH_MOUSEID ? ImGuiMouseSource_TouchScreen : ImGuiMouseSource_Mouse);
|
||||
io.AddMousePosEvent(mouse_pos.x, mouse_pos.y);
|
||||
return true;
|
||||
}
|
||||
case SDL_EVENT_MOUSE_WHEEL:
|
||||
{
|
||||
if (ImGui_ImplSDL3_GetViewportForWindowID(event->wheel.windowID) == nullptr)
|
||||
return false;
|
||||
//IMGUI_DEBUG_LOG("wheel %.2f %.2f, precise %.2f %.2f\n", (float)event->wheel.x, (float)event->wheel.y, event->wheel.preciseX, event->wheel.preciseY);
|
||||
float wheel_x = -event->wheel.x;
|
||||
float wheel_y = event->wheel.y;
|
||||
io.AddMouseSourceEvent(event->wheel.which == SDL_TOUCH_MOUSEID ? ImGuiMouseSource_TouchScreen : ImGuiMouseSource_Mouse);
|
||||
io.AddMouseWheelEvent(wheel_x, wheel_y);
|
||||
return true;
|
||||
}
|
||||
case SDL_EVENT_MOUSE_BUTTON_DOWN:
|
||||
case SDL_EVENT_MOUSE_BUTTON_UP:
|
||||
{
|
||||
if (ImGui_ImplSDL3_GetViewportForWindowID(event->button.windowID) == nullptr)
|
||||
return false;
|
||||
int mouse_button = -1;
|
||||
if (event->button.button == SDL_BUTTON_LEFT) { mouse_button = 0; }
|
||||
if (event->button.button == SDL_BUTTON_RIGHT) { mouse_button = 1; }
|
||||
if (event->button.button == SDL_BUTTON_MIDDLE) { mouse_button = 2; }
|
||||
if (event->button.button == SDL_BUTTON_X1) { mouse_button = 3; }
|
||||
if (event->button.button == SDL_BUTTON_X2) { mouse_button = 4; }
|
||||
if (mouse_button == -1)
|
||||
break;
|
||||
io.AddMouseSourceEvent(event->button.which == SDL_TOUCH_MOUSEID ? ImGuiMouseSource_TouchScreen : ImGuiMouseSource_Mouse);
|
||||
io.AddMouseButtonEvent(mouse_button, (event->type == SDL_EVENT_MOUSE_BUTTON_DOWN));
|
||||
bd->MouseButtonsDown = (event->type == SDL_EVENT_MOUSE_BUTTON_DOWN) ? (bd->MouseButtonsDown | (1 << mouse_button)) : (bd->MouseButtonsDown & ~(1 << mouse_button));
|
||||
return true;
|
||||
}
|
||||
case SDL_EVENT_TEXT_INPUT:
|
||||
{
|
||||
if (ImGui_ImplSDL3_GetViewportForWindowID(event->text.windowID) == nullptr)
|
||||
return false;
|
||||
io.AddInputCharactersUTF8(event->text.text);
|
||||
return true;
|
||||
}
|
||||
case SDL_EVENT_KEY_DOWN:
|
||||
case SDL_EVENT_KEY_UP:
|
||||
{
|
||||
if (ImGui_ImplSDL3_GetViewportForWindowID(event->key.windowID) == nullptr)
|
||||
return false;
|
||||
ImGui_ImplSDL3_UpdateKeyModifiers((SDL_Keymod)event->key.mod);
|
||||
//IMGUI_DEBUG_LOG("SDL_EVENT_KEY_%s : key=%d ('%s'), scancode=%d ('%s'), mod=%X\n",
|
||||
// (event->type == SDL_EVENT_KEY_DOWN) ? "DOWN" : "UP ", event->key.key, SDL_GetKeyName(event->key.key), event->key.scancode, SDL_GetScancodeName(event->key.scancode), event->key.mod);
|
||||
ImGuiKey key = ImGui_ImplSDL3_KeyEventToImGuiKey(event->key.key, event->key.scancode);
|
||||
io.AddKeyEvent(key, (event->type == SDL_EVENT_KEY_DOWN));
|
||||
io.SetKeyEventNativeData(key, (int)event->key.key, (int)event->key.scancode, (int)event->key.scancode); // To support legacy indexing (<1.87 user code). Legacy backend uses SDLK_*** as indices to IsKeyXXX() functions.
|
||||
return true;
|
||||
}
|
||||
case SDL_EVENT_WINDOW_MOUSE_ENTER:
|
||||
{
|
||||
if (ImGui_ImplSDL3_GetViewportForWindowID(event->window.windowID) == nullptr)
|
||||
return false;
|
||||
bd->MouseWindowID = event->window.windowID;
|
||||
bd->MousePendingLeaveFrame = 0;
|
||||
return true;
|
||||
}
|
||||
// - In some cases, when detaching a window from main viewport SDL may send SDL_WINDOWEVENT_ENTER one frame too late,
|
||||
// causing SDL_WINDOWEVENT_LEAVE on previous frame to interrupt drag operation by clear mouse position. This is why
|
||||
// we delay process the SDL_WINDOWEVENT_LEAVE events by one frame. See issue #5012 for details.
|
||||
// FIXME: Unconfirmed whether this is still needed with SDL3.
|
||||
case SDL_EVENT_WINDOW_MOUSE_LEAVE:
|
||||
{
|
||||
if (ImGui_ImplSDL3_GetViewportForWindowID(event->window.windowID) == nullptr)
|
||||
return false;
|
||||
bd->MousePendingLeaveFrame = ImGui::GetFrameCount() + 1;
|
||||
return true;
|
||||
}
|
||||
case SDL_EVENT_WINDOW_FOCUS_GAINED:
|
||||
case SDL_EVENT_WINDOW_FOCUS_LOST:
|
||||
{
|
||||
if (ImGui_ImplSDL3_GetViewportForWindowID(event->window.windowID) == nullptr)
|
||||
return false;
|
||||
io.AddFocusEvent(event->type == SDL_EVENT_WINDOW_FOCUS_GAINED);
|
||||
return true;
|
||||
}
|
||||
case SDL_EVENT_GAMEPAD_ADDED:
|
||||
case SDL_EVENT_GAMEPAD_REMOVED:
|
||||
{
|
||||
bd->WantUpdateGamepadsList = true;
|
||||
return true;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static void ImGui_ImplSDL3_SetupPlatformHandles(ImGuiViewport* viewport, SDL_Window* window)
|
||||
{
|
||||
viewport->PlatformHandle = (void*)(intptr_t)SDL_GetWindowID(window);
|
||||
viewport->PlatformHandleRaw = nullptr;
|
||||
#if defined(_WIN32) && !defined(__WINRT__)
|
||||
viewport->PlatformHandleRaw = (HWND)SDL_GetPointerProperty(SDL_GetWindowProperties(window), SDL_PROP_WINDOW_WIN32_HWND_POINTER, nullptr);
|
||||
#elif defined(__APPLE__)
|
||||
viewport->PlatformHandleRaw = SDL_GetPointerProperty(SDL_GetWindowProperties(window), SDL_PROP_WINDOW_COCOA_WINDOW_POINTER, nullptr);
|
||||
#endif
|
||||
}
|
||||
|
||||
static bool ImGui_ImplSDL3_Init(SDL_Window* window, SDL_Renderer* renderer, void* sdl_gl_context)
|
||||
{
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
IMGUI_CHECKVERSION();
|
||||
IM_ASSERT(io.BackendPlatformUserData == nullptr && "Already initialized a platform backend!");
|
||||
IM_UNUSED(sdl_gl_context); // Unused in this branch
|
||||
|
||||
const int ver_linked = SDL_GetVersion();
|
||||
|
||||
// Setup backend capabilities flags
|
||||
ImGui_ImplSDL3_Data* bd = IM_NEW(ImGui_ImplSDL3_Data)();
|
||||
snprintf(bd->BackendPlatformName, sizeof(bd->BackendPlatformName), "imgui_impl_sdl3 (%d.%d.%d; %d.%d.%d)",
|
||||
SDL_MAJOR_VERSION, SDL_MINOR_VERSION, SDL_MICRO_VERSION, SDL_VERSIONNUM_MAJOR(ver_linked), SDL_VERSIONNUM_MINOR(ver_linked), SDL_VERSIONNUM_MICRO(ver_linked));
|
||||
io.BackendPlatformUserData = (void*)bd;
|
||||
io.BackendPlatformName = bd->BackendPlatformName;
|
||||
io.BackendFlags |= ImGuiBackendFlags_HasMouseCursors; // We can honor GetMouseCursor() values (optional)
|
||||
io.BackendFlags |= ImGuiBackendFlags_HasSetMousePos; // We can honor io.WantSetMousePos requests (optional, rarely used)
|
||||
|
||||
bd->Window = window;
|
||||
bd->WindowID = SDL_GetWindowID(window);
|
||||
bd->Renderer = renderer;
|
||||
|
||||
// Check and store if we are on a SDL backend that supports SDL_GetGlobalMouseState() and SDL_CaptureMouse()
|
||||
// ("wayland" and "rpi" don't support it, but we chose to use a white-list instead of a black-list)
|
||||
bd->MouseCanUseGlobalState = false;
|
||||
bd->MouseCanUseCapture = false;
|
||||
#if SDL_HAS_CAPTURE_AND_GLOBAL_MOUSE
|
||||
const char* sdl_backend = SDL_GetCurrentVideoDriver();
|
||||
const char* capture_and_global_state_whitelist[] = { "windows", "cocoa", "x11", "DIVE", "VMAN" };
|
||||
for (const char* item : capture_and_global_state_whitelist)
|
||||
if (strncmp(sdl_backend, item, strlen(item)) == 0)
|
||||
bd->MouseCanUseGlobalState = bd->MouseCanUseCapture = true;
|
||||
#endif
|
||||
|
||||
ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO();
|
||||
platform_io.Platform_SetClipboardTextFn = ImGui_ImplSDL3_SetClipboardText;
|
||||
platform_io.Platform_GetClipboardTextFn = ImGui_ImplSDL3_GetClipboardText;
|
||||
platform_io.Platform_SetImeDataFn = ImGui_ImplSDL3_PlatformSetImeData;
|
||||
platform_io.Platform_OpenInShellFn = [](ImGuiContext*, const char* url) { return SDL_OpenURL(url) == 0; };
|
||||
|
||||
// Gamepad handling
|
||||
bd->GamepadMode = ImGui_ImplSDL3_GamepadMode_AutoFirst;
|
||||
bd->WantUpdateGamepadsList = true;
|
||||
|
||||
// Load mouse cursors
|
||||
bd->MouseCursors[ImGuiMouseCursor_Arrow] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_DEFAULT);
|
||||
bd->MouseCursors[ImGuiMouseCursor_TextInput] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_TEXT);
|
||||
bd->MouseCursors[ImGuiMouseCursor_ResizeAll] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_MOVE);
|
||||
bd->MouseCursors[ImGuiMouseCursor_ResizeNS] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_NS_RESIZE);
|
||||
bd->MouseCursors[ImGuiMouseCursor_ResizeEW] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_EW_RESIZE);
|
||||
bd->MouseCursors[ImGuiMouseCursor_ResizeNESW] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_NESW_RESIZE);
|
||||
bd->MouseCursors[ImGuiMouseCursor_ResizeNWSE] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_NWSE_RESIZE);
|
||||
bd->MouseCursors[ImGuiMouseCursor_Hand] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_POINTER);
|
||||
bd->MouseCursors[ImGuiMouseCursor_Wait] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_WAIT);
|
||||
bd->MouseCursors[ImGuiMouseCursor_Progress] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_PROGRESS);
|
||||
bd->MouseCursors[ImGuiMouseCursor_NotAllowed] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_NOT_ALLOWED);
|
||||
|
||||
// Set platform dependent data in viewport
|
||||
// Our mouse update function expect PlatformHandle to be filled for the main viewport
|
||||
ImGuiViewport* main_viewport = ImGui::GetMainViewport();
|
||||
ImGui_ImplSDL3_SetupPlatformHandles(main_viewport, window);
|
||||
|
||||
// From 2.0.5: Set SDL hint to receive mouse click events on window focus, otherwise SDL doesn't emit the event.
|
||||
// Without this, when clicking to gain focus, our widgets wouldn't activate even though they showed as hovered.
|
||||
// (This is unfortunately a global SDL setting, so enabling it might have a side-effect on your application.
|
||||
// It is unlikely to make a difference, but if your app absolutely needs to ignore the initial on-focus click:
|
||||
// you can ignore SDL_EVENT_MOUSE_BUTTON_DOWN events coming right after a SDL_WINDOWEVENT_FOCUS_GAINED)
|
||||
#ifdef SDL_HINT_MOUSE_FOCUS_CLICKTHROUGH
|
||||
SDL_SetHint(SDL_HINT_MOUSE_FOCUS_CLICKTHROUGH, "1");
|
||||
#endif
|
||||
|
||||
// From 2.0.22: Disable auto-capture, this is preventing drag and drop across multiple windows (see #5710)
|
||||
#ifdef SDL_HINT_MOUSE_AUTO_CAPTURE
|
||||
SDL_SetHint(SDL_HINT_MOUSE_AUTO_CAPTURE, "0");
|
||||
#endif
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ImGui_ImplSDL3_InitForOpenGL(SDL_Window* window, void* sdl_gl_context)
|
||||
{
|
||||
IM_UNUSED(sdl_gl_context); // Viewport branch will need this.
|
||||
return ImGui_ImplSDL3_Init(window, nullptr, sdl_gl_context);
|
||||
}
|
||||
|
||||
bool ImGui_ImplSDL3_InitForVulkan(SDL_Window* window)
|
||||
{
|
||||
return ImGui_ImplSDL3_Init(window, nullptr, nullptr);
|
||||
}
|
||||
|
||||
bool ImGui_ImplSDL3_InitForD3D(SDL_Window* window)
|
||||
{
|
||||
#if !defined(_WIN32)
|
||||
IM_ASSERT(0 && "Unsupported");
|
||||
#endif
|
||||
return ImGui_ImplSDL3_Init(window, nullptr, nullptr);
|
||||
}
|
||||
|
||||
bool ImGui_ImplSDL3_InitForMetal(SDL_Window* window)
|
||||
{
|
||||
return ImGui_ImplSDL3_Init(window, nullptr, nullptr);
|
||||
}
|
||||
|
||||
bool ImGui_ImplSDL3_InitForSDLRenderer(SDL_Window* window, SDL_Renderer* renderer)
|
||||
{
|
||||
return ImGui_ImplSDL3_Init(window, renderer, nullptr);
|
||||
}
|
||||
|
||||
bool ImGui_ImplSDL3_InitForSDLGPU(SDL_Window* window)
|
||||
{
|
||||
return ImGui_ImplSDL3_Init(window, nullptr, nullptr);
|
||||
}
|
||||
|
||||
bool ImGui_ImplSDL3_InitForOther(SDL_Window* window)
|
||||
{
|
||||
return ImGui_ImplSDL3_Init(window, nullptr, nullptr);
|
||||
}
|
||||
|
||||
static void ImGui_ImplSDL3_CloseGamepads();
|
||||
|
||||
void ImGui_ImplSDL3_Shutdown()
|
||||
{
|
||||
ImGui_ImplSDL3_Data* bd = ImGui_ImplSDL3_GetBackendData();
|
||||
IM_ASSERT(bd != nullptr && "No platform backend to shutdown, or already shutdown?");
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
|
||||
if (bd->ClipboardTextData)
|
||||
SDL_free(bd->ClipboardTextData);
|
||||
for (ImGuiMouseCursor cursor_n = 0; cursor_n < ImGuiMouseCursor_COUNT; cursor_n++)
|
||||
SDL_DestroyCursor(bd->MouseCursors[cursor_n]);
|
||||
ImGui_ImplSDL3_CloseGamepads();
|
||||
|
||||
io.BackendPlatformName = nullptr;
|
||||
io.BackendPlatformUserData = nullptr;
|
||||
io.BackendFlags &= ~(ImGuiBackendFlags_HasMouseCursors | ImGuiBackendFlags_HasSetMousePos | ImGuiBackendFlags_HasGamepad);
|
||||
IM_DELETE(bd);
|
||||
}
|
||||
|
||||
static void ImGui_ImplSDL3_UpdateMouseData()
|
||||
{
|
||||
ImGui_ImplSDL3_Data* bd = ImGui_ImplSDL3_GetBackendData();
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
|
||||
// We forward mouse input when hovered or captured (via SDL_EVENT_MOUSE_MOTION) or when focused (below)
|
||||
#if SDL_HAS_CAPTURE_AND_GLOBAL_MOUSE
|
||||
// - SDL_CaptureMouse() let the OS know e.g. that our drags can extend outside of parent boundaries (we want updated position) and shouldn't trigger other operations outside.
|
||||
// - Debuggers under Linux tends to leave captured mouse on break, which may be very inconvenient, so to mitigate the issue we wait until mouse has moved to begin capture.
|
||||
if (bd->MouseCanUseCapture)
|
||||
{
|
||||
bool want_capture = false;
|
||||
for (int button_n = 0; button_n < ImGuiMouseButton_COUNT && !want_capture; button_n++)
|
||||
if (ImGui::IsMouseDragging(button_n, 1.0f))
|
||||
want_capture = true;
|
||||
SDL_CaptureMouse(want_capture);
|
||||
}
|
||||
|
||||
SDL_Window* focused_window = SDL_GetKeyboardFocus();
|
||||
const bool is_app_focused = (bd->Window == focused_window);
|
||||
#else
|
||||
SDL_Window* focused_window = bd->Window;
|
||||
const bool is_app_focused = (SDL_GetWindowFlags(bd->Window) & SDL_WINDOW_INPUT_FOCUS) != 0; // SDL 2.0.3 and non-windowed systems: single-viewport only
|
||||
#endif
|
||||
if (is_app_focused)
|
||||
{
|
||||
// (Optional) Set OS mouse position from Dear ImGui if requested (rarely used, only when io.ConfigNavMoveSetMousePos is enabled by user)
|
||||
if (io.WantSetMousePos)
|
||||
SDL_WarpMouseInWindow(bd->Window, io.MousePos.x, io.MousePos.y);
|
||||
|
||||
// (Optional) Fallback to provide mouse position when focused (SDL_EVENT_MOUSE_MOTION already provides this when hovered or captured)
|
||||
const bool is_relative_mouse_mode = SDL_GetWindowRelativeMouseMode(bd->Window);
|
||||
if (bd->MouseCanUseGlobalState && bd->MouseButtonsDown == 0 && !is_relative_mouse_mode)
|
||||
{
|
||||
// Single-viewport mode: mouse position in client window coordinates (io.MousePos is (0,0) when the mouse is on the upper-left corner of the app window)
|
||||
float mouse_x_global, mouse_y_global;
|
||||
int window_x, window_y;
|
||||
SDL_GetGlobalMouseState(&mouse_x_global, &mouse_y_global);
|
||||
SDL_GetWindowPosition(focused_window, &window_x, &window_y);
|
||||
io.AddMousePosEvent(mouse_x_global - window_x, mouse_y_global - window_y);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void ImGui_ImplSDL3_UpdateMouseCursor()
|
||||
{
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
if (io.ConfigFlags & ImGuiConfigFlags_NoMouseCursorChange)
|
||||
return;
|
||||
ImGui_ImplSDL3_Data* bd = ImGui_ImplSDL3_GetBackendData();
|
||||
|
||||
ImGuiMouseCursor imgui_cursor = ImGui::GetMouseCursor();
|
||||
if (io.MouseDrawCursor || imgui_cursor == ImGuiMouseCursor_None)
|
||||
{
|
||||
// Hide OS mouse cursor if imgui is drawing it or if it wants no cursor
|
||||
SDL_HideCursor();
|
||||
}
|
||||
else
|
||||
{
|
||||
// Show OS mouse cursor
|
||||
SDL_Cursor* expected_cursor = bd->MouseCursors[imgui_cursor] ? bd->MouseCursors[imgui_cursor] : bd->MouseCursors[ImGuiMouseCursor_Arrow];
|
||||
if (bd->MouseLastCursor != expected_cursor)
|
||||
{
|
||||
SDL_SetCursor(expected_cursor); // SDL function doesn't have an early out (see #6113)
|
||||
bd->MouseLastCursor = expected_cursor;
|
||||
}
|
||||
SDL_ShowCursor();
|
||||
}
|
||||
}
|
||||
|
||||
static void ImGui_ImplSDL3_CloseGamepads()
|
||||
{
|
||||
ImGui_ImplSDL3_Data* bd = ImGui_ImplSDL3_GetBackendData();
|
||||
if (bd->GamepadMode != ImGui_ImplSDL3_GamepadMode_Manual)
|
||||
for (SDL_Gamepad* gamepad : bd->Gamepads)
|
||||
SDL_CloseGamepad(gamepad);
|
||||
bd->Gamepads.resize(0);
|
||||
}
|
||||
|
||||
void ImGui_ImplSDL3_SetGamepadMode(ImGui_ImplSDL3_GamepadMode mode, SDL_Gamepad** manual_gamepads_array, int manual_gamepads_count)
|
||||
{
|
||||
ImGui_ImplSDL3_Data* bd = ImGui_ImplSDL3_GetBackendData();
|
||||
ImGui_ImplSDL3_CloseGamepads();
|
||||
if (mode == ImGui_ImplSDL3_GamepadMode_Manual)
|
||||
{
|
||||
IM_ASSERT(manual_gamepads_array != nullptr || manual_gamepads_count <= 0);
|
||||
for (int n = 0; n < manual_gamepads_count; n++)
|
||||
bd->Gamepads.push_back(manual_gamepads_array[n]);
|
||||
}
|
||||
else
|
||||
{
|
||||
IM_ASSERT(manual_gamepads_array == nullptr && manual_gamepads_count <= 0);
|
||||
bd->WantUpdateGamepadsList = true;
|
||||
}
|
||||
bd->GamepadMode = mode;
|
||||
}
|
||||
|
||||
static void ImGui_ImplSDL3_UpdateGamepadButton(ImGui_ImplSDL3_Data* bd, ImGuiIO& io, ImGuiKey key, SDL_GamepadButton button_no)
|
||||
{
|
||||
bool merged_value = false;
|
||||
for (SDL_Gamepad* gamepad : bd->Gamepads)
|
||||
merged_value |= SDL_GetGamepadButton(gamepad, button_no) != 0;
|
||||
io.AddKeyEvent(key, merged_value);
|
||||
}
|
||||
|
||||
static inline float Saturate(float v) { return v < 0.0f ? 0.0f : v > 1.0f ? 1.0f : v; }
|
||||
static void ImGui_ImplSDL3_UpdateGamepadAnalog(ImGui_ImplSDL3_Data* bd, ImGuiIO& io, ImGuiKey key, SDL_GamepadAxis axis_no, float v0, float v1)
|
||||
{
|
||||
float merged_value = 0.0f;
|
||||
for (SDL_Gamepad* gamepad : bd->Gamepads)
|
||||
{
|
||||
float vn = Saturate((float)(SDL_GetGamepadAxis(gamepad, axis_no) - v0) / (float)(v1 - v0));
|
||||
if (merged_value < vn)
|
||||
merged_value = vn;
|
||||
}
|
||||
io.AddKeyAnalogEvent(key, merged_value > 0.1f, merged_value);
|
||||
}
|
||||
|
||||
static void ImGui_ImplSDL3_UpdateGamepads()
|
||||
{
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
ImGui_ImplSDL3_Data* bd = ImGui_ImplSDL3_GetBackendData();
|
||||
|
||||
// Update list of gamepads to use
|
||||
if (bd->WantUpdateGamepadsList && bd->GamepadMode != ImGui_ImplSDL3_GamepadMode_Manual)
|
||||
{
|
||||
ImGui_ImplSDL3_CloseGamepads();
|
||||
int sdl_gamepads_count = 0;
|
||||
SDL_JoystickID* sdl_gamepads = SDL_GetGamepads(&sdl_gamepads_count);
|
||||
for (int n = 0; n < sdl_gamepads_count; n++)
|
||||
if (SDL_Gamepad* gamepad = SDL_OpenGamepad(sdl_gamepads[n]))
|
||||
{
|
||||
bd->Gamepads.push_back(gamepad);
|
||||
if (bd->GamepadMode == ImGui_ImplSDL3_GamepadMode_AutoFirst)
|
||||
break;
|
||||
}
|
||||
bd->WantUpdateGamepadsList = false;
|
||||
SDL_free(sdl_gamepads);
|
||||
}
|
||||
|
||||
io.BackendFlags &= ~ImGuiBackendFlags_HasGamepad;
|
||||
if (bd->Gamepads.Size == 0)
|
||||
return;
|
||||
io.BackendFlags |= ImGuiBackendFlags_HasGamepad;
|
||||
|
||||
// Update gamepad inputs
|
||||
const int thumb_dead_zone = 8000; // SDL_gamepad.h suggests using this value.
|
||||
ImGui_ImplSDL3_UpdateGamepadButton(bd, io, ImGuiKey_GamepadStart, SDL_GAMEPAD_BUTTON_START);
|
||||
ImGui_ImplSDL3_UpdateGamepadButton(bd, io, ImGuiKey_GamepadBack, SDL_GAMEPAD_BUTTON_BACK);
|
||||
ImGui_ImplSDL3_UpdateGamepadButton(bd, io, ImGuiKey_GamepadFaceLeft, SDL_GAMEPAD_BUTTON_WEST); // Xbox X, PS Square
|
||||
ImGui_ImplSDL3_UpdateGamepadButton(bd, io, ImGuiKey_GamepadFaceRight, SDL_GAMEPAD_BUTTON_EAST); // Xbox B, PS Circle
|
||||
ImGui_ImplSDL3_UpdateGamepadButton(bd, io, ImGuiKey_GamepadFaceUp, SDL_GAMEPAD_BUTTON_NORTH); // Xbox Y, PS Triangle
|
||||
ImGui_ImplSDL3_UpdateGamepadButton(bd, io, ImGuiKey_GamepadFaceDown, SDL_GAMEPAD_BUTTON_SOUTH); // Xbox A, PS Cross
|
||||
ImGui_ImplSDL3_UpdateGamepadButton(bd, io, ImGuiKey_GamepadDpadLeft, SDL_GAMEPAD_BUTTON_DPAD_LEFT);
|
||||
ImGui_ImplSDL3_UpdateGamepadButton(bd, io, ImGuiKey_GamepadDpadRight, SDL_GAMEPAD_BUTTON_DPAD_RIGHT);
|
||||
ImGui_ImplSDL3_UpdateGamepadButton(bd, io, ImGuiKey_GamepadDpadUp, SDL_GAMEPAD_BUTTON_DPAD_UP);
|
||||
ImGui_ImplSDL3_UpdateGamepadButton(bd, io, ImGuiKey_GamepadDpadDown, SDL_GAMEPAD_BUTTON_DPAD_DOWN);
|
||||
ImGui_ImplSDL3_UpdateGamepadButton(bd, io, ImGuiKey_GamepadL1, SDL_GAMEPAD_BUTTON_LEFT_SHOULDER);
|
||||
ImGui_ImplSDL3_UpdateGamepadButton(bd, io, ImGuiKey_GamepadR1, SDL_GAMEPAD_BUTTON_RIGHT_SHOULDER);
|
||||
ImGui_ImplSDL3_UpdateGamepadAnalog(bd, io, ImGuiKey_GamepadL2, SDL_GAMEPAD_AXIS_LEFT_TRIGGER, 0.0f, 32767);
|
||||
ImGui_ImplSDL3_UpdateGamepadAnalog(bd, io, ImGuiKey_GamepadR2, SDL_GAMEPAD_AXIS_RIGHT_TRIGGER, 0.0f, 32767);
|
||||
ImGui_ImplSDL3_UpdateGamepadButton(bd, io, ImGuiKey_GamepadL3, SDL_GAMEPAD_BUTTON_LEFT_STICK);
|
||||
ImGui_ImplSDL3_UpdateGamepadButton(bd, io, ImGuiKey_GamepadR3, SDL_GAMEPAD_BUTTON_RIGHT_STICK);
|
||||
ImGui_ImplSDL3_UpdateGamepadAnalog(bd, io, ImGuiKey_GamepadLStickLeft, SDL_GAMEPAD_AXIS_LEFTX, -thumb_dead_zone, -32768);
|
||||
ImGui_ImplSDL3_UpdateGamepadAnalog(bd, io, ImGuiKey_GamepadLStickRight, SDL_GAMEPAD_AXIS_LEFTX, +thumb_dead_zone, +32767);
|
||||
ImGui_ImplSDL3_UpdateGamepadAnalog(bd, io, ImGuiKey_GamepadLStickUp, SDL_GAMEPAD_AXIS_LEFTY, -thumb_dead_zone, -32768);
|
||||
ImGui_ImplSDL3_UpdateGamepadAnalog(bd, io, ImGuiKey_GamepadLStickDown, SDL_GAMEPAD_AXIS_LEFTY, +thumb_dead_zone, +32767);
|
||||
ImGui_ImplSDL3_UpdateGamepadAnalog(bd, io, ImGuiKey_GamepadRStickLeft, SDL_GAMEPAD_AXIS_RIGHTX, -thumb_dead_zone, -32768);
|
||||
ImGui_ImplSDL3_UpdateGamepadAnalog(bd, io, ImGuiKey_GamepadRStickRight, SDL_GAMEPAD_AXIS_RIGHTX, +thumb_dead_zone, +32767);
|
||||
ImGui_ImplSDL3_UpdateGamepadAnalog(bd, io, ImGuiKey_GamepadRStickUp, SDL_GAMEPAD_AXIS_RIGHTY, -thumb_dead_zone, -32768);
|
||||
ImGui_ImplSDL3_UpdateGamepadAnalog(bd, io, ImGuiKey_GamepadRStickDown, SDL_GAMEPAD_AXIS_RIGHTY, +thumb_dead_zone, +32767);
|
||||
}
|
||||
|
||||
static void ImGui_ImplSDL3_GetWindowSizeAndFramebufferScale(SDL_Window* window, ImVec2* out_size, ImVec2* out_framebuffer_scale)
|
||||
{
|
||||
int w, h;
|
||||
int display_w, display_h;
|
||||
SDL_GetWindowSize(window, &w, &h);
|
||||
if (SDL_GetWindowFlags(window) & SDL_WINDOW_MINIMIZED)
|
||||
w = h = 0;
|
||||
SDL_GetWindowSizeInPixels(window, &display_w, &display_h);
|
||||
if (out_size != nullptr)
|
||||
*out_size = ImVec2((float)w, (float)h);
|
||||
if (out_framebuffer_scale != nullptr)
|
||||
*out_framebuffer_scale = (w > 0 && h > 0) ? ImVec2((float)display_w / w, (float)display_h / h) : ImVec2(1.0f, 1.0f);
|
||||
}
|
||||
|
||||
void ImGui_ImplSDL3_NewFrame()
|
||||
{
|
||||
ImGui_ImplSDL3_Data* bd = ImGui_ImplSDL3_GetBackendData();
|
||||
IM_ASSERT(bd != nullptr && "Context or backend not initialized! Did you call ImGui_ImplSDL3_Init()?");
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
|
||||
// Setup main viewport size (every frame to accommodate for window resizing)
|
||||
ImGui_ImplSDL3_GetWindowSizeAndFramebufferScale(bd->Window, &io.DisplaySize, &io.DisplayFramebufferScale);
|
||||
|
||||
// Setup time step (we could also use SDL_GetTicksNS() available since SDL3)
|
||||
// (Accept SDL_GetPerformanceCounter() not returning a monotonically increasing value. Happens in VMs and Emscripten, see #6189, #6114, #3644)
|
||||
static Uint64 frequency = SDL_GetPerformanceFrequency();
|
||||
Uint64 current_time = SDL_GetPerformanceCounter();
|
||||
if (current_time <= bd->Time)
|
||||
current_time = bd->Time + 1;
|
||||
io.DeltaTime = bd->Time > 0 ? (float)((double)(current_time - bd->Time) / frequency) : (float)(1.0f / 60.0f);
|
||||
bd->Time = current_time;
|
||||
|
||||
if (bd->MousePendingLeaveFrame && bd->MousePendingLeaveFrame >= ImGui::GetFrameCount() && bd->MouseButtonsDown == 0)
|
||||
{
|
||||
bd->MouseWindowID = 0;
|
||||
bd->MousePendingLeaveFrame = 0;
|
||||
io.AddMousePosEvent(-FLT_MAX, -FLT_MAX);
|
||||
}
|
||||
|
||||
ImGui_ImplSDL3_UpdateMouseData();
|
||||
ImGui_ImplSDL3_UpdateMouseCursor();
|
||||
|
||||
// Update game controllers (if enabled and available)
|
||||
ImGui_ImplSDL3_UpdateGamepads();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#if defined(__clang__)
|
||||
#pragma clang diagnostic pop
|
||||
#endif
|
||||
|
||||
#endif // #ifndef IMGUI_DISABLE
|
||||
@@ -0,0 +1,137 @@
|
||||
/*
|
||||
* engine.cxx, now included in digital modulations, was initialy a file from miniDart project
|
||||
* Author : Eric Bachard / lundi 3 octobre 2016, 14:35:03 (UTC+0200)
|
||||
* This file is under GPL v2 License
|
||||
* See : http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*/
|
||||
|
||||
|
||||
#include "SDL3/SDL.h" // We use SDL3
|
||||
|
||||
#include "imgui_impl_sdl3.h"
|
||||
#include "imgui_impl_opengl3.h"
|
||||
#include "engine.h" // class Engine
|
||||
#include "application.h" // WINDOW_WIDTH, WINDOW_HEIGHT,
|
||||
|
||||
#include <GL/gl.h> // OpenGL
|
||||
|
||||
#include "digital_modulation_fr.hpp"
|
||||
|
||||
// TODO later : kept for good reasons (the fact is we currently do not cross-compile for MS Windows)
|
||||
#ifndef NATIVE_BUILD
|
||||
#define NATIVE_BUILD
|
||||
#endif
|
||||
|
||||
using std::cout;
|
||||
using std::endl;
|
||||
|
||||
void Engine::sdl_application_abort(const char * msg)
|
||||
{
|
||||
std::cout << SDL_GetError() << std::endl;
|
||||
SDL_Quit();
|
||||
exit (-1);
|
||||
}
|
||||
|
||||
Engine::Engine()
|
||||
{
|
||||
int anErr = init_SDL();
|
||||
|
||||
if (anErr != 0)
|
||||
{
|
||||
std::cerr << "Cannot initialize SDL or OpenGL. Exiting" << std::endl;
|
||||
SDL_Quit();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Engine::~Engine()
|
||||
{
|
||||
SDL_GL_DestroyContext(getGL_Context());
|
||||
SDL_DestroyWindow(getWindow());
|
||||
window = nullptr;
|
||||
}
|
||||
|
||||
int Engine::init_SDL()
|
||||
{
|
||||
std::cout << "\n";
|
||||
SDL_Log("AVX %s\n", SDL_HasAVX()? "detected" : "not detected");
|
||||
SDL_Log("AVX2 %s\n", SDL_HasAVX2()? "detected" : "not detected");
|
||||
SDL_Log("AVX512F %s\n", SDL_HasAVX512F()? "detected" : "not detected");
|
||||
std::cout << "\n";
|
||||
|
||||
// ericb 2022 08 19
|
||||
// source :
|
||||
// https://answers.opencv.org/question/120699/can-opencv-310-be-set-to-capture-an-rtsp-stream-over-udp/
|
||||
// setenv("OPENCV_FFMPEG_CAPTURE_OPTIONS", "rtsp_transport;udp", 1);
|
||||
|
||||
#ifdef NATIVE_BUILD
|
||||
// https://github.com/libsdl-org/SDL/issues/2917
|
||||
putenv((char *)"SDL_PULSEAUDIO_INCLUDE_MONITORS=true");
|
||||
#endif
|
||||
// https://www.gog.com/forum/thimbleweed_park/linux_unable_to_init_sdl_mixer_alsa_couldnt_open_audio_device_no_such_device
|
||||
// https://wiki.libsdl.org/FAQUsingSDL
|
||||
#ifndef NATIVE_BUILD
|
||||
SDL_setenv("SDL_AUDIODRIVER", "DirectSound", true);
|
||||
putenv((char *)"SDL_AUDIODRIVER=DirectSound");
|
||||
#else
|
||||
// SDL_setenv("SDL_AUDIODRIVER", "alsa", true);
|
||||
putenv((char *)"SDL_AUDIODRIVER=alsa");
|
||||
// putenv((char *)"SDL_AUDIODEV=pulse");
|
||||
#endif
|
||||
|
||||
// --------------------- SDL INIT ---------------------
|
||||
// about issues between OpenGL 3.3. and OpenGL 3.0 (only Linux concerned)
|
||||
// https://discourse.libsdl.org/t/confused-about-what-opengl-context-is-being-used-with-sdl/22860
|
||||
// avoid using compatiblity profile
|
||||
|
||||
if (!SDL_Init(SDL_INIT_VIDEO))
|
||||
{
|
||||
fprintf(stdout, "SDL init error: %s\n", SDL_GetError());
|
||||
return -1;
|
||||
}
|
||||
//const char* glsl_version = "#version 130";
|
||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
|
||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
|
||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 3);
|
||||
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
|
||||
|
||||
setWindow((SDL_Window*)SDL_CreateWindow( MAIN_SDL3_WINDOW_NAME,
|
||||
DEFAULT_SDL_WINDOW_WIDTH,
|
||||
DEFAULT_SDL_WINDOW_HEIGHT,
|
||||
SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE
|
||||
));
|
||||
|
||||
// check whether the SDL3 window exists
|
||||
if (getWindow() == nullptr)
|
||||
sdl_application_abort("Problem creating the SDL window.\n");
|
||||
else
|
||||
std::cout << "SDL3 Window created " << "\n";
|
||||
|
||||
gl_context = SDL_GL_CreateContext(getWindow());
|
||||
|
||||
std::cout << "GL_Context : " << getGL_Context() << "\n";
|
||||
|
||||
if (getGL_Context() == nullptr)
|
||||
sdl_application_abort("Problem creating GL context.\n");
|
||||
else
|
||||
std::cout << "GL Context created \n" << "\n";
|
||||
|
||||
SDL_GL_MakeCurrent(getWindow(), getGL_Context());
|
||||
|
||||
// 1 == enable VSync ; 0 == disable VSync
|
||||
#define USE_VSYNC
|
||||
#ifdef USE_VSYNC
|
||||
SDL_GL_SetSwapInterval(1);
|
||||
#else
|
||||
SDL_GL_SetSwapInterval(0);
|
||||
#endif
|
||||
|
||||
std::cout << "\nImGui version = " << IMGUI_VERSION << "\n\n";
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Fichier binaire non affiché.
Fichier diff supprimé car celui-ci est trop grand
Voir la Diff
Fichier diff supprimé car celui-ci est trop grand
Voir la Diff
Fichier diff supprimé car celui-ci est trop grand
Voir la Diff
Fichier diff supprimé car celui-ci est trop grand
Voir la Diff
Fichier diff supprimé car celui-ci est trop grand
Voir la Diff
@@ -0,0 +1,177 @@
|
||||
/* **************************************************************************************
|
||||
* Author: Eric Bachard
|
||||
* eric poin_t bachard arrowbase free d_ot fr
|
||||
* 2018 december 30th
|
||||
*
|
||||
* MIT License
|
||||
* -----------
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
* **************************************************************************************/
|
||||
#include "imgui_themes.h"
|
||||
|
||||
// Legacy miniDart theme
|
||||
void ImGui::StyleColorsLightGreen(ImGuiStyle* dst)
|
||||
{
|
||||
ImGuiStyle* style = dst ? dst : &ImGui::GetStyle();
|
||||
ImVec4* colors = style->Colors;
|
||||
|
||||
style->WindowRounding = 2.0f; // Radius of window corners rounding. Set to 0.0f to have rectangular windows
|
||||
style->ScrollbarRounding = 3.0f; // Radius of grab corners rounding for scrollbar
|
||||
style->GrabRounding = 2.0f; // Radius of grabs corners rounding. Set to 0.0f to have rectangular slider grabs.
|
||||
style->AntiAliasedLines = true;
|
||||
style->AntiAliasedFill = true;
|
||||
style->WindowRounding = 2.0f;
|
||||
style->ChildRounding = 2.0f;
|
||||
style->ScrollbarSize = 16.0f;
|
||||
style->ScrollbarRounding = 3.0f;
|
||||
style->GrabRounding = 2.0f;
|
||||
style->ItemSpacing.x = 10.0f;
|
||||
style->ItemSpacing.y = 4.0f;
|
||||
style->IndentSpacing = 22.0f;
|
||||
style->FramePadding.x = 6.0f;
|
||||
style->FramePadding.y = 4.0f;
|
||||
style->Alpha = 1.0f;
|
||||
style->FrameRounding = 3.0f;
|
||||
//style->TabBorderSize = 3.0f;
|
||||
|
||||
colors[ImGuiCol_Text] = ImVec4(0.00f, 0.00f, 0.00f, 1.00f);
|
||||
colors[ImGuiCol_TextDisabled] = ImVec4(0.60f, 0.60f, 0.60f, 1.00f);
|
||||
colors[ImGuiCol_WindowBg] = ImVec4(0.86f, 0.86f, 0.86f, 1.00f);
|
||||
// unused ??
|
||||
// ImGui 1.75+
|
||||
//ImGuiCol_ChildWindowBg -> use ImGuiCol_ChildBg
|
||||
#if (IMGUI_VERSION_NUM > 17202)
|
||||
colors[ImGuiCol_ChildBg] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f);
|
||||
#else
|
||||
colors[ImGuiCol_ChildWindowBg] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f);
|
||||
#endif
|
||||
// ??
|
||||
colors[ImGuiCol_ChildBg] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f);
|
||||
colors[ImGuiCol_PopupBg] = ImVec4(0.93f, 0.93f, 0.93f, 0.98f);
|
||||
colors[ImGuiCol_Border] = ImVec4(0.71f, 0.71f, 0.71f, 0.08f);
|
||||
colors[ImGuiCol_BorderShadow] = ImVec4(0.00f, 0.00f, 0.00f, 0.04f);
|
||||
colors[ImGuiCol_FrameBg] = ImVec4(0.71f, 0.71f, 0.71f, 0.55f);
|
||||
colors[ImGuiCol_FrameBgHovered] = ImVec4(0.94f, 0.94f, 0.94f, 0.55f);
|
||||
colors[ImGuiCol_FrameBgActive] = ImVec4(0.71f, 0.78f, 0.69f, 0.98f);
|
||||
// colors[ImGuiCol_TitleBg] = ImVec4(0.85f, 0.85f, 0.85f, 1.00f);
|
||||
// Testing new color scheme
|
||||
colors[ImGuiCol_TitleBg] = ImVec4(0.718f, 0.816f, 0.451f, 1.00f);
|
||||
colors[ImGuiCol_TitleBgCollapsed] = ImVec4(0.82f, 0.78f, 0.78f, 0.51f);
|
||||
// colors[ImGuiCol_TitleBgActive] = ImVec4(0.78f, 0.78f, 0.78f, 1.00f);
|
||||
// Testing new color scheme
|
||||
colors[ImGuiCol_TitleBgActive] = ImVec4(1.00f, 0.823f, 0.369f, 1.00f);
|
||||
colors[ImGuiCol_MenuBarBg] = ImVec4(0.86f, 0.86f, 0.86f, 1.00f);
|
||||
colors[ImGuiCol_ScrollbarBg] = ImVec4(0.20f, 0.25f, 0.30f, 0.61f);
|
||||
colors[ImGuiCol_ScrollbarGrab] = ImVec4(0.90f, 0.90f, 0.90f, 0.30f);
|
||||
colors[ImGuiCol_ScrollbarGrabHovered] = ImVec4(0.92f, 0.92f, 0.92f, 0.78f);
|
||||
colors[ImGuiCol_ScrollbarGrabActive] = ImVec4(1.00f, 1.00f, 1.00f, 1.00f);
|
||||
colors[ImGuiCol_CheckMark] = ImVec4(0.184f, 0.407f, 0.193f, 1.00f);
|
||||
colors[ImGuiCol_SliderGrab] = ImVec4(0.26f, 0.59f, 0.98f, 0.78f);
|
||||
colors[ImGuiCol_SliderGrabActive] = ImVec4(0.26f, 0.59f, 0.98f, 1.00f);
|
||||
colors[ImGuiCol_Button] = ImVec4(0.71f, 0.78f, 0.69f, 0.40f);
|
||||
colors[ImGuiCol_ButtonHovered] = ImVec4(0.725f, 0.805f, 0.702f, 1.00f);
|
||||
colors[ImGuiCol_ButtonActive] = ImVec4(0.793f, 0.900f, 0.836f, 1.00f);
|
||||
colors[ImGuiCol_Header] = ImVec4(0.71f, 0.78f, 0.69f, 0.31f);
|
||||
colors[ImGuiCol_HeaderHovered] = ImVec4(0.71f, 0.78f, 0.69f, 0.80f);
|
||||
colors[ImGuiCol_HeaderActive] = ImVec4(0.71f, 0.78f, 0.69f, 1.00f);
|
||||
colors[ImGuiCol_Separator] = ImVec4(0.39f, 0.39f, 0.39f, 1.00f);
|
||||
colors[ImGuiCol_SeparatorHovered] = ImVec4(0.26f, 0.59f, 0.98f, 0.78f);
|
||||
colors[ImGuiCol_SeparatorActive] = ImVec4(0.26f, 0.59f, 0.98f, 1.00f);
|
||||
colors[ImGuiCol_ResizeGrip] = ImVec4(1.00f, 1.00f, 1.00f, 0.00f);
|
||||
colors[ImGuiCol_ResizeGripHovered] = ImVec4(0.26f, 0.59f, 0.98f, 0.45f);
|
||||
colors[ImGuiCol_ResizeGripActive] = ImVec4(0.26f, 0.59f, 0.98f, 0.78f);
|
||||
colors[ImGuiCol_Tab] = ImVec4(0.69f, 0.69f, 0.69f, 1.00f);
|
||||
colors[ImGuiCol_TabHovered] = colors[ImGuiCol_ButtonHovered];
|
||||
colors[ImGuiCol_TabActive] = colors[ImGuiCol_ButtonActive];
|
||||
colors[ImGuiCol_TabUnfocused] = ImVec4(0.71f, 0.78f, 0.69f, 0.40f);
|
||||
colors[ImGuiCol_TabUnfocusedActive] = ImVec4(0.71f, 0.78f, 0.69f, 0.40f);;
|
||||
colors[ImGuiCol_PlotLines] = ImVec4(0.39f, 0.39f, 0.39f, 1.00f);
|
||||
colors[ImGuiCol_PlotLinesHovered] = ImVec4(1.00f, 0.43f, 0.35f, 1.00f);
|
||||
colors[ImGuiCol_PlotHistogram] = ImVec4(0.90f, 0.70f, 0.00f, 1.00f);
|
||||
colors[ImGuiCol_PlotHistogramHovered] = ImVec4(1.00f, 0.60f, 0.00f, 1.00f);
|
||||
colors[ImGuiCol_TextSelectedBg] = ImVec4(0.26f, 0.59f, 0.98f, 0.35f);
|
||||
// FIXME : trouver la version où la définition a été supprimée
|
||||
// colors[ImGuiCol_ModalWindowDarkening] = ImVec4(0.20f, 0.20f, 0.20f, 0.35f);
|
||||
colors[ImGuiCol_DragDropTarget] = ImVec4(0.26f, 0.59f, 0.98f, 0.95f);
|
||||
colors[ImGuiCol_NavHighlight] = colors[ImGuiCol_HeaderHovered];
|
||||
colors[ImGuiCol_NavWindowingHighlight] = ImVec4(0.70f, 0.70f, 0.70f, 0.70f);
|
||||
}
|
||||
|
||||
|
||||
void ImGui::StyleColorsWindows(ImGuiStyle* dst)
|
||||
{
|
||||
ImGuiStyle* style = &ImGui::GetStyle();
|
||||
|
||||
style->WindowRounding = 0.0f;
|
||||
style->FrameRounding = 0.0f;
|
||||
|
||||
style->WindowBorderSize = 0.0f;
|
||||
style->FrameBorderSize = 1.0f;
|
||||
style->PopupBorderSize = 1.0f;
|
||||
|
||||
style->ScrollbarSize = 20.0f;
|
||||
style->ScrollbarRounding = 0.0f;
|
||||
style->GrabMinSize = 5.0f;
|
||||
style->GrabRounding = 0.0f;
|
||||
|
||||
ImVec4 white = ImVec4(1.00f, 1.00f, 1.00f, 1.00f);
|
||||
ImVec4 transparent = ImVec4(0.00f, 0.00f, 0.00f, 0.00f);
|
||||
ImVec4 dark = ImVec4(0.00f, 0.00f, 0.00f, 0.20f);
|
||||
ImVec4 darker = ImVec4(0.00f, 0.00f, 0.00f, 0.50f);
|
||||
|
||||
ImVec4 background = ImVec4(0.95f, 0.95f, 0.95f, 1.00f);
|
||||
ImVec4 text = ImVec4(0.10f, 0.10f, 0.10f, 1.00f);
|
||||
ImVec4 border = ImVec4(0.60f, 0.60f, 0.60f, 1.00f);
|
||||
ImVec4 grab = ImVec4(0.69f, 0.69f, 0.69f, 1.00f);
|
||||
ImVec4 header = ImVec4(0.86f, 0.86f, 0.86f, 1.00f);
|
||||
ImVec4 active = ImVec4(0.00f, 0.47f, 0.84f, 1.00f);
|
||||
ImVec4 hover = ImVec4(0.00f, 0.47f, 0.84f, 0.20f);
|
||||
|
||||
style->Colors[ImGuiCol_Text] = text;
|
||||
style->Colors[ImGuiCol_WindowBg] = background;
|
||||
style->Colors[ImGuiCol_ChildBg] = background;
|
||||
style->Colors[ImGuiCol_PopupBg] = white;
|
||||
|
||||
style->Colors[ImGuiCol_Border] = border;
|
||||
style->Colors[ImGuiCol_BorderShadow] = transparent;
|
||||
|
||||
style->Colors[ImGuiCol_Button] = header;
|
||||
style->Colors[ImGuiCol_ButtonHovered] = hover;
|
||||
style->Colors[ImGuiCol_ButtonActive] = active;
|
||||
|
||||
style->Colors[ImGuiCol_FrameBg] = white;
|
||||
style->Colors[ImGuiCol_FrameBgHovered] = hover;
|
||||
style->Colors[ImGuiCol_FrameBgActive] = active;
|
||||
|
||||
style->Colors[ImGuiCol_MenuBarBg] = header;
|
||||
style->Colors[ImGuiCol_Header] = header;
|
||||
style->Colors[ImGuiCol_HeaderHovered] = hover;
|
||||
style->Colors[ImGuiCol_HeaderActive] = active;
|
||||
|
||||
style->Colors[ImGuiCol_CheckMark] = text;
|
||||
style->Colors[ImGuiCol_SliderGrab] = grab;
|
||||
style->Colors[ImGuiCol_SliderGrabActive] = darker;
|
||||
|
||||
style->Colors[ImGuiCol_ScrollbarBg] = header;
|
||||
style->Colors[ImGuiCol_ScrollbarGrab] = grab;
|
||||
style->Colors[ImGuiCol_ScrollbarGrabHovered] = dark;
|
||||
style->Colors[ImGuiCol_ScrollbarGrabActive] = darker;
|
||||
}
|
||||
Fichier diff supprimé car celui-ci est trop grand
Voir la Diff
@@ -0,0 +1,627 @@
|
||||
// [DEAR IMGUI]
|
||||
// This is a slightly modified version of stb_rect_pack.h 1.01.
|
||||
// Grep for [DEAR IMGUI] to find the changes.
|
||||
//
|
||||
// stb_rect_pack.h - v1.01 - public domain - rectangle packing
|
||||
// Sean Barrett 2014
|
||||
//
|
||||
// Useful for e.g. packing rectangular textures into an atlas.
|
||||
// Does not do rotation.
|
||||
//
|
||||
// Before #including,
|
||||
//
|
||||
// #define STB_RECT_PACK_IMPLEMENTATION
|
||||
//
|
||||
// in the file that you want to have the implementation.
|
||||
//
|
||||
// Not necessarily the awesomest packing method, but better than
|
||||
// the totally naive one in stb_truetype (which is primarily what
|
||||
// this is meant to replace).
|
||||
//
|
||||
// Has only had a few tests run, may have issues.
|
||||
//
|
||||
// More docs to come.
|
||||
//
|
||||
// No memory allocations; uses qsort() and assert() from stdlib.
|
||||
// Can override those by defining STBRP_SORT and STBRP_ASSERT.
|
||||
//
|
||||
// This library currently uses the Skyline Bottom-Left algorithm.
|
||||
//
|
||||
// Please note: better rectangle packers are welcome! Please
|
||||
// implement them to the same API, but with a different init
|
||||
// function.
|
||||
//
|
||||
// Credits
|
||||
//
|
||||
// Library
|
||||
// Sean Barrett
|
||||
// Minor features
|
||||
// Martins Mozeiko
|
||||
// github:IntellectualKitty
|
||||
//
|
||||
// Bugfixes / warning fixes
|
||||
// Jeremy Jaussaud
|
||||
// Fabian Giesen
|
||||
//
|
||||
// Version history:
|
||||
//
|
||||
// 1.01 (2021-07-11) always use large rect mode, expose STBRP__MAXVAL in public section
|
||||
// 1.00 (2019-02-25) avoid small space waste; gracefully fail too-wide rectangles
|
||||
// 0.99 (2019-02-07) warning fixes
|
||||
// 0.11 (2017-03-03) return packing success/fail result
|
||||
// 0.10 (2016-10-25) remove cast-away-const to avoid warnings
|
||||
// 0.09 (2016-08-27) fix compiler warnings
|
||||
// 0.08 (2015-09-13) really fix bug with empty rects (w=0 or h=0)
|
||||
// 0.07 (2015-09-13) fix bug with empty rects (w=0 or h=0)
|
||||
// 0.06 (2015-04-15) added STBRP_SORT to allow replacing qsort
|
||||
// 0.05: added STBRP_ASSERT to allow replacing assert
|
||||
// 0.04: fixed minor bug in STBRP_LARGE_RECTS support
|
||||
// 0.01: initial release
|
||||
//
|
||||
// LICENSE
|
||||
//
|
||||
// See end of file for license information.
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// INCLUDE SECTION
|
||||
//
|
||||
|
||||
#ifndef STB_INCLUDE_STB_RECT_PACK_H
|
||||
#define STB_INCLUDE_STB_RECT_PACK_H
|
||||
|
||||
#define STB_RECT_PACK_VERSION 1
|
||||
|
||||
#ifdef STBRP_STATIC
|
||||
#define STBRP_DEF static
|
||||
#else
|
||||
#define STBRP_DEF extern
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct stbrp_context stbrp_context;
|
||||
typedef struct stbrp_node stbrp_node;
|
||||
typedef struct stbrp_rect stbrp_rect;
|
||||
|
||||
typedef int stbrp_coord;
|
||||
|
||||
#define STBRP__MAXVAL 0x7fffffff
|
||||
// Mostly for internal use, but this is the maximum supported coordinate value.
|
||||
|
||||
STBRP_DEF int stbrp_pack_rects (stbrp_context *context, stbrp_rect *rects, int num_rects);
|
||||
// Assign packed locations to rectangles. The rectangles are of type
|
||||
// 'stbrp_rect' defined below, stored in the array 'rects', and there
|
||||
// are 'num_rects' many of them.
|
||||
//
|
||||
// Rectangles which are successfully packed have the 'was_packed' flag
|
||||
// set to a non-zero value and 'x' and 'y' store the minimum location
|
||||
// on each axis (i.e. bottom-left in cartesian coordinates, top-left
|
||||
// if you imagine y increasing downwards). Rectangles which do not fit
|
||||
// have the 'was_packed' flag set to 0.
|
||||
//
|
||||
// You should not try to access the 'rects' array from another thread
|
||||
// while this function is running, as the function temporarily reorders
|
||||
// the array while it executes.
|
||||
//
|
||||
// To pack into another rectangle, you need to call stbrp_init_target
|
||||
// again. To continue packing into the same rectangle, you can call
|
||||
// this function again. Calling this multiple times with multiple rect
|
||||
// arrays will probably produce worse packing results than calling it
|
||||
// a single time with the full rectangle array, but the option is
|
||||
// available.
|
||||
//
|
||||
// The function returns 1 if all of the rectangles were successfully
|
||||
// packed and 0 otherwise.
|
||||
|
||||
struct stbrp_rect
|
||||
{
|
||||
// reserved for your use:
|
||||
int id;
|
||||
|
||||
// input:
|
||||
stbrp_coord w, h;
|
||||
|
||||
// output:
|
||||
stbrp_coord x, y;
|
||||
int was_packed; // non-zero if valid packing
|
||||
|
||||
}; // 16 bytes, nominally
|
||||
|
||||
|
||||
STBRP_DEF void stbrp_init_target (stbrp_context *context, int width, int height, stbrp_node *nodes, int num_nodes);
|
||||
// Initialize a rectangle packer to:
|
||||
// pack a rectangle that is 'width' by 'height' in dimensions
|
||||
// using temporary storage provided by the array 'nodes', which is 'num_nodes' long
|
||||
//
|
||||
// You must call this function every time you start packing into a new target.
|
||||
//
|
||||
// There is no "shutdown" function. The 'nodes' memory must stay valid for
|
||||
// the following stbrp_pack_rects() call (or calls), but can be freed after
|
||||
// the call (or calls) finish.
|
||||
//
|
||||
// Note: to guarantee best results, either:
|
||||
// 1. make sure 'num_nodes' >= 'width'
|
||||
// or 2. call stbrp_allow_out_of_mem() defined below with 'allow_out_of_mem = 1'
|
||||
//
|
||||
// If you don't do either of the above things, widths will be quantized to multiples
|
||||
// of small integers to guarantee the algorithm doesn't run out of temporary storage.
|
||||
//
|
||||
// If you do #2, then the non-quantized algorithm will be used, but the algorithm
|
||||
// may run out of temporary storage and be unable to pack some rectangles.
|
||||
|
||||
STBRP_DEF void stbrp_setup_allow_out_of_mem (stbrp_context *context, int allow_out_of_mem);
|
||||
// Optionally call this function after init but before doing any packing to
|
||||
// change the handling of the out-of-temp-memory scenario, described above.
|
||||
// If you call init again, this will be reset to the default (false).
|
||||
|
||||
|
||||
STBRP_DEF void stbrp_setup_heuristic (stbrp_context *context, int heuristic);
|
||||
// Optionally select which packing heuristic the library should use. Different
|
||||
// heuristics will produce better/worse results for different data sets.
|
||||
// If you call init again, this will be reset to the default.
|
||||
|
||||
enum
|
||||
{
|
||||
STBRP_HEURISTIC_Skyline_default=0,
|
||||
STBRP_HEURISTIC_Skyline_BL_sortHeight = STBRP_HEURISTIC_Skyline_default,
|
||||
STBRP_HEURISTIC_Skyline_BF_sortHeight
|
||||
};
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// the details of the following structures don't matter to you, but they must
|
||||
// be visible so you can handle the memory allocations for them
|
||||
|
||||
struct stbrp_node
|
||||
{
|
||||
stbrp_coord x,y;
|
||||
stbrp_node *next;
|
||||
};
|
||||
|
||||
struct stbrp_context
|
||||
{
|
||||
int width;
|
||||
int height;
|
||||
int align;
|
||||
int init_mode;
|
||||
int heuristic;
|
||||
int num_nodes;
|
||||
stbrp_node *active_head;
|
||||
stbrp_node *free_head;
|
||||
stbrp_node extra[2]; // we allocate two extra nodes so optimal user-node-count is 'width' not 'width+2'
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPLEMENTATION SECTION
|
||||
//
|
||||
|
||||
#ifdef STB_RECT_PACK_IMPLEMENTATION
|
||||
#ifndef STBRP_SORT
|
||||
#include <stdlib.h>
|
||||
#define STBRP_SORT qsort
|
||||
#endif
|
||||
|
||||
#ifndef STBRP_ASSERT
|
||||
#include <assert.h>
|
||||
#define STBRP_ASSERT assert
|
||||
#endif
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#define STBRP__NOTUSED(v) (void)(v)
|
||||
#define STBRP__CDECL __cdecl
|
||||
#else
|
||||
#define STBRP__NOTUSED(v) (void)sizeof(v)
|
||||
#define STBRP__CDECL
|
||||
#endif
|
||||
|
||||
enum
|
||||
{
|
||||
STBRP__INIT_skyline = 1
|
||||
};
|
||||
|
||||
STBRP_DEF void stbrp_setup_heuristic(stbrp_context *context, int heuristic)
|
||||
{
|
||||
switch (context->init_mode) {
|
||||
case STBRP__INIT_skyline:
|
||||
STBRP_ASSERT(heuristic == STBRP_HEURISTIC_Skyline_BL_sortHeight || heuristic == STBRP_HEURISTIC_Skyline_BF_sortHeight);
|
||||
context->heuristic = heuristic;
|
||||
break;
|
||||
default:
|
||||
STBRP_ASSERT(0);
|
||||
}
|
||||
}
|
||||
|
||||
STBRP_DEF void stbrp_setup_allow_out_of_mem(stbrp_context *context, int allow_out_of_mem)
|
||||
{
|
||||
if (allow_out_of_mem)
|
||||
// if it's ok to run out of memory, then don't bother aligning them;
|
||||
// this gives better packing, but may fail due to OOM (even though
|
||||
// the rectangles easily fit). @TODO a smarter approach would be to only
|
||||
// quantize once we've hit OOM, then we could get rid of this parameter.
|
||||
context->align = 1;
|
||||
else {
|
||||
// if it's not ok to run out of memory, then quantize the widths
|
||||
// so that num_nodes is always enough nodes.
|
||||
//
|
||||
// I.e. num_nodes * align >= width
|
||||
// align >= width / num_nodes
|
||||
// align = ceil(width/num_nodes)
|
||||
|
||||
context->align = (context->width + context->num_nodes-1) / context->num_nodes;
|
||||
}
|
||||
}
|
||||
|
||||
STBRP_DEF void stbrp_init_target(stbrp_context *context, int width, int height, stbrp_node *nodes, int num_nodes)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i=0; i < num_nodes-1; ++i)
|
||||
nodes[i].next = &nodes[i+1];
|
||||
nodes[i].next = NULL;
|
||||
context->init_mode = STBRP__INIT_skyline;
|
||||
context->heuristic = STBRP_HEURISTIC_Skyline_default;
|
||||
context->free_head = &nodes[0];
|
||||
context->active_head = &context->extra[0];
|
||||
context->width = width;
|
||||
context->height = height;
|
||||
context->num_nodes = num_nodes;
|
||||
stbrp_setup_allow_out_of_mem(context, 0);
|
||||
|
||||
// node 0 is the full width, node 1 is the sentinel (lets us not store width explicitly)
|
||||
context->extra[0].x = 0;
|
||||
context->extra[0].y = 0;
|
||||
context->extra[0].next = &context->extra[1];
|
||||
context->extra[1].x = (stbrp_coord) width;
|
||||
context->extra[1].y = (1<<30);
|
||||
context->extra[1].next = NULL;
|
||||
}
|
||||
|
||||
// find minimum y position if it starts at x1
|
||||
static int stbrp__skyline_find_min_y(stbrp_context *c, stbrp_node *first, int x0, int width, int *pwaste)
|
||||
{
|
||||
stbrp_node *node = first;
|
||||
int x1 = x0 + width;
|
||||
int min_y, visited_width, waste_area;
|
||||
|
||||
STBRP__NOTUSED(c);
|
||||
|
||||
STBRP_ASSERT(first->x <= x0);
|
||||
|
||||
#if 0
|
||||
// skip in case we're past the node
|
||||
while (node->next->x <= x0)
|
||||
++node;
|
||||
#else
|
||||
STBRP_ASSERT(node->next->x > x0); // we ended up handling this in the caller for efficiency
|
||||
#endif
|
||||
|
||||
STBRP_ASSERT(node->x <= x0);
|
||||
|
||||
min_y = 0;
|
||||
waste_area = 0;
|
||||
visited_width = 0;
|
||||
while (node->x < x1) {
|
||||
if (node->y > min_y) {
|
||||
// raise min_y higher.
|
||||
// we've accounted for all waste up to min_y,
|
||||
// but we'll now add more waste for everything we've visted
|
||||
waste_area += visited_width * (node->y - min_y);
|
||||
min_y = node->y;
|
||||
// the first time through, visited_width might be reduced
|
||||
if (node->x < x0)
|
||||
visited_width += node->next->x - x0;
|
||||
else
|
||||
visited_width += node->next->x - node->x;
|
||||
} else {
|
||||
// add waste area
|
||||
int under_width = node->next->x - node->x;
|
||||
if (under_width + visited_width > width)
|
||||
under_width = width - visited_width;
|
||||
waste_area += under_width * (min_y - node->y);
|
||||
visited_width += under_width;
|
||||
}
|
||||
node = node->next;
|
||||
}
|
||||
|
||||
*pwaste = waste_area;
|
||||
return min_y;
|
||||
}
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int x,y;
|
||||
stbrp_node **prev_link;
|
||||
} stbrp__findresult;
|
||||
|
||||
static stbrp__findresult stbrp__skyline_find_best_pos(stbrp_context *c, int width, int height)
|
||||
{
|
||||
int best_waste = (1<<30), best_x, best_y = (1 << 30);
|
||||
stbrp__findresult fr;
|
||||
stbrp_node **prev, *node, *tail, **best = NULL;
|
||||
|
||||
// align to multiple of c->align
|
||||
width = (width + c->align - 1);
|
||||
width -= width % c->align;
|
||||
STBRP_ASSERT(width % c->align == 0);
|
||||
|
||||
// if it can't possibly fit, bail immediately
|
||||
if (width > c->width || height > c->height) {
|
||||
fr.prev_link = NULL;
|
||||
fr.x = fr.y = 0;
|
||||
return fr;
|
||||
}
|
||||
|
||||
node = c->active_head;
|
||||
prev = &c->active_head;
|
||||
while (node->x + width <= c->width) {
|
||||
int y,waste;
|
||||
y = stbrp__skyline_find_min_y(c, node, node->x, width, &waste);
|
||||
if (c->heuristic == STBRP_HEURISTIC_Skyline_BL_sortHeight) { // actually just want to test BL
|
||||
// bottom left
|
||||
if (y < best_y) {
|
||||
best_y = y;
|
||||
best = prev;
|
||||
}
|
||||
} else {
|
||||
// best-fit
|
||||
if (y + height <= c->height) {
|
||||
// can only use it if it first vertically
|
||||
if (y < best_y || (y == best_y && waste < best_waste)) {
|
||||
best_y = y;
|
||||
best_waste = waste;
|
||||
best = prev;
|
||||
}
|
||||
}
|
||||
}
|
||||
prev = &node->next;
|
||||
node = node->next;
|
||||
}
|
||||
|
||||
best_x = (best == NULL) ? 0 : (*best)->x;
|
||||
|
||||
// if doing best-fit (BF), we also have to try aligning right edge to each node position
|
||||
//
|
||||
// e.g, if fitting
|
||||
//
|
||||
// ____________________
|
||||
// |____________________|
|
||||
//
|
||||
// into
|
||||
//
|
||||
// | |
|
||||
// | ____________|
|
||||
// |____________|
|
||||
//
|
||||
// then right-aligned reduces waste, but bottom-left BL is always chooses left-aligned
|
||||
//
|
||||
// This makes BF take about 2x the time
|
||||
|
||||
if (c->heuristic == STBRP_HEURISTIC_Skyline_BF_sortHeight) {
|
||||
tail = c->active_head;
|
||||
node = c->active_head;
|
||||
prev = &c->active_head;
|
||||
// find first node that's admissible
|
||||
while (tail->x < width)
|
||||
tail = tail->next;
|
||||
while (tail) {
|
||||
int xpos = tail->x - width;
|
||||
int y,waste;
|
||||
STBRP_ASSERT(xpos >= 0);
|
||||
// find the left position that matches this
|
||||
while (node->next->x <= xpos) {
|
||||
prev = &node->next;
|
||||
node = node->next;
|
||||
}
|
||||
STBRP_ASSERT(node->next->x > xpos && node->x <= xpos);
|
||||
y = stbrp__skyline_find_min_y(c, node, xpos, width, &waste);
|
||||
if (y + height <= c->height) {
|
||||
if (y <= best_y) {
|
||||
if (y < best_y || waste < best_waste || (waste==best_waste && xpos < best_x)) {
|
||||
best_x = xpos;
|
||||
//STBRP_ASSERT(y <= best_y); [DEAR IMGUI]
|
||||
best_y = y;
|
||||
best_waste = waste;
|
||||
best = prev;
|
||||
}
|
||||
}
|
||||
}
|
||||
tail = tail->next;
|
||||
}
|
||||
}
|
||||
|
||||
fr.prev_link = best;
|
||||
fr.x = best_x;
|
||||
fr.y = best_y;
|
||||
return fr;
|
||||
}
|
||||
|
||||
static stbrp__findresult stbrp__skyline_pack_rectangle(stbrp_context *context, int width, int height)
|
||||
{
|
||||
// find best position according to heuristic
|
||||
stbrp__findresult res = stbrp__skyline_find_best_pos(context, width, height);
|
||||
stbrp_node *node, *cur;
|
||||
|
||||
// bail if:
|
||||
// 1. it failed
|
||||
// 2. the best node doesn't fit (we don't always check this)
|
||||
// 3. we're out of memory
|
||||
if (res.prev_link == NULL || res.y + height > context->height || context->free_head == NULL) {
|
||||
res.prev_link = NULL;
|
||||
return res;
|
||||
}
|
||||
|
||||
// on success, create new node
|
||||
node = context->free_head;
|
||||
node->x = (stbrp_coord) res.x;
|
||||
node->y = (stbrp_coord) (res.y + height);
|
||||
|
||||
context->free_head = node->next;
|
||||
|
||||
// insert the new node into the right starting point, and
|
||||
// let 'cur' point to the remaining nodes needing to be
|
||||
// stiched back in
|
||||
|
||||
cur = *res.prev_link;
|
||||
if (cur->x < res.x) {
|
||||
// preserve the existing one, so start testing with the next one
|
||||
stbrp_node *next = cur->next;
|
||||
cur->next = node;
|
||||
cur = next;
|
||||
} else {
|
||||
*res.prev_link = node;
|
||||
}
|
||||
|
||||
// from here, traverse cur and free the nodes, until we get to one
|
||||
// that shouldn't be freed
|
||||
while (cur->next && cur->next->x <= res.x + width) {
|
||||
stbrp_node *next = cur->next;
|
||||
// move the current node to the free list
|
||||
cur->next = context->free_head;
|
||||
context->free_head = cur;
|
||||
cur = next;
|
||||
}
|
||||
|
||||
// stitch the list back in
|
||||
node->next = cur;
|
||||
|
||||
if (cur->x < res.x + width)
|
||||
cur->x = (stbrp_coord) (res.x + width);
|
||||
|
||||
#ifdef _DEBUG
|
||||
cur = context->active_head;
|
||||
while (cur->x < context->width) {
|
||||
STBRP_ASSERT(cur->x < cur->next->x);
|
||||
cur = cur->next;
|
||||
}
|
||||
STBRP_ASSERT(cur->next == NULL);
|
||||
|
||||
{
|
||||
int count=0;
|
||||
cur = context->active_head;
|
||||
while (cur) {
|
||||
cur = cur->next;
|
||||
++count;
|
||||
}
|
||||
cur = context->free_head;
|
||||
while (cur) {
|
||||
cur = cur->next;
|
||||
++count;
|
||||
}
|
||||
STBRP_ASSERT(count == context->num_nodes+2);
|
||||
}
|
||||
#endif
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
static int STBRP__CDECL rect_height_compare(const void *a, const void *b)
|
||||
{
|
||||
const stbrp_rect *p = (const stbrp_rect *) a;
|
||||
const stbrp_rect *q = (const stbrp_rect *) b;
|
||||
if (p->h > q->h)
|
||||
return -1;
|
||||
if (p->h < q->h)
|
||||
return 1;
|
||||
return (p->w > q->w) ? -1 : (p->w < q->w);
|
||||
}
|
||||
|
||||
static int STBRP__CDECL rect_original_order(const void *a, const void *b)
|
||||
{
|
||||
const stbrp_rect *p = (const stbrp_rect *) a;
|
||||
const stbrp_rect *q = (const stbrp_rect *) b;
|
||||
return (p->was_packed < q->was_packed) ? -1 : (p->was_packed > q->was_packed);
|
||||
}
|
||||
|
||||
STBRP_DEF int stbrp_pack_rects(stbrp_context *context, stbrp_rect *rects, int num_rects)
|
||||
{
|
||||
int i, all_rects_packed = 1;
|
||||
|
||||
// we use the 'was_packed' field internally to allow sorting/unsorting
|
||||
for (i=0; i < num_rects; ++i) {
|
||||
rects[i].was_packed = i;
|
||||
}
|
||||
|
||||
// sort according to heuristic
|
||||
STBRP_SORT(rects, num_rects, sizeof(rects[0]), rect_height_compare);
|
||||
|
||||
for (i=0; i < num_rects; ++i) {
|
||||
if (rects[i].w == 0 || rects[i].h == 0) {
|
||||
rects[i].x = rects[i].y = 0; // empty rect needs no space
|
||||
} else {
|
||||
stbrp__findresult fr = stbrp__skyline_pack_rectangle(context, rects[i].w, rects[i].h);
|
||||
if (fr.prev_link) {
|
||||
rects[i].x = (stbrp_coord) fr.x;
|
||||
rects[i].y = (stbrp_coord) fr.y;
|
||||
} else {
|
||||
rects[i].x = rects[i].y = STBRP__MAXVAL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// unsort
|
||||
STBRP_SORT(rects, num_rects, sizeof(rects[0]), rect_original_order);
|
||||
|
||||
// set was_packed flags and all_rects_packed status
|
||||
for (i=0; i < num_rects; ++i) {
|
||||
rects[i].was_packed = !(rects[i].x == STBRP__MAXVAL && rects[i].y == STBRP__MAXVAL);
|
||||
if (!rects[i].was_packed)
|
||||
all_rects_packed = 0;
|
||||
}
|
||||
|
||||
// return the all_rects_packed status
|
||||
return all_rects_packed;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
------------------------------------------------------------------------------
|
||||
This software is available under 2 licenses -- choose whichever you prefer.
|
||||
------------------------------------------------------------------------------
|
||||
ALTERNATIVE A - MIT License
|
||||
Copyright (c) 2017 Sean Barrett
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
------------------------------------------------------------------------------
|
||||
ALTERNATIVE B - Public Domain (www.unlicense.org)
|
||||
This is free and unencumbered software released into the public domain.
|
||||
Anyone is free to copy, modify, publish, use, compile, sell, or distribute this
|
||||
software, either in source code form or as a compiled binary, for any purpose,
|
||||
commercial or non-commercial, and by any means.
|
||||
In jurisdictions that recognize copyright laws, the author or authors of this
|
||||
software dedicate any and all copyright interest in the software to the public
|
||||
domain. We make this dedication for the benefit of the public at large and to
|
||||
the detriment of our heirs and successors. We intend this dedication to be an
|
||||
overt act of relinquishment in perpetuity of all present and future rights to
|
||||
this software under copyright law.
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
||||
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
------------------------------------------------------------------------------
|
||||
*/
|
||||
Fichier diff supprimé car celui-ci est trop grand
Voir la Diff
Fichier diff supprimé car celui-ci est trop grand
Voir la Diff
Fichier diff supprimé car celui-ci est trop grand
Voir la Diff
Fichier diff supprimé car celui-ci est trop grand
Voir la Diff
Fichier diff supprimé car celui-ci est trop grand
Voir la Diff
@@ -0,0 +1,85 @@
|
||||
/* gl_helpers.cpp */
|
||||
|
||||
// Eric Bachard 2024/11/05 17h01
|
||||
#include "imgui.h"
|
||||
#include "imgui_impl_sdl3.h"
|
||||
#include "imgui_impl_opengl3.h"
|
||||
#include <stdio.h>
|
||||
#include <SDL3/SDL.h>
|
||||
#if defined(IMGUI_IMPL_OPENGL_ES2)
|
||||
#include <SDL_opengles2.h>
|
||||
#else
|
||||
#include <SDL3/SDL_opengl.h>
|
||||
#endif
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#define _CRT_SECURE_NO_WARNINGS
|
||||
#define STB_IMAGE_IMPLEMENTATION
|
||||
#include "stb_image.h"
|
||||
#include "gl_helpers.h"
|
||||
|
||||
// Simple helper function to load an image into a OpenGL texture with common settings
|
||||
bool LoadTextureFromMemory(const void* data, size_t data_size, GLuint* out_texture, int* out_width, int* out_height)
|
||||
{
|
||||
// Load from file
|
||||
int image_width = 0;
|
||||
int image_height = 0;
|
||||
unsigned char* image_data = stbi_load_from_memory((const unsigned char*)data, (int)data_size, &image_width, &image_height, NULL, 4);
|
||||
|
||||
if (image_data == NULL)
|
||||
{
|
||||
std::cout << "image_data == NULL" << "\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
// Create a OpenGL texture identifier
|
||||
GLuint image_texture;
|
||||
glGenTextures(1, &image_texture);
|
||||
glBindTexture(GL_TEXTURE_2D, image_texture);
|
||||
|
||||
// Setup filtering parameters for display
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
|
||||
// Upload pixels into texture
|
||||
glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, image_width, image_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, image_data);
|
||||
stbi_image_free(image_data);
|
||||
|
||||
*out_texture = image_texture;
|
||||
*out_width = image_width;
|
||||
*out_height = image_height;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Open and read a file, then forward to LoadTextureFromMemory()
|
||||
bool LoadTextureFromFile(const char* file_name, GLuint* out_texture, int* out_width, int* out_height)
|
||||
{
|
||||
FILE* f = fopen(file_name, "rb");
|
||||
|
||||
if (f == NULL)
|
||||
return false;
|
||||
|
||||
fseek(f, 0, SEEK_END);
|
||||
size_t file_size = (size_t)ftell(f);
|
||||
|
||||
if (file_size < 0)
|
||||
return false;
|
||||
|
||||
fseek(f, 0, SEEK_SET);
|
||||
void* file_data = IM_ALLOC(file_size);
|
||||
unsigned int taille_image = fread(file_data, 1, file_size, f);
|
||||
|
||||
if (0 >= taille_image)
|
||||
{
|
||||
fprintf(stdout, "Erreur avec le chargement de l'image en mémoire");
|
||||
return false;
|
||||
}
|
||||
bool ret = LoadTextureFromMemory(file_data, file_size, out_texture, out_width, out_height);
|
||||
IM_FREE(file_data);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
Fichier binaire non affiché.
|
Après Largeur: | Hauteur: | Taille: 62 KiB |
@@ -0,0 +1,275 @@
|
||||
/* ImGui utils */
|
||||
|
||||
/* Fichier contenant quelques fonctionnalités basées sur ImGui :
|
||||
* VToggleButton() dérivé de ToggleButton
|
||||
* DrawVToggleButton
|
||||
*
|
||||
* Copyright Eric Bachard 2026/01/14 18h20
|
||||
* License GPL v2
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
#include <cmath>
|
||||
#include <string>
|
||||
|
||||
#ifndef IMGUI_DEFINE_MATH_OPERATORS
|
||||
#define IMGUI_DEFINE_MATH_OPERATORS
|
||||
#endif
|
||||
|
||||
#include "digital_modulation_fr.hpp"
|
||||
#include "imgui.h"
|
||||
#include "vtoggle_button.h"
|
||||
#include "imgui_utils.h"
|
||||
#include "imgui_themes.h"
|
||||
|
||||
#ifdef M_PI
|
||||
#undef M_PI
|
||||
#define M_PI 3.14159265358979323846f
|
||||
#endif
|
||||
|
||||
void selectThemeMenu(Application * p_app)
|
||||
{
|
||||
static THEME selected_menutheme = p_app->get_current_theme();
|
||||
|
||||
if (ImGui::BeginMenu(THEME_MENU_ENTRY))
|
||||
{
|
||||
if (ImGui::Selectable(TRADITIONAL_GREEN_THEME_MENU_ENTRY))
|
||||
selected_menutheme = LIGHT_GREEN_THEME;
|
||||
|
||||
if (ImGui::Selectable(DARK_THEME_MENU_ENTRY))
|
||||
selected_menutheme = DARK_THEME;
|
||||
|
||||
if (ImGui::Selectable(CLASSIC_THEME_MENU_ENTRY))
|
||||
selected_menutheme = CLASSIC_THEME;
|
||||
|
||||
if (ImGui::Selectable(LIGHT_BLUE_THEME_MENU_ENTRY))
|
||||
selected_menutheme = LIGHT_BLUE_THEME;
|
||||
|
||||
if (ImGui::Selectable(WINDOWS_THEME_MENU_ENTRY))
|
||||
selected_menutheme = WINDOWS_THEME;
|
||||
|
||||
if (selected_menutheme != p_app->get_current_theme())
|
||||
p_app->setTheme(selected_menutheme);
|
||||
|
||||
ImGui::EndMenu();
|
||||
}
|
||||
}
|
||||
|
||||
void selectFrameSize(DigitalModulation * p_Dmod)
|
||||
{
|
||||
// by default, we recopy the current value
|
||||
int frame_length = p_Dmod->getWordSize();
|
||||
|
||||
if (ImGui::BeginMenu(FRAME_SIZE))
|
||||
{
|
||||
if (ImGui::Selectable(HEIGHT_BITS_FRAME_SIZE))
|
||||
frame_length = 8;
|
||||
|
||||
if (ImGui::Selectable(SIXTEEN_BITS_FRAME_SIZE))
|
||||
frame_length = 16;
|
||||
|
||||
if (ImGui::Selectable(TWENTY_FOUR_BITS_FRAME_SIZE))
|
||||
frame_length = 24;
|
||||
|
||||
if (frame_length != p_Dmod->getWordSize())
|
||||
p_Dmod->setWordSize(frame_length);
|
||||
|
||||
ImGui::EndMenu();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// ToogleButton transformé en VToggleButton
|
||||
bool VToggleButton(const char* str_id, bool* v)
|
||||
{
|
||||
ImVec2 p = ImGui::GetCursorScreenPos();
|
||||
ImDrawList* draw_list = ImGui::GetWindowDrawList();
|
||||
|
||||
// Taille du toggle
|
||||
// FIXME : elaborate
|
||||
float width = ImGui::GetFrameHeight();
|
||||
//float width = VTOGGLEBUTTON_WIDTH;
|
||||
float height = width * 1.8f;
|
||||
float radius = width * 0.5f;
|
||||
|
||||
ImGui::InvisibleButton(str_id, ImVec2(width, height));
|
||||
|
||||
// Vérifie si le bouton a été cliqué
|
||||
bool clicked = ImGui::IsItemClicked();
|
||||
if (clicked)
|
||||
*v = !*v;
|
||||
|
||||
// Choix de la couleur de fond selon l'état
|
||||
ImU32 col_bg = ImGui::IsItemHovered()
|
||||
? (*v ? IM_COL32(165,231,88,255) : IM_COL32(200,200,200,255)) //ON
|
||||
: (*v ? IM_COL32(145,211,68,255) : IM_COL32(218,218,218,255)); //OFF
|
||||
|
||||
draw_list->AddRectFilled( p, ImVec2(p.x + width, p.y + height), col_bg, radius ); // Dessine le rectangle du Toggle
|
||||
float cy = *v ? (p.y + radius) : (p.y + height - radius); // Position verticale du petit rond
|
||||
draw_list->AddCircleFilled( ImVec2(p.x + radius, cy), radius - 2.0f, IM_COL32(255,255,255,255) ); // Dessine le rond blanc du Toggle
|
||||
|
||||
return clicked;
|
||||
}
|
||||
|
||||
void drawVToggleButtons(int * dm_bits, int wordSize)
|
||||
{
|
||||
// CHILD2_WIDTH = 300.0f
|
||||
float drawSize = ImGui::GetContentRegionAvail().x - CHILD2_WIDTH;
|
||||
|
||||
// FIXME : calculer sérieusement ces valeurs
|
||||
//TEST
|
||||
|
||||
// La formule :
|
||||
// draw_size = (P+B)wordSize + P + marges // Il y a 1 padding de plus que de boutons dessinés
|
||||
//
|
||||
// 20.0f because fo the left/right margins
|
||||
// On dessine dans la child window 1,
|
||||
// et le nombre de pixels n'est plus le même en plein écran
|
||||
// exemple : drawSize = 664.0f contre 1304.0f en plein écran.
|
||||
// 2 solutions : soit dessiner a valeur définie et testée (pas très pro)
|
||||
// soit calculer précisément le padding. Or la formule ne semble pas fonctionner ...
|
||||
// La valeur de 20.0f est soustraite car il faut tenir compte d'une marge à gauche
|
||||
// et d'une marge à droite pour le canvas.
|
||||
// current best value : 20.0f
|
||||
float padding = ((drawSize - 20.0f) - VTOGGLEBUTTON_WIDTH * (float)wordSize)/((float)wordSize + 1);
|
||||
|
||||
// hack ... le temps de corriger la formule
|
||||
if (wordSize == 8)
|
||||
padding += 32.0f;
|
||||
|
||||
if (wordSize == 16)
|
||||
padding += 7.5f;
|
||||
|
||||
if (drawSize > 1000.0F)
|
||||
{
|
||||
if (wordSize == 8)
|
||||
padding += 7.3f; // best value 7.3f
|
||||
|
||||
if (wordSize == 16)
|
||||
padding += 2.3f; // best value 2.3f
|
||||
else
|
||||
padding += 1.2f; // best value 1.2f
|
||||
}
|
||||
// end hack
|
||||
|
||||
ImGui::Dummy(ImVec2(padding / 2.0f, 0.0f)); ImGui::SameLine(); // Padding pour le premier bouton
|
||||
|
||||
for (int i = 0; i < wordSize ; i++)
|
||||
{
|
||||
ImGui::PushID(i);
|
||||
bool bit = (dm_bits[i] != 0);
|
||||
|
||||
if (VToggleButton("##Button", &bit))
|
||||
dm_bits[i] = bit ? 1 : 0;
|
||||
ImGui::PopID();
|
||||
|
||||
if (i < (wordSize - 1)) // Pas de padding pour le dernier
|
||||
{
|
||||
ImGui::SameLine();
|
||||
ImGui::Dummy(ImVec2(padding, 0.0f)); ImGui::SameLine();
|
||||
}
|
||||
}
|
||||
// debug purpose
|
||||
//#define DEBUG_ME
|
||||
#ifdef DEBUG_ME
|
||||
ImGui::Text(" wordSize : %d", wordSize);
|
||||
ImGui::SameLine();
|
||||
ImGui::Text(" padding : %f", padding);
|
||||
ImGui::SameLine();
|
||||
ImGui::Text(" drawSize : %f", drawSize);
|
||||
ImGui::SameLine();
|
||||
ImGui::Text("VTOGGLEBUTTON_WIDTH : %f", VTOGGLEBUTTON_WIDTH);
|
||||
#endif /* DEBUG_ME */
|
||||
}
|
||||
|
||||
void highlightFrame(int * dm_bits, int wordSize)
|
||||
{
|
||||
ImVec2 text_pos = ImGui::GetCursorScreenPos();
|
||||
// pour avoir la surbrillance de longueur variable
|
||||
std::string text_trame = "Trame :";
|
||||
|
||||
for (int i = 0; i < wordSize; i++)
|
||||
{
|
||||
if (0 == i % 8 && i != 0) // Découpage par octets
|
||||
text_trame += " ";
|
||||
|
||||
text_trame += " ";
|
||||
text_trame += std::to_string(dm_bits[i]);
|
||||
}
|
||||
|
||||
ImVec2 text_size = ImGui::CalcTextSize(text_trame.c_str());
|
||||
ImGui::GetWindowDrawList()->AddRectFilled(
|
||||
text_pos,
|
||||
ImVec2(text_pos.x + text_size.x, text_pos.y + text_size.y),
|
||||
IM_COL32(255, 255, 0, 128) // Jaune semi-transparent
|
||||
);
|
||||
ImGui::Text("%s", text_trame.c_str());
|
||||
ImGui::NewLine();
|
||||
ImGui::Separator();
|
||||
}
|
||||
|
||||
// Helper to draw a small modulation example (Témoin visuel). Code proposé par
|
||||
void DrawIndicator(const char * label,
|
||||
float * carrier_freq,
|
||||
DigitalModulationType * p_modulation_type,
|
||||
int * samples_per_bit,
|
||||
float amp_scale,
|
||||
float phase_offset,
|
||||
ImU32 color,
|
||||
ImVec2 size)
|
||||
{
|
||||
ImGui::Text("%s", label);
|
||||
ImVec2 p = ImGui::GetCursorScreenPos();
|
||||
ImDrawList* draw_list = ImGui::GetWindowDrawList();
|
||||
|
||||
// Fond gris clair pour le témoin
|
||||
draw_list->AddRectFilled(p, ImVec2(p.x + size.x, p.y + size.y), IM_COL32(245, 245, 245, 255));
|
||||
|
||||
// Bordure
|
||||
draw_list->AddRect(p, ImVec2(p.x + size.x, p.y + size.y), IM_COL32(180, 180, 180, 255));
|
||||
|
||||
float cy = p.y + size.y * 0.5f; // Centre vertical
|
||||
float base_amp = (size.y * 0.35f); // Amplitude de base (laisse une marge)
|
||||
|
||||
ImVec2 prev;
|
||||
bool first = true;
|
||||
|
||||
// On dessine 2 périodes (ou le double si un symbole est codé sur 2 bits),
|
||||
// pour bien visualiser la forme
|
||||
static float k2 = 1.0f;
|
||||
|
||||
switch (*p_modulation_type)
|
||||
{
|
||||
case MOD_MASK_TYPE :
|
||||
case MOD_M_QAM_TYPE:
|
||||
case MOD_4_QAM_TYPE:
|
||||
case MOD_MFSK_TYPE :
|
||||
k2 = 2.0f;
|
||||
break;
|
||||
|
||||
default:
|
||||
k2 = 1.0f;
|
||||
break;
|
||||
}
|
||||
|
||||
// tracé de la courbe
|
||||
for (int i = 0; i <= *samples_per_bit; i++)
|
||||
{
|
||||
float t = (float)i / (float)*samples_per_bit; // 0 à 1
|
||||
// Formule du signal : sin(2*PI * f * t + phase)
|
||||
float y = cy - sinf(k2 * 2.0f * M_PI * (* carrier_freq) * t + phase_offset) * (base_amp * amp_scale);
|
||||
float x = p.x + t * size.x;
|
||||
ImVec2 curr(x, y);
|
||||
|
||||
if (!first)
|
||||
draw_list->AddLine(prev, curr, color, 1.5f); // Ligne un peu plus épaisse
|
||||
prev = curr;
|
||||
first = false;
|
||||
}
|
||||
|
||||
// Réserve l'espace pour qu'ImGui ne dessine pas par dessus
|
||||
ImGui::Dummy(size);
|
||||
// Petit espacement vertical après
|
||||
ImGui::Dummy(ImVec2(0, 5));
|
||||
}
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
/* application.h fichier d'en-tête qui contient des constantes utiles à toute l'application */
|
||||
|
||||
#ifndef __APPLICATION_H
|
||||
#define __APPLICATION_H
|
||||
|
||||
#define DEFAULT_THEME LIGHT_BLUE_THEME
|
||||
|
||||
#define DEFAULT_SDL_WINDOW_WIDTH 1280
|
||||
#define DEFAULT_SDL_WINDOW_HEIGHT 800
|
||||
|
||||
#include "engine.h"
|
||||
|
||||
typedef enum TAB_name
|
||||
{
|
||||
Amplitude_TAB,
|
||||
Frequency_TAB,
|
||||
Phase_TAB,
|
||||
M_QAM_TAB,
|
||||
NOT_a_TAB
|
||||
} TAB_Name;
|
||||
|
||||
typedef enum aTheme
|
||||
{
|
||||
LIGHT_GREEN_THEME = 0,
|
||||
CLASSIC_THEME = 1,
|
||||
DARK_THEME = 2,
|
||||
LIGHT_BLUE_THEME = 3,
|
||||
WINDOWS_THEME = 4
|
||||
} THEME;
|
||||
|
||||
|
||||
class Application
|
||||
{
|
||||
public:
|
||||
Application();
|
||||
~Application();
|
||||
|
||||
void setTheme(THEME theme);
|
||||
inline THEME get_current_theme() const { return current_theme; }
|
||||
|
||||
inline TAB_name get_current_tab() const { return current_tab; }
|
||||
void set_current_tab(TAB_name aTab);
|
||||
|
||||
private:
|
||||
THEME current_theme;
|
||||
TAB_name current_tab;
|
||||
float windowWidth;
|
||||
float windowHeight;
|
||||
};
|
||||
|
||||
#endif /* __APPLICATION_H */
|
||||
@@ -0,0 +1,23 @@
|
||||
/* gl_helpers.h header file of gl_helpers.cpp */
|
||||
|
||||
// Eric Bachard 2024/11/05 17h11
|
||||
|
||||
#ifndef _GL_HELPERS_H
|
||||
#define _GL_HELPERS_H
|
||||
|
||||
#include "imgui.h"
|
||||
#include "imgui_impl_sdl3.h"
|
||||
#include "imgui_impl_opengl3.h"
|
||||
#include <stdio.h>
|
||||
#include <SDL3/SDL.h>
|
||||
#if defined(IMGUI_IMPL_OPENGL_ES2)
|
||||
#include <SDL_opengles2.h>
|
||||
#else
|
||||
#include <SDL3/SDL_opengl.h>
|
||||
#endif
|
||||
|
||||
bool LoadTextureFromMemory(const void*, size_t, GLuint*, int*, int*);
|
||||
|
||||
bool LoadTextureFromFile(const char*, GLuint*, int*, int*);
|
||||
|
||||
#endif /* _GL_HELPERS_H*/
|
||||
@@ -0,0 +1,68 @@
|
||||
// dear imgui: Renderer Backend for modern OpenGL with shaders / programmatic pipeline
|
||||
// - Desktop GL: 2.x 3.x 4.x
|
||||
// - Embedded GL: ES 2.0 (WebGL 1.0), ES 3.0 (WebGL 2.0)
|
||||
// This needs to be used along with a Platform Backend (e.g. GLFW, SDL, Win32, custom..)
|
||||
|
||||
// Implemented features:
|
||||
// [X] Renderer: User texture binding. Use 'GLuint' OpenGL texture as texture identifier. Read the FAQ about ImTextureID/ImTextureRef!
|
||||
// [x] Renderer: Large meshes support (64k+ vertices) even with 16-bit indices (ImGuiBackendFlags_RendererHasVtxOffset) [Desktop OpenGL only!]
|
||||
// [X] Renderer: Texture updates support for dynamic font atlas (ImGuiBackendFlags_RendererHasTextures).
|
||||
|
||||
// About WebGL/ES:
|
||||
// - You need to '#define IMGUI_IMPL_OPENGL_ES2' or '#define IMGUI_IMPL_OPENGL_ES3' to use WebGL or OpenGL ES.
|
||||
// - This is done automatically on iOS, Android and Emscripten targets.
|
||||
// - For other targets, the define needs to be visible from the imgui_impl_opengl3.cpp compilation unit. If unsure, define globally or in imconfig.h.
|
||||
|
||||
// You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this.
|
||||
// Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need.
|
||||
// Learn about Dear ImGui:
|
||||
// - FAQ https://dearimgui.com/faq
|
||||
// - Getting Started https://dearimgui.com/getting-started
|
||||
// - Documentation https://dearimgui.com/docs (same as your local docs/ folder).
|
||||
// - Introduction, links and more at the top of imgui.cpp
|
||||
|
||||
// About GLSL version:
|
||||
// The 'glsl_version' initialization parameter should be nullptr (default) or a "#version XXX" string.
|
||||
// On computer platform the GLSL version default to "#version 130". On OpenGL ES 3 platform it defaults to "#version 300 es"
|
||||
// Only override if your GL version doesn't handle this GLSL version. See GLSL version table at the top of imgui_impl_opengl3.cpp.
|
||||
|
||||
#pragma once
|
||||
#include "imgui.h" // IMGUI_IMPL_API
|
||||
#ifndef IMGUI_DISABLE
|
||||
|
||||
// Follow "Getting Started" link and check examples/ folder to learn about using backends!
|
||||
IMGUI_IMPL_API bool ImGui_ImplOpenGL3_Init(const char* glsl_version = nullptr);
|
||||
IMGUI_IMPL_API void ImGui_ImplOpenGL3_Shutdown();
|
||||
IMGUI_IMPL_API void ImGui_ImplOpenGL3_NewFrame();
|
||||
IMGUI_IMPL_API void ImGui_ImplOpenGL3_RenderDrawData(ImDrawData* draw_data);
|
||||
|
||||
// (Optional) Called by Init/NewFrame/Shutdown
|
||||
IMGUI_IMPL_API bool ImGui_ImplOpenGL3_CreateDeviceObjects();
|
||||
IMGUI_IMPL_API void ImGui_ImplOpenGL3_DestroyDeviceObjects();
|
||||
|
||||
// (Advanced) Use e.g. if you need to precisely control the timing of texture updates (e.g. for staged rendering), by setting ImDrawData::Textures = NULL to handle this manually.
|
||||
IMGUI_IMPL_API void ImGui_ImplOpenGL3_UpdateTexture(ImTextureData* tex);
|
||||
|
||||
// Configuration flags to add in your imconfig file:
|
||||
//#define IMGUI_IMPL_OPENGL_ES2 // Enable ES 2 (Auto-detected on Emscripten)
|
||||
//#define IMGUI_IMPL_OPENGL_ES3 // Enable ES 3 (Auto-detected on iOS/Android)
|
||||
|
||||
// You can explicitly select GLES2 or GLES3 API by using one of the '#define IMGUI_IMPL_OPENGL_LOADER_XXX' in imconfig.h or compiler command-line.
|
||||
#if !defined(IMGUI_IMPL_OPENGL_ES2) \
|
||||
&& !defined(IMGUI_IMPL_OPENGL_ES3)
|
||||
|
||||
// Try to detect GLES on matching platforms
|
||||
#if defined(__APPLE__)
|
||||
#include <TargetConditionals.h>
|
||||
#endif
|
||||
#if (defined(__APPLE__) && (TARGET_OS_IOS || TARGET_OS_TV)) || (defined(__ANDROID__))
|
||||
#define IMGUI_IMPL_OPENGL_ES3 // iOS, Android -> GL ES 3, "#version 300 es"
|
||||
#elif defined(__EMSCRIPTEN__) || defined(__amigaos4__)
|
||||
#define IMGUI_IMPL_OPENGL_ES2 // Emscripten -> GL ES 2, "#version 100"
|
||||
#else
|
||||
// Otherwise imgui_impl_opengl3_loader.h will be used.
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#endif // #ifndef IMGUI_DISABLE
|
||||
@@ -0,0 +1,929 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// About imgui_impl_opengl3_loader.h:
|
||||
//
|
||||
// We embed our own OpenGL loader to not require user to provide their own or to have to use ours,
|
||||
// which proved to be endless problems for users.
|
||||
// Our loader is custom-generated, based on gl3w but automatically filtered to only include
|
||||
// enums/functions that we use in our imgui_impl_opengl3.cpp source file in order to be small.
|
||||
//
|
||||
// YOU SHOULD NOT NEED TO INCLUDE/USE THIS DIRECTLY. THIS IS USED BY imgui_impl_opengl3.cpp ONLY.
|
||||
// THE REST OF YOUR APP SHOULD USE A DIFFERENT GL LOADER: ANY GL LOADER OF YOUR CHOICE.
|
||||
//
|
||||
// IF YOU GET BUILD ERRORS IN THIS FILE (commonly macro redefinitions or function redefinitions):
|
||||
// IT LIKELY MEANS THAT YOU ARE BUILDING 'imgui_impl_opengl3.cpp' OR INCLUDING 'imgui_impl_opengl3_loader.h'
|
||||
// IN THE SAME COMPILATION UNIT AS ONE OF YOUR FILE WHICH IS USING A THIRD-PARTY OPENGL LOADER.
|
||||
// (e.g. COULD HAPPEN IF YOU ARE DOING A UNITY/JUMBO BUILD, OR INCLUDING .CPP FILES FROM OTHERS)
|
||||
// YOU SHOULD NOT BUILD BOTH IN THE SAME COMPILATION UNIT.
|
||||
// BUT IF YOU REALLY WANT TO, you can '#define IMGUI_IMPL_OPENGL_LOADER_CUSTOM' and imgui_impl_opengl3.cpp
|
||||
// WILL NOT BE USING OUR LOADER, AND INSTEAD EXPECT ANOTHER/YOUR LOADER TO BE AVAILABLE IN THE COMPILATION UNIT.
|
||||
//
|
||||
// Regenerate with:
|
||||
// python3 gl3w_gen.py --output ../imgui/backends/imgui_impl_opengl3_loader.h --ref ../imgui/backends/imgui_impl_opengl3.cpp ./extra_symbols.txt
|
||||
//
|
||||
// More info:
|
||||
// https://github.com/dearimgui/gl3w_stripped
|
||||
// https://github.com/ocornut/imgui/issues/4445
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
/*
|
||||
* This file was generated with gl3w_gen.py, part of imgl3w
|
||||
* (hosted at https://github.com/dearimgui/gl3w_stripped)
|
||||
*
|
||||
* This is free and unencumbered software released into the public domain.
|
||||
*
|
||||
* Anyone is free to copy, modify, publish, use, compile, sell, or
|
||||
* distribute this software, either in source code form or as a compiled
|
||||
* binary, for any purpose, commercial or non-commercial, and by any
|
||||
* means.
|
||||
*
|
||||
* In jurisdictions that recognize copyright laws, the author or authors
|
||||
* of this software dedicate any and all copyright interest in the
|
||||
* software to the public domain. We make this dedication for the benefit
|
||||
* of the public at large and to the detriment of our heirs and
|
||||
* successors. We intend this dedication to be an overt act of
|
||||
* relinquishment in perpetuity of all present and future rights to this
|
||||
* software under copyright law.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
* IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
||||
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
* OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef __gl3w_h_
|
||||
#define __gl3w_h_
|
||||
|
||||
// Adapted from KHR/khrplatform.h to avoid including entire file.
|
||||
#ifndef __khrplatform_h_
|
||||
typedef float khronos_float_t;
|
||||
typedef signed char khronos_int8_t;
|
||||
typedef unsigned char khronos_uint8_t;
|
||||
typedef signed short int khronos_int16_t;
|
||||
typedef unsigned short int khronos_uint16_t;
|
||||
#ifdef _WIN64
|
||||
typedef signed long long int khronos_intptr_t;
|
||||
typedef signed long long int khronos_ssize_t;
|
||||
#else
|
||||
typedef signed long int khronos_intptr_t;
|
||||
typedef signed long int khronos_ssize_t;
|
||||
#endif
|
||||
|
||||
#if defined(_MSC_VER) && !defined(__clang__)
|
||||
typedef signed __int64 khronos_int64_t;
|
||||
typedef unsigned __int64 khronos_uint64_t;
|
||||
#elif (defined(__clang__) || defined(__GNUC__)) && (__cplusplus < 201100)
|
||||
#include <stdint.h>
|
||||
typedef int64_t khronos_int64_t;
|
||||
typedef uint64_t khronos_uint64_t;
|
||||
#else
|
||||
typedef signed long long khronos_int64_t;
|
||||
typedef unsigned long long khronos_uint64_t;
|
||||
#endif
|
||||
#endif // __khrplatform_h_
|
||||
|
||||
#ifndef __gl_glcorearb_h_
|
||||
#define __gl_glcorearb_h_ 1
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
/*
|
||||
** Copyright 2013-2020 The Khronos Group Inc.
|
||||
** SPDX-License-Identifier: MIT
|
||||
**
|
||||
** This header is generated from the Khronos OpenGL / OpenGL ES XML
|
||||
** API Registry. The current version of the Registry, generator scripts
|
||||
** used to make the header, and the header can be found at
|
||||
** https://github.com/KhronosGroup/OpenGL-Registry
|
||||
*/
|
||||
#if defined(_WIN32) && !defined(APIENTRY) && !defined(__CYGWIN__) && !defined(__SCITECH_SNAP__)
|
||||
#ifndef WIN32_LEAN_AND_MEAN
|
||||
#define WIN32_LEAN_AND_MEAN 1
|
||||
#endif
|
||||
#include <windows.h>
|
||||
#endif
|
||||
#ifndef APIENTRY
|
||||
#define APIENTRY
|
||||
#endif
|
||||
#ifndef APIENTRYP
|
||||
#define APIENTRYP APIENTRY *
|
||||
#endif
|
||||
#ifndef GLAPI
|
||||
#define GLAPI extern
|
||||
#endif
|
||||
/* glcorearb.h is for use with OpenGL core profile implementations.
|
||||
** It should should be placed in the same directory as gl.h and
|
||||
** included as <GL/glcorearb.h>.
|
||||
**
|
||||
** glcorearb.h includes only APIs in the latest OpenGL core profile
|
||||
** implementation together with APIs in newer ARB extensions which
|
||||
** can be supported by the core profile. It does not, and never will
|
||||
** include functionality removed from the core profile, such as
|
||||
** fixed-function vertex and fragment processing.
|
||||
**
|
||||
** Do not #include both <GL/glcorearb.h> and either of <GL/gl.h> or
|
||||
** <GL/glext.h> in the same source file.
|
||||
*/
|
||||
/* Generated C header for:
|
||||
* API: gl
|
||||
* Profile: core
|
||||
* Versions considered: .*
|
||||
* Versions emitted: .*
|
||||
* Default extensions included: glcore
|
||||
* Additional extensions included: _nomatch_^
|
||||
* Extensions removed: _nomatch_^
|
||||
*/
|
||||
#ifndef GL_VERSION_1_0
|
||||
typedef void GLvoid;
|
||||
typedef unsigned int GLenum;
|
||||
|
||||
typedef khronos_float_t GLfloat;
|
||||
typedef int GLint;
|
||||
typedef int GLsizei;
|
||||
typedef unsigned int GLbitfield;
|
||||
typedef double GLdouble;
|
||||
typedef unsigned int GLuint;
|
||||
typedef unsigned char GLboolean;
|
||||
typedef khronos_uint8_t GLubyte;
|
||||
#define GL_COLOR_BUFFER_BIT 0x00004000
|
||||
#define GL_FALSE 0
|
||||
#define GL_TRUE 1
|
||||
#define GL_TRIANGLES 0x0004
|
||||
#define GL_ONE 1
|
||||
#define GL_SRC_ALPHA 0x0302
|
||||
#define GL_ONE_MINUS_SRC_ALPHA 0x0303
|
||||
#define GL_FRONT 0x0404
|
||||
#define GL_BACK 0x0405
|
||||
#define GL_FRONT_AND_BACK 0x0408
|
||||
#define GL_POLYGON_MODE 0x0B40
|
||||
#define GL_CULL_FACE 0x0B44
|
||||
#define GL_DEPTH_TEST 0x0B71
|
||||
#define GL_STENCIL_TEST 0x0B90
|
||||
#define GL_VIEWPORT 0x0BA2
|
||||
#define GL_BLEND 0x0BE2
|
||||
#define GL_SCISSOR_BOX 0x0C10
|
||||
#define GL_SCISSOR_TEST 0x0C11
|
||||
#define GL_UNPACK_ROW_LENGTH 0x0CF2
|
||||
#define GL_UNPACK_ALIGNMENT 0x0CF5
|
||||
#define GL_PACK_ALIGNMENT 0x0D05
|
||||
#define GL_MAX_TEXTURE_SIZE 0x0D33
|
||||
#define GL_TEXTURE_2D 0x0DE1
|
||||
#define GL_UNSIGNED_BYTE 0x1401
|
||||
#define GL_UNSIGNED_SHORT 0x1403
|
||||
#define GL_UNSIGNED_INT 0x1405
|
||||
#define GL_FLOAT 0x1406
|
||||
#define GL_RGBA 0x1908
|
||||
#define GL_FILL 0x1B02
|
||||
#define GL_VENDOR 0x1F00
|
||||
#define GL_RENDERER 0x1F01
|
||||
#define GL_VERSION 0x1F02
|
||||
#define GL_EXTENSIONS 0x1F03
|
||||
#define GL_LINEAR 0x2601
|
||||
#define GL_TEXTURE_MAG_FILTER 0x2800
|
||||
#define GL_TEXTURE_MIN_FILTER 0x2801
|
||||
#define GL_TEXTURE_WRAP_S 0x2802
|
||||
#define GL_TEXTURE_WRAP_T 0x2803
|
||||
#define GL_REPEAT 0x2901
|
||||
typedef void (APIENTRYP PFNGLPOLYGONMODEPROC) (GLenum face, GLenum mode);
|
||||
typedef void (APIENTRYP PFNGLSCISSORPROC) (GLint x, GLint y, GLsizei width, GLsizei height);
|
||||
typedef void (APIENTRYP PFNGLTEXPARAMETERIPROC) (GLenum target, GLenum pname, GLint param);
|
||||
typedef void (APIENTRYP PFNGLTEXIMAGE2DPROC) (GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const void *pixels);
|
||||
typedef void (APIENTRYP PFNGLCLEARPROC) (GLbitfield mask);
|
||||
typedef void (APIENTRYP PFNGLCLEARCOLORPROC) (GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha);
|
||||
typedef void (APIENTRYP PFNGLDISABLEPROC) (GLenum cap);
|
||||
typedef void (APIENTRYP PFNGLENABLEPROC) (GLenum cap);
|
||||
typedef void (APIENTRYP PFNGLFLUSHPROC) (void);
|
||||
typedef void (APIENTRYP PFNGLPIXELSTOREIPROC) (GLenum pname, GLint param);
|
||||
typedef void (APIENTRYP PFNGLREADPIXELSPROC) (GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, void *pixels);
|
||||
typedef GLenum (APIENTRYP PFNGLGETERRORPROC) (void);
|
||||
typedef void (APIENTRYP PFNGLGETINTEGERVPROC) (GLenum pname, GLint *data);
|
||||
typedef const GLubyte *(APIENTRYP PFNGLGETSTRINGPROC) (GLenum name);
|
||||
typedef GLboolean (APIENTRYP PFNGLISENABLEDPROC) (GLenum cap);
|
||||
typedef void (APIENTRYP PFNGLVIEWPORTPROC) (GLint x, GLint y, GLsizei width, GLsizei height);
|
||||
#ifdef GL_GLEXT_PROTOTYPES
|
||||
GLAPI void APIENTRY glPolygonMode (GLenum face, GLenum mode);
|
||||
GLAPI void APIENTRY glScissor (GLint x, GLint y, GLsizei width, GLsizei height);
|
||||
GLAPI void APIENTRY glTexParameteri (GLenum target, GLenum pname, GLint param);
|
||||
GLAPI void APIENTRY glTexImage2D (GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const void *pixels);
|
||||
GLAPI void APIENTRY glClear (GLbitfield mask);
|
||||
GLAPI void APIENTRY glClearColor (GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha);
|
||||
GLAPI void APIENTRY glDisable (GLenum cap);
|
||||
GLAPI void APIENTRY glEnable (GLenum cap);
|
||||
GLAPI void APIENTRY glFlush (void);
|
||||
GLAPI void APIENTRY glPixelStorei (GLenum pname, GLint param);
|
||||
GLAPI void APIENTRY glReadPixels (GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, void *pixels);
|
||||
GLAPI GLenum APIENTRY glGetError (void);
|
||||
GLAPI void APIENTRY glGetIntegerv (GLenum pname, GLint *data);
|
||||
GLAPI const GLubyte *APIENTRY glGetString (GLenum name);
|
||||
GLAPI GLboolean APIENTRY glIsEnabled (GLenum cap);
|
||||
GLAPI void APIENTRY glViewport (GLint x, GLint y, GLsizei width, GLsizei height);
|
||||
#endif
|
||||
#endif /* GL_VERSION_1_0 */
|
||||
#ifndef GL_VERSION_1_1
|
||||
typedef khronos_float_t GLclampf;
|
||||
typedef double GLclampd;
|
||||
#define GL_TEXTURE_BINDING_2D 0x8069
|
||||
typedef void (APIENTRYP PFNGLDRAWELEMENTSPROC) (GLenum mode, GLsizei count, GLenum type, const void *indices);
|
||||
typedef void (APIENTRYP PFNGLTEXSUBIMAGE2DPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const void *pixels);
|
||||
typedef void (APIENTRYP PFNGLBINDTEXTUREPROC) (GLenum target, GLuint texture);
|
||||
typedef void (APIENTRYP PFNGLDELETETEXTURESPROC) (GLsizei n, const GLuint *textures);
|
||||
typedef void (APIENTRYP PFNGLGENTEXTURESPROC) (GLsizei n, GLuint *textures);
|
||||
#ifdef GL_GLEXT_PROTOTYPES
|
||||
GLAPI void APIENTRY glDrawElements (GLenum mode, GLsizei count, GLenum type, const void *indices);
|
||||
GLAPI void APIENTRY glTexSubImage2D (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const void *pixels);
|
||||
GLAPI void APIENTRY glBindTexture (GLenum target, GLuint texture);
|
||||
GLAPI void APIENTRY glDeleteTextures (GLsizei n, const GLuint *textures);
|
||||
GLAPI void APIENTRY glGenTextures (GLsizei n, GLuint *textures);
|
||||
#endif
|
||||
#endif /* GL_VERSION_1_1 */
|
||||
#ifndef GL_VERSION_1_2
|
||||
#define GL_CLAMP_TO_EDGE 0x812F
|
||||
#endif /* GL_VERSION_1_2 */
|
||||
#ifndef GL_VERSION_1_3
|
||||
#define GL_TEXTURE0 0x84C0
|
||||
#define GL_ACTIVE_TEXTURE 0x84E0
|
||||
typedef void (APIENTRYP PFNGLACTIVETEXTUREPROC) (GLenum texture);
|
||||
#ifdef GL_GLEXT_PROTOTYPES
|
||||
GLAPI void APIENTRY glActiveTexture (GLenum texture);
|
||||
#endif
|
||||
#endif /* GL_VERSION_1_3 */
|
||||
#ifndef GL_VERSION_1_4
|
||||
#define GL_BLEND_DST_RGB 0x80C8
|
||||
#define GL_BLEND_SRC_RGB 0x80C9
|
||||
#define GL_BLEND_DST_ALPHA 0x80CA
|
||||
#define GL_BLEND_SRC_ALPHA 0x80CB
|
||||
#define GL_FUNC_ADD 0x8006
|
||||
typedef void (APIENTRYP PFNGLBLENDFUNCSEPARATEPROC) (GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorAlpha, GLenum dfactorAlpha);
|
||||
typedef void (APIENTRYP PFNGLBLENDEQUATIONPROC) (GLenum mode);
|
||||
#ifdef GL_GLEXT_PROTOTYPES
|
||||
GLAPI void APIENTRY glBlendFuncSeparate (GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorAlpha, GLenum dfactorAlpha);
|
||||
GLAPI void APIENTRY glBlendEquation (GLenum mode);
|
||||
#endif
|
||||
#endif /* GL_VERSION_1_4 */
|
||||
#ifndef GL_VERSION_1_5
|
||||
typedef khronos_ssize_t GLsizeiptr;
|
||||
typedef khronos_intptr_t GLintptr;
|
||||
#define GL_ARRAY_BUFFER 0x8892
|
||||
#define GL_ELEMENT_ARRAY_BUFFER 0x8893
|
||||
#define GL_ARRAY_BUFFER_BINDING 0x8894
|
||||
#define GL_ELEMENT_ARRAY_BUFFER_BINDING 0x8895
|
||||
#define GL_STREAM_DRAW 0x88E0
|
||||
typedef void (APIENTRYP PFNGLBINDBUFFERPROC) (GLenum target, GLuint buffer);
|
||||
typedef void (APIENTRYP PFNGLDELETEBUFFERSPROC) (GLsizei n, const GLuint *buffers);
|
||||
typedef void (APIENTRYP PFNGLGENBUFFERSPROC) (GLsizei n, GLuint *buffers);
|
||||
typedef void (APIENTRYP PFNGLBUFFERDATAPROC) (GLenum target, GLsizeiptr size, const void *data, GLenum usage);
|
||||
typedef void (APIENTRYP PFNGLBUFFERSUBDATAPROC) (GLenum target, GLintptr offset, GLsizeiptr size, const void *data);
|
||||
#ifdef GL_GLEXT_PROTOTYPES
|
||||
GLAPI void APIENTRY glBindBuffer (GLenum target, GLuint buffer);
|
||||
GLAPI void APIENTRY glDeleteBuffers (GLsizei n, const GLuint *buffers);
|
||||
GLAPI void APIENTRY glGenBuffers (GLsizei n, GLuint *buffers);
|
||||
GLAPI void APIENTRY glBufferData (GLenum target, GLsizeiptr size, const void *data, GLenum usage);
|
||||
GLAPI void APIENTRY glBufferSubData (GLenum target, GLintptr offset, GLsizeiptr size, const void *data);
|
||||
#endif
|
||||
#endif /* GL_VERSION_1_5 */
|
||||
#ifndef GL_VERSION_2_0
|
||||
typedef char GLchar;
|
||||
typedef khronos_int16_t GLshort;
|
||||
typedef khronos_int8_t GLbyte;
|
||||
typedef khronos_uint16_t GLushort;
|
||||
#define GL_BLEND_EQUATION_RGB 0x8009
|
||||
#define GL_VERTEX_ATTRIB_ARRAY_ENABLED 0x8622
|
||||
#define GL_VERTEX_ATTRIB_ARRAY_SIZE 0x8623
|
||||
#define GL_VERTEX_ATTRIB_ARRAY_STRIDE 0x8624
|
||||
#define GL_VERTEX_ATTRIB_ARRAY_TYPE 0x8625
|
||||
#define GL_VERTEX_ATTRIB_ARRAY_POINTER 0x8645
|
||||
#define GL_BLEND_EQUATION_ALPHA 0x883D
|
||||
#define GL_VERTEX_ATTRIB_ARRAY_NORMALIZED 0x886A
|
||||
#define GL_FRAGMENT_SHADER 0x8B30
|
||||
#define GL_VERTEX_SHADER 0x8B31
|
||||
#define GL_COMPILE_STATUS 0x8B81
|
||||
#define GL_LINK_STATUS 0x8B82
|
||||
#define GL_INFO_LOG_LENGTH 0x8B84
|
||||
#define GL_CURRENT_PROGRAM 0x8B8D
|
||||
#define GL_UPPER_LEFT 0x8CA2
|
||||
typedef void (APIENTRYP PFNGLBLENDEQUATIONSEPARATEPROC) (GLenum modeRGB, GLenum modeAlpha);
|
||||
typedef void (APIENTRYP PFNGLATTACHSHADERPROC) (GLuint program, GLuint shader);
|
||||
typedef void (APIENTRYP PFNGLCOMPILESHADERPROC) (GLuint shader);
|
||||
typedef GLuint (APIENTRYP PFNGLCREATEPROGRAMPROC) (void);
|
||||
typedef GLuint (APIENTRYP PFNGLCREATESHADERPROC) (GLenum type);
|
||||
typedef void (APIENTRYP PFNGLDELETEPROGRAMPROC) (GLuint program);
|
||||
typedef void (APIENTRYP PFNGLDELETESHADERPROC) (GLuint shader);
|
||||
typedef void (APIENTRYP PFNGLDETACHSHADERPROC) (GLuint program, GLuint shader);
|
||||
typedef void (APIENTRYP PFNGLDISABLEVERTEXATTRIBARRAYPROC) (GLuint index);
|
||||
typedef void (APIENTRYP PFNGLENABLEVERTEXATTRIBARRAYPROC) (GLuint index);
|
||||
typedef GLint (APIENTRYP PFNGLGETATTRIBLOCATIONPROC) (GLuint program, const GLchar *name);
|
||||
typedef void (APIENTRYP PFNGLGETPROGRAMIVPROC) (GLuint program, GLenum pname, GLint *params);
|
||||
typedef void (APIENTRYP PFNGLGETPROGRAMINFOLOGPROC) (GLuint program, GLsizei bufSize, GLsizei *length, GLchar *infoLog);
|
||||
typedef void (APIENTRYP PFNGLGETSHADERIVPROC) (GLuint shader, GLenum pname, GLint *params);
|
||||
typedef void (APIENTRYP PFNGLGETSHADERINFOLOGPROC) (GLuint shader, GLsizei bufSize, GLsizei *length, GLchar *infoLog);
|
||||
typedef GLint (APIENTRYP PFNGLGETUNIFORMLOCATIONPROC) (GLuint program, const GLchar *name);
|
||||
typedef void (APIENTRYP PFNGLGETVERTEXATTRIBIVPROC) (GLuint index, GLenum pname, GLint *params);
|
||||
typedef void (APIENTRYP PFNGLGETVERTEXATTRIBPOINTERVPROC) (GLuint index, GLenum pname, void **pointer);
|
||||
typedef GLboolean (APIENTRYP PFNGLISPROGRAMPROC) (GLuint program);
|
||||
typedef void (APIENTRYP PFNGLLINKPROGRAMPROC) (GLuint program);
|
||||
typedef void (APIENTRYP PFNGLSHADERSOURCEPROC) (GLuint shader, GLsizei count, const GLchar *const*string, const GLint *length);
|
||||
typedef void (APIENTRYP PFNGLUSEPROGRAMPROC) (GLuint program);
|
||||
typedef void (APIENTRYP PFNGLUNIFORM1IPROC) (GLint location, GLint v0);
|
||||
typedef void (APIENTRYP PFNGLUNIFORMMATRIX4FVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
|
||||
typedef void (APIENTRYP PFNGLVERTEXATTRIBPOINTERPROC) (GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const void *pointer);
|
||||
#ifdef GL_GLEXT_PROTOTYPES
|
||||
GLAPI void APIENTRY glBlendEquationSeparate (GLenum modeRGB, GLenum modeAlpha);
|
||||
GLAPI void APIENTRY glAttachShader (GLuint program, GLuint shader);
|
||||
GLAPI void APIENTRY glCompileShader (GLuint shader);
|
||||
GLAPI GLuint APIENTRY glCreateProgram (void);
|
||||
GLAPI GLuint APIENTRY glCreateShader (GLenum type);
|
||||
GLAPI void APIENTRY glDeleteProgram (GLuint program);
|
||||
GLAPI void APIENTRY glDeleteShader (GLuint shader);
|
||||
GLAPI void APIENTRY glDetachShader (GLuint program, GLuint shader);
|
||||
GLAPI void APIENTRY glDisableVertexAttribArray (GLuint index);
|
||||
GLAPI void APIENTRY glEnableVertexAttribArray (GLuint index);
|
||||
GLAPI GLint APIENTRY glGetAttribLocation (GLuint program, const GLchar *name);
|
||||
GLAPI void APIENTRY glGetProgramiv (GLuint program, GLenum pname, GLint *params);
|
||||
GLAPI void APIENTRY glGetProgramInfoLog (GLuint program, GLsizei bufSize, GLsizei *length, GLchar *infoLog);
|
||||
GLAPI void APIENTRY glGetShaderiv (GLuint shader, GLenum pname, GLint *params);
|
||||
GLAPI void APIENTRY glGetShaderInfoLog (GLuint shader, GLsizei bufSize, GLsizei *length, GLchar *infoLog);
|
||||
GLAPI GLint APIENTRY glGetUniformLocation (GLuint program, const GLchar *name);
|
||||
GLAPI void APIENTRY glGetVertexAttribiv (GLuint index, GLenum pname, GLint *params);
|
||||
GLAPI void APIENTRY glGetVertexAttribPointerv (GLuint index, GLenum pname, void **pointer);
|
||||
GLAPI GLboolean APIENTRY glIsProgram (GLuint program);
|
||||
GLAPI void APIENTRY glLinkProgram (GLuint program);
|
||||
GLAPI void APIENTRY glShaderSource (GLuint shader, GLsizei count, const GLchar *const*string, const GLint *length);
|
||||
GLAPI void APIENTRY glUseProgram (GLuint program);
|
||||
GLAPI void APIENTRY glUniform1i (GLint location, GLint v0);
|
||||
GLAPI void APIENTRY glUniformMatrix4fv (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
|
||||
GLAPI void APIENTRY glVertexAttribPointer (GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const void *pointer);
|
||||
#endif
|
||||
#endif /* GL_VERSION_2_0 */
|
||||
#ifndef GL_VERSION_2_1
|
||||
#define GL_PIXEL_UNPACK_BUFFER 0x88EC
|
||||
#define GL_PIXEL_UNPACK_BUFFER_BINDING 0x88EF
|
||||
#endif /* GL_VERSION_2_1 */
|
||||
#ifndef GL_VERSION_3_0
|
||||
typedef khronos_uint16_t GLhalf;
|
||||
#define GL_MAJOR_VERSION 0x821B
|
||||
#define GL_MINOR_VERSION 0x821C
|
||||
#define GL_NUM_EXTENSIONS 0x821D
|
||||
#define GL_FRAMEBUFFER_SRGB 0x8DB9
|
||||
#define GL_VERTEX_ARRAY_BINDING 0x85B5
|
||||
typedef void (APIENTRYP PFNGLGETBOOLEANI_VPROC) (GLenum target, GLuint index, GLboolean *data);
|
||||
typedef void (APIENTRYP PFNGLGETINTEGERI_VPROC) (GLenum target, GLuint index, GLint *data);
|
||||
typedef const GLubyte *(APIENTRYP PFNGLGETSTRINGIPROC) (GLenum name, GLuint index);
|
||||
typedef void (APIENTRYP PFNGLBINDVERTEXARRAYPROC) (GLuint array);
|
||||
typedef void (APIENTRYP PFNGLDELETEVERTEXARRAYSPROC) (GLsizei n, const GLuint *arrays);
|
||||
typedef void (APIENTRYP PFNGLGENVERTEXARRAYSPROC) (GLsizei n, GLuint *arrays);
|
||||
#ifdef GL_GLEXT_PROTOTYPES
|
||||
GLAPI const GLubyte *APIENTRY glGetStringi (GLenum name, GLuint index);
|
||||
GLAPI void APIENTRY glBindVertexArray (GLuint array);
|
||||
GLAPI void APIENTRY glDeleteVertexArrays (GLsizei n, const GLuint *arrays);
|
||||
GLAPI void APIENTRY glGenVertexArrays (GLsizei n, GLuint *arrays);
|
||||
#endif
|
||||
#endif /* GL_VERSION_3_0 */
|
||||
#ifndef GL_VERSION_3_1
|
||||
#define GL_VERSION_3_1 1
|
||||
#define GL_PRIMITIVE_RESTART 0x8F9D
|
||||
#endif /* GL_VERSION_3_1 */
|
||||
#ifndef GL_VERSION_3_2
|
||||
#define GL_VERSION_3_2 1
|
||||
typedef struct __GLsync *GLsync;
|
||||
typedef khronos_uint64_t GLuint64;
|
||||
typedef khronos_int64_t GLint64;
|
||||
#define GL_CONTEXT_COMPATIBILITY_PROFILE_BIT 0x00000002
|
||||
#define GL_CONTEXT_PROFILE_MASK 0x9126
|
||||
typedef void (APIENTRYP PFNGLDRAWELEMENTSBASEVERTEXPROC) (GLenum mode, GLsizei count, GLenum type, const void *indices, GLint basevertex);
|
||||
typedef void (APIENTRYP PFNGLGETINTEGER64I_VPROC) (GLenum target, GLuint index, GLint64 *data);
|
||||
#ifdef GL_GLEXT_PROTOTYPES
|
||||
GLAPI void APIENTRY glDrawElementsBaseVertex (GLenum mode, GLsizei count, GLenum type, const void *indices, GLint basevertex);
|
||||
#endif
|
||||
#endif /* GL_VERSION_3_2 */
|
||||
#ifndef GL_VERSION_3_3
|
||||
#define GL_VERSION_3_3 1
|
||||
#define GL_SAMPLER_BINDING 0x8919
|
||||
typedef void (APIENTRYP PFNGLBINDSAMPLERPROC) (GLuint unit, GLuint sampler);
|
||||
#ifdef GL_GLEXT_PROTOTYPES
|
||||
GLAPI void APIENTRY glBindSampler (GLuint unit, GLuint sampler);
|
||||
#endif
|
||||
#endif /* GL_VERSION_3_3 */
|
||||
#ifndef GL_VERSION_4_1
|
||||
typedef void (APIENTRYP PFNGLGETFLOATI_VPROC) (GLenum target, GLuint index, GLfloat *data);
|
||||
typedef void (APIENTRYP PFNGLGETDOUBLEI_VPROC) (GLenum target, GLuint index, GLdouble *data);
|
||||
#endif /* GL_VERSION_4_1 */
|
||||
#ifndef GL_VERSION_4_3
|
||||
typedef void (APIENTRY *GLDEBUGPROC)(GLenum source,GLenum type,GLuint id,GLenum severity,GLsizei length,const GLchar *message,const void *userParam);
|
||||
#endif /* GL_VERSION_4_3 */
|
||||
#ifndef GL_VERSION_4_5
|
||||
#define GL_CLIP_ORIGIN 0x935C
|
||||
typedef void (APIENTRYP PFNGLGETTRANSFORMFEEDBACKI_VPROC) (GLuint xfb, GLenum pname, GLuint index, GLint *param);
|
||||
typedef void (APIENTRYP PFNGLGETTRANSFORMFEEDBACKI64_VPROC) (GLuint xfb, GLenum pname, GLuint index, GLint64 *param);
|
||||
#endif /* GL_VERSION_4_5 */
|
||||
#ifndef GL_ARB_bindless_texture
|
||||
typedef khronos_uint64_t GLuint64EXT;
|
||||
#endif /* GL_ARB_bindless_texture */
|
||||
#ifndef GL_ARB_cl_event
|
||||
struct _cl_context;
|
||||
struct _cl_event;
|
||||
#endif /* GL_ARB_cl_event */
|
||||
#ifndef GL_ARB_clip_control
|
||||
#define GL_ARB_clip_control 1
|
||||
#endif /* GL_ARB_clip_control */
|
||||
#ifndef GL_ARB_debug_output
|
||||
typedef void (APIENTRY *GLDEBUGPROCARB)(GLenum source,GLenum type,GLuint id,GLenum severity,GLsizei length,const GLchar *message,const void *userParam);
|
||||
#endif /* GL_ARB_debug_output */
|
||||
#ifndef GL_EXT_EGL_image_storage
|
||||
typedef void *GLeglImageOES;
|
||||
#endif /* GL_EXT_EGL_image_storage */
|
||||
#ifndef GL_EXT_direct_state_access
|
||||
typedef void (APIENTRYP PFNGLGETFLOATI_VEXTPROC) (GLenum pname, GLuint index, GLfloat *params);
|
||||
typedef void (APIENTRYP PFNGLGETDOUBLEI_VEXTPROC) (GLenum pname, GLuint index, GLdouble *params);
|
||||
typedef void (APIENTRYP PFNGLGETPOINTERI_VEXTPROC) (GLenum pname, GLuint index, void **params);
|
||||
typedef void (APIENTRYP PFNGLGETVERTEXARRAYINTEGERI_VEXTPROC) (GLuint vaobj, GLuint index, GLenum pname, GLint *param);
|
||||
typedef void (APIENTRYP PFNGLGETVERTEXARRAYPOINTERI_VEXTPROC) (GLuint vaobj, GLuint index, GLenum pname, void **param);
|
||||
#endif /* GL_EXT_direct_state_access */
|
||||
#ifndef GL_NV_draw_vulkan_image
|
||||
typedef void (APIENTRY *GLVULKANPROCNV)(void);
|
||||
#endif /* GL_NV_draw_vulkan_image */
|
||||
#ifndef GL_NV_gpu_shader5
|
||||
typedef khronos_int64_t GLint64EXT;
|
||||
#endif /* GL_NV_gpu_shader5 */
|
||||
#ifndef GL_NV_vertex_buffer_unified_memory
|
||||
typedef void (APIENTRYP PFNGLGETINTEGERUI64I_VNVPROC) (GLenum value, GLuint index, GLuint64EXT *result);
|
||||
#endif /* GL_NV_vertex_buffer_unified_memory */
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef GL3W_API
|
||||
#define GL3W_API
|
||||
#endif
|
||||
|
||||
#ifndef __gl_h_
|
||||
#define __gl_h_
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define GL3W_OK 0
|
||||
#define GL3W_ERROR_INIT -1
|
||||
#define GL3W_ERROR_LIBRARY_OPEN -2
|
||||
#define GL3W_ERROR_OPENGL_VERSION -3
|
||||
|
||||
typedef void (*GL3WglProc)(void);
|
||||
typedef GL3WglProc (*GL3WGetProcAddressProc)(const char *proc);
|
||||
|
||||
/* gl3w api */
|
||||
GL3W_API int imgl3wInit(void);
|
||||
GL3W_API int imgl3wInit2(GL3WGetProcAddressProc proc);
|
||||
GL3W_API void imgl3wShutdown(void);
|
||||
GL3W_API int imgl3wIsSupported(int major, int minor);
|
||||
GL3W_API GL3WglProc imgl3wGetProcAddress(const char *proc);
|
||||
|
||||
/* gl3w internal state */
|
||||
union ImGL3WProcs {
|
||||
GL3WglProc ptr[60];
|
||||
struct {
|
||||
PFNGLACTIVETEXTUREPROC ActiveTexture;
|
||||
PFNGLATTACHSHADERPROC AttachShader;
|
||||
PFNGLBINDBUFFERPROC BindBuffer;
|
||||
PFNGLBINDSAMPLERPROC BindSampler;
|
||||
PFNGLBINDTEXTUREPROC BindTexture;
|
||||
PFNGLBINDVERTEXARRAYPROC BindVertexArray;
|
||||
PFNGLBLENDEQUATIONPROC BlendEquation;
|
||||
PFNGLBLENDEQUATIONSEPARATEPROC BlendEquationSeparate;
|
||||
PFNGLBLENDFUNCSEPARATEPROC BlendFuncSeparate;
|
||||
PFNGLBUFFERDATAPROC BufferData;
|
||||
PFNGLBUFFERSUBDATAPROC BufferSubData;
|
||||
PFNGLCLEARPROC Clear;
|
||||
PFNGLCLEARCOLORPROC ClearColor;
|
||||
PFNGLCOMPILESHADERPROC CompileShader;
|
||||
PFNGLCREATEPROGRAMPROC CreateProgram;
|
||||
PFNGLCREATESHADERPROC CreateShader;
|
||||
PFNGLDELETEBUFFERSPROC DeleteBuffers;
|
||||
PFNGLDELETEPROGRAMPROC DeleteProgram;
|
||||
PFNGLDELETESHADERPROC DeleteShader;
|
||||
PFNGLDELETETEXTURESPROC DeleteTextures;
|
||||
PFNGLDELETEVERTEXARRAYSPROC DeleteVertexArrays;
|
||||
PFNGLDETACHSHADERPROC DetachShader;
|
||||
PFNGLDISABLEPROC Disable;
|
||||
PFNGLDISABLEVERTEXATTRIBARRAYPROC DisableVertexAttribArray;
|
||||
PFNGLDRAWELEMENTSPROC DrawElements;
|
||||
PFNGLDRAWELEMENTSBASEVERTEXPROC DrawElementsBaseVertex;
|
||||
PFNGLENABLEPROC Enable;
|
||||
PFNGLENABLEVERTEXATTRIBARRAYPROC EnableVertexAttribArray;
|
||||
PFNGLFLUSHPROC Flush;
|
||||
PFNGLGENBUFFERSPROC GenBuffers;
|
||||
PFNGLGENTEXTURESPROC GenTextures;
|
||||
PFNGLGENVERTEXARRAYSPROC GenVertexArrays;
|
||||
PFNGLGETATTRIBLOCATIONPROC GetAttribLocation;
|
||||
PFNGLGETERRORPROC GetError;
|
||||
PFNGLGETINTEGERVPROC GetIntegerv;
|
||||
PFNGLGETPROGRAMINFOLOGPROC GetProgramInfoLog;
|
||||
PFNGLGETPROGRAMIVPROC GetProgramiv;
|
||||
PFNGLGETSHADERINFOLOGPROC GetShaderInfoLog;
|
||||
PFNGLGETSHADERIVPROC GetShaderiv;
|
||||
PFNGLGETSTRINGPROC GetString;
|
||||
PFNGLGETSTRINGIPROC GetStringi;
|
||||
PFNGLGETUNIFORMLOCATIONPROC GetUniformLocation;
|
||||
PFNGLGETVERTEXATTRIBPOINTERVPROC GetVertexAttribPointerv;
|
||||
PFNGLGETVERTEXATTRIBIVPROC GetVertexAttribiv;
|
||||
PFNGLISENABLEDPROC IsEnabled;
|
||||
PFNGLISPROGRAMPROC IsProgram;
|
||||
PFNGLLINKPROGRAMPROC LinkProgram;
|
||||
PFNGLPIXELSTOREIPROC PixelStorei;
|
||||
PFNGLPOLYGONMODEPROC PolygonMode;
|
||||
PFNGLREADPIXELSPROC ReadPixels;
|
||||
PFNGLSCISSORPROC Scissor;
|
||||
PFNGLSHADERSOURCEPROC ShaderSource;
|
||||
PFNGLTEXIMAGE2DPROC TexImage2D;
|
||||
PFNGLTEXPARAMETERIPROC TexParameteri;
|
||||
PFNGLTEXSUBIMAGE2DPROC TexSubImage2D;
|
||||
PFNGLUNIFORM1IPROC Uniform1i;
|
||||
PFNGLUNIFORMMATRIX4FVPROC UniformMatrix4fv;
|
||||
PFNGLUSEPROGRAMPROC UseProgram;
|
||||
PFNGLVERTEXATTRIBPOINTERPROC VertexAttribPointer;
|
||||
PFNGLVIEWPORTPROC Viewport;
|
||||
} gl;
|
||||
};
|
||||
|
||||
GL3W_API extern union ImGL3WProcs imgl3wProcs;
|
||||
|
||||
/* OpenGL functions */
|
||||
#define glActiveTexture imgl3wProcs.gl.ActiveTexture
|
||||
#define glAttachShader imgl3wProcs.gl.AttachShader
|
||||
#define glBindBuffer imgl3wProcs.gl.BindBuffer
|
||||
#define glBindSampler imgl3wProcs.gl.BindSampler
|
||||
#define glBindTexture imgl3wProcs.gl.BindTexture
|
||||
#define glBindVertexArray imgl3wProcs.gl.BindVertexArray
|
||||
#define glBlendEquation imgl3wProcs.gl.BlendEquation
|
||||
#define glBlendEquationSeparate imgl3wProcs.gl.BlendEquationSeparate
|
||||
#define glBlendFuncSeparate imgl3wProcs.gl.BlendFuncSeparate
|
||||
#define glBufferData imgl3wProcs.gl.BufferData
|
||||
#define glBufferSubData imgl3wProcs.gl.BufferSubData
|
||||
#define glClear imgl3wProcs.gl.Clear
|
||||
#define glClearColor imgl3wProcs.gl.ClearColor
|
||||
#define glCompileShader imgl3wProcs.gl.CompileShader
|
||||
#define glCreateProgram imgl3wProcs.gl.CreateProgram
|
||||
#define glCreateShader imgl3wProcs.gl.CreateShader
|
||||
#define glDeleteBuffers imgl3wProcs.gl.DeleteBuffers
|
||||
#define glDeleteProgram imgl3wProcs.gl.DeleteProgram
|
||||
#define glDeleteShader imgl3wProcs.gl.DeleteShader
|
||||
#define glDeleteTextures imgl3wProcs.gl.DeleteTextures
|
||||
#define glDeleteVertexArrays imgl3wProcs.gl.DeleteVertexArrays
|
||||
#define glDetachShader imgl3wProcs.gl.DetachShader
|
||||
#define glDisable imgl3wProcs.gl.Disable
|
||||
#define glDisableVertexAttribArray imgl3wProcs.gl.DisableVertexAttribArray
|
||||
#define glDrawElements imgl3wProcs.gl.DrawElements
|
||||
#define glDrawElementsBaseVertex imgl3wProcs.gl.DrawElementsBaseVertex
|
||||
#define glEnable imgl3wProcs.gl.Enable
|
||||
#define glEnableVertexAttribArray imgl3wProcs.gl.EnableVertexAttribArray
|
||||
#define glFlush imgl3wProcs.gl.Flush
|
||||
#define glGenBuffers imgl3wProcs.gl.GenBuffers
|
||||
#define glGenTextures imgl3wProcs.gl.GenTextures
|
||||
#define glGenVertexArrays imgl3wProcs.gl.GenVertexArrays
|
||||
#define glGetAttribLocation imgl3wProcs.gl.GetAttribLocation
|
||||
#define glGetError imgl3wProcs.gl.GetError
|
||||
#define glGetIntegerv imgl3wProcs.gl.GetIntegerv
|
||||
#define glGetProgramInfoLog imgl3wProcs.gl.GetProgramInfoLog
|
||||
#define glGetProgramiv imgl3wProcs.gl.GetProgramiv
|
||||
#define glGetShaderInfoLog imgl3wProcs.gl.GetShaderInfoLog
|
||||
#define glGetShaderiv imgl3wProcs.gl.GetShaderiv
|
||||
#define glGetString imgl3wProcs.gl.GetString
|
||||
#define glGetStringi imgl3wProcs.gl.GetStringi
|
||||
#define glGetUniformLocation imgl3wProcs.gl.GetUniformLocation
|
||||
#define glGetVertexAttribPointerv imgl3wProcs.gl.GetVertexAttribPointerv
|
||||
#define glGetVertexAttribiv imgl3wProcs.gl.GetVertexAttribiv
|
||||
#define glIsEnabled imgl3wProcs.gl.IsEnabled
|
||||
#define glIsProgram imgl3wProcs.gl.IsProgram
|
||||
#define glLinkProgram imgl3wProcs.gl.LinkProgram
|
||||
#define glPixelStorei imgl3wProcs.gl.PixelStorei
|
||||
#define glPolygonMode imgl3wProcs.gl.PolygonMode
|
||||
#define glReadPixels imgl3wProcs.gl.ReadPixels
|
||||
#define glScissor imgl3wProcs.gl.Scissor
|
||||
#define glShaderSource imgl3wProcs.gl.ShaderSource
|
||||
#define glTexImage2D imgl3wProcs.gl.TexImage2D
|
||||
#define glTexParameteri imgl3wProcs.gl.TexParameteri
|
||||
#define glTexSubImage2D imgl3wProcs.gl.TexSubImage2D
|
||||
#define glUniform1i imgl3wProcs.gl.Uniform1i
|
||||
#define glUniformMatrix4fv imgl3wProcs.gl.UniformMatrix4fv
|
||||
#define glUseProgram imgl3wProcs.gl.UseProgram
|
||||
#define glVertexAttribPointer imgl3wProcs.gl.VertexAttribPointer
|
||||
#define glViewport imgl3wProcs.gl.Viewport
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef IMGL3W_IMPL
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#define GL3W_ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
|
||||
|
||||
#if defined(_WIN32)
|
||||
#ifndef WIN32_LEAN_AND_MEAN
|
||||
#define WIN32_LEAN_AND_MEAN 1
|
||||
#endif
|
||||
#include <windows.h>
|
||||
|
||||
static HMODULE libgl = NULL;
|
||||
typedef PROC(__stdcall* GL3WglGetProcAddr)(LPCSTR);
|
||||
static GL3WglGetProcAddr wgl_get_proc_address;
|
||||
|
||||
static int open_libgl(void)
|
||||
{
|
||||
libgl = LoadLibraryA("opengl32.dll");
|
||||
if (!libgl)
|
||||
return GL3W_ERROR_LIBRARY_OPEN;
|
||||
wgl_get_proc_address = (GL3WglGetProcAddr)GetProcAddress(libgl, "wglGetProcAddress");
|
||||
return GL3W_OK;
|
||||
}
|
||||
|
||||
static void close_libgl(void) { FreeLibrary(libgl); libgl = NULL; }
|
||||
static GL3WglProc get_proc(const char *proc)
|
||||
{
|
||||
GL3WglProc res;
|
||||
res = (GL3WglProc)wgl_get_proc_address(proc);
|
||||
if (!res)
|
||||
res = (GL3WglProc)GetProcAddress(libgl, proc);
|
||||
return res;
|
||||
}
|
||||
#elif defined(__APPLE__)
|
||||
#include <dlfcn.h>
|
||||
|
||||
static void *libgl = NULL;
|
||||
static int open_libgl(void)
|
||||
{
|
||||
libgl = dlopen("/System/Library/Frameworks/OpenGL.framework/OpenGL", RTLD_LAZY | RTLD_LOCAL);
|
||||
if (!libgl)
|
||||
return GL3W_ERROR_LIBRARY_OPEN;
|
||||
return GL3W_OK;
|
||||
}
|
||||
|
||||
static void close_libgl(void) { dlclose(libgl); libgl = NULL; }
|
||||
|
||||
static GL3WglProc get_proc(const char *proc)
|
||||
{
|
||||
GL3WglProc res;
|
||||
*(void **)(&res) = dlsym(libgl, proc);
|
||||
return res;
|
||||
}
|
||||
#else
|
||||
#include <dlfcn.h>
|
||||
|
||||
static void* libgl; // OpenGL library
|
||||
static void* libglx; // GLX library
|
||||
static void* libegl; // EGL library
|
||||
static GL3WGetProcAddressProc gl_get_proc_address;
|
||||
|
||||
static void close_libgl(void)
|
||||
{
|
||||
if (libgl) {
|
||||
dlclose(libgl);
|
||||
libgl = NULL;
|
||||
}
|
||||
if (libegl) {
|
||||
dlclose(libegl);
|
||||
libegl = NULL;
|
||||
}
|
||||
if (libglx) {
|
||||
dlclose(libglx);
|
||||
libglx = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static int is_library_loaded(const char* name, void** lib)
|
||||
{
|
||||
*lib = dlopen(name, RTLD_LAZY | RTLD_LOCAL | RTLD_NOLOAD);
|
||||
return *lib != NULL;
|
||||
}
|
||||
|
||||
static int open_libs(void)
|
||||
{
|
||||
// On Linux we have two APIs to get process addresses: EGL and GLX.
|
||||
// EGL is supported under both X11 and Wayland, whereas GLX is X11-specific.
|
||||
|
||||
libgl = NULL;
|
||||
libegl = NULL;
|
||||
libglx = NULL;
|
||||
|
||||
// First check what's already loaded, the windowing library might have
|
||||
// already loaded either EGL or GLX and we want to use the same one.
|
||||
|
||||
if (is_library_loaded("libEGL.so.1", &libegl) ||
|
||||
is_library_loaded("libGLX.so.0", &libglx)) {
|
||||
libgl = dlopen("libOpenGL.so.0", RTLD_LAZY | RTLD_LOCAL);
|
||||
if (libgl)
|
||||
return GL3W_OK;
|
||||
else
|
||||
close_libgl();
|
||||
}
|
||||
|
||||
if (is_library_loaded("libGL.so", &libgl))
|
||||
return GL3W_OK;
|
||||
if (is_library_loaded("libGL.so.1", &libgl))
|
||||
return GL3W_OK;
|
||||
if (is_library_loaded("libGL.so.3", &libgl))
|
||||
return GL3W_OK;
|
||||
|
||||
// Neither is already loaded, so we have to load one. Try EGL first
|
||||
// because it is supported under both X11 and Wayland.
|
||||
|
||||
// Load OpenGL + EGL
|
||||
libgl = dlopen("libOpenGL.so.0", RTLD_LAZY | RTLD_LOCAL);
|
||||
libegl = dlopen("libEGL.so.1", RTLD_LAZY | RTLD_LOCAL);
|
||||
if (libgl && libegl)
|
||||
return GL3W_OK;
|
||||
else
|
||||
close_libgl();
|
||||
|
||||
// Fall back to legacy libGL, which includes GLX
|
||||
// While most systems use libGL.so.1, NetBSD seems to use that libGL.so.3. See https://github.com/ocornut/imgui/issues/6983
|
||||
libgl = dlopen("libGL.so", RTLD_LAZY | RTLD_LOCAL);
|
||||
if (!libgl)
|
||||
libgl = dlopen("libGL.so.1", RTLD_LAZY | RTLD_LOCAL);
|
||||
if (!libgl)
|
||||
libgl = dlopen("libGL.so.3", RTLD_LAZY | RTLD_LOCAL);
|
||||
|
||||
if (libgl)
|
||||
return GL3W_OK;
|
||||
|
||||
return GL3W_ERROR_LIBRARY_OPEN;
|
||||
}
|
||||
|
||||
static int open_libgl(void)
|
||||
{
|
||||
int res = open_libs();
|
||||
if (res)
|
||||
return res;
|
||||
|
||||
if (libegl)
|
||||
*(void**)(&gl_get_proc_address) = dlsym(libegl, "eglGetProcAddress");
|
||||
else if (libglx)
|
||||
*(void**)(&gl_get_proc_address) = dlsym(libglx, "glXGetProcAddressARB");
|
||||
else
|
||||
*(void**)(&gl_get_proc_address) = dlsym(libgl, "glXGetProcAddressARB");
|
||||
|
||||
if (!gl_get_proc_address) {
|
||||
close_libgl();
|
||||
return GL3W_ERROR_LIBRARY_OPEN;
|
||||
}
|
||||
|
||||
return GL3W_OK;
|
||||
}
|
||||
|
||||
static GL3WglProc get_proc(const char* proc)
|
||||
{
|
||||
GL3WglProc res = NULL;
|
||||
|
||||
// Before EGL version 1.5, eglGetProcAddress doesn't support querying core
|
||||
// functions and may return a dummy function if we try, so try to load the
|
||||
// function from the GL library directly first.
|
||||
if (libegl)
|
||||
*(void**)(&res) = dlsym(libgl, proc);
|
||||
|
||||
if (!res)
|
||||
res = gl_get_proc_address(proc);
|
||||
|
||||
if (!libegl && !res)
|
||||
*(void**)(&res) = dlsym(libgl, proc);
|
||||
|
||||
return res;
|
||||
}
|
||||
#endif
|
||||
|
||||
static struct { int major, minor; } version;
|
||||
|
||||
static int parse_version(void)
|
||||
{
|
||||
if (!glGetIntegerv)
|
||||
return GL3W_ERROR_INIT;
|
||||
glGetIntegerv(GL_MAJOR_VERSION, &version.major);
|
||||
glGetIntegerv(GL_MINOR_VERSION, &version.minor);
|
||||
if (version.major == 0 && version.minor == 0)
|
||||
{
|
||||
// Query GL_VERSION in desktop GL 2.x, the string will start with "<major>.<minor>"
|
||||
if (const char* gl_version = (const char*)glGetString(GL_VERSION))
|
||||
sscanf(gl_version, "%d.%d", &version.major, &version.minor);
|
||||
}
|
||||
if (version.major < 2)
|
||||
return GL3W_ERROR_OPENGL_VERSION;
|
||||
return GL3W_OK;
|
||||
}
|
||||
|
||||
static void load_procs(GL3WGetProcAddressProc proc);
|
||||
|
||||
int imgl3wInit(void)
|
||||
{
|
||||
int res = open_libgl();
|
||||
if (res)
|
||||
return res;
|
||||
atexit(close_libgl);
|
||||
return imgl3wInit2(get_proc);
|
||||
}
|
||||
|
||||
int imgl3wInit2(GL3WGetProcAddressProc proc)
|
||||
{
|
||||
load_procs(proc);
|
||||
return parse_version();
|
||||
}
|
||||
|
||||
void imgl3wShutdown(void)
|
||||
{
|
||||
close_libgl();
|
||||
}
|
||||
|
||||
int imgl3wIsSupported(int major, int minor)
|
||||
{
|
||||
if (major < 2)
|
||||
return 0;
|
||||
if (version.major == major)
|
||||
return version.minor >= minor;
|
||||
return version.major >= major;
|
||||
}
|
||||
|
||||
GL3WglProc imgl3wGetProcAddress(const char *proc) { return get_proc(proc); }
|
||||
|
||||
static const char *proc_names[] = {
|
||||
"glActiveTexture",
|
||||
"glAttachShader",
|
||||
"glBindBuffer",
|
||||
"glBindSampler",
|
||||
"glBindTexture",
|
||||
"glBindVertexArray",
|
||||
"glBlendEquation",
|
||||
"glBlendEquationSeparate",
|
||||
"glBlendFuncSeparate",
|
||||
"glBufferData",
|
||||
"glBufferSubData",
|
||||
"glClear",
|
||||
"glClearColor",
|
||||
"glCompileShader",
|
||||
"glCreateProgram",
|
||||
"glCreateShader",
|
||||
"glDeleteBuffers",
|
||||
"glDeleteProgram",
|
||||
"glDeleteShader",
|
||||
"glDeleteTextures",
|
||||
"glDeleteVertexArrays",
|
||||
"glDetachShader",
|
||||
"glDisable",
|
||||
"glDisableVertexAttribArray",
|
||||
"glDrawElements",
|
||||
"glDrawElementsBaseVertex",
|
||||
"glEnable",
|
||||
"glEnableVertexAttribArray",
|
||||
"glFlush",
|
||||
"glGenBuffers",
|
||||
"glGenTextures",
|
||||
"glGenVertexArrays",
|
||||
"glGetAttribLocation",
|
||||
"glGetError",
|
||||
"glGetIntegerv",
|
||||
"glGetProgramInfoLog",
|
||||
"glGetProgramiv",
|
||||
"glGetShaderInfoLog",
|
||||
"glGetShaderiv",
|
||||
"glGetString",
|
||||
"glGetStringi",
|
||||
"glGetUniformLocation",
|
||||
"glGetVertexAttribPointerv",
|
||||
"glGetVertexAttribiv",
|
||||
"glIsEnabled",
|
||||
"glIsProgram",
|
||||
"glLinkProgram",
|
||||
"glPixelStorei",
|
||||
"glPolygonMode",
|
||||
"glReadPixels",
|
||||
"glScissor",
|
||||
"glShaderSource",
|
||||
"glTexImage2D",
|
||||
"glTexParameteri",
|
||||
"glTexSubImage2D",
|
||||
"glUniform1i",
|
||||
"glUniformMatrix4fv",
|
||||
"glUseProgram",
|
||||
"glVertexAttribPointer",
|
||||
"glViewport",
|
||||
};
|
||||
|
||||
GL3W_API union ImGL3WProcs imgl3wProcs;
|
||||
|
||||
static void load_procs(GL3WGetProcAddressProc proc)
|
||||
{
|
||||
size_t i;
|
||||
for (i = 0; i < GL3W_ARRAY_SIZE(proc_names); i++)
|
||||
imgl3wProcs.ptr[i] = proc(proc_names[i]);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
@@ -0,0 +1,47 @@
|
||||
// dear imgui: Platform Backend for SDL3
|
||||
// This needs to be used along with a Renderer (e.g. SDL_GPU, DirectX11, OpenGL3, Vulkan..)
|
||||
// (Info: SDL3 is a cross-platform general purpose library for handling windows, inputs, graphics context creation, etc.)
|
||||
|
||||
// Implemented features:
|
||||
// [X] Platform: Clipboard support.
|
||||
// [X] Platform: Mouse support. Can discriminate Mouse/TouchScreen.
|
||||
// [X] Platform: Keyboard support. Since 1.87 we are using the io.AddKeyEvent() function. Pass ImGuiKey values to all key functions e.g. ImGui::IsKeyPressed(ImGuiKey_Space). [Legacy SDL_SCANCODE_* values are obsolete since 1.87 and not supported since 1.91.5]
|
||||
// [X] Platform: Gamepad support.
|
||||
// [X] Platform: Mouse cursor shape and visibility (ImGuiBackendFlags_HasMouseCursors). Disable with 'io.ConfigFlags |= ImGuiConfigFlags_NoMouseCursorChange'.
|
||||
// [X] Platform: IME support.
|
||||
|
||||
// You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this.
|
||||
// Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need.
|
||||
// Learn about Dear ImGui:
|
||||
// - FAQ https://dearimgui.com/faq
|
||||
// - Getting Started https://dearimgui.com/getting-started
|
||||
// - Documentation https://dearimgui.com/docs (same as your local docs/ folder).
|
||||
// - Introduction, links and more at the top of imgui.cpp
|
||||
|
||||
#pragma once
|
||||
#include "imgui.h" // IMGUI_IMPL_API
|
||||
#ifndef IMGUI_DISABLE
|
||||
|
||||
struct SDL_Window;
|
||||
struct SDL_Renderer;
|
||||
struct SDL_Gamepad;
|
||||
typedef union SDL_Event SDL_Event;
|
||||
|
||||
// Follow "Getting Started" link and check examples/ folder to learn about using backends!
|
||||
IMGUI_IMPL_API bool ImGui_ImplSDL3_InitForOpenGL(SDL_Window* window, void* sdl_gl_context);
|
||||
IMGUI_IMPL_API bool ImGui_ImplSDL3_InitForVulkan(SDL_Window* window);
|
||||
IMGUI_IMPL_API bool ImGui_ImplSDL3_InitForD3D(SDL_Window* window);
|
||||
IMGUI_IMPL_API bool ImGui_ImplSDL3_InitForMetal(SDL_Window* window);
|
||||
IMGUI_IMPL_API bool ImGui_ImplSDL3_InitForSDLRenderer(SDL_Window* window, SDL_Renderer* renderer);
|
||||
IMGUI_IMPL_API bool ImGui_ImplSDL3_InitForSDLGPU(SDL_Window* window);
|
||||
IMGUI_IMPL_API bool ImGui_ImplSDL3_InitForOther(SDL_Window* window);
|
||||
IMGUI_IMPL_API void ImGui_ImplSDL3_Shutdown();
|
||||
IMGUI_IMPL_API void ImGui_ImplSDL3_NewFrame();
|
||||
IMGUI_IMPL_API bool ImGui_ImplSDL3_ProcessEvent(const SDL_Event* event);
|
||||
|
||||
// Gamepad selection automatically starts in AutoFirst mode, picking first available SDL_Gamepad. You may override this.
|
||||
// When using manual mode, caller is responsible for opening/closing gamepad.
|
||||
enum ImGui_ImplSDL3_GamepadMode { ImGui_ImplSDL3_GamepadMode_AutoFirst, ImGui_ImplSDL3_GamepadMode_AutoAll, ImGui_ImplSDL3_GamepadMode_Manual };
|
||||
IMGUI_IMPL_API void ImGui_ImplSDL3_SetGamepadMode(ImGui_ImplSDL3_GamepadMode mode, SDL_Gamepad** manual_gamepads_array = nullptr, int manual_gamepads_count = -1);
|
||||
|
||||
#endif // #ifndef IMGUI_DISABLE
|
||||
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* engine.h is initialy a file frome miniDart project
|
||||
* Author : Eric Bachard / lundi 3 octobre 2016, 14:35:03 (UTC+0200)
|
||||
* This file is under GPL v2 license
|
||||
* See : http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*/
|
||||
|
||||
#ifndef __ENGINE_H
|
||||
#define __ENGINE_H
|
||||
|
||||
#ifndef GL_GLEXT_PROTOTYPES
|
||||
#define GL_GLEXT_PROTOTYPES
|
||||
#endif
|
||||
#ifndef GL3_PROTOTYPES
|
||||
#define GL3_PROTOTYPES 1
|
||||
#endif
|
||||
|
||||
#include <iostream>
|
||||
#include <SDL3/SDL.h>
|
||||
|
||||
// TODO : implement OpenGL 4.x and more recent glsl versions
|
||||
#define GLSL_VERSION_130 "#version 130"
|
||||
|
||||
class Engine
|
||||
{
|
||||
public:
|
||||
Engine();
|
||||
~Engine();
|
||||
|
||||
int init_SDL();
|
||||
void sdl_application_abort(const char *);
|
||||
void clean_and_close();
|
||||
|
||||
SDL_GLContext getGL_Context(){ return gl_context; }
|
||||
void setGL_Context(SDL_GLContext aContext){ gl_context = aContext; }
|
||||
|
||||
SDL_Window * getWindow(){ return window; }
|
||||
void setWindow(SDL_Window * aWindow){ window = aWindow; }
|
||||
|
||||
void getSystemDisplayDPI(int, float*, float*);
|
||||
bool setApplicationDisplayDPI(float);
|
||||
float getDpi() { return dpi; }
|
||||
float getDefaultDpi() { return defaultDpi; }
|
||||
SDL_DisplayMode current;
|
||||
int getWidth(){ return mWidth; }
|
||||
int getHeight(){ return mHeight; }
|
||||
inline void setWidth( int dWidth ){ mWidth = dWidth; }
|
||||
inline void setHeight(int dHeight ){ mHeight = dHeight; }
|
||||
|
||||
inline void setDpi(float new_dpi) { dpi = new_dpi; }
|
||||
|
||||
void set_glsl_version(char *);
|
||||
const char * get_glsl_version() { return glsl_version; }
|
||||
|
||||
int displayIndex;
|
||||
int DisplayNumber;
|
||||
|
||||
int windowDpiScaledWidth;
|
||||
int windowDpiScaledHeight;
|
||||
int windowDpiUnscaledWidth;
|
||||
int windowDpiUnscaledHeight;
|
||||
|
||||
private:
|
||||
const char * glsl_version;
|
||||
SDL_GLContext gl_context;
|
||||
SDL_Window * window;
|
||||
float dpi;
|
||||
float defaultDpi;
|
||||
int mWidth;
|
||||
int mHeight;
|
||||
};
|
||||
|
||||
#endif /* __ENGINE_H */
|
||||
@@ -0,0 +1,145 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// DEAR IMGUI COMPILE-TIME OPTIONS
|
||||
// Runtime options (clipboard callbacks, enabling various features, etc.) can generally be set via the ImGuiIO structure.
|
||||
// You can use ImGui::SetAllocatorFunctions() before calling ImGui::CreateContext() to rewire memory allocation functions.
|
||||
//-----------------------------------------------------------------------------
|
||||
// A) You may edit imconfig.h (and not overwrite it when updating Dear ImGui, or maintain a patch/rebased branch with your modifications to it)
|
||||
// B) or '#define IMGUI_USER_CONFIG "my_imgui_config.h"' in your project and then add directives in your own file without touching this template.
|
||||
//-----------------------------------------------------------------------------
|
||||
// You need to make sure that configuration settings are defined consistently _everywhere_ Dear ImGui is used, which include the imgui*.cpp
|
||||
// files but also _any_ of your code that uses Dear ImGui. This is because some compile-time options have an affect on data structures.
|
||||
// Defining those options in imconfig.h will ensure every compilation unit gets to see the same data structure layouts.
|
||||
// Call IMGUI_CHECKVERSION() from your .cpp file to verify that the data structures your files are using are matching the ones imgui.cpp is using.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#pragma once
|
||||
|
||||
//---- Define assertion handler. Defaults to calling assert().
|
||||
// If your macro uses multiple statements, make sure is enclosed in a 'do { .. } while (0)' block so it can be used as a single statement.
|
||||
//#define IM_ASSERT(_EXPR) MyAssert(_EXPR)
|
||||
//#define IM_ASSERT(_EXPR) ((void)(_EXPR)) // Disable asserts
|
||||
|
||||
//---- Define attributes of all API symbols declarations, e.g. for DLL under Windows
|
||||
// Using Dear ImGui via a shared library is not recommended, because of function call overhead and because we don't guarantee backward nor forward ABI compatibility.
|
||||
// - Windows DLL users: heaps and globals are not shared across DLL boundaries! You will need to call SetCurrentContext() + SetAllocatorFunctions()
|
||||
// for each static/DLL boundary you are calling from. Read "Context and Memory Allocators" section of imgui.cpp for more details.
|
||||
//#define IMGUI_API __declspec(dllexport) // MSVC Windows: DLL export
|
||||
//#define IMGUI_API __declspec(dllimport) // MSVC Windows: DLL import
|
||||
//#define IMGUI_API __attribute__((visibility("default"))) // GCC/Clang: override visibility when set is hidden
|
||||
|
||||
//---- Don't define obsolete functions/enums/behaviors. Consider enabling from time to time after updating to clean your code of obsolete function/names.
|
||||
//#define IMGUI_DISABLE_OBSOLETE_FUNCTIONS
|
||||
|
||||
//---- Disable all of Dear ImGui or don't implement standard windows/tools.
|
||||
// It is very strongly recommended to NOT disable the demo windows and debug tool during development. They are extremely useful in day to day work. Please read comments in imgui_demo.cpp.
|
||||
//#define IMGUI_DISABLE // Disable everything: all headers and source files will be empty.
|
||||
//#define IMGUI_DISABLE_DEMO_WINDOWS // Disable demo windows: ShowDemoWindow()/ShowStyleEditor() will be empty.
|
||||
//#define IMGUI_DISABLE_DEBUG_TOOLS // Disable metrics/debugger and other debug tools: ShowMetricsWindow(), ShowDebugLogWindow() and ShowIDStackToolWindow() will be empty.
|
||||
|
||||
//---- Don't implement some functions to reduce linkage requirements.
|
||||
//#define IMGUI_DISABLE_WIN32_DEFAULT_CLIPBOARD_FUNCTIONS // [Win32] Don't implement default clipboard handler. Won't use and link with OpenClipboard/GetClipboardData/CloseClipboard etc. (user32.lib/.a, kernel32.lib/.a)
|
||||
//#define IMGUI_ENABLE_WIN32_DEFAULT_IME_FUNCTIONS // [Win32] [Default with Visual Studio] Implement default IME handler (require imm32.lib/.a, auto-link for Visual Studio, -limm32 on command-line for MinGW)
|
||||
//#define IMGUI_DISABLE_WIN32_DEFAULT_IME_FUNCTIONS // [Win32] [Default with non-Visual Studio compilers] Don't implement default IME handler (won't require imm32.lib/.a)
|
||||
//#define IMGUI_DISABLE_WIN32_FUNCTIONS // [Win32] Won't use and link with any Win32 function (clipboard, IME).
|
||||
//#define IMGUI_ENABLE_OSX_DEFAULT_CLIPBOARD_FUNCTIONS // [OSX] Implement default OSX clipboard handler (need to link with '-framework ApplicationServices', this is why this is not the default).
|
||||
//#define IMGUI_DISABLE_DEFAULT_SHELL_FUNCTIONS // Don't implement default platform_io.Platform_OpenInShellFn() handler (Win32: ShellExecute(), require shell32.lib/.a, Mac/Linux: use system("")).
|
||||
//#define IMGUI_DISABLE_DEFAULT_FORMAT_FUNCTIONS // Don't implement ImFormatString/ImFormatStringV so you can implement them yourself (e.g. if you don't want to link with vsnprintf)
|
||||
//#define IMGUI_DISABLE_DEFAULT_MATH_FUNCTIONS // Don't implement ImFabs/ImSqrt/ImPow/ImFmod/ImCos/ImSin/ImAcos/ImAtan2 so you can implement them yourself.
|
||||
//#define IMGUI_DISABLE_FILE_FUNCTIONS // Don't implement ImFileOpen/ImFileClose/ImFileRead/ImFileWrite and ImFileHandle at all (replace them with dummies)
|
||||
//#define IMGUI_DISABLE_DEFAULT_FILE_FUNCTIONS // Don't implement ImFileOpen/ImFileClose/ImFileRead/ImFileWrite and ImFileHandle so you can implement them yourself if you don't want to link with fopen/fclose/fread/fwrite. This will also disable the LogToTTY() function.
|
||||
//#define IMGUI_DISABLE_DEFAULT_ALLOCATORS // Don't implement default allocators calling malloc()/free() to avoid linking with them. You will need to call ImGui::SetAllocatorFunctions().
|
||||
//#define IMGUI_DISABLE_DEFAULT_FONT // Disable default embedded font (ProggyClean.ttf), remove ~9.5 KB from output binary. AddFontDefault() will assert.
|
||||
//#define IMGUI_DISABLE_SSE // Disable use of SSE intrinsics even if available
|
||||
|
||||
//---- Enable Test Engine / Automation features.
|
||||
//#define IMGUI_ENABLE_TEST_ENGINE // Enable imgui_test_engine hooks. Generally set automatically by include "imgui_te_config.h", see Test Engine for details.
|
||||
|
||||
//---- Include imgui_user.h at the end of imgui.h as a convenience
|
||||
// May be convenient for some users to only explicitly include vanilla imgui.h and have extra stuff included.
|
||||
//#define IMGUI_INCLUDE_IMGUI_USER_H
|
||||
//#define IMGUI_USER_H_FILENAME "my_folder/my_imgui_user.h"
|
||||
|
||||
//---- Pack vertex colors as BGRA8 instead of RGBA8 (to avoid converting from one to another). Need dedicated backend support.
|
||||
//#define IMGUI_USE_BGRA_PACKED_COLOR
|
||||
|
||||
//---- Use legacy CRC32-adler tables (used before 1.91.6), in order to preserve old .ini data that you cannot afford to invalidate.
|
||||
//#define IMGUI_USE_LEGACY_CRC32_ADLER
|
||||
|
||||
//---- Use 32-bit for ImWchar (default is 16-bit) to support Unicode planes 1-16. (e.g. point beyond 0xFFFF like emoticons, dingbats, symbols, shapes, ancient languages, etc...)
|
||||
//#define IMGUI_USE_WCHAR32
|
||||
|
||||
//---- Avoid multiple STB libraries implementations, or redefine path/filenames to prioritize another version
|
||||
// By default the embedded implementations are declared static and not available outside of Dear ImGui sources files.
|
||||
//#define IMGUI_STB_TRUETYPE_FILENAME "my_folder/stb_truetype.h"
|
||||
//#define IMGUI_STB_RECT_PACK_FILENAME "my_folder/stb_rect_pack.h"
|
||||
//#define IMGUI_STB_SPRINTF_FILENAME "my_folder/stb_sprintf.h" // only used if IMGUI_USE_STB_SPRINTF is defined.
|
||||
//#define IMGUI_DISABLE_STB_TRUETYPE_IMPLEMENTATION
|
||||
//#define IMGUI_DISABLE_STB_RECT_PACK_IMPLEMENTATION
|
||||
//#define IMGUI_DISABLE_STB_SPRINTF_IMPLEMENTATION // only disabled if IMGUI_USE_STB_SPRINTF is defined.
|
||||
|
||||
//---- Use stb_sprintf.h for a faster implementation of vsnprintf instead of the one from libc (unless IMGUI_DISABLE_DEFAULT_FORMAT_FUNCTIONS is defined)
|
||||
// Compatibility checks of arguments and formats done by clang and GCC will be disabled in order to support the extra formats provided by stb_sprintf.h.
|
||||
//#define IMGUI_USE_STB_SPRINTF
|
||||
|
||||
//---- Use FreeType to build and rasterize the font atlas (instead of stb_truetype which is embedded by default in Dear ImGui)
|
||||
// Requires FreeType headers to be available in the include path. Requires program to be compiled with 'misc/freetype/imgui_freetype.cpp' (in this repository) + the FreeType library (not provided).
|
||||
// On Windows you may use vcpkg with 'vcpkg install freetype --triplet=x64-windows' + 'vcpkg integrate install'.
|
||||
//#define IMGUI_ENABLE_FREETYPE
|
||||
|
||||
//---- Use FreeType + plutosvg or lunasvg to render OpenType SVG fonts (SVGinOT)
|
||||
// Only works in combination with IMGUI_ENABLE_FREETYPE.
|
||||
// - plutosvg is currently easier to install, as e.g. it is part of vcpkg. It will support more fonts and may load them faster. See misc/freetype/README for instructions.
|
||||
// - Both require headers to be available in the include path + program to be linked with the library code (not provided).
|
||||
// - (note: lunasvg implementation is based on Freetype's rsvg-port.c which is licensed under CeCILL-C Free Software License Agreement)
|
||||
//#define IMGUI_ENABLE_FREETYPE_PLUTOSVG
|
||||
//#define IMGUI_ENABLE_FREETYPE_LUNASVG
|
||||
|
||||
//---- Use stb_truetype to build and rasterize the font atlas (default)
|
||||
// The only purpose of this define is if you want force compilation of the stb_truetype backend ALONG with the FreeType backend.
|
||||
//#define IMGUI_ENABLE_STB_TRUETYPE
|
||||
|
||||
//---- Define constructor and implicit cast operators to convert back<>forth between your math types and ImVec2/ImVec4.
|
||||
// This will be inlined as part of ImVec2 and ImVec4 class declarations.
|
||||
/*
|
||||
#define IM_VEC2_CLASS_EXTRA \
|
||||
constexpr ImVec2(const MyVec2& f) : x(f.x), y(f.y) {} \
|
||||
operator MyVec2() const { return MyVec2(x,y); }
|
||||
|
||||
#define IM_VEC4_CLASS_EXTRA \
|
||||
constexpr ImVec4(const MyVec4& f) : x(f.x), y(f.y), z(f.z), w(f.w) {} \
|
||||
operator MyVec4() const { return MyVec4(x,y,z,w); }
|
||||
*/
|
||||
//---- ...Or use Dear ImGui's own very basic math operators.
|
||||
//#define IMGUI_DEFINE_MATH_OPERATORS
|
||||
|
||||
//---- Use 32-bit vertex indices (default is 16-bit) is one way to allow large meshes with more than 64K vertices.
|
||||
// Your renderer backend will need to support it (most example renderer backends support both 16/32-bit indices).
|
||||
// Another way to allow large meshes while keeping 16-bit indices is to handle ImDrawCmd::VtxOffset in your renderer.
|
||||
// Read about ImGuiBackendFlags_RendererHasVtxOffset for details.
|
||||
//#define ImDrawIdx unsigned int
|
||||
|
||||
//---- Override ImDrawCallback signature (will need to modify renderer backends accordingly)
|
||||
//struct ImDrawList;
|
||||
//struct ImDrawCmd;
|
||||
//typedef void (*MyImDrawCallback)(const ImDrawList* draw_list, const ImDrawCmd* cmd, void* my_renderer_user_data);
|
||||
//#define ImDrawCallback MyImDrawCallback
|
||||
|
||||
//---- Debug Tools: Macro to break in Debugger (we provide a default implementation of this in the codebase)
|
||||
// (use 'Metrics->Tools->Item Picker' to pick widgets with the mouse and break into them for easy debugging.)
|
||||
//#define IM_DEBUG_BREAK IM_ASSERT(0)
|
||||
//#define IM_DEBUG_BREAK __debugbreak()
|
||||
|
||||
//---- Debug Tools: Enable highlight ID conflicts _before_ hovering items. When io.ConfigDebugHighlightIdConflicts is set.
|
||||
// (THIS WILL SLOW DOWN DEAR IMGUI. Only use occasionally and disable after use)
|
||||
//#define IMGUI_DEBUG_HIGHLIGHT_ALL_ID_CONFLICTS
|
||||
|
||||
//---- Debug Tools: Enable slower asserts
|
||||
//#define IMGUI_DEBUG_PARANOID
|
||||
|
||||
//---- Tip: You can add extra functions within the ImGui:: namespace from anywhere (e.g. your own sources/header files)
|
||||
/*
|
||||
namespace ImGui
|
||||
{
|
||||
void MyFunction(const char* name, MyMatrix44* mtx);
|
||||
}
|
||||
*/
|
||||
Fichier diff supprimé car celui-ci est trop grand
Voir la Diff
Fichier diff supprimé car celui-ci est trop grand
Voir la Diff
@@ -0,0 +1,627 @@
|
||||
// [DEAR IMGUI]
|
||||
// This is a slightly modified version of stb_rect_pack.h 1.01.
|
||||
// Grep for [DEAR IMGUI] to find the changes.
|
||||
//
|
||||
// stb_rect_pack.h - v1.01 - public domain - rectangle packing
|
||||
// Sean Barrett 2014
|
||||
//
|
||||
// Useful for e.g. packing rectangular textures into an atlas.
|
||||
// Does not do rotation.
|
||||
//
|
||||
// Before #including,
|
||||
//
|
||||
// #define STB_RECT_PACK_IMPLEMENTATION
|
||||
//
|
||||
// in the file that you want to have the implementation.
|
||||
//
|
||||
// Not necessarily the awesomest packing method, but better than
|
||||
// the totally naive one in stb_truetype (which is primarily what
|
||||
// this is meant to replace).
|
||||
//
|
||||
// Has only had a few tests run, may have issues.
|
||||
//
|
||||
// More docs to come.
|
||||
//
|
||||
// No memory allocations; uses qsort() and assert() from stdlib.
|
||||
// Can override those by defining STBRP_SORT and STBRP_ASSERT.
|
||||
//
|
||||
// This library currently uses the Skyline Bottom-Left algorithm.
|
||||
//
|
||||
// Please note: better rectangle packers are welcome! Please
|
||||
// implement them to the same API, but with a different init
|
||||
// function.
|
||||
//
|
||||
// Credits
|
||||
//
|
||||
// Library
|
||||
// Sean Barrett
|
||||
// Minor features
|
||||
// Martins Mozeiko
|
||||
// github:IntellectualKitty
|
||||
//
|
||||
// Bugfixes / warning fixes
|
||||
// Jeremy Jaussaud
|
||||
// Fabian Giesen
|
||||
//
|
||||
// Version history:
|
||||
//
|
||||
// 1.01 (2021-07-11) always use large rect mode, expose STBRP__MAXVAL in public section
|
||||
// 1.00 (2019-02-25) avoid small space waste; gracefully fail too-wide rectangles
|
||||
// 0.99 (2019-02-07) warning fixes
|
||||
// 0.11 (2017-03-03) return packing success/fail result
|
||||
// 0.10 (2016-10-25) remove cast-away-const to avoid warnings
|
||||
// 0.09 (2016-08-27) fix compiler warnings
|
||||
// 0.08 (2015-09-13) really fix bug with empty rects (w=0 or h=0)
|
||||
// 0.07 (2015-09-13) fix bug with empty rects (w=0 or h=0)
|
||||
// 0.06 (2015-04-15) added STBRP_SORT to allow replacing qsort
|
||||
// 0.05: added STBRP_ASSERT to allow replacing assert
|
||||
// 0.04: fixed minor bug in STBRP_LARGE_RECTS support
|
||||
// 0.01: initial release
|
||||
//
|
||||
// LICENSE
|
||||
//
|
||||
// See end of file for license information.
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// INCLUDE SECTION
|
||||
//
|
||||
|
||||
#ifndef STB_INCLUDE_STB_RECT_PACK_H
|
||||
#define STB_INCLUDE_STB_RECT_PACK_H
|
||||
|
||||
#define STB_RECT_PACK_VERSION 1
|
||||
|
||||
#ifdef STBRP_STATIC
|
||||
#define STBRP_DEF static
|
||||
#else
|
||||
#define STBRP_DEF extern
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct stbrp_context stbrp_context;
|
||||
typedef struct stbrp_node stbrp_node;
|
||||
typedef struct stbrp_rect stbrp_rect;
|
||||
|
||||
typedef int stbrp_coord;
|
||||
|
||||
#define STBRP__MAXVAL 0x7fffffff
|
||||
// Mostly for internal use, but this is the maximum supported coordinate value.
|
||||
|
||||
STBRP_DEF int stbrp_pack_rects (stbrp_context *context, stbrp_rect *rects, int num_rects);
|
||||
// Assign packed locations to rectangles. The rectangles are of type
|
||||
// 'stbrp_rect' defined below, stored in the array 'rects', and there
|
||||
// are 'num_rects' many of them.
|
||||
//
|
||||
// Rectangles which are successfully packed have the 'was_packed' flag
|
||||
// set to a non-zero value and 'x' and 'y' store the minimum location
|
||||
// on each axis (i.e. bottom-left in cartesian coordinates, top-left
|
||||
// if you imagine y increasing downwards). Rectangles which do not fit
|
||||
// have the 'was_packed' flag set to 0.
|
||||
//
|
||||
// You should not try to access the 'rects' array from another thread
|
||||
// while this function is running, as the function temporarily reorders
|
||||
// the array while it executes.
|
||||
//
|
||||
// To pack into another rectangle, you need to call stbrp_init_target
|
||||
// again. To continue packing into the same rectangle, you can call
|
||||
// this function again. Calling this multiple times with multiple rect
|
||||
// arrays will probably produce worse packing results than calling it
|
||||
// a single time with the full rectangle array, but the option is
|
||||
// available.
|
||||
//
|
||||
// The function returns 1 if all of the rectangles were successfully
|
||||
// packed and 0 otherwise.
|
||||
|
||||
struct stbrp_rect
|
||||
{
|
||||
// reserved for your use:
|
||||
int id;
|
||||
|
||||
// input:
|
||||
stbrp_coord w, h;
|
||||
|
||||
// output:
|
||||
stbrp_coord x, y;
|
||||
int was_packed; // non-zero if valid packing
|
||||
|
||||
}; // 16 bytes, nominally
|
||||
|
||||
|
||||
STBRP_DEF void stbrp_init_target (stbrp_context *context, int width, int height, stbrp_node *nodes, int num_nodes);
|
||||
// Initialize a rectangle packer to:
|
||||
// pack a rectangle that is 'width' by 'height' in dimensions
|
||||
// using temporary storage provided by the array 'nodes', which is 'num_nodes' long
|
||||
//
|
||||
// You must call this function every time you start packing into a new target.
|
||||
//
|
||||
// There is no "shutdown" function. The 'nodes' memory must stay valid for
|
||||
// the following stbrp_pack_rects() call (or calls), but can be freed after
|
||||
// the call (or calls) finish.
|
||||
//
|
||||
// Note: to guarantee best results, either:
|
||||
// 1. make sure 'num_nodes' >= 'width'
|
||||
// or 2. call stbrp_allow_out_of_mem() defined below with 'allow_out_of_mem = 1'
|
||||
//
|
||||
// If you don't do either of the above things, widths will be quantized to multiples
|
||||
// of small integers to guarantee the algorithm doesn't run out of temporary storage.
|
||||
//
|
||||
// If you do #2, then the non-quantized algorithm will be used, but the algorithm
|
||||
// may run out of temporary storage and be unable to pack some rectangles.
|
||||
|
||||
STBRP_DEF void stbrp_setup_allow_out_of_mem (stbrp_context *context, int allow_out_of_mem);
|
||||
// Optionally call this function after init but before doing any packing to
|
||||
// change the handling of the out-of-temp-memory scenario, described above.
|
||||
// If you call init again, this will be reset to the default (false).
|
||||
|
||||
|
||||
STBRP_DEF void stbrp_setup_heuristic (stbrp_context *context, int heuristic);
|
||||
// Optionally select which packing heuristic the library should use. Different
|
||||
// heuristics will produce better/worse results for different data sets.
|
||||
// If you call init again, this will be reset to the default.
|
||||
|
||||
enum
|
||||
{
|
||||
STBRP_HEURISTIC_Skyline_default=0,
|
||||
STBRP_HEURISTIC_Skyline_BL_sortHeight = STBRP_HEURISTIC_Skyline_default,
|
||||
STBRP_HEURISTIC_Skyline_BF_sortHeight
|
||||
};
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// the details of the following structures don't matter to you, but they must
|
||||
// be visible so you can handle the memory allocations for them
|
||||
|
||||
struct stbrp_node
|
||||
{
|
||||
stbrp_coord x,y;
|
||||
stbrp_node *next;
|
||||
};
|
||||
|
||||
struct stbrp_context
|
||||
{
|
||||
int width;
|
||||
int height;
|
||||
int align;
|
||||
int init_mode;
|
||||
int heuristic;
|
||||
int num_nodes;
|
||||
stbrp_node *active_head;
|
||||
stbrp_node *free_head;
|
||||
stbrp_node extra[2]; // we allocate two extra nodes so optimal user-node-count is 'width' not 'width+2'
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPLEMENTATION SECTION
|
||||
//
|
||||
|
||||
#ifdef STB_RECT_PACK_IMPLEMENTATION
|
||||
#ifndef STBRP_SORT
|
||||
#include <stdlib.h>
|
||||
#define STBRP_SORT qsort
|
||||
#endif
|
||||
|
||||
#ifndef STBRP_ASSERT
|
||||
#include <assert.h>
|
||||
#define STBRP_ASSERT assert
|
||||
#endif
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#define STBRP__NOTUSED(v) (void)(v)
|
||||
#define STBRP__CDECL __cdecl
|
||||
#else
|
||||
#define STBRP__NOTUSED(v) (void)sizeof(v)
|
||||
#define STBRP__CDECL
|
||||
#endif
|
||||
|
||||
enum
|
||||
{
|
||||
STBRP__INIT_skyline = 1
|
||||
};
|
||||
|
||||
STBRP_DEF void stbrp_setup_heuristic(stbrp_context *context, int heuristic)
|
||||
{
|
||||
switch (context->init_mode) {
|
||||
case STBRP__INIT_skyline:
|
||||
STBRP_ASSERT(heuristic == STBRP_HEURISTIC_Skyline_BL_sortHeight || heuristic == STBRP_HEURISTIC_Skyline_BF_sortHeight);
|
||||
context->heuristic = heuristic;
|
||||
break;
|
||||
default:
|
||||
STBRP_ASSERT(0);
|
||||
}
|
||||
}
|
||||
|
||||
STBRP_DEF void stbrp_setup_allow_out_of_mem(stbrp_context *context, int allow_out_of_mem)
|
||||
{
|
||||
if (allow_out_of_mem)
|
||||
// if it's ok to run out of memory, then don't bother aligning them;
|
||||
// this gives better packing, but may fail due to OOM (even though
|
||||
// the rectangles easily fit). @TODO a smarter approach would be to only
|
||||
// quantize once we've hit OOM, then we could get rid of this parameter.
|
||||
context->align = 1;
|
||||
else {
|
||||
// if it's not ok to run out of memory, then quantize the widths
|
||||
// so that num_nodes is always enough nodes.
|
||||
//
|
||||
// I.e. num_nodes * align >= width
|
||||
// align >= width / num_nodes
|
||||
// align = ceil(width/num_nodes)
|
||||
|
||||
context->align = (context->width + context->num_nodes-1) / context->num_nodes;
|
||||
}
|
||||
}
|
||||
|
||||
STBRP_DEF void stbrp_init_target(stbrp_context *context, int width, int height, stbrp_node *nodes, int num_nodes)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i=0; i < num_nodes-1; ++i)
|
||||
nodes[i].next = &nodes[i+1];
|
||||
nodes[i].next = NULL;
|
||||
context->init_mode = STBRP__INIT_skyline;
|
||||
context->heuristic = STBRP_HEURISTIC_Skyline_default;
|
||||
context->free_head = &nodes[0];
|
||||
context->active_head = &context->extra[0];
|
||||
context->width = width;
|
||||
context->height = height;
|
||||
context->num_nodes = num_nodes;
|
||||
stbrp_setup_allow_out_of_mem(context, 0);
|
||||
|
||||
// node 0 is the full width, node 1 is the sentinel (lets us not store width explicitly)
|
||||
context->extra[0].x = 0;
|
||||
context->extra[0].y = 0;
|
||||
context->extra[0].next = &context->extra[1];
|
||||
context->extra[1].x = (stbrp_coord) width;
|
||||
context->extra[1].y = (1<<30);
|
||||
context->extra[1].next = NULL;
|
||||
}
|
||||
|
||||
// find minimum y position if it starts at x1
|
||||
static int stbrp__skyline_find_min_y(stbrp_context *c, stbrp_node *first, int x0, int width, int *pwaste)
|
||||
{
|
||||
stbrp_node *node = first;
|
||||
int x1 = x0 + width;
|
||||
int min_y, visited_width, waste_area;
|
||||
|
||||
STBRP__NOTUSED(c);
|
||||
|
||||
STBRP_ASSERT(first->x <= x0);
|
||||
|
||||
#if 0
|
||||
// skip in case we're past the node
|
||||
while (node->next->x <= x0)
|
||||
++node;
|
||||
#else
|
||||
STBRP_ASSERT(node->next->x > x0); // we ended up handling this in the caller for efficiency
|
||||
#endif
|
||||
|
||||
STBRP_ASSERT(node->x <= x0);
|
||||
|
||||
min_y = 0;
|
||||
waste_area = 0;
|
||||
visited_width = 0;
|
||||
while (node->x < x1) {
|
||||
if (node->y > min_y) {
|
||||
// raise min_y higher.
|
||||
// we've accounted for all waste up to min_y,
|
||||
// but we'll now add more waste for everything we've visted
|
||||
waste_area += visited_width * (node->y - min_y);
|
||||
min_y = node->y;
|
||||
// the first time through, visited_width might be reduced
|
||||
if (node->x < x0)
|
||||
visited_width += node->next->x - x0;
|
||||
else
|
||||
visited_width += node->next->x - node->x;
|
||||
} else {
|
||||
// add waste area
|
||||
int under_width = node->next->x - node->x;
|
||||
if (under_width + visited_width > width)
|
||||
under_width = width - visited_width;
|
||||
waste_area += under_width * (min_y - node->y);
|
||||
visited_width += under_width;
|
||||
}
|
||||
node = node->next;
|
||||
}
|
||||
|
||||
*pwaste = waste_area;
|
||||
return min_y;
|
||||
}
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int x,y;
|
||||
stbrp_node **prev_link;
|
||||
} stbrp__findresult;
|
||||
|
||||
static stbrp__findresult stbrp__skyline_find_best_pos(stbrp_context *c, int width, int height)
|
||||
{
|
||||
int best_waste = (1<<30), best_x, best_y = (1 << 30);
|
||||
stbrp__findresult fr;
|
||||
stbrp_node **prev, *node, *tail, **best = NULL;
|
||||
|
||||
// align to multiple of c->align
|
||||
width = (width + c->align - 1);
|
||||
width -= width % c->align;
|
||||
STBRP_ASSERT(width % c->align == 0);
|
||||
|
||||
// if it can't possibly fit, bail immediately
|
||||
if (width > c->width || height > c->height) {
|
||||
fr.prev_link = NULL;
|
||||
fr.x = fr.y = 0;
|
||||
return fr;
|
||||
}
|
||||
|
||||
node = c->active_head;
|
||||
prev = &c->active_head;
|
||||
while (node->x + width <= c->width) {
|
||||
int y,waste;
|
||||
y = stbrp__skyline_find_min_y(c, node, node->x, width, &waste);
|
||||
if (c->heuristic == STBRP_HEURISTIC_Skyline_BL_sortHeight) { // actually just want to test BL
|
||||
// bottom left
|
||||
if (y < best_y) {
|
||||
best_y = y;
|
||||
best = prev;
|
||||
}
|
||||
} else {
|
||||
// best-fit
|
||||
if (y + height <= c->height) {
|
||||
// can only use it if it first vertically
|
||||
if (y < best_y || (y == best_y && waste < best_waste)) {
|
||||
best_y = y;
|
||||
best_waste = waste;
|
||||
best = prev;
|
||||
}
|
||||
}
|
||||
}
|
||||
prev = &node->next;
|
||||
node = node->next;
|
||||
}
|
||||
|
||||
best_x = (best == NULL) ? 0 : (*best)->x;
|
||||
|
||||
// if doing best-fit (BF), we also have to try aligning right edge to each node position
|
||||
//
|
||||
// e.g, if fitting
|
||||
//
|
||||
// ____________________
|
||||
// |____________________|
|
||||
//
|
||||
// into
|
||||
//
|
||||
// | |
|
||||
// | ____________|
|
||||
// |____________|
|
||||
//
|
||||
// then right-aligned reduces waste, but bottom-left BL is always chooses left-aligned
|
||||
//
|
||||
// This makes BF take about 2x the time
|
||||
|
||||
if (c->heuristic == STBRP_HEURISTIC_Skyline_BF_sortHeight) {
|
||||
tail = c->active_head;
|
||||
node = c->active_head;
|
||||
prev = &c->active_head;
|
||||
// find first node that's admissible
|
||||
while (tail->x < width)
|
||||
tail = tail->next;
|
||||
while (tail) {
|
||||
int xpos = tail->x - width;
|
||||
int y,waste;
|
||||
STBRP_ASSERT(xpos >= 0);
|
||||
// find the left position that matches this
|
||||
while (node->next->x <= xpos) {
|
||||
prev = &node->next;
|
||||
node = node->next;
|
||||
}
|
||||
STBRP_ASSERT(node->next->x > xpos && node->x <= xpos);
|
||||
y = stbrp__skyline_find_min_y(c, node, xpos, width, &waste);
|
||||
if (y + height <= c->height) {
|
||||
if (y <= best_y) {
|
||||
if (y < best_y || waste < best_waste || (waste==best_waste && xpos < best_x)) {
|
||||
best_x = xpos;
|
||||
//STBRP_ASSERT(y <= best_y); [DEAR IMGUI]
|
||||
best_y = y;
|
||||
best_waste = waste;
|
||||
best = prev;
|
||||
}
|
||||
}
|
||||
}
|
||||
tail = tail->next;
|
||||
}
|
||||
}
|
||||
|
||||
fr.prev_link = best;
|
||||
fr.x = best_x;
|
||||
fr.y = best_y;
|
||||
return fr;
|
||||
}
|
||||
|
||||
static stbrp__findresult stbrp__skyline_pack_rectangle(stbrp_context *context, int width, int height)
|
||||
{
|
||||
// find best position according to heuristic
|
||||
stbrp__findresult res = stbrp__skyline_find_best_pos(context, width, height);
|
||||
stbrp_node *node, *cur;
|
||||
|
||||
// bail if:
|
||||
// 1. it failed
|
||||
// 2. the best node doesn't fit (we don't always check this)
|
||||
// 3. we're out of memory
|
||||
if (res.prev_link == NULL || res.y + height > context->height || context->free_head == NULL) {
|
||||
res.prev_link = NULL;
|
||||
return res;
|
||||
}
|
||||
|
||||
// on success, create new node
|
||||
node = context->free_head;
|
||||
node->x = (stbrp_coord) res.x;
|
||||
node->y = (stbrp_coord) (res.y + height);
|
||||
|
||||
context->free_head = node->next;
|
||||
|
||||
// insert the new node into the right starting point, and
|
||||
// let 'cur' point to the remaining nodes needing to be
|
||||
// stiched back in
|
||||
|
||||
cur = *res.prev_link;
|
||||
if (cur->x < res.x) {
|
||||
// preserve the existing one, so start testing with the next one
|
||||
stbrp_node *next = cur->next;
|
||||
cur->next = node;
|
||||
cur = next;
|
||||
} else {
|
||||
*res.prev_link = node;
|
||||
}
|
||||
|
||||
// from here, traverse cur and free the nodes, until we get to one
|
||||
// that shouldn't be freed
|
||||
while (cur->next && cur->next->x <= res.x + width) {
|
||||
stbrp_node *next = cur->next;
|
||||
// move the current node to the free list
|
||||
cur->next = context->free_head;
|
||||
context->free_head = cur;
|
||||
cur = next;
|
||||
}
|
||||
|
||||
// stitch the list back in
|
||||
node->next = cur;
|
||||
|
||||
if (cur->x < res.x + width)
|
||||
cur->x = (stbrp_coord) (res.x + width);
|
||||
|
||||
#ifdef _DEBUG
|
||||
cur = context->active_head;
|
||||
while (cur->x < context->width) {
|
||||
STBRP_ASSERT(cur->x < cur->next->x);
|
||||
cur = cur->next;
|
||||
}
|
||||
STBRP_ASSERT(cur->next == NULL);
|
||||
|
||||
{
|
||||
int count=0;
|
||||
cur = context->active_head;
|
||||
while (cur) {
|
||||
cur = cur->next;
|
||||
++count;
|
||||
}
|
||||
cur = context->free_head;
|
||||
while (cur) {
|
||||
cur = cur->next;
|
||||
++count;
|
||||
}
|
||||
STBRP_ASSERT(count == context->num_nodes+2);
|
||||
}
|
||||
#endif
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
static int STBRP__CDECL rect_height_compare(const void *a, const void *b)
|
||||
{
|
||||
const stbrp_rect *p = (const stbrp_rect *) a;
|
||||
const stbrp_rect *q = (const stbrp_rect *) b;
|
||||
if (p->h > q->h)
|
||||
return -1;
|
||||
if (p->h < q->h)
|
||||
return 1;
|
||||
return (p->w > q->w) ? -1 : (p->w < q->w);
|
||||
}
|
||||
|
||||
static int STBRP__CDECL rect_original_order(const void *a, const void *b)
|
||||
{
|
||||
const stbrp_rect *p = (const stbrp_rect *) a;
|
||||
const stbrp_rect *q = (const stbrp_rect *) b;
|
||||
return (p->was_packed < q->was_packed) ? -1 : (p->was_packed > q->was_packed);
|
||||
}
|
||||
|
||||
STBRP_DEF int stbrp_pack_rects(stbrp_context *context, stbrp_rect *rects, int num_rects)
|
||||
{
|
||||
int i, all_rects_packed = 1;
|
||||
|
||||
// we use the 'was_packed' field internally to allow sorting/unsorting
|
||||
for (i=0; i < num_rects; ++i) {
|
||||
rects[i].was_packed = i;
|
||||
}
|
||||
|
||||
// sort according to heuristic
|
||||
STBRP_SORT(rects, num_rects, sizeof(rects[0]), rect_height_compare);
|
||||
|
||||
for (i=0; i < num_rects; ++i) {
|
||||
if (rects[i].w == 0 || rects[i].h == 0) {
|
||||
rects[i].x = rects[i].y = 0; // empty rect needs no space
|
||||
} else {
|
||||
stbrp__findresult fr = stbrp__skyline_pack_rectangle(context, rects[i].w, rects[i].h);
|
||||
if (fr.prev_link) {
|
||||
rects[i].x = (stbrp_coord) fr.x;
|
||||
rects[i].y = (stbrp_coord) fr.y;
|
||||
} else {
|
||||
rects[i].x = rects[i].y = STBRP__MAXVAL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// unsort
|
||||
STBRP_SORT(rects, num_rects, sizeof(rects[0]), rect_original_order);
|
||||
|
||||
// set was_packed flags and all_rects_packed status
|
||||
for (i=0; i < num_rects; ++i) {
|
||||
rects[i].was_packed = !(rects[i].x == STBRP__MAXVAL && rects[i].y == STBRP__MAXVAL);
|
||||
if (!rects[i].was_packed)
|
||||
all_rects_packed = 0;
|
||||
}
|
||||
|
||||
// return the all_rects_packed status
|
||||
return all_rects_packed;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
------------------------------------------------------------------------------
|
||||
This software is available under 2 licenses -- choose whichever you prefer.
|
||||
------------------------------------------------------------------------------
|
||||
ALTERNATIVE A - MIT License
|
||||
Copyright (c) 2017 Sean Barrett
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
------------------------------------------------------------------------------
|
||||
ALTERNATIVE B - Public Domain (www.unlicense.org)
|
||||
This is free and unencumbered software released into the public domain.
|
||||
Anyone is free to copy, modify, publish, use, compile, sell, or distribute this
|
||||
software, either in source code form or as a compiled binary, for any purpose,
|
||||
commercial or non-commercial, and by any means.
|
||||
In jurisdictions that recognize copyright laws, the author or authors of this
|
||||
software dedicate any and all copyright interest in the software to the public
|
||||
domain. We make this dedication for the benefit of the public at large and to
|
||||
the detriment of our heirs and successors. We intend this dedication to be an
|
||||
overt act of relinquishment in perpetuity of all present and future rights to
|
||||
this software under copyright law.
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
||||
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
------------------------------------------------------------------------------
|
||||
*/
|
||||
Fichier diff supprimé car celui-ci est trop grand
Voir la Diff
Fichier diff supprimé car celui-ci est trop grand
Voir la Diff
Fichier diff supprimé car celui-ci est trop grand
Voir la Diff
@@ -0,0 +1,23 @@
|
||||
/* gl_helpers.h header file of gl_helpers.cpp */
|
||||
|
||||
// Eric Bachard 2024/11/05 17h11
|
||||
|
||||
#ifndef _GL_HELPERS_H
|
||||
#define _GL_HELPERS_H
|
||||
|
||||
#include "imgui.h"
|
||||
#include "imgui_impl_sdl3.h"
|
||||
#include "imgui_impl_opengl3.h"
|
||||
#include <stdio.h>
|
||||
#include <SDL3/SDL.h>
|
||||
#if defined(IMGUI_IMPL_OPENGL_ES2)
|
||||
#include <SDL_opengles2.h>
|
||||
#else
|
||||
#include <SDL3/SDL_opengl.h>
|
||||
#endif
|
||||
|
||||
bool LoadTextureFromMemory(const void*, size_t, GLuint*, int*, int*);
|
||||
|
||||
bool LoadTextureFromFile(const char*, GLuint*, int*, int*);
|
||||
|
||||
#endif /* _GL_HELPERS_H*/
|
||||
@@ -0,0 +1,65 @@
|
||||
/* **************************************************************************************
|
||||
* Author: Eric Bachard
|
||||
* eric.bachard@free.fr
|
||||
* 2018 december 30th
|
||||
*
|
||||
* MIT License
|
||||
* -----------
|
||||
* eric.bachard@free.fr
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
* **************************************************************************************/
|
||||
|
||||
#ifndef IMGUI_THEMES_HPP
|
||||
#define IMGUI_THEMES_HPP
|
||||
|
||||
#ifndef IMGUI_DEFINE_MATH_OPERATORS
|
||||
#define IMGUI_DEFINE_MATH_OPERATORS
|
||||
#endif
|
||||
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include "imgui.h"
|
||||
#include "imgui_internal.h"
|
||||
|
||||
// Extra Math Helpers (Set the proper define below in imgui_internal.h)
|
||||
#ifdef IMGUI_DEFINE_MATH_OPERATORS
|
||||
//static inline ImVec4 operator+(const ImVec4& lhs, const ImVec4& rhs) { return ImVec4(lhs.x+rhs.x, lhs.y+rhs.y, lhs.z+rhs.z, lhs.w+rhs.w); }
|
||||
//static inline ImVec4 operator*(const ImVec4& lhs, const ImVec4& rhs) { return ImVec4(lhs.x*rhs.x, lhs.y*rhs.y, lhs.z*rhs.z, lhs.w*rhs.w); }
|
||||
//static inline ImVec4 operator/(const ImVec4& lhs, const ImVec4& rhs) { return ImVec4(lhs.x/rhs.x, lhs.y/rhs.y, lhs.z/rhs.z, lhs.w/rhs.w); }
|
||||
|
||||
static inline ImVec4& operator+=(ImVec4& lhs, const ImVec4& rhs) { lhs.x += rhs.x; lhs.y += rhs.y; lhs.z += rhs.z; lhs.w += rhs.w; return lhs;}
|
||||
static inline ImVec4& operator-=(ImVec4& lhs, const ImVec4& rhs) { lhs.x -= rhs.x; lhs.y -= rhs.y; lhs.z -= rhs.z; lhs.w -= rhs.w; return lhs;}
|
||||
static inline ImVec4& operator*=(ImVec4& lhs, const ImVec4& rhs) { lhs.x *= rhs.x; lhs.y *= rhs.y; lhs.z *= rhs.z; lhs.w *= rhs.w; return lhs;}
|
||||
static inline ImVec4& operator/=(ImVec4& lhs, const ImVec4& rhs) { lhs.x /= rhs.x; lhs.y /= rhs.y; lhs.z /= rhs.z; lhs.w /= rhs.w; return lhs;}
|
||||
#endif
|
||||
|
||||
namespace ImGui
|
||||
{
|
||||
// New style inspired from Traditionnal Green (gtk+) on Linux + to be improved !
|
||||
IMGUI_API void StyleColorsLightGreen(ImGuiStyle* dst = NULL); // the default style in miniDart software
|
||||
|
||||
// New style inspired from Windows theme to be improved !
|
||||
IMGUI_API void StyleColorsWindows(ImGuiStyle* dst = NULL);
|
||||
|
||||
|
||||
} // namespace ImGui
|
||||
#endif //IMGUI_THEMES_H
|
||||
@@ -0,0 +1,28 @@
|
||||
/* imgui_utils.h : contient plusieurs fonctions utiles (dessin, etc)
|
||||
*
|
||||
*
|
||||
* Copyright Eric Bachard 2026/01/14 23h23
|
||||
* License GPL v2
|
||||
*/
|
||||
|
||||
#ifndef __IMGUI_UTILS_H
|
||||
#define __IMGUI_UTILS_H
|
||||
|
||||
#include "modulations.h"
|
||||
|
||||
void selectThemeMenu(Application *);
|
||||
|
||||
void selectFrameSize(DigitalModulation *);
|
||||
|
||||
// ToogleButton transformé en VToggleButton
|
||||
bool VToggleButton(const char*, bool*);
|
||||
|
||||
void drawVToggleButtons(int *, int);
|
||||
|
||||
void highlightFrame(int *, int);
|
||||
|
||||
void DrawIndicator(const char *, float *, DigitalModulationType *, int *, float, float, ImU32, ImVec2);
|
||||
|
||||
#endif /* __IMGUI_UTILS_H */
|
||||
|
||||
|
||||
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
* modulations.h fichier d'en-tête
|
||||
* Licence GPL v2
|
||||
* Author and copyright : Eric Bachard 2026/01/08 18h03
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef __MODULATIONS_H
|
||||
#define __MODULATIONS_H
|
||||
|
||||
#define DEFAULT_WORD_SIZE 8
|
||||
#define WORD_SIZE_MAX 24
|
||||
|
||||
#define DEFAULT_SAMPLES_PER_BIT 400
|
||||
#define SAMPLES_PER_BIT_MAX 400
|
||||
|
||||
#define VTOGGLEBUTTON_WIDTH 30.8f
|
||||
#define CHILD2_WIDTH 300.0f
|
||||
#define LARGE_CHILD2_WIDTH 400.0f
|
||||
#define CANVAS_HEIGHT 400.0f
|
||||
|
||||
#define SINUS_AMPLITUDE (0.35 * CANVAS_HEIGHT)
|
||||
|
||||
#include "application.h"
|
||||
|
||||
|
||||
typedef enum DigitalModulationType
|
||||
{
|
||||
// Amplitude
|
||||
MOD_OOK_TYPE = 0,
|
||||
MOD_ASK_TYPE = 1,
|
||||
MOD_MASK_TYPE = 2,
|
||||
// Phase
|
||||
MOD_BPSK_TYPE = 3,
|
||||
MOD_DPSK_TYPE = 4,
|
||||
// Fréquence
|
||||
MOD_FSK_TYPE = 5,
|
||||
MOD_MFSK_TYPE = 6,
|
||||
// M-QAM
|
||||
MOD_M_QAM_TYPE = 7,
|
||||
MOD_4_QAM_TYPE = 8,
|
||||
MOD_16_QAM_TYPE = 9,
|
||||
// We can dream (wifi 7)
|
||||
MOD_256_QAM_TYPE = 10,
|
||||
// Should never be used
|
||||
NOT_A_MODULATION = 100
|
||||
} DigitalModulationType;
|
||||
|
||||
class DigitalModulation
|
||||
{
|
||||
public:
|
||||
// Ctor
|
||||
DigitalModulation();
|
||||
|
||||
// Dtor
|
||||
~DigitalModulation();
|
||||
|
||||
short int AmplitudeDigitalModulation(float *, int *, DigitalModulationType *);
|
||||
short int FrequencyDigitalModulation(float *, int *, DigitalModulationType *);
|
||||
short int PhaseDigitalModulation (float *, int *, DigitalModulationType *);
|
||||
short int M_QAM_DigitalModulation (float *, int *, DigitalModulationType *);
|
||||
|
||||
inline int getWordSize() { return mdWordSize; }
|
||||
inline void setWordSize(int aWordSize) { mdWordSize = aWordSize; }
|
||||
|
||||
inline DigitalModulationType get_AM_DigitalModulationType() { return md_AM_DigitalModulation_t; }
|
||||
inline DigitalModulationType get_FM_DigitalModulationType() { return md_FM_DigitalModulation_t; }
|
||||
inline DigitalModulationType get_PM_DigitalModulationType() { return md_PM_DigitalModulation_t; }
|
||||
inline DigitalModulationType getM_QAM_DigitalModulationType() { return md_M_QAM_DigitalModulation_t; }
|
||||
|
||||
void setDigitalModulationType (TAB_Name aTab, DigitalModulationType aType);
|
||||
|
||||
private:
|
||||
int mdWordSize;
|
||||
|
||||
DigitalModulationType md_AM_DigitalModulation_t;
|
||||
DigitalModulationType md_FM_DigitalModulation_t;
|
||||
DigitalModulationType md_PM_DigitalModulation_t;
|
||||
DigitalModulationType md_M_QAM_DigitalModulation_t;
|
||||
};
|
||||
|
||||
|
||||
#endif /* __MODULATIONS_H */
|
||||
@@ -0,0 +1,14 @@
|
||||
#ifndef __VTOGGLE_BUTTON
|
||||
#define __VTOGGLE_BUTTON
|
||||
|
||||
// ToggleButton
|
||||
// Bouton ON/OFF vertical type switch
|
||||
// - str_id : identifiant ImGui (utilise ## pour cacher le label)
|
||||
// - v : pointeur sur l’état booléen
|
||||
// Retourne true si l’état a changé
|
||||
|
||||
bool VToggleButton(const char *, bool *);
|
||||
|
||||
void drawVToggleButtons(int *, int);
|
||||
|
||||
#endif /* __VTOGGLE_BUTTON */
|
||||
@@ -0,0 +1,34 @@
|
||||
/* digital_modulation_fr.hpp
|
||||
* French localization file for Digital Modulation application
|
||||
* Copyright Eric Bachard 2026/01/11 22h
|
||||
* License GPL v2 */
|
||||
|
||||
#define APPLICATION_NAME "Modulations numériques"
|
||||
|
||||
#define APPLICATION_MENU_HEAD "Application"
|
||||
|
||||
#define APPLICATION_QUIT "Quitter"
|
||||
|
||||
#define APPLICATION_QUIT_SHORTCUT " Alt + F4"
|
||||
|
||||
#define MAIN_SDL3_WINDOW_NAME "Simulation de modulations numériques"
|
||||
|
||||
#define THEME_MENU_ENTRY "Theme"
|
||||
|
||||
#define TRADITIONAL_GREEN_THEME_MENU_ENTRY " Light green"
|
||||
|
||||
#define DARK_THEME_MENU_ENTRY " Dark"
|
||||
|
||||
#define CLASSIC_THEME_MENU_ENTRY " Classic"
|
||||
|
||||
#define LIGHT_BLUE_THEME_MENU_ENTRY " Light blue"
|
||||
|
||||
#define WINDOWS_THEME_MENU_ENTRY " Windows"
|
||||
|
||||
#define FRAME_SIZE "Longueur trame"
|
||||
|
||||
#define HEIGHT_BITS_FRAME_SIZE " 8 bits "
|
||||
|
||||
#define SIXTEEN_BITS_FRAME_SIZE " 16 bits "
|
||||
|
||||
#define TWENTY_FOUR_BITS_FRAME_SIZE " 24 bits "
|
||||
+231
@@ -0,0 +1,231 @@
|
||||
// Dear ImGui + SDL3 + OpenGL3
|
||||
#include <cmath>
|
||||
#include <iostream>
|
||||
#include <SDL3/SDL.h>
|
||||
#include <SDL3/SDL_opengl.h>
|
||||
|
||||
#include "imgui_themes.h"
|
||||
#include "imgui.h"
|
||||
#include "imgui_impl_sdl3.h"
|
||||
#include "imgui_impl_opengl3.h"
|
||||
|
||||
#include "digital_modulation_fr.hpp"
|
||||
#include "engine.h"
|
||||
#include "imgui_utils.h"
|
||||
#include "modulations.h"
|
||||
#include "application.h"
|
||||
|
||||
|
||||
static void showApplicationQuitMenu()
|
||||
{
|
||||
if (ImGui::BeginMenu(APPLICATION_MENU_HEAD))
|
||||
{
|
||||
if (ImGui::MenuItem(APPLICATION_QUIT, APPLICATION_QUIT_SHORTCUT) )
|
||||
{
|
||||
SDL_Event event;
|
||||
event.type = SDL_EVENT_QUIT;
|
||||
SDL_PushEvent( &event );
|
||||
}
|
||||
ImGui::EndMenu();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int main(void)
|
||||
{
|
||||
// démarrage de l'application
|
||||
Application app;
|
||||
Application * p_app = &app;
|
||||
|
||||
// --------------------- SDL INIT ---------------------
|
||||
if (!SDL_Init(SDL_INIT_VIDEO))
|
||||
{
|
||||
fprintf(stdout, "SDL init error: %s\n", SDL_GetError());
|
||||
return -1;
|
||||
}
|
||||
|
||||
Engine engine;
|
||||
|
||||
// -----------------IMGUI INIT---------------------------
|
||||
IMGUI_CHECKVERSION();
|
||||
ImGui::CreateContext();
|
||||
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
ImGui::StyleColorsLight();
|
||||
|
||||
ImGui_ImplSDL3_InitForOpenGL(engine.getWindow(), engine.getGL_Context());
|
||||
ImGui_ImplOpenGL3_Init(engine.get_glsl_version());
|
||||
|
||||
ImGuiStyle& style = ImGui::GetStyle();
|
||||
style.FontSizeBase = 22.0f;
|
||||
io.Fonts->AddFontFromFileTTF("../fonts/DroidSans.ttf");
|
||||
|
||||
// Création d'une instance de la classe DigitalModulation
|
||||
// (son initialisation est réalisée par le constructeur de la classe)
|
||||
DigitalModulation dmod;
|
||||
// Pointeur, utilisé par les différents menus
|
||||
DigitalModulation * p_dmod = &dmod;
|
||||
|
||||
// ---------------------- MAIN LOOP ----------------------
|
||||
bool done = false;
|
||||
|
||||
while (!done)
|
||||
{
|
||||
SDL_Event event;
|
||||
while (SDL_PollEvent(&event))
|
||||
{
|
||||
ImGui_ImplSDL3_ProcessEvent(&event);
|
||||
|
||||
switch (event.type)
|
||||
{
|
||||
case SDL_EVENT_QUIT:
|
||||
done = true;
|
||||
break;
|
||||
|
||||
case SDL_EVENT_WINDOW_RESIZED:
|
||||
{
|
||||
SDL_SetWindowSize(engine.getWindow(), event.window.data1, event.window.data2);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
ImGui_ImplOpenGL3_NewFrame();
|
||||
ImGui_ImplSDL3_NewFrame();
|
||||
ImGui::NewFrame();
|
||||
|
||||
// Corrige le redimensionnement (se voit quand on change de thème)
|
||||
ImGui::SetNextWindowPos(ImVec2(0,27), ImGuiCond_Always);
|
||||
ImGui::SetNextWindowSize(ImGui::GetIO().DisplaySize, ImGuiCond_Always);
|
||||
|
||||
ImGui::Begin( "Modulation numerique",
|
||||
nullptr,
|
||||
ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoScrollbar
|
||||
| ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize
|
||||
);
|
||||
|
||||
// some geometry to avoid hidden main application menu
|
||||
// on commence par calculer la place disponible et on soustrait 23.0 pixels en y
|
||||
ImVec2 windowSize(ImGui::GetIO().DisplaySize.x, ImGui::GetIO().DisplaySize.y - 23.0f);
|
||||
ImGui::SetNextWindowSize(windowSize);
|
||||
|
||||
// On décale ensuite le contenu de 23.0 pixels vers le bas, ce qui représente 1 ligne environ
|
||||
ImVec2 main_viewport_pos = ImGui::GetMainViewport()->Pos;
|
||||
ImGui::SetNextWindowPos(ImVec2(main_viewport_pos.x,main_viewport_pos.y + 23.0f));
|
||||
|
||||
if (ImGui::BeginMainMenuBar())
|
||||
{
|
||||
showApplicationQuitMenu();
|
||||
selectThemeMenu(p_app);
|
||||
selectFrameSize(p_dmod);
|
||||
ImGui::EndMainMenuBar();
|
||||
}
|
||||
|
||||
ImGuiTabBarFlags tab_bar_flags = ImGuiTabBarFlags_None | ImGuiTabBarFlags_Reorderable | ImGuiTabBarFlags_NoTooltip;
|
||||
|
||||
int anErr = 0;
|
||||
if (ImGui::BeginTabBar("Modulation Numérique d'Amplitude", tab_bar_flags))
|
||||
{
|
||||
if (ImGui::BeginTabItem("Modulation numérique d'Amplitude"))
|
||||
{
|
||||
app.set_current_tab(Amplitude_TAB);
|
||||
static int am_bits[WORD_SIZE_MAX] = {0};
|
||||
static float am_carrier_freq = 2.0f;
|
||||
|
||||
dmod.setDigitalModulationType(Amplitude_TAB, MOD_OOK_TYPE);
|
||||
static DigitalModulationType aType = dmod.get_AM_DigitalModulationType();
|
||||
|
||||
anErr = dmod.AmplitudeDigitalModulation(&am_carrier_freq, &am_bits[0], &aType);
|
||||
|
||||
if (anErr != EXIT_SUCCESS)
|
||||
{
|
||||
std::cout << "Problème !!" << "\n";
|
||||
return (-1);
|
||||
}
|
||||
ImGui::EndTabItem();
|
||||
}
|
||||
|
||||
if (ImGui::BeginTabItem("Modulation numérique de fréquence"))
|
||||
{
|
||||
app.set_current_tab(Frequency_TAB);
|
||||
static int fm_bits[WORD_SIZE_MAX] = {0};
|
||||
static float fm_carrier_freq = 2.0f;
|
||||
dmod.setDigitalModulationType(Frequency_TAB, MOD_FSK_TYPE);
|
||||
|
||||
static DigitalModulationType fm_Type = dmod.get_FM_DigitalModulationType();
|
||||
|
||||
anErr = dmod.FrequencyDigitalModulation(&fm_carrier_freq, &fm_bits[0], &fm_Type);
|
||||
|
||||
if (anErr != EXIT_SUCCESS)
|
||||
{
|
||||
std::cout << "Problème !!" << "\n";
|
||||
return (-1);
|
||||
}
|
||||
ImGui::EndTabItem();
|
||||
}
|
||||
|
||||
if (ImGui::BeginTabItem("Modulation numérique de phase"))
|
||||
{
|
||||
app.set_current_tab(Phase_TAB);
|
||||
static int pm_bits[WORD_SIZE_MAX] = {0};
|
||||
static float pm_carrier_freq = 2.0f;
|
||||
|
||||
dmod.setDigitalModulationType(Phase_TAB, MOD_BPSK_TYPE);
|
||||
static DigitalModulationType pm_Type = p_dmod->get_PM_DigitalModulationType();
|
||||
|
||||
anErr = dmod.PhaseDigitalModulation(&pm_carrier_freq, &pm_bits[0], &pm_Type);
|
||||
|
||||
if (anErr != EXIT_SUCCESS)
|
||||
{
|
||||
std::cout << "Problème !!" << "\n";
|
||||
return (-1);
|
||||
}
|
||||
ImGui::EndTabItem();
|
||||
}
|
||||
|
||||
if (ImGui::BeginTabItem("Modulation numérique M-QAM"))
|
||||
{
|
||||
app.set_current_tab(M_QAM_TAB);
|
||||
static int pm_bits[WORD_SIZE_MAX] = {0};
|
||||
static float pm_carrier_freq = 2.0f;
|
||||
|
||||
dmod.setDigitalModulationType(M_QAM_TAB, MOD_4_QAM_TYPE);
|
||||
static DigitalModulationType pm_Type = p_dmod->getM_QAM_DigitalModulationType();
|
||||
|
||||
anErr = dmod.M_QAM_DigitalModulation(&pm_carrier_freq, &pm_bits[0], &pm_Type);
|
||||
|
||||
if (anErr != EXIT_SUCCESS)
|
||||
{
|
||||
std::cout << "Problème !!" << "\n";
|
||||
return (-1);
|
||||
}
|
||||
ImGui::EndTabItem();
|
||||
}
|
||||
ImGui::EndTabBar();
|
||||
}
|
||||
ImGui::End();
|
||||
|
||||
// -----------------------RENDER ----------------------
|
||||
ImGui::Render();
|
||||
glViewport(0, 0, (int)io.DisplaySize.x, (int)io.DisplaySize.y);
|
||||
glClearColor(0.95f, 0.95f, 0.95f, 1.0f);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
|
||||
SDL_GL_SwapWindow(engine.getWindow());
|
||||
}
|
||||
|
||||
// ------------------ CLEANUP ------------------
|
||||
ImGui_ImplOpenGL3_Shutdown();
|
||||
ImGui_ImplSDL3_Shutdown();
|
||||
ImGui::DestroyContext();
|
||||
engine.~Engine();
|
||||
dmod.~DigitalModulation();
|
||||
app.~Application();
|
||||
SDL_Quit();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,893 @@
|
||||
/* Fichier d'implémentation de la classe DigitalModulations numériques
|
||||
* - d'amplitude ;
|
||||
* - de fréquence;
|
||||
* - de phase ;
|
||||
* - M-QAM
|
||||
*
|
||||
* Author : Eric Bachard 2026/01/08 18h37
|
||||
* Licence GPL v2
|
||||
*/
|
||||
|
||||
#include <cstdlib>
|
||||
#include <cstdint>
|
||||
#include "math.h"
|
||||
#include "imgui.h"
|
||||
#include "imgui_utils.h"
|
||||
#include "vtoggle_button.h"
|
||||
#include "gl_helpers.h"
|
||||
|
||||
#ifdef M_PI
|
||||
#undef M_PI
|
||||
#define M_PI 3.14159265358979323846f
|
||||
#endif
|
||||
|
||||
// FIXME image
|
||||
static int my_image_width = 0;
|
||||
static int my_image_height = 0;
|
||||
static GLuint my_image_texture = 0;
|
||||
|
||||
DigitalModulation::DigitalModulation()
|
||||
: mdWordSize(DEFAULT_WORD_SIZE)
|
||||
{
|
||||
setDigitalModulationType (Amplitude_TAB, MOD_OOK_TYPE);
|
||||
setDigitalModulationType (Frequency_TAB, MOD_FSK_TYPE);
|
||||
setDigitalModulationType (Phase_TAB, MOD_BPSK_TYPE);
|
||||
// TODO Later
|
||||
//setDigitalModulationType (M_QAM_TAB, MOD_M_QAM_TYPE);
|
||||
};
|
||||
|
||||
DigitalModulation::~DigitalModulation()
|
||||
{
|
||||
};
|
||||
|
||||
short int DigitalModulation::AmplitudeDigitalModulation(float * carrier_freq,
|
||||
int * am_bits,
|
||||
DigitalModulationType * p_aType)
|
||||
{
|
||||
// TODO : améliorer cette partie
|
||||
static DigitalModulationType amplitude_modulation_t = *p_aType;
|
||||
static float c_freq = *carrier_freq;
|
||||
|
||||
// --------------------- LEFT : SIGNAL -----------------
|
||||
ImGui::BeginChild("Signal", ImVec2(ImGui::GetContentRegionAvail().x - CHILD2_WIDTH, 0), false);
|
||||
|
||||
// pour 1 bit, 100 échantillons (400 pour la modulation de fréquence pour fporteuse max)
|
||||
static int samples_per_bit = SAMPLES_PER_BIT_MAX;
|
||||
|
||||
ImGui::NewLine();
|
||||
ImGui::SliderFloat("Frequence porteuse ", &c_freq, 2.0f, 10.0f);
|
||||
#if defined(DEBUG)
|
||||
ImGui::SliderInt("Nombre de points par symbole", &samples_per_bit, DEFAULT_SAMPLES_PER_BIT, 500);
|
||||
#endif
|
||||
ImGui::NewLine();
|
||||
|
||||
// Surbrillance de la trame affichée
|
||||
highlightFrame(am_bits, getWordSize());
|
||||
|
||||
// position du curseur + dimensions du canvas.
|
||||
// canvas_pos contient les coordonnées du curseur (marque l'endroit d'où l'on dessine à ce point du programme)
|
||||
ImVec2 canvas_pos = ImGui::GetCursorScreenPos();
|
||||
|
||||
// Dimensions du cadre dans lequel on dessine la sinusoïde
|
||||
ImVec2 canvas_size(ImGui::GetContentRegionAvail().x, CANVAS_HEIGHT);
|
||||
|
||||
// ce qui va être dessiné
|
||||
ImDrawList* draw_list = ImGui::GetWindowDrawList();
|
||||
|
||||
// On dessine un fond blanc
|
||||
draw_list->AddRectFilled
|
||||
(
|
||||
canvas_pos,
|
||||
ImVec2(canvas_pos.x + canvas_size.x, canvas_pos.y + canvas_size.y),
|
||||
IM_COL32(255,255,255,255)
|
||||
);
|
||||
|
||||
// on ajoute par dessus un tour noir
|
||||
draw_list->AddRect
|
||||
(
|
||||
canvas_pos,
|
||||
ImVec2(canvas_pos.x + canvas_size.x, canvas_pos.y + canvas_size.y),
|
||||
IM_COL32(0,0,0,255)
|
||||
);
|
||||
|
||||
// calcul des coordonnées du centre de la frame
|
||||
float center_y = canvas_pos.y + canvas_size.y / 2.0f;
|
||||
|
||||
// amplitude de la sinusoïde de base
|
||||
float base_amp = SINUS_AMPLITUDE;
|
||||
float total_samples = getWordSize() * samples_per_bit;
|
||||
float dx = canvas_size.x / total_samples;
|
||||
float x = canvas_pos.x;
|
||||
|
||||
ImVec2 prev(x, center_y);
|
||||
|
||||
for (int bit_traite = 0; bit_traite < getWordSize(); bit_traite++)
|
||||
{
|
||||
draw_list->AddLine
|
||||
(
|
||||
ImVec2(x, canvas_pos.y),
|
||||
ImVec2(x, canvas_pos.y + canvas_size.y),
|
||||
IM_COL32(0,120,255,255)
|
||||
);
|
||||
|
||||
float amplitude = 0.0f;
|
||||
|
||||
switch (amplitude_modulation_t)
|
||||
{
|
||||
case MOD_OOK_TYPE:
|
||||
amplitude = am_bits[bit_traite] ? base_amp : 0.0f;
|
||||
break;
|
||||
|
||||
case MOD_ASK_TYPE:
|
||||
amplitude = am_bits[bit_traite] ? base_amp : base_amp * 0.4f;
|
||||
break;
|
||||
|
||||
case MOD_MASK_TYPE:
|
||||
if ((bit_traite % 2) == 0) // bit pair => bits 0, 2, 4 ou 6
|
||||
amplitude = base_amp * (0.25 + 0.5 * am_bits[bit_traite] + 0.25 * am_bits[bit_traite+1]);
|
||||
else // bit impair => bits 1, 3, 5 ou 7
|
||||
amplitude = base_amp * (0.25 + 0.5 * am_bits[bit_traite-1] + 0.25 * am_bits[bit_traite]);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
// on dessine 100 échantillons par bit de la trame
|
||||
for (int i = 0; i < samples_per_bit; i++)
|
||||
{
|
||||
float t = (bit_traite * samples_per_bit + i) / (float)samples_per_bit;
|
||||
float y = center_y - sinf(2.0f * M_PI * c_freq * t) * amplitude;
|
||||
|
||||
ImVec2 p(x, y);
|
||||
//if (i != (samples_per_bit -1))
|
||||
// Le dernier raccord peut poser problème dans certains cas
|
||||
// et on ne dessine pas la ligne entre le dernier point du bit précédent
|
||||
// et le premier point du bit suivant. Ceci en M_QAM pour l'instant (pour tester).
|
||||
if (MOD_MASK_TYPE == *p_aType)
|
||||
{
|
||||
if (i != 0)
|
||||
draw_list->AddLine(prev, p, IM_COL32(255,0,0,255), 2.0f);
|
||||
else
|
||||
draw_list->AddLine(p, p, IM_COL32(255,0,0,255), 2.0f);
|
||||
}
|
||||
else
|
||||
draw_list->AddLine(prev, p, IM_COL32(255,0,0,255), 2.0f);
|
||||
|
||||
prev = p;
|
||||
x += dx;
|
||||
}
|
||||
|
||||
// FIXME : d'où viennent ces valeurs 5 et 22 ?
|
||||
draw_list->AddText ( ImVec2(x - samples_per_bit * dx + 5, canvas_pos.y + canvas_size.y - 22),
|
||||
IM_COL32(0,0,255,255),
|
||||
am_bits[bit_traite] ? " 1 " : " 0 "
|
||||
);
|
||||
}
|
||||
|
||||
ImGui::Dummy(canvas_size);
|
||||
ImGui::NewLine();
|
||||
ImGui::SeparatorText("Bits");
|
||||
|
||||
drawVToggleButtons(am_bits, getWordSize());
|
||||
|
||||
ImGui::EndChild();
|
||||
|
||||
// ----------------------------- RIGHT : OPTIONS ------------------------
|
||||
ImGui::SameLine();
|
||||
ImGui::BeginChild("Options", ImVec2(CHILD2_WIDTH - 8.0f /* minus the border */, 0), true);
|
||||
|
||||
ImGui::Text("Type de modulation");
|
||||
ImGui::Separator();
|
||||
|
||||
ImGui::RadioButton("OOK " , (int*)&litude_modulation_t, MOD_OOK_TYPE);
|
||||
ImGui::RadioButton("ASK " , (int*)&litude_modulation_t, MOD_ASK_TYPE);
|
||||
ImGui::RadioButton("4-ASK ", (int*)&litude_modulation_t, MOD_MASK_TYPE);
|
||||
|
||||
// --- AJOUT TÉMOIN ---
|
||||
ImGui::Spacing();
|
||||
ImGui::Separator();
|
||||
ImGui::Text("Principe :");
|
||||
ImGui::Spacing();
|
||||
|
||||
ImVec2 ind_size(ImGui::GetContentRegionAvail().x - 10, 50);
|
||||
ImU32 col = IM_COL32(0, 120, 255, 255); // Même bleu que le signal
|
||||
|
||||
switch(amplitude_modulation_t)
|
||||
{
|
||||
case MOD_OOK_TYPE:
|
||||
case MOD_ASK_TYPE:
|
||||
ImGui::Text("1 bit par symbole");
|
||||
ImGui::NewLine();
|
||||
DrawIndicator("Le bit vaut 1 :", &c_freq, &litude_modulation_t, &samples_per_bit, 1.0f, 0.0f, col, ind_size);
|
||||
|
||||
ImGui::NewLine();
|
||||
DrawIndicator ("Le bit vaut 0 :",
|
||||
&c_freq, &litude_modulation_t,
|
||||
&samples_per_bit, ((MOD_ASK_TYPE == amplitude_modulation_t) ? 0.4f : 0.0f),
|
||||
0.0f,
|
||||
col,
|
||||
ind_size
|
||||
);
|
||||
break;
|
||||
|
||||
case MOD_MASK_TYPE:
|
||||
ImGui::Text("2 bits par symbole");
|
||||
ImGui::NewLine();
|
||||
DrawIndicator("Le symbole vaut 11 : ", &c_freq, &litude_modulation_t, &samples_per_bit, 1.0f, 0.0f, col, ind_size);
|
||||
ImGui::NewLine();
|
||||
DrawIndicator("Le symbole vaut 10 : ", &c_freq, &litude_modulation_t, &samples_per_bit, 0.75f, 0.0f, col, ind_size);
|
||||
ImGui::NewLine();
|
||||
DrawIndicator("Le symbole vaut 01 : ", &c_freq, &litude_modulation_t, &samples_per_bit, 0.4f, 0.0f, col, ind_size);
|
||||
ImGui::NewLine();
|
||||
DrawIndicator("Le symbole vaut 00 : ", &c_freq, &litude_modulation_t, &samples_per_bit, 0.15f, 0.0f, col, ind_size);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
// ------- FIN AJOUT TEMOIN -------------
|
||||
|
||||
|
||||
ImGui::EndChild();
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
short int DigitalModulation::FrequencyDigitalModulation(float * carrier_freq, int * fm_bits, DigitalModulationType * fm_type)
|
||||
{
|
||||
static DigitalModulationType frequency_modulation_t = *fm_type;
|
||||
static float c_freq = *carrier_freq;
|
||||
|
||||
// --------------------- LEFT : SIGNAL -----------------
|
||||
// FIXME : LAYOUT
|
||||
ImGui::BeginChild("Signal2", ImVec2(ImGui::GetContentRegionAvail().x - CHILD2_WIDTH , 0), false);
|
||||
|
||||
// pour 1 bit, 100 échantillons (400 donne de meilleurs résultats en MFSK)
|
||||
static int samples_per_bit = SAMPLES_PER_BIT_MAX; // limite le sous-échantillonnage
|
||||
static float k = 2.0f; // default
|
||||
ImGui::NewLine();
|
||||
|
||||
// affichage bruité au-delà de 4.0f
|
||||
ImGui::SliderFloat("Frequence porteuse ", carrier_freq, 2.0f, 4.0f);
|
||||
#ifdef DEBUG
|
||||
static int k2 = 2;
|
||||
ImGui::SliderInt("Nombre de points par symbole", &samples_per_bit, DEFAULT_SAMPLES_PER_BIT, 500);
|
||||
ImGui::SliderInt("Rapport fréquence modulée / fréquence de base ", &k2, 4, 10);
|
||||
k = (float)k2;
|
||||
#else
|
||||
k = 2.0f;
|
||||
#endif
|
||||
ImGui::NewLine();
|
||||
|
||||
// Surbrillance
|
||||
highlightFrame(fm_bits, getWordSize());
|
||||
|
||||
ImVec2 canvas_pos = ImGui::GetCursorScreenPos();
|
||||
ImVec2 canvas_size(ImGui::GetContentRegionAvail().x, CANVAS_HEIGHT);
|
||||
|
||||
ImDrawList* draw_list = ImGui::GetWindowDrawList();
|
||||
draw_list->AddRectFilled
|
||||
(
|
||||
canvas_pos,
|
||||
ImVec2(canvas_pos.x + canvas_size.x, canvas_pos.y + canvas_size.y),
|
||||
IM_COL32(255,255,255,255)
|
||||
);
|
||||
|
||||
draw_list->AddRect
|
||||
(
|
||||
canvas_pos,
|
||||
ImVec2(canvas_pos.x + canvas_size.x, canvas_pos.y + canvas_size.y),
|
||||
IM_COL32(0,0,0,255)
|
||||
);
|
||||
|
||||
float center_y = canvas_pos.y + canvas_size.y / 2.0f;
|
||||
float base_amp = 100.0f;
|
||||
float total_samples = getWordSize() * samples_per_bit;
|
||||
float dx = canvas_size.x / total_samples;
|
||||
float x = canvas_pos.x;
|
||||
|
||||
ImVec2 prev(x, center_y);
|
||||
|
||||
for (int bit_traite = 0; bit_traite < getWordSize(); bit_traite++)
|
||||
{
|
||||
draw_list->AddLine
|
||||
(
|
||||
ImVec2(x, canvas_pos.y),
|
||||
ImVec2(x, canvas_pos.y + canvas_size.y),
|
||||
IM_COL32(0,120,255,255)
|
||||
);
|
||||
|
||||
switch (frequency_modulation_t)
|
||||
{
|
||||
case MOD_FSK_TYPE:
|
||||
c_freq = fm_bits[bit_traite] ? (*carrier_freq) * k : *carrier_freq ;
|
||||
break;
|
||||
|
||||
case MOD_MFSK_TYPE:
|
||||
// On doit dessiner la même amplitude pour les bits (0,1), (2,3), (4,5) et (6,7)
|
||||
// => la parité de bit_traite nous donne la réponse
|
||||
if ((bit_traite % 2) == 0) // bit pair => bits 0, 2, 4 ou 6
|
||||
c_freq = (*carrier_freq) * ( 1 + k * (2 * fm_bits[bit_traite] + fm_bits[bit_traite+1]));
|
||||
else // bit impair => bits 1, 3, 5 ou 7
|
||||
c_freq = (*carrier_freq) * ( 1 + k * (2 * fm_bits[bit_traite-1] + fm_bits[bit_traite]));
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
for (int i = 0; i < samples_per_bit; i++)
|
||||
{
|
||||
float t = (bit_traite * samples_per_bit + i) / (float)samples_per_bit;
|
||||
float y = center_y - sinf(2.0f * M_PI * c_freq * t) * base_amp;
|
||||
|
||||
ImVec2 p(x, y);
|
||||
draw_list->AddLine(prev, p, IM_COL32(255,0,0,255), 2.0f);
|
||||
prev = p;
|
||||
x += dx;
|
||||
}
|
||||
|
||||
draw_list->AddText ( ImVec2(x - samples_per_bit * dx + 5, canvas_pos.y + canvas_size.y - 22),
|
||||
IM_COL32(0,0,255,255),
|
||||
fm_bits[bit_traite] ? " 1 " : " 0 "
|
||||
);
|
||||
}
|
||||
|
||||
ImGui::Dummy(canvas_size);
|
||||
ImGui::NewLine();
|
||||
ImGui::SeparatorText("Bits");
|
||||
|
||||
drawVToggleButtons(fm_bits, getWordSize());
|
||||
|
||||
ImGui::EndChild();
|
||||
|
||||
// ----------------------------- RIGHT : OPTIONS ------------------------
|
||||
ImGui::SameLine();
|
||||
ImGui::BeginChild("Options", ImVec2(CHILD2_WIDTH - 8.0f, 0), true);
|
||||
|
||||
ImGui::Text("Type de modulation");
|
||||
ImGui::Separator();
|
||||
|
||||
ImGui::RadioButton("FSK " , (int*)&frequency_modulation_t, MOD_FSK_TYPE);
|
||||
ImGui::RadioButton("4-FSK " , (int*)&frequency_modulation_t, MOD_MFSK_TYPE);
|
||||
|
||||
// --- AJOUT TÉMOIN ---
|
||||
ImGui::Spacing();
|
||||
ImGui::Separator();
|
||||
ImGui::Text("Principe :");
|
||||
ImGui::Spacing();
|
||||
|
||||
ImVec2 ind_size(ImGui::GetContentRegionAvail().x - 10, 50);
|
||||
ImU32 col = IM_COL32(0, 120, 255, 255); // Même bleu que le signal
|
||||
|
||||
switch(frequency_modulation_t)
|
||||
{
|
||||
case MOD_FSK_TYPE:
|
||||
ImGui::Text("1 bit par symbole");
|
||||
ImGui::NewLine();
|
||||
|
||||
c_freq = (*carrier_freq) * k;
|
||||
|
||||
DrawIndicator("Le bit vaut 1 :", &c_freq, &frequency_modulation_t, &samples_per_bit, 1.0f, 0.0f, col, ind_size);
|
||||
|
||||
c_freq = *carrier_freq;
|
||||
|
||||
ImGui::NewLine();
|
||||
DrawIndicator ("Le bit vaut 0 :",
|
||||
&c_freq, &frequency_modulation_t,
|
||||
&samples_per_bit,
|
||||
1.0f, // amplitude
|
||||
0.0f, // phase
|
||||
col,
|
||||
ind_size
|
||||
);
|
||||
break;
|
||||
|
||||
case MOD_MFSK_TYPE:
|
||||
ImGui::Text("2 bits par symbole");
|
||||
ImGui::NewLine();
|
||||
|
||||
c_freq = (*carrier_freq) * 4.0f * k;
|
||||
DrawIndicator("Le symbole vaut 11 : ", &c_freq, &frequency_modulation_t, &samples_per_bit, 1.0f, 0.0f, col, ind_size);
|
||||
|
||||
ImGui::NewLine();
|
||||
c_freq = (*carrier_freq) * 2.0f * k;
|
||||
DrawIndicator("Le symbole vaut 10 : ", &c_freq, &frequency_modulation_t, &samples_per_bit, 1.0f, 0.0f, col, ind_size);
|
||||
|
||||
ImGui::NewLine();
|
||||
c_freq = (*carrier_freq) * k;
|
||||
DrawIndicator("Le symbole vaut 01 : ", &c_freq, &frequency_modulation_t, &samples_per_bit, 1.0f, 0.0f, col, ind_size);
|
||||
|
||||
ImGui::NewLine();
|
||||
c_freq = (*carrier_freq) ;
|
||||
DrawIndicator("Le symbole vaut 00 : ", &c_freq, &frequency_modulation_t, &samples_per_bit, 1.0f, 0.0f, col, ind_size);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
// ------- FIN AJOUT TEMOIN -------------
|
||||
|
||||
|
||||
ImGui::EndChild();
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
short int DigitalModulation::PhaseDigitalModulation(float * carrier_freq, int * pm_bits, DigitalModulationType * pm_type)
|
||||
{
|
||||
static DigitalModulationType phase_modulation_t = *pm_type;
|
||||
|
||||
// --------------------- LEFT : SIGNAL -----------------
|
||||
ImGui::BeginChild("Signal2", ImVec2(ImGui::GetContentRegionAvail().x - CHILD2_WIDTH , 0), false);
|
||||
|
||||
static int samples_per_bit = DEFAULT_SAMPLES_PER_BIT;
|
||||
|
||||
ImGui::NewLine();
|
||||
ImGui::SliderFloat("Frequence porteuse du signal", carrier_freq, 2.0f, 10.0f);
|
||||
#if defined(DEBUG)
|
||||
ImGui::SliderInt("Nombre de points par symbole", &samples_per_bit, DEFAULT_SAMPLES_PER_BIT, 500);
|
||||
#endif
|
||||
ImGui::NewLine();
|
||||
|
||||
// Surbrillance
|
||||
highlightFrame(pm_bits, getWordSize());
|
||||
|
||||
ImVec2 canvas_pos = ImGui::GetCursorScreenPos();
|
||||
ImVec2 canvas_size(ImGui::GetContentRegionAvail().x, CANVAS_HEIGHT);
|
||||
|
||||
ImDrawList* draw_list = ImGui::GetWindowDrawList();
|
||||
draw_list->AddRectFilled
|
||||
(
|
||||
canvas_pos,
|
||||
ImVec2(canvas_pos.x + canvas_size.x, canvas_pos.y + canvas_size.y),
|
||||
IM_COL32(255,255,255,255)
|
||||
);
|
||||
|
||||
draw_list->AddRect
|
||||
(
|
||||
canvas_pos,
|
||||
ImVec2(canvas_pos.x + canvas_size.x, canvas_pos.y + canvas_size.y),
|
||||
IM_COL32(0,0,0,255)
|
||||
);
|
||||
|
||||
float center_y = canvas_pos.y + canvas_size.y / 2.0f;
|
||||
float base_amp = 100.0f;
|
||||
float total_samples = getWordSize() * samples_per_bit;
|
||||
float dx = canvas_size.x / total_samples;
|
||||
float x = canvas_pos.x;
|
||||
|
||||
ImVec2 prev(x, center_y);
|
||||
|
||||
float phi = 0.0f;
|
||||
float delta_phi = 0.0f;
|
||||
|
||||
for (int bit_traite = 0; bit_traite < getWordSize(); bit_traite++)
|
||||
{
|
||||
draw_list->AddLine
|
||||
(
|
||||
ImVec2(x, canvas_pos.y),
|
||||
ImVec2(x, canvas_pos.y + canvas_size.y),
|
||||
IM_COL32(0,120,255,255)
|
||||
);
|
||||
|
||||
switch (phase_modulation_t)
|
||||
{
|
||||
case MOD_BPSK_TYPE:
|
||||
phi = pm_bits[bit_traite] ? 0.0f : M_PI;
|
||||
break;
|
||||
|
||||
case MOD_DPSK_TYPE:
|
||||
if (bit_traite < 1)
|
||||
phi = pm_bits[bit_traite] ? 0.0f : M_PI;
|
||||
else
|
||||
{
|
||||
if ((!pm_bits[bit_traite-1] && pm_bits[bit_traite]) ||
|
||||
((pm_bits[bit_traite-1]) && (pm_bits[bit_traite])))
|
||||
delta_phi = M_PI;
|
||||
else
|
||||
delta_phi = 0.0f;
|
||||
}
|
||||
phi += delta_phi;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
for (int i = 0; i < samples_per_bit; i++)
|
||||
{
|
||||
float t = (bit_traite * samples_per_bit + i) / (float)samples_per_bit;
|
||||
float y = center_y - sinf(2.0f * M_PI * (*carrier_freq) * t + phi) * base_amp;
|
||||
|
||||
ImVec2 p(x, y);
|
||||
draw_list->AddLine(prev, p, IM_COL32(255,0,0,255), 2.0f);
|
||||
prev = p;
|
||||
x += dx;
|
||||
}
|
||||
|
||||
draw_list->AddText ( ImVec2(x - samples_per_bit * dx + 5, canvas_pos.y + canvas_size.y - 22),
|
||||
IM_COL32(0,0,255,255),
|
||||
pm_bits[bit_traite] ? " 1 " : " 0 "
|
||||
);
|
||||
}
|
||||
|
||||
ImGui::Dummy(canvas_size);
|
||||
ImGui::NewLine();
|
||||
ImGui::SeparatorText("Bits");
|
||||
drawVToggleButtons(pm_bits, getWordSize());
|
||||
ImGui::EndChild();
|
||||
|
||||
// ----------------------------- RIGHT : OPTIONS ------------------------
|
||||
ImGui::SameLine();
|
||||
ImGui::BeginChild("Options", ImVec2(CHILD2_WIDTH - 8.0f, 0), true);
|
||||
|
||||
ImGui::Text("Type de modulation");
|
||||
ImGui::Separator();
|
||||
|
||||
ImGui::RadioButton("BPSK " , (int*)&phase_modulation_t, MOD_BPSK_TYPE);
|
||||
ImGui::RadioButton("DPSK " , (int*)&phase_modulation_t, MOD_DPSK_TYPE);
|
||||
|
||||
// --- AJOUT TÉMOIN ---
|
||||
ImGui::Spacing();
|
||||
ImGui::Separator();
|
||||
|
||||
if (MOD_DPSK_TYPE != phase_modulation_t)
|
||||
ImGui::Text("Principe :");
|
||||
|
||||
ImGui::Spacing();
|
||||
|
||||
ImVec2 ind_size(ImGui::GetContentRegionAvail().x - 10, 50);
|
||||
ImU32 col = IM_COL32(0, 120, 255, 255); // Même bleu que le signal
|
||||
|
||||
switch(phase_modulation_t)
|
||||
{
|
||||
case MOD_BPSK_TYPE:
|
||||
ImGui::Text("1 bit par symbole");
|
||||
ImGui::NewLine();
|
||||
|
||||
DrawIndicator("Le bit vaut 1 :",
|
||||
carrier_freq,
|
||||
&phase_modulation_t,
|
||||
&samples_per_bit,
|
||||
1.0f, // amplitude
|
||||
0.0f, // phase
|
||||
col,
|
||||
ind_size);
|
||||
|
||||
ImGui::NewLine();
|
||||
DrawIndicator ("Le bit vaut 0 :",
|
||||
carrier_freq, &phase_modulation_t,
|
||||
&samples_per_bit,
|
||||
1.0f, // amplitude
|
||||
M_PI, // phase
|
||||
col,
|
||||
ind_size
|
||||
);
|
||||
break;
|
||||
case MOD_DPSK_TYPE:
|
||||
ImGui::Text("1 bits par symbole");
|
||||
ImGui::NewLine();
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
// ------- FIN AJOUT TEMOIN -------------
|
||||
|
||||
ImGui::EndChild();
|
||||
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
short int DigitalModulation::M_QAM_DigitalModulation(float * carrier_freq, int * qam_bits, DigitalModulationType * qam_type)
|
||||
{
|
||||
// TODO : améliorer cette partie
|
||||
static DigitalModulationType qam_modulation_t = *qam_type;
|
||||
static float c_freq = *carrier_freq;
|
||||
|
||||
// --------------------- LEFT : SIGNAL -----------------
|
||||
ImGui::BeginChild("Signal", ImVec2(ImGui::GetContentRegionAvail().x - CHILD2_WIDTH, 0), false);
|
||||
|
||||
// pour 1 bit, 100 échantillons (400 pour la modulation de fréquence pour fporteuse max)
|
||||
static int samples_per_bit = SAMPLES_PER_BIT_MAX;
|
||||
|
||||
ImGui::NewLine();
|
||||
ImGui::SliderFloat("Frequence porteuse ", &c_freq, 2.0f, 10.0f);
|
||||
#if defined(DEBUG)
|
||||
ImGui::SliderInt("Nombre de points par symbole", &samples_per_bit, DEFAULT_SAMPLES_PER_BIT, 500);
|
||||
#endif
|
||||
ImGui::NewLine();
|
||||
|
||||
// Surbrillance de la trame affichée
|
||||
highlightFrame(qam_bits, getWordSize());
|
||||
|
||||
// position du curseur + dimensions du canvas.
|
||||
// canvas_pos contient les coordonnées du curseur (marque l'endroit d'où l'on dessine à ce point du programme)
|
||||
ImVec2 canvas_pos = ImGui::GetCursorScreenPos();
|
||||
|
||||
// Dimensions du cadre dans lequel on dessine la sinusoïde
|
||||
ImVec2 canvas_size(ImGui::GetContentRegionAvail().x, CANVAS_HEIGHT);
|
||||
|
||||
// ce qui va être dessiné
|
||||
ImDrawList* draw_list = ImGui::GetWindowDrawList();
|
||||
|
||||
// On dessine un fond blanc
|
||||
draw_list->AddRectFilled
|
||||
(
|
||||
canvas_pos,
|
||||
ImVec2(canvas_pos.x + canvas_size.x, canvas_pos.y + canvas_size.y),
|
||||
IM_COL32(255,255,255,255)
|
||||
);
|
||||
|
||||
// on ajoute par dessus un tour noir
|
||||
draw_list->AddRect
|
||||
(
|
||||
canvas_pos,
|
||||
ImVec2(canvas_pos.x + canvas_size.x, canvas_pos.y + canvas_size.y),
|
||||
IM_COL32(0,0,0,255)
|
||||
);
|
||||
|
||||
// calcul des coordonnées du centre de la frame
|
||||
float center_y = canvas_pos.y + canvas_size.y / 2.0f;
|
||||
|
||||
// amplitude de la sinusoïde de base
|
||||
float base_amp = 100.0f;
|
||||
float total_samples = getWordSize() * samples_per_bit;
|
||||
float dx = canvas_size.x / total_samples;
|
||||
float x = canvas_pos.x;
|
||||
|
||||
ImVec2 prev(x, center_y);
|
||||
|
||||
for (int bit_traite = 0; bit_traite < getWordSize(); bit_traite++)
|
||||
{
|
||||
draw_list->AddLine
|
||||
(
|
||||
ImVec2(x, canvas_pos.y),
|
||||
ImVec2(x, canvas_pos.y + canvas_size.y),
|
||||
IM_COL32(0,120,255,255)
|
||||
);
|
||||
|
||||
float amplitude = 0.0f;
|
||||
|
||||
|
||||
float coeff_sin = 1.0f; // terme devant le sinus (première fréquence porteuse)
|
||||
float coeff_cos = 1.0f; // terme devant le cosinus (pour la seconde porteuse en quadrature)
|
||||
// Pour la modulation M-QAM, on se place dans le plan complexe.
|
||||
// Cas de la constellation 4-QAM (cas particulier, où elle est identique à la constellation 4-PSK)
|
||||
/*
|
||||
^ sin
|
||||
|
|
||||
01 | 11
|
||||
+ | +
|
||||
|
|
||||
---------------------> cos
|
||||
|
|
||||
+ | +
|
||||
00 | 10
|
||||
|
|
||||
|
||||
*/
|
||||
// /!\ LIRE d'abord sin, puis cos ci-dessous !!
|
||||
// 00 -> (-1;-1) / 01 -> (1;-1) / 10 -> (-1;1) / 11 -> (1;1)
|
||||
// ce qui donne les tableaux de coefficients suivants :
|
||||
|
||||
// tableau des valeurs de sinus
|
||||
const float tab_sinus[4] = { /* 11 */ 1.0f, /* 01 */ 1.0f, /* 10 */-1.0f, /* 00 */-1.0f};
|
||||
|
||||
// tableau des valeurs de cosinus
|
||||
const float tab_cosinus[4] = { /* 11 */ 1.0f ,/* 01 */-1.0f, /* 10 */ 1.0f, /* 00 */-1.0f};
|
||||
|
||||
// 16-QAM
|
||||
const float tab_sin16[16] = { -3.0f, -1.0f, 3.0f, 1.0f,-3.0f,-1.0f, 3.0f, 1.0f,-3.0f,-1.0f, 3.0f, 1.0f,-3.0f,-1.0f, 3.0f, 1.0f };
|
||||
const float tab_cos16[16] = { -3.0f, -3.0f,-3.0f,-3.0f,-1.0f,-1.0f,-1.0f,-1.0f, 3.0f, 3.0f, 3.0f, 3.0f, 1.0f, 1.0f, 1.0, 1.0f };
|
||||
|
||||
switch (qam_modulation_t)
|
||||
{
|
||||
case MOD_4_QAM_TYPE:
|
||||
// Contraintes :
|
||||
// En MODULATION M-QAM : tous les points sont équi-distants (optimisation du rapport S/(S+B))
|
||||
// - on doit dessiner le même signal pour les bits (0,1), (2,3), (4,5) et (6,7)
|
||||
// - si le bit testé est pair, alors il s'agit du bit 0, 2, 4 ou 6
|
||||
// et il faut tester la valeur du mot binaire 2 *bit traite + bit-traite+1
|
||||
// - si le bit testé est impair, il s'agit du bit 1, 3, 5 ou 7
|
||||
// et il faut tester la valeur du mot 2 *bit_traite -1 + bit-traite
|
||||
// - ce cas simple nous impose de diviser aussi l'amplitude de base par racine de 2
|
||||
// (sinon la sinusoïde ne tient pas dans le canvas)
|
||||
//
|
||||
// ce premier calcul nous donne les coefficients devant le sinus ou le cosinus
|
||||
// De plus n doit dessiner le même signal pour les bits (0,1), (2,3), (4,5) et (6,7)
|
||||
// => la parité de bit_traite nous donne les coefficients
|
||||
|
||||
// Ensuite, Le calcul des coefficients est lié à la valeur des deux bits considérés
|
||||
// L'expression du mot binaire sur 2 bits, nous donne les coefficients
|
||||
// 4 cas sont possibles : 00, 01, 10 et 11, cf la constellation + haut.
|
||||
|
||||
amplitude = 0.707f * base_amp;
|
||||
|
||||
if ((bit_traite % 2) == 0) // bit pair => bits 0, 2, 4 ou 6
|
||||
{
|
||||
coeff_sin = tab_sinus[2*qam_bits[bit_traite]+qam_bits[bit_traite+1]];
|
||||
coeff_cos = tab_cosinus[2*qam_bits[bit_traite]+qam_bits[bit_traite+1]];
|
||||
}
|
||||
else // bit impair => bits 1, 3, 5 ou 7
|
||||
{
|
||||
coeff_sin = tab_sinus[2*qam_bits[bit_traite-1]+qam_bits[bit_traite]];
|
||||
coeff_cos = tab_cosinus[2*qam_bits[bit_traite-1]+qam_bits[bit_traite]];
|
||||
}
|
||||
break;
|
||||
|
||||
case MOD_16_QAM_TYPE:
|
||||
// On code cette fois chaque symbole sur 4 bits
|
||||
// La constellation est la suivante
|
||||
// (+ toutes les permutations circulaire et symétries possibles !!) :
|
||||
//
|
||||
// 0010 0110 | 1110 1010
|
||||
// |
|
||||
// 0011 0111 | 1111 1011
|
||||
// ___-3___-1 _|__ 1____3__
|
||||
// 0001 0101 | 1101 1001
|
||||
// |
|
||||
// 0000 0100 | 1100 1000
|
||||
// |
|
||||
// Horizontalement et verticalement, 4 valeurs possibles:
|
||||
// -3 -1, 1 et 3 pour les 2 sinusoïdes, ce qui donne les 16 cas
|
||||
// 16 coefficients pour cos et sin :
|
||||
// Exemple : on codera 0011 (MSB = 0, LSB = 1 ici), avec les amplitudes -3 pour le cos et +1 pour le sin
|
||||
// etc
|
||||
// De plus il faudra tester le bit traité module 4
|
||||
|
||||
// On normalise l'amplitude : la plus grande pouvant valoir 3 x 1.414 ~ 4.24
|
||||
amplitude = base_amp/4.24f;
|
||||
|
||||
if ((bit_traite % 4 ) == 0) // bit 0 modulo 4 (0,4,8,12,16 ...)
|
||||
{
|
||||
coeff_sin = tab_sin16[8*qam_bits[bit_traite]+4*qam_bits[bit_traite+1]+2*qam_bits[bit_traite+2] + qam_bits[bit_traite+3]];
|
||||
coeff_cos = tab_cos16[8*qam_bits[bit_traite]+4*qam_bits[bit_traite+1]+2*qam_bits[bit_traite+2] + qam_bits[bit_traite+3]];
|
||||
}
|
||||
else if ((bit_traite % 4 ) == 1) // bit 1 modulo 4 (1,5,9,13,17 ...)
|
||||
{
|
||||
coeff_sin = tab_sin16[8*qam_bits[bit_traite-1]+4*qam_bits[bit_traite] + 2*qam_bits[bit_traite+1] + qam_bits[bit_traite+2]];
|
||||
coeff_cos = tab_cos16[8*qam_bits[bit_traite-1]+4*qam_bits[bit_traite] + 2*qam_bits[bit_traite+1] + qam_bits[bit_traite+2]];
|
||||
}
|
||||
else if ((bit_traite % 4 ) == 2) // bit 2 modulo 4 (2,6,10,14,18 ...)
|
||||
{
|
||||
coeff_sin = tab_sin16[8*qam_bits[bit_traite-2]+4*qam_bits[bit_traite-1]+2*qam_bits[bit_traite] + qam_bits[bit_traite+1]];
|
||||
coeff_cos = tab_cos16[8*qam_bits[bit_traite-2]+4*qam_bits[bit_traite-1]+2*qam_bits[bit_traite] + qam_bits[bit_traite+1]];
|
||||
}
|
||||
else if ((bit_traite % 4 ) == 3) // bit 3 [modulo 4] (3,7,11,15 ...)
|
||||
{
|
||||
coeff_sin = tab_sin16[8*qam_bits[bit_traite-3]+4*qam_bits[bit_traite-2]+2*qam_bits[bit_traite-1]+ qam_bits[bit_traite]];
|
||||
coeff_cos = tab_cos16[8*qam_bits[bit_traite-3]+4*qam_bits[bit_traite-2]+2*qam_bits[bit_traite-1]+ qam_bits[bit_traite]];
|
||||
}
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
// on dessine 100 échantillons par bit de la trame
|
||||
for (int i = 0; i < samples_per_bit; i++)
|
||||
{
|
||||
float t = (bit_traite * samples_per_bit + i) / (float)samples_per_bit;
|
||||
float y = center_y - (coeff_sin * sinf(2.0f * M_PI * c_freq * t) + coeff_cos * cosf(2.0f * M_PI * c_freq * t)) * amplitude;
|
||||
|
||||
ImVec2 p(x, y);
|
||||
//if (i != (samples_per_bit -1))
|
||||
// Le dernier raccord peut poser problème dans certains cas
|
||||
// et on ne dessine pas la ligne entre le dernier point du bit précédent
|
||||
// et le premier point du bit suivant. Ceci en M_QAM pour l'instant (pour tester).
|
||||
if (MOD_M_QAM_TYPE == *qam_type)
|
||||
{
|
||||
if (i != 0)
|
||||
draw_list->AddLine(prev, p, IM_COL32(255,0,0,255), 2.0f);
|
||||
else
|
||||
draw_list->AddLine(p, p, IM_COL32(255,0,0,255), 2.0f);
|
||||
}
|
||||
else
|
||||
draw_list->AddLine(prev, p, IM_COL32(255,0,0,255), 2.0f);
|
||||
|
||||
prev = p;
|
||||
x += dx;
|
||||
}
|
||||
|
||||
// FIXME : d'où viennent ces valeurs 5 et 22 ?
|
||||
draw_list->AddText ( ImVec2(x - samples_per_bit * dx + 5, canvas_pos.y + canvas_size.y - 22),
|
||||
IM_COL32(0,0,255,255),
|
||||
qam_bits[bit_traite] ? " 1 " : " 0 "
|
||||
);
|
||||
}
|
||||
|
||||
ImGui::Dummy(canvas_size);
|
||||
ImGui::NewLine();
|
||||
ImGui::SeparatorText("Bits");
|
||||
|
||||
drawVToggleButtons(qam_bits, getWordSize());
|
||||
|
||||
ImGui::EndChild();
|
||||
|
||||
// ----------------------------- RIGHT : OPTIONS ------------------------
|
||||
ImGui::SameLine();
|
||||
ImGui::BeginChild("Options", ImVec2(CHILD2_WIDTH - 8.0f /* minus the border */, 0), true);
|
||||
|
||||
ImGui::Text("Type de modulation");
|
||||
ImGui::Separator();
|
||||
|
||||
ImGui::RadioButton("4-QAM (= 4-PSK)" , (int*)&qam_modulation_t, MOD_4_QAM_TYPE);
|
||||
ImGui::RadioButton("16-QAM " , (int*)&qam_modulation_t, MOD_16_QAM_TYPE);
|
||||
|
||||
// --- AJOUT TÉMOIN ---
|
||||
ImGui::Spacing();
|
||||
ImGui::Separator();
|
||||
ImGui::Text("Principe :");
|
||||
ImGui::Spacing();
|
||||
|
||||
ImVec2 ind_size(ImGui::GetContentRegionAvail().x - 10, 50);
|
||||
ImU32 col = IM_COL32(0, 120, 255, 255); // Même bleu que le signal
|
||||
|
||||
switch(qam_modulation_t)
|
||||
{
|
||||
case MOD_4_QAM_TYPE:
|
||||
ImGui::Text("2 bits par symbole");
|
||||
ImGui::NewLine();
|
||||
// Use 4-QAM rules
|
||||
DrawIndicator("Le symbole vaut 11 : ", &c_freq, &qam_modulation_t, &samples_per_bit, 1.0f, -3.0f * M_PI/4.0f, col, ind_size);
|
||||
|
||||
ImGui::NewLine();
|
||||
DrawIndicator("Le symbole vaut 10 : ", &c_freq, &qam_modulation_t, &samples_per_bit, 1.0f, 3.0f * M_PI/4.0f, col, ind_size);
|
||||
|
||||
ImGui::NewLine();
|
||||
DrawIndicator("Le symbole vaut 01 : ", &c_freq, &qam_modulation_t, &samples_per_bit, 1.0f, -M_PI/4.0f, col, ind_size);
|
||||
|
||||
ImGui::NewLine();
|
||||
DrawIndicator("Le symbole vaut 00 : ", &c_freq, &qam_modulation_t, &samples_per_bit, 1.0f, M_PI/4.0f, col, ind_size);
|
||||
break;
|
||||
|
||||
case MOD_16_QAM_TYPE:
|
||||
ImGui::Text("4 bits par symbole");
|
||||
ImGui::NewLine();
|
||||
ImGui::Text("Constellation 16-QAM : ");
|
||||
LoadTextureFromFile("../images/Constellation_modulation_numerique_16_QAM.jpg",
|
||||
&my_image_texture,
|
||||
&my_image_width,
|
||||
&my_image_height);
|
||||
ImGui::Image((ImTextureID)(intptr_t)my_image_texture, ImVec2((float)ImGui::GetWindowSize().x - 18.0f, (float)ImGui::GetWindowSize().x - 18.0f));
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
// ------- FIN AJOUT TEMOIN -------------
|
||||
|
||||
|
||||
ImGui::EndChild();
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
void DigitalModulation::setDigitalModulationType(TAB_Name aTab, DigitalModulationType aType)
|
||||
{
|
||||
switch (aTab)
|
||||
{
|
||||
case Amplitude_TAB:
|
||||
md_AM_DigitalModulation_t = aType;
|
||||
break;
|
||||
|
||||
case Frequency_TAB:
|
||||
md_FM_DigitalModulation_t = aType;
|
||||
break;
|
||||
|
||||
case Phase_TAB:
|
||||
md_PM_DigitalModulation_t = aType;
|
||||
break;
|
||||
|
||||
case M_QAM_TAB:
|
||||
md_M_QAM_DigitalModulation_t = aType;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
Référencer dans un nouveau ticket
Bloquer un utilisateur