277 Commits

Author SHA1 Message Date
df4b1641d5 remove unsed assets
All checks were successful
Linux arm64 / Build (push) Successful in 5m42s
2024-04-02 22:46:09 +02:00
7daf2bae0c don't move player when menu is opened
All checks were successful
Linux arm64 / Build (push) Successful in 5m53s
2024-04-02 22:30:58 +02:00
a7b235da38 Possibilité de changer la cadence de tir (#33)
Some checks failed
Linux arm64 / Build (push) Has been cancelled
ajout d'un changement pour la cadence de tir

Co-authored-by: Morph01 <145839520+Morph01@users.noreply.github.com>
Co-authored-by: Persson-dev <sim16.prib@gmail.com>
Reviewed-on: #33
Reviewed-by: Simon Pribylski <sim16.prib@gmail.com>
Co-authored-by: Morph01 <thibaut6969delastreet@gmail.com>
Co-committed-by: Morph01 <thibaut6969delastreet@gmail.com>
2024-04-02 22:25:47 +02:00
e27cc29eb0 Réglage de la gravité (#31)
All checks were successful
Linux arm64 / Build (push) Successful in 5m4s
Fix #6

Co-authored-by: Morph01 <145839520+Morph01@users.noreply.github.com>
Reviewed-on: #31
Co-authored-by: Persson-dev <sim16.prib@gmail.com>
Co-committed-by: Persson-dev <sim16.prib@gmail.com>
2024-03-30 19:38:17 +01:00
d59467dd23 Le laser sort de la main à la première personne (#30)
Some checks are pending
Linux arm64 / Build (push) Waiting to run
Fix #25

Reviewed-on: #30
Co-authored-by: Persson-dev <sim16.prib@gmail.com>
Co-committed-by: Persson-dev <sim16.prib@gmail.com>
2024-03-30 19:37:40 +01:00
0ed577bbc2 On sait quand on gagne (#29)
Some checks are pending
Linux arm64 / Build (push) Waiting to run
L'écran de fin est mis à jour correctement selon si la victoire nous appartient ou non.
Le cas d'égalité n'est cependant pas traité ! Seulement un joueur peut gagner à l'état actuel

Reviewed-on: #29
Co-authored-by: Persson-dev <sim16.prib@gmail.com>
Co-committed-by: Persson-dev <sim16.prib@gmail.com>
2024-03-30 19:37:08 +01:00
aa29b9d718 use Vec3 for PlayerController members
All checks were successful
Linux arm64 / Build (push) Successful in 4m39s
2024-03-30 11:53:07 +01:00
1cce7fcd35 remove unused variable
All checks were successful
Linux arm64 / Build (push) Successful in 4m38s
2024-03-30 09:55:07 +01:00
9e93c1a1de better trail effect
All checks were successful
Linux arm64 / Build (push) Successful in 4m43s
2024-03-29 09:11:19 +01:00
4119fe37cc fix run dir 2024-03-29 09:11:01 +01:00
0511511702 Update BlitzClient.lua
All checks were successful
Linux arm64 / Build (push) Successful in 4m41s
2024-03-28 22:35:54 +01:00
2484eb5377 Chemtrails (#28)
All checks were successful
Linux arm64 / Build (push) Successful in 4m37s
Co-authored-by: Morph01 <145839520+Morph01@users.noreply.github.com>
Reviewed-on: #28
Co-authored-by: Persson-dev <sim16.prib@gmail.com>
Co-committed-by: Persson-dev <sim16.prib@gmail.com>
2024-03-28 21:42:26 +01:00
61ae530238 fiiiiiiiiiiiiiiix
All checks were successful
Linux arm64 / Build (push) Successful in 5m4s
2024-03-28 21:35:41 +01:00
Morph01
7c90ecfbd3 Refactor ServerGui.cpp: Remove unused variables
Some checks failed
Linux arm64 / Build (push) Has been cancelled
2024-03-28 21:33:39 +01:00
6e47fa6996 Add admin window and server duration settings (#27)
Some checks failed
Linux arm64 / Build (push) Failing after 3m33s
Fix #11

Co-authored-by: Morph01 <145839520+Morph01@users.noreply.github.com>
Reviewed-on: #27
2024-03-28 21:17:24 +01:00
83649ddbab fix linux build
Some checks failed
Linux arm64 / Build (push) Has been cancelled
2024-03-28 18:42:40 +01:00
Morph01
83c4599aa3 add finish screen
Some checks failed
Linux arm64 / Build (push) Failing after 2m55s
2024-03-28 18:29:52 +01:00
0247ee3cc1 add delay timer
All checks were successful
Linux arm64 / Build (push) Successful in 4m38s
2024-03-28 17:48:59 +01:00
Morph01
58b401f257 Update types of texture variables
All checks were successful
Linux arm64 / Build (push) Successful in 4m56s
2024-03-28 16:40:41 +01:00
c5b07e2ae6 fix network test for windows
All checks were successful
Linux arm64 / Build (push) Successful in 5m19s
2024-03-28 16:30:51 +01:00
507946a0f4 fix operator- for Vector
All checks were successful
Linux arm64 / Build (push) Successful in 4m41s
2024-03-28 16:14:01 +01:00
f9b79b0d64 Ajout d'états de jeu (#26)
All checks were successful
Linux arm64 / Build (push) Successful in 4m42s
La partie est d'abord en mode "Attente de joueurs"
Lorsque 2 joueurs sont présents, la partie passe en mode "Préparation" et un décompte de 10s commence
La partie passe ensuite en mode "Jeu" pendant 3 min
Pour finir, la partie passe en mode "Fin" pendant 30s pour rebasculer en mode "Jeu" si le nombre de joueurs est toujours suffisant.

Reviewed-on: #26
Co-authored-by: Persson-dev <sim16.prib@gmail.com>
Co-committed-by: Persson-dev <sim16.prib@gmail.com>
2024-03-28 15:58:39 +01:00
Morph01
78d68446f2 Fix data type inconsistencies lets cook
All checks were successful
Linux arm64 / Build (push) Successful in 4m39s
2024-03-28 15:32:08 +01:00
255eafa35e fix return type
All checks were successful
Linux arm64 / Build (push) Successful in 4m44s
2024-03-26 20:25:15 +01:00
e254452a6c Meilleure interface (#15)
All checks were successful
Linux arm64 / Build (push) Successful in 4m55s
améliorer l'interface, déplacement de certains boutons etc.

Co-authored-by: Persson-dev <sim16.prib@gmail.com>
Co-authored-by: Morph01 <145839520+Morph01@users.noreply.github.com>
Co-authored-by: Simon Pribylski <sim16.prib@gmail.com>
Reviewed-on: #15
Co-authored-by: Morph01 <thibaut6969delastreet@gmail.com>
Co-committed-by: Morph01 <thibaut6969delastreet@gmail.com>
2024-03-26 12:52:07 +01:00
920c2e20b3 Merge pull request 'Merge new features' (#23) from dev into main
All checks were successful
Linux arm64 / Build (push) Successful in 4m46s
Reviewed-on: #23
2024-03-26 12:07:09 +01:00
1e1880376d fix merge
All checks were successful
Linux arm64 / Build (push) Successful in 4m52s
2024-03-26 11:47:47 +01:00
de22c89975 Squashed commit of the following:
commit 0adeba26e4
Author: = <=>
Date:   Tue Mar 26 11:35:37 2024 +0100

    minor fix

commit 011d8a573c
Author: = <=>
Date:   Tue Mar 26 11:33:56 2024 +0100

    fix stupid build error

commit 22406ad020
Author: = <=>
Date:   Tue Mar 26 11:25:35 2024 +0100

    yes

commit 4db55a372b
Author: = <=>
Date:   Tue Mar 26 11:13:22 2024 +0100

    csavgfdslgakdf;g

commit 20d176ccb5
Author: AquaEBM <AquaEBM@gmail.com>
Date:   Tue Mar 26 11:07:27 2024 +0100

    add range overlapping check utilities

commit 3863e7907f
Author: AquaEBM <AquaEBM@gmail.com>
Date:   Tue Mar 26 10:24:35 2024 +0100

    better edge case handling

commit 35b7d7bab0
Author: = <=>
Date:   Tue Mar 26 10:19:21 2024 +0100

    I am fucking retarded what the fuck is this stupid brain smoking

commit 6aca413b4f
Author: Persson-dev <sim16.prib@gmail.com>
Date:   Sun Mar 24 18:14:02 2024 +0100

    small refactor

commit ee322e3e7b
Author: AquaEBM@gmail.com <AquaEBM@gmail.com>
Date:   Sun Mar 24 17:40:39 2024 +0100

    improve tests, fix some bugs in Distance, (not working yet)

commit 864a15e4c8
Merge: 7efd821 c1ded40
Author: Persson-dev <sim16.prib@gmail.com>
Date:   Fri Mar 22 19:33:45 2024 +0100

    Squashed commit of the following:

    commit c1ded40cc4
    Author: Persson-dev <sim16.prib@gmail.com>
    Date:   Thu Mar 21 17:24:05 2024 +0100

        improve network test

    commit 285bf880ee
    Author: Persson-dev <sim16.prib@gmail.com>
    Date:   Thu Mar 21 17:14:43 2024 +0100

        fix warning

    commit 06ff76607d
    Author: Persson-dev <sim16.prib@gmail.com>
    Date:   Thu Mar 21 15:45:33 2024 +0100

        add bots

    commit 19229bbe8a
    Author: Persson-dev <sim16.prib@gmail.com>
    Date:   Thu Mar 21 14:55:57 2024 +0100

        fix warnings

    commit 2b0930a734
    Author: Morph01 <thibaut6969delastreet@gmail.com>
    Date:   Tue Mar 19 10:43:55 2024 +0100

        hud of blitz (#16)

        Résoudre partiellement #12

        Co-authored-by: Persson-dev <sim16.prib@gmail.com>
        Co-authored-by: Morph01 <145839520+Morph01@users.noreply.github.com>
        Co-authored-by: Simon Pribylski <sim16.prib@gmail.com>
        Reviewed-on: #16

    commit 84b6acad4c
    Author: Persson-dev <sim16.prib@gmail.com>
    Date:   Tue Mar 19 10:15:54 2024 +0100

        less spooky light

    commit 9f94d51fc4
    Author: Persson-dev <sim16.prib@gmail.com>
    Date:   Thu Mar 14 16:36:15 2024 +0100

        Ajout de tests d'intégration (#17)

        Le paquet fournissant OpenGL a été temporairement remplacé par glew

        Reviewed-on: #17
        Co-authored-by: Persson-dev <sim16.prib@gmail.com>
        Co-committed-by: Persson-dev <sim16.prib@gmail.com>

    commit 9951256881
    Author: Simon Pribylski <sim16.prib@gmail.com>
    Date:   Wed Mar 13 20:19:37 2024 +0100

        action: install libsdl via apt

    commit 4a02054648
    Author: Morph01 <145839520+Morph01@users.noreply.github.com>
    Date:   Wed Mar 13 13:53:20 2024 +0100

        compression tests

    commit 19c39312bf
    Author: Morph01 <145839520+Morph01@users.noreply.github.com>
    Date:   Wed Mar 13 13:51:57 2024 +0100

        setup action

    commit d5014b1e8a
    Author: Persson-dev <sim16.prib@gmail.com>
    Date:   Tue Mar 12 10:26:47 2024 +0100

        Revert "extend Vec3"

        This reverts commit dccfa9c936.

    commit dccfa9c936
    Author: = <=>
    Date:   Tue Mar 12 10:01:00 2024 +0100

        extend Vec3
    Merge branch 'main' into physics

commit 7efd8218ea
Author: Persson-dev <sim16.prib@gmail.com>
Date:   Fri Mar 22 19:28:46 2024 +0100

    moved functions in Maths.h

commit 08db7f84b9
Author: Persson-dev <sim16.prib@gmail.com>
Date:   Fri Mar 22 19:16:48 2024 +0100

    add missing include

commit 7119dea783
Author: Persson-dev <sim16.prib@gmail.com>
Date:   Fri Mar 22 19:15:01 2024 +0100

    merge 'main' branch

    commit c1ded40cc4
    Author: Persson-dev <sim16.prib@gmail.com>
    Date:   Thu Mar 21 17:24:05 2024 +0100

        improve network test

    commit 285bf880ee
    Author: Persson-dev <sim16.prib@gmail.com>
    Date:   Thu Mar 21 17:14:43 2024 +0100

        fix warning

    commit 06ff76607d
    Author: Persson-dev <sim16.prib@gmail.com>
    Date:   Thu Mar 21 15:45:33 2024 +0100

        add bots

    commit 19229bbe8a
    Author: Persson-dev <sim16.prib@gmail.com>
    Date:   Thu Mar 21 14:55:57 2024 +0100

        fix warnings

    commit 2b0930a734
    Author: Morph01 <thibaut6969delastreet@gmail.com>
    Date:   Tue Mar 19 10:43:55 2024 +0100

        hud of blitz (#16)

        Résoudre partiellement #12

        Co-authored-by: Persson-dev <sim16.prib@gmail.com>
        Co-authored-by: Morph01 <145839520+Morph01@users.noreply.github.com>
        Co-authored-by: Simon Pribylski <sim16.prib@gmail.com>
        Reviewed-on: #16

    commit 84b6acad4c
    Author: Persson-dev <sim16.prib@gmail.com>
    Date:   Tue Mar 19 10:15:54 2024 +0100

        less spooky light

    commit 9f94d51fc4
    Author: Persson-dev <sim16.prib@gmail.com>
    Date:   Thu Mar 14 16:36:15 2024 +0100

        Ajout de tests d'intégration (#17)

        Le paquet fournissant OpenGL a été temporairement remplacé par glew

        Reviewed-on: #17
        Co-authored-by: Persson-dev <sim16.prib@gmail.com>
        Co-committed-by: Persson-dev <sim16.prib@gmail.com>

    commit 9951256881
    Author: Simon Pribylski <sim16.prib@gmail.com>
    Date:   Wed Mar 13 20:19:37 2024 +0100

        action: install libsdl via apt

    commit 4a02054648
    Author: Morph01 <145839520+Morph01@users.noreply.github.com>
    Date:   Wed Mar 13 13:53:20 2024 +0100

        compression tests

    commit 19c39312bf
    Author: Morph01 <145839520+Morph01@users.noreply.github.com>
    Date:   Wed Mar 13 13:51:57 2024 +0100

        setup action

    commit d5014b1e8a
    Author: Persson-dev <sim16.prib@gmail.com>
    Date:   Tue Mar 12 10:26:47 2024 +0100

        Revert "extend Vec3"

        This reverts commit dccfa9c936.

    commit dccfa9c936
    Author: = <=>
    Date:   Tue Mar 12 10:01:00 2024 +0100

        extend Vec3

commit 6e998fc368
Author: AquaEBM@gmail.com <AquaEBM@gmail.com>
Date:   Fri Mar 22 16:41:52 2024 +0100

    change tests

commit 441131a2f5
Author: AquaEBM@gmail.com <AquaEBM@gmail.com>
Date:   Fri Mar 22 16:14:56 2024 +0100

    rename Intersects to distance

commit c875fa1dee
Author: Persson-dev <sim16.prib@gmail.com>
Date:   Fri Mar 22 15:50:32 2024 +0100

    more template

commit 5e4b318d67
Author: AquaEBM@gmail.com <AquaEBM@gmail.com>
Date:   Fri Mar 22 15:26:07 2024 +0100

    inline Reduce_<> functions

commit 076fa7badc
Author: AquaEBM@gmail.com <AquaEBM@gmail.com>
Date:   Fri Mar 22 15:18:39 2024 +0100

    fix compilation error

commit 1091abd034
Author: AquaEBM <AquaEBM@gmail.com>
Date:   Fri Mar 22 14:58:26 2024 +0100

    fix some compilation errors

commit dd9ea3ece8
Author: AquaEBM <AquaEBM@gmail.com>
Date:   Fri Mar 22 12:02:39 2024 +0100

    update intersects, document changes

commit 6226161e31
Author: AquaEBM <AquaEBM@gmail.com>
Date:   Fri Mar 22 09:22:06 2024 +0100

    fix compilation error, add min/max functions for Vec3d

commit 6b32e8878e
Author: AquaEBM <AquaEBM@gmail.com>
Date:   Fri Mar 22 09:18:34 2024 +0100

    fix min/max functions
2024-03-26 11:44:37 +01:00
7a388bcd62 Add crosshair (#20)
All checks were successful
Linux arm64 / Build (push) Successful in 4m30s
Reviewed-on: #20
Co-authored-by: Persson-dev <sim16.prib@gmail.com>
Co-committed-by: Persson-dev <sim16.prib@gmail.com>
2024-03-26 09:11:20 +01:00
d1bb086daf temp intersect
Some checks failed
Linux arm64 / Build (push) Failing after 4m42s
2024-03-26 09:00:47 +01:00
7f5aee9e16 fix merge 2024-03-26 09:00:30 +01:00
1bdf35a4e6 Merge branch 'death' into dev
Some checks failed
Linux arm64 / Build (push) Failing after 2m17s
2024-03-26 08:39:18 +01:00
2bef8801e8 Physique presque finie (#21)
Some checks failed
Linux arm64 / Build (push) Failing after 4m47s
Co-authored-by: = <=>
Co-authored-by: AquaEBM <AquaEBM@gmail.com>
Co-authored-by: AquaEBM@gmail.com <AquaEBM@gmail.com>
Reviewed-on: #21
Co-authored-by: Persson-dev <sim16.prib@gmail.com>
Co-committed-by: Persson-dev <sim16.prib@gmail.com>
2024-03-26 08:31:02 +01:00
c1ded40cc4 improve network test
Some checks failed
Linux arm64 / Build (push) Has been cancelled
2024-03-21 17:24:05 +01:00
285bf880ee fix warning
Some checks failed
Linux arm64 / Build (push) Has been cancelled
2024-03-21 17:20:36 +01:00
5492f52806 fix warning
Some checks failed
Linux arm64 / Build (push) Failing after 4m53s
2024-03-21 17:14:43 +01:00
2cbe3f1219 move player on death
Some checks failed
Linux arm64 / Build (push) Failing after 3m53s
2024-03-21 16:46:38 +01:00
fe68b98ba1 update health to client 2024-03-21 16:43:45 +01:00
860ec70829 Squashed commit of the following:
commit 06ff76607d
Author: Persson-dev <sim16.prib@gmail.com>
Date:   Thu Mar 21 15:45:33 2024 +0100

    add bots

commit 19229bbe8a
Author: Persson-dev <sim16.prib@gmail.com>
Date:   Thu Mar 21 14:55:57 2024 +0100

    fix warnings

commit 2b0930a734
Author: Morph01 <thibaut6969delastreet@gmail.com>
Date:   Tue Mar 19 10:43:55 2024 +0100

    hud of blitz (#16)

    Résoudre partiellement #12

    Co-authored-by: Persson-dev <sim16.prib@gmail.com>
    Co-authored-by: Morph01 <145839520+Morph01@users.noreply.github.com>
    Co-authored-by: Simon Pribylski <sim16.prib@gmail.com>
    Reviewed-on: #16

commit 84b6acad4c
Author: Persson-dev <sim16.prib@gmail.com>
Date:   Tue Mar 19 10:15:54 2024 +0100

    less spooky light

commit 9f94d51fc4
Author: Persson-dev <sim16.prib@gmail.com>
Date:   Thu Mar 14 16:36:15 2024 +0100

    Ajout de tests d'intégration (#17)

    Le paquet fournissant OpenGL a été temporairement remplacé par glew

    Reviewed-on: #17
    Co-authored-by: Persson-dev <sim16.prib@gmail.com>
    Co-committed-by: Persson-dev <sim16.prib@gmail.com>

commit 9951256881
Author: Simon Pribylski <sim16.prib@gmail.com>
Date:   Wed Mar 13 20:19:37 2024 +0100

    action: install libsdl via apt

commit 4a02054648
Author: Morph01 <145839520+Morph01@users.noreply.github.com>
Date:   Wed Mar 13 13:53:20 2024 +0100

    compression tests

commit 19c39312bf
Author: Morph01 <145839520+Morph01@users.noreply.github.com>
Date:   Wed Mar 13 13:51:57 2024 +0100

    setup action

commit d5014b1e8a
Author: Persson-dev <sim16.prib@gmail.com>
Date:   Tue Mar 12 10:26:47 2024 +0100

    Revert "extend Vec3"

    This reverts commit dccfa9c936.

commit dccfa9c936
Author: = <=>
Date:   Tue Mar 12 10:01:00 2024 +0100

    extend Vec3
2024-03-21 15:51:57 +01:00
06ff76607d add bots
Some checks failed
Linux arm64 / Build (push) Failing after 3m31s
2024-03-21 15:45:33 +01:00
19229bbe8a fix warnings
Some checks failed
Linux arm64 / Build (push) Failing after 11m53s
2024-03-21 14:55:57 +01:00
438bc4a968 remove unused variable
Some checks failed
Linux arm64 / Build (push) Failing after 4m32s
2024-03-21 14:39:18 +01:00
9aa546881a better shoot logging
Some checks failed
Linux arm64 / Build (push) Has been cancelled
2024-03-21 14:35:41 +01:00
4db03f2b83 working shoot
Some checks failed
Linux arm64 / Build (push) Has been cancelled
2024-03-21 14:32:03 +01:00
0119d36b5c should work
All checks were successful
Linux arm64 / Build (push) Successful in 5m5s
2024-03-19 13:01:17 +01:00
249d7534a4 Squashed commit of the following:
All checks were successful
Linux arm64 / Build (push) Successful in 4m20s
commit 2b0930a734
Author: Morph01 <thibaut6969delastreet@gmail.com>
Date:   Tue Mar 19 10:43:55 2024 +0100

    hud of blitz (#16)

    Résoudre partiellement #12

    Co-authored-by: Persson-dev <sim16.prib@gmail.com>
    Co-authored-by: Morph01 <145839520+Morph01@users.noreply.github.com>
    Co-authored-by: Simon Pribylski <sim16.prib@gmail.com>
    Reviewed-on: #16

commit 84b6acad4c
Author: Persson-dev <sim16.prib@gmail.com>
Date:   Tue Mar 19 10:15:54 2024 +0100

    less spooky light

commit 9f94d51fc4
Author: Persson-dev <sim16.prib@gmail.com>
Date:   Thu Mar 14 16:36:15 2024 +0100

    Ajout de tests d'intégration (#17)

    Le paquet fournissant OpenGL a été temporairement remplacé par glew

    Reviewed-on: #17
    Co-authored-by: Persson-dev <sim16.prib@gmail.com>
    Co-committed-by: Persson-dev <sim16.prib@gmail.com>

commit 9951256881
Author: Simon Pribylski <sim16.prib@gmail.com>
Date:   Wed Mar 13 20:19:37 2024 +0100

    action: install libsdl via apt

commit 4a02054648
Author: Morph01 <145839520+Morph01@users.noreply.github.com>
Date:   Wed Mar 13 13:53:20 2024 +0100

    compression tests

commit 19c39312bf
Author: Morph01 <145839520+Morph01@users.noreply.github.com>
Date:   Wed Mar 13 13:51:57 2024 +0100

    setup action

commit d5014b1e8a
Author: Persson-dev <sim16.prib@gmail.com>
Date:   Tue Mar 12 10:26:47 2024 +0100

    Revert "extend Vec3"

    This reverts commit dccfa9c936.

commit dccfa9c936
Author: = <=>
Date:   Tue Mar 12 10:01:00 2024 +0100

    extend Vec3
2024-03-19 12:16:23 +01:00
=
abe89d2089 remove debug prints 2024-03-19 12:10:32 +01:00
f070b28d8b revert c_cpp_properties 2024-03-19 12:03:12 +01:00
=
a7f734d22e fix Intersects, add tests 2024-03-19 11:56:29 +01:00
2b0930a734 hud of blitz (#16)
All checks were successful
Linux arm64 / Build (push) Successful in 4m33s
Résoudre partiellement #12

Co-authored-by: Persson-dev <sim16.prib@gmail.com>
Co-authored-by: Morph01 <145839520+Morph01@users.noreply.github.com>
Co-authored-by: Simon Pribylski <sim16.prib@gmail.com>
Reviewed-on: #16
2024-03-19 10:43:55 +01:00
=
abbc4419fa update intersects function 2024-03-19 10:36:43 +01:00
84b6acad4c less spooky light
All checks were successful
Linux arm64 / Build (push) Successful in 4m23s
2024-03-19 10:15:54 +01:00
9f94d51fc4 Ajout de tests d'intégration (#17)
All checks were successful
Linux arm64 / Build (push) Successful in 4m28s
Le paquet fournissant OpenGL a été temporairement remplacé par glew

Reviewed-on: #17
Co-authored-by: Persson-dev <sim16.prib@gmail.com>
Co-committed-by: Persson-dev <sim16.prib@gmail.com>
2024-03-14 16:36:15 +01:00
9951256881 action: install libsdl via apt
Some checks failed
Linux arm64 / Build (push) Failing after 54m19s
2024-03-13 20:19:37 +01:00
Morph01
4a02054648 compression tests
Some checks failed
Linux arm64 / Build (push) Failing after 57m27s
2024-03-13 13:53:20 +01:00
Morph01
19c39312bf setup action 2024-03-13 13:51:57 +01:00
86e47601d7 idk 2024-03-12 11:31:04 +01:00
d5014b1e8a Revert "extend Vec3"
This reverts commit dccfa9c936.
2024-03-12 10:26:47 +01:00
=
a3b6d2488f extend Vec3, implement AABB intersection 2024-03-12 10:25:27 +01:00
=
dccfa9c936 extend Vec3 2024-03-12 10:01:00 +01:00
e39fc8aa70 Star Wars (#14)
Reviewed-on: #14
2024-03-12 08:55:49 +01:00
d42f67724d fix error 2024-03-12 08:32:53 +01:00
71bc4dd249 add keybindings (#13)
Co-authored-by: Morph01 <thibaut6969delastreet@gmail.com>
Reviewed-on: #13
Co-authored-by: Persson-dev <sim16.prib@gmail.com>
Co-committed-by: Persson-dev <sim16.prib@gmail.com>
2024-03-09 18:37:54 +01:00
2cb5074140 better server logs 2024-03-09 11:01:30 +01:00
269ac16d28 more precise logging 2024-03-08 22:59:50 +01:00
b7926d7a98 pretty log 2024-03-08 22:57:38 +01:00
52da1cf19b explicit server in logs 2024-03-07 23:10:37 +01:00
2da89c8dab xmake: remove global include 2024-03-07 21:12:41 +01:00
88cb433ecf xmake: relative paths 2024-03-07 21:03:23 +01:00
d96b01074e split xmake targets 2024-03-07 20:50:14 +01:00
a1effa05cd remove github ci 2024-03-07 20:14:12 +01:00
7b58117f36 fix warnings 2024-03-07 20:13:05 +01:00
bf8a6458a0 valgrind full info 2024-03-05 12:30:09 +01:00
18ddede8c0 add shoot 2024-03-05 12:29:39 +01:00
d3467418c7 Merge branch 'main' of github.com:Persson-dev/Blitz 2024-03-05 09:01:15 +01:00
d98939cb31 remove useless add_requires 2024-03-05 08:39:24 +01:00
0d039caa0e Merge branch 'weirdshoot' 2024-03-05 08:38:34 +01:00
848f12e58b Vecxuc wrong type 2024-02-27 12:15:35 +01:00
ce249359c6 non copyable classes 2024-02-26 11:27:16 +01:00
9591836074 add valgrind test 2024-01-30 09:14:07 +01:00
7305051062 fix memory warnings 2024-01-30 08:53:26 +01:00
617e1fa95e branchless 2024-01-28 19:09:30 +01:00
73b4539e8d add gun animation 2024-01-28 18:30:16 +01:00
de3ff4326a CooldownTimer to template 2024-01-28 18:29:55 +01:00
51f046f44e fix compile error 2024-01-27 20:12:14 +01:00
3b5208aeba clamp horizonal movement vector norm to 1 (fix diagonal movement speed increase) 2024-01-27 20:10:10 +01:00
a40cd1cd61 change smoothing time const names 2024-01-27 19:11:04 +01:00
1ccf525dd6 fix wrong filter equation 2024-01-27 19:08:56 +01:00
7cf93fa16f add Rotate function 2024-01-27 18:34:14 +01:00
b345d6eb49 fixed-alpha movement smoothing 2024-01-27 17:54:26 +01:00
a7dbf69a4a oooo? 2024-01-27 17:48:37 +01:00
d57195cef2 fix gun model 2024-01-27 17:42:49 +01:00
b6eae6575e fix contructor def 2024-01-27 17:29:54 +01:00
f7d471d3ad format + fix compiling 2024-01-27 17:29:22 +01:00
956aae9b83 first fix attempt 2024-01-27 17:22:54 +01:00
bb86e96884 fix more bugs 2024-01-27 17:00:00 +01:00
22e19c7a97 fix ldflags typo and other compile errors 2024-01-27 16:54:07 +01:00
a71a5ea2bc smoothing test 2024-01-27 16:40:59 +01:00
6450354d0f fix Android inputs 2024-01-27 13:31:00 +01:00
e350f23c4e refactor PlayerController 2024-01-27 13:19:48 +01:00
9ada85f5e6 fix light bug 2024-01-27 13:17:31 +01:00
7496c25669 make mouse grabbing restrict input reaction 2024-01-27 13:09:41 +01:00
a75e4669c0 minor renaming, chage jump height 2024-01-27 13:04:50 +01:00
667f997338 small PlayerController refactor 2024-01-25 23:48:53 +01:00
e86a1b578e install package locally 2024-01-25 23:38:45 +01:00
39ce24935d xmake.lua msg 2024-01-25 23:38:34 +01:00
9e5fd829a5 use doccomments for field docs 2024-01-25 19:51:32 +01:00
2b4ae457cb implement simple jumping 2024-01-25 19:50:48 +01:00
dfc2170ec8 first attempt at jump 2024-01-25 19:06:12 +01:00
1066b15612 indent xmake.lua 2024-01-23 08:47:16 +01:00
0eea01a5b9 FPS mode in game 2024-01-21 14:23:01 +01:00
b9204db9c0 Squashed commit of the handgun branch:
commit cb02631040e0d4ccac5ce844d9c429715d768181
Author: Morph01 <145839520+Morph01@users.noreply.github.com>
Date:   Wed Jan 17 22:14:13 2024 +0100

    position et rotation finger gun

commit 1f1c6f0721963f6ca7d85b8edbc48c1467ab43ba
Author: Persson-dev <sim16.prib@gmail.com>
Date:   Wed Jan 17 18:41:25 2024 +0100

    colors

commit 19e6e99c5d9111d8944c40f5043368ba55abc0f5
Author: Persson-dev <sim16.prib@gmail.com>
Date:   Wed Jan 17 18:35:17 2024 +0100

    fix rotation

commit acc444d45f8bb2d43efde92ff518b674ca998f4b
Author: Persson-dev <sim16.prib@gmail.com>
Date:   Wed Jan 17 18:23:20 2024 +0100

    handgun adjust menu

Co-authored-by: Morph01 <145839520+Morph01@users.noreply.github.com>
2024-01-18 16:02:02 +01:00
d5ccd8a3fa refactor player pos update code 2024-01-18 15:41:38 +01:00
ef5e274ef9 add PlayerController class 2024-01-18 15:08:56 +01:00
f237158fb4 temp show mouse again 2024-01-18 15:06:57 +01:00
Morph01
d1e70745eb Finger Gun model v2 small 2024-01-17 17:36:23 +01:00
Morph01
b368922f9f Finger Gun model v1 2024-01-17 17:12:21 +01:00
195a337df9 hide mouse in game 2024-01-12 19:51:58 +01:00
Simon Pribylski
bde4292d9e fix MSVC build 2024-01-11 17:45:45 -08:00
502de9e778 simplify xmake.lua 2024-01-03 17:41:31 +01:00
8ec1ea139e Merge branch 'glbinding' 2024-01-03 17:35:42 +01:00
11a85a6ef4 Ignore clangd cache 2024-01-02 19:23:49 +01:00
1e09572491 use glbinding instead of glew 2024-01-02 19:22:31 +01:00
a692c35f3a fix shaders for Android 2023-12-20 20:29:44 +01:00
ea95ab94e8 spookier light 2023-12-20 19:18:43 +01:00
810d5e0906 assert shader compilation with blitz_debug_assert 2023-12-20 19:05:48 +01:00
a1e8207bbb add blitz_debug_assert 2023-12-20 19:05:21 +01:00
b9296bf9a4 fix shaders for Android 2023-12-20 19:01:05 +01:00
cba7b0c3f7 shader compile assertion 2023-12-20 18:51:40 +01:00
17d55b5ffa crash program if shader does not compile 2023-12-20 13:38:05 +01:00
01efad9308 rework shaders code 2023-12-20 13:32:54 +01:00
bf4f31a6b0 attach camera to player 2023-12-18 20:31:23 +01:00
Simon Pribylski
b94b28d717 Github: add macOs action (#2)
* Create macos.yml

* Fix macos.yml

* remove anonymous namespace identifier

* forgot one ...

* fix macos build

* add tests for macos.yml

* macOS action trigger only on main or PR
2023-12-18 18:05:41 +01:00
Simon Pribylski
bd46fc5894 Add Windows action (#1)
* Create windows.yml

* Fix windows.yml

* add tests for windows.yml

* remove Windows arm action

* Windows action trigger only on main and PR
2023-12-18 18:00:29 +01:00
9d74a5288f unregister handler on delete (again) 2023-12-15 20:01:14 +01:00
1f53fc9015 doc: Test.h 2023-12-15 19:56:23 +01:00
55e5f679ab gui: add leave game button 2023-12-15 19:34:33 +01:00
2dd3e15bdf unregister handler on delete 2023-12-15 19:33:44 +01:00
Simon Pribylski
f567143b05 fix typo 2023-12-15 18:07:59 -08:00
de0195d05f doc: tests work on release too 2023-12-15 19:05:44 +01:00
652987b236 test: allow to build in release 2023-12-15 19:05:04 +01:00
fe7baa99b0 test: Vector.h 2023-12-12 20:22:17 +01:00
0a2059d14a set xmake minimum version to 2.8.5 2023-12-12 20:18:32 +01:00
83f48886fc doc: add tests 2023-12-12 20:00:31 +01:00
7cf29bca45 add test framework 2023-12-12 20:00:14 +01:00
a767e9744e fix Vector operators 2023-12-12 19:59:47 +01:00
0a61e24e84 doc: KeepAlivePacket.h 2023-12-11 19:28:54 +01:00
3718bc644e doc: PlayerJoinPacket.h 2023-12-11 19:16:01 +01:00
edb4bf6984 doc: Defines.h 2023-12-11 19:04:38 +01:00
ecff4c9f64 doc: PacketType 2023-12-11 18:48:50 +01:00
09f603f4fb add doxygen dark mode toogle 2023-12-11 17:41:38 +01:00
c416efc294 format html files 2023-12-11 16:47:46 +01:00
cf6ce6bae7 allow custom doxygen html 2023-12-11 16:44:52 +01:00
81386e7407 add network namespace doc 2023-12-11 00:20:09 +01:00
6c31a45719 minor fix for doc 2023-12-10 23:45:26 +01:00
10aacd361d refactor project 2023-12-10 23:41:50 +01:00
da62b98345 add network doc 2023-12-10 23:31:04 +01:00
3c64df12ec remove useless include 2023-12-10 23:27:38 +01:00
4bad9b6041 remove useless tcp function 2023-12-10 22:36:53 +01:00
b279d7b4b3 fix doc link 2023-12-10 22:31:04 +01:00
a564898445 remove useless tcp code 2023-12-10 22:10:07 +01:00
a7fe7caacc better doxyfile 2023-12-10 21:51:56 +01:00
1760241d15 change xmake link 2023-12-10 21:51:33 +01:00
a1bd852deb update doxygen mainpage 2023-12-10 19:24:53 +01:00
e9a5786524 update the README for doxygen 2023-12-10 18:29:44 +01:00
ddf5634b10 better doxygen style 2023-12-10 17:48:45 +01:00
f98f5a5ee4 Update README 2023-12-09 21:22:53 +01:00
7a58d35a08 remove whitespace 2023-12-09 21:20:43 +01:00
7da1ae5848 remove repetitive Display::Destroy call 2023-12-09 20:37:25 +01:00
d9f5678077 fix Windows networking 2023-12-09 20:13:07 +01:00
Simon Pribylski
2a9b087769 make Blitz lib static for Windows 2023-12-09 18:21:24 -08:00
Simon Pribylski
f92a5663d6 add dirty windows xmake.lua fix 2023-12-09 17:58:55 -08:00
44b31e7c58 refactor networking code 2023-12-09 18:36:23 +01:00
d640170d2c fix small warning 2023-12-09 18:26:04 +01:00
Simon Pribylski
f995b2e6b4 fix msvc imgui link error 2023-12-09 17:13:19 -08:00
a45b5dae3b change chat fade time to 2s 2023-11-28 11:14:07 +01:00
c39340f4de fix chat not closing properly 2023-11-28 11:11:14 +01:00
54cbfc2c33 adjust menu heights 2023-11-28 11:05:15 +01:00
0390f165dd display fps in right corner 2023-11-28 10:55:49 +01:00
d873d635cc feat: show settings during game 2023-11-28 10:52:24 +01:00
4f2c815a87 spooky light 2023-11-20 13:46:22 +01:00
Morph01
32c049f7f4 new map model, fix player model, ajust eyeHeight 2023-11-18 18:42:45 +01:00
53ae5d2e4f remove broken map 2023-11-18 17:17:07 +01:00
3846512c84 rework ModelLoader 2023-11-18 17:15:29 +01:00
fea0cb6b0d remove useless shader code 2023-11-18 17:12:44 +01:00
ce78a28d21 add ambient lighting 2023-11-18 17:12:19 +01:00
Morph01
f31bede304 broken fbx map 2023-11-17 13:56:57 +01:00
62767a04aa add skycolor 2023-11-16 22:48:08 +01:00
aa4abba135 fixing Android build 2023-11-16 22:32:16 +01:00
0ff0279772 rework PacketFactory
Applying @AquaEBM suggestion

Co-Authored-By: AquaEBM <79016373+aquaebm@users.noreply.github.com>
2023-11-16 22:24:39 +01:00
0ca47817d9 fix cam sensitivity 2023-11-15 18:42:03 +01:00
4519bd3fcb fixing loading model bug
AHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
2023-11-14 14:11:01 +01:00
9115d3bfea update Android shaders 2023-11-10 22:47:30 +01:00
087d12091b more assets debugging 2023-11-10 22:26:59 +01:00
fe63734ef1 use AssetsManager for textures 2023-11-10 22:16:41 +01:00
c6fb45be2f fix Android build 2023-11-10 22:15:22 +01:00
179f5112ea force sdl version 2023-11-10 22:14:41 +01:00
d4bbfcf030 update AssetsManager 2023-11-10 20:05:03 +01:00
711502650f add texture support 2023-11-10 09:19:53 +01:00
7edb7f1f02 resize texture image 2023-11-10 09:16:36 +01:00
Morph01
ac3aab4a36 texture of the ground 2023-11-09 21:43:45 +01:00
Morph01
dfe65025a5 ajusted eyeHeight 2023-11-09 21:36:32 +01:00
Morph01
ded2153c2b human model and map with texture 2023-11-09 21:33:06 +01:00
f82324d819 feat: save settings 2023-11-09 21:28:25 +01:00
a9a0b50bc0 add json dep 2023-11-09 19:59:17 +01:00
86518ecc22 add InputManager 2023-11-09 19:50:08 +01:00
07e6d3bbe5 revert light player direction 2023-11-09 18:36:56 +01:00
dbe37b4eec add face culling 2023-11-09 18:35:41 +01:00
1cff3b6880 add antialiasing 2023-11-09 16:53:40 +01:00
fddb48d6ab add basic lighting 2023-11-09 16:36:50 +01:00
e9c1de0e0d add normal loading (+fix weird bug) 2023-11-09 16:23:19 +01:00
6514372b92 Disable face culling
This should be reenabled at some point !
2023-11-09 13:07:14 +01:00
Simon Pribylski
fe18004939 Update README.md
Fix typo
2023-11-08 23:51:06 +01:00
5198b47db3 fix Windows build 2023-11-05 14:48:50 +01:00
168d7c72fc use AssetsManager to load font 2023-11-04 19:59:21 +01:00
ec45885525 add AssetsManager 2023-11-04 19:44:01 +01:00
24cbc81cab improve Android support 2023-11-04 19:18:47 +01:00
Simon Pribylski
acbc20ed75 fix README typo 2023-11-04 17:18:52 +01:00
Simon Pribylski
8aab96cd72 indent correctly 2023-11-04 17:18:13 +01:00
Simon Pribylski
3f73f6ddf9 Indent README 2023-11-04 17:17:27 +01:00
cf99d08e7f update README 2023-11-04 17:16:00 +01:00
3fc3d52e10 update Protocol doc 2023-11-04 16:48:40 +01:00
c132234b0b rework VarInt 2023-11-04 16:43:11 +01:00
0951ca2587 remove useless include 2023-11-04 16:34:37 +01:00
f55ec17747 fix map 2023-11-04 13:21:10 +01:00
445ea3f616 render map 2023-11-04 13:16:09 +01:00
89fd026b71 fix Android build 2023-11-04 12:38:52 +01:00
9634f2737b use of VarLong for Packet size 2023-11-02 23:43:50 +01:00
3a1b2d277c refactor VarInt 2023-11-02 23:43:15 +01:00
26bde206cb remove useless function 2023-11-02 23:04:45 +01:00
041281ac61 use of VarInt 2023-11-02 22:53:46 +01:00
23ddc9e292 refactor 2023-11-02 22:53:18 +01:00
a285a61ff9 add VarInt 2023-11-02 22:52:52 +01:00
1173cf4087 remove useless function 2023-11-02 22:25:40 +01:00
8d6db5036e remove DataBuffer ToString 2023-11-02 22:06:48 +01:00
539001aad4 move REMOVE_COPY in hix own file 2023-11-02 21:37:34 +01:00
d8b781e619 explicit constructor 2023-11-02 21:35:30 +01:00
c08a28cedd add gui support for Android 2023-11-02 13:37:03 +01:00
527d43742d opengl includes for Android 2023-11-02 13:36:34 +01:00
82d562a4fc fix compiling for Android 2023-11-02 13:35:47 +01:00
90e411d747 ignore src directory for doc 2023-11-02 13:13:14 +01:00
Morph01
abb46e278b Merge branch 'main' of https://github.com/Persson-dev/Blitz 2023-10-31 10:36:36 +01:00
Morph01
956dca7ef8 add an empty map 2023-10-31 10:36:26 +01:00
f72aa2e959 don't render own player model 2023-10-27 00:47:41 +02:00
0aa4963972 moved PlayerID def 2023-10-27 00:46:51 +02:00
87b68750d5 document Protocol.h 2023-10-22 14:56:25 +02:00
0c156db744 remove more useless includes 2023-10-22 13:48:01 +02:00
1069b5319d add basic doc 2023-10-22 13:47:40 +02:00
69b2d4e568 remove useless includes 2023-10-22 13:36:43 +02:00
5a99281428 moved vectors in their own file 2023-10-22 13:03:54 +02:00
889743480a small refactor 2023-10-22 12:48:54 +02:00
99f25f932b interpolate player movement 2023-10-22 12:45:00 +02:00
1d94c5f61a add * vect operator 2023-10-22 12:42:51 +02:00
335fb87382 remove useless paramters 2023-10-21 12:59:58 +02:00
fbed05f55a add compile flag for Android 2023-10-21 11:20:48 +02:00
9c94d2e36e sync player rotation 2023-10-19 18:00:19 +02:00
fdd2e34756 use of matricies to translate 2023-10-19 17:45:43 +02:00
f0d85c2c90 render players + sync 2023-10-19 17:23:34 +02:00
2d523693eb fix typo 2023-10-19 16:39:27 +02:00
52a338e3b5 better network sync 2023-10-19 16:36:17 +02:00
fa030d1ea5 add face culling 2023-10-19 16:23:30 +02:00
585c092e3a player position sync 2023-10-19 15:49:20 +02:00
14b390f2c4 add player pos packet 2023-10-19 15:14:26 +02:00
67f987d02c add line 2023-10-19 14:39:44 +02:00
40d6224204 refactor chat 2023-10-19 14:37:20 +02:00
ff0c2c3e02 don't move cam in chat 2023-10-19 14:22:10 +02:00
3b7398599d readd include path 2023-10-19 13:11:27 +02:00
4ed38ad4e4 camera better timings 2023-10-19 13:08:43 +02:00
1dd2637b07 move load model function 2023-10-19 12:42:00 +02:00
3d1dfd77d9 optimize bug fix 2023-10-19 12:29:36 +02:00
227c98bcf9 render player model 2023-10-18 21:04:05 +02:00
7d913589de FIXING THE BUG 2023-10-18 21:01:33 +02:00
bc01621fe3 small cam correction 2023-10-18 20:57:25 +02:00
Morph01
cd1710b0a3 add human model 2023-10-18 20:49:44 +02:00
b6d1fbe1f2 basic camera movement 2023-10-18 19:21:59 +02:00
cc9db304b8 fixing critical bug 2023-10-18 19:01:22 +02:00
764ee2db98 less vscode config 2023-10-18 17:17:46 +02:00
182 changed files with 68406 additions and 1412 deletions

View File

@@ -0,0 +1,38 @@
name: Linux arm64
run-name: Build And Test
on: [push]
jobs:
Build:
runs-on: ubuntu-latest
steps:
- name: Install deps
run : |
apt update
apt install -y libsdl2-dev libassimp-dev libglew-dev
- name: Check out repository code
uses: actions/checkout@v3
- name: Prepare XMake
uses: xmake-io/github-action-setup-xmake@v1
with:
xmake-version: latest
actions-cache-folder: '.xmake-cache'
actions-cache-key: 'ubuntu'
- name: Packages cache
uses: actions/cache@v4
with:
path: ~/.xmake
key: 'ubuntu-packages'
- name: XMake config
run: xmake f -p linux -y --root
- name: Build
run: xmake --root
- name: Test
run: xmake test --root

9
.gitignore vendored
View File

@@ -9,4 +9,11 @@ build/
.vscode
# IMGay
imgui.ini
imgui.ini
# Blitz settings
assets/settings.json
# Vim Cache
.cache
compile_commands.json

3
.gitmodules vendored Normal file
View File

@@ -0,0 +1,3 @@
[submodule "doxygen/doxygen-awesome-css"]
path = doxygen/doxygen-awesome-css
url = https://github.com/jothepro/doxygen-awesome-css.git

View File

@@ -1,18 +1,13 @@
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/include",
"${workspaceFolder}/libs/imgui"
],
"defines": [],
"compilerPath": "/usr/bin/clang",
"cStandard": "c17",
"cppStandard": "c++17",
"intelliSenseMode": "linux-clang-x64",
"compileCommands": ".vscode/compile_commands.json"
}
],
"version": 4
"configurations": [
{
"name": "Blitz",
"cppStandard": "c++17",
"includePath": [
"include"
],
"compileCommands": ".vscode/compile_commands.json"
}
],
"version": 4
}

7
.vscode/launch.json vendored
View File

@@ -2,6 +2,13 @@
// Xmake debug
"version": "0.2.0",
"configurations": [
{
"type": "xmake",
"request": "launch",
"name": "debug intersects test",
"target": "test_intersects",
"cwd": "",
},
{
"type": "xmake",
"request": "launch",

View File

@@ -1 +1,88 @@
# Blitz
# Blitz 🎮
Fast FPS written in C++
# Prerequisites 🛠️
You will need a recent compiler supporting c++17 and [xmake](https://xmake.io) (version 2.8.5 or higher).
xmake should download all the dependencies for you.
# Client 💻
## Build ⚙️
```
xmake [BlitzClient]
```
## Run 🏃
```
xmake run [BlitzClient]
```
# Server 🗄
## Build ⚙️
```
xmake build BlitzServer
```
## Run 🏃
```
xmake run BlitzServer [-P port]
```
# Debug 🏗️
Switch to debug mode
```
xmake f -m debug
```
Switch to release mode
```
xmake f -m release
```
Run with debugger
```
xmake run -d # Client
xmake run -d BlitzServer # Server
```
# Testing 🧐
Run tests :
```
xmake test
```
Run tests with verbose :
```
xmake test -v
```
# Generate docs 📖
First, clone the submodule for the enhanced css :
```
git submodule update --init
```
Then, refresh the doc :
```
xmake doxygen
```
# Visual Studio Code integration 🎛
Generate `compile_commands.json` :
```
xmake project -k compile_commands
```
Alternatively, you can install the [XMake extension](https://marketplace.visualstudio.com/items?itemName=tboox.xmake-vscode) for VsCode.

BIN
assets/base_deambu.glb Normal file

Binary file not shown.

BIN
assets/carrelage.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 298 KiB

BIN
assets/crosshair.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.1 KiB

BIN
assets/cube.glb Normal file

Binary file not shown.

454
assets/fingergun.obj Normal file
View File

@@ -0,0 +1,454 @@
# Blender 4.0.2
# www.blender.org
mtllib fingergun.mtl
o Cube
v 0.28522 -0.306557 -0.869022
v 0.322362 -0.317165 -0.761062
v 0.343467 -0.302403 -0.885416
v 0.368924 -0.313485 -0.773896
v 0.290013 -0.112715 -0.788332
v 0.323476 -0.173525 -0.715829
v 0.352603 -0.107768 -0.805584
v 0.370039 -0.169845 -0.728663
v 0.313472 -0.282474 -0.98082
v 0.305899 -0.094307 -0.966123
v 0.25069 -0.288091 -0.963829
v 0.248265 -0.098863 -0.950236
v 0.315042 -0.255677 -0.741247
v 0.353448 -0.222605 -0.866318
v 0.376243 -0.25084 -0.758116
v 0.275133 -0.228795 -0.844732
v 0.306822 -0.188042 -0.997506
v 0.242783 -0.193417 -0.979751
v 0.328963 -0.094936 -0.887948
v 0.26606 -0.099642 -0.870998
v 0.256312 -0.29401 -0.929786
v 0.325556 -0.290373 -0.95117
v 0.331511 -0.201707 -0.945538
v 0.249474 -0.208163 -0.925103
v 0.3156 -0.212794 -0.726928
v 0.356824 -0.163947 -0.837251
v 0.306541 -0.136889 -0.988441
v 0.376801 -0.207956 -0.743797
v 0.278508 -0.170136 -0.815665
v 0.24314 -0.1419 -0.970965
v 0.334727 -0.146782 -0.918122
v 0.253545 -0.153198 -0.895745
v 0.376243 -0.285911 -0.768173
v 0.274555 -0.274639 -0.858509
v 0.244437 -0.249179 -0.968971
v 0.315042 -0.290748 -0.751303
v 0.353299 -0.268056 -0.87989
v 0.312528 -0.243154 -0.9863
v 0.246945 -0.259562 -0.929467
v 0.333607 -0.251364 -0.952175
v 0.285002 -0.111885 -1.0476
v 0.284624 -0.075309 -1.03848
v 0.240924 -0.078763 -1.02644
v 0.241302 -0.115339 -1.03555
v 0.265142 -0.095745 -1.09905
v 0.26471 -0.06569 -1.092
v 0.231536 -0.068311 -1.08285
v 0.231968 -0.098367 -1.0899
v 0.245138 -0.079879 -1.14484
v 0.244853 -0.060082 -1.1402
v 0.223002 -0.061809 -1.13417
v 0.223287 -0.081606 -1.13882
v 0.238589 -0.126121 -1.04304
v 0.238302 -0.156446 -1.05277
v 0.282403 -0.152961 -1.06493
v 0.282689 -0.122635 -1.05519
v 0.224842 -0.104653 -1.10809
v 0.224605 -0.129737 -1.11614
v 0.259885 -0.126949 -1.12586
v 0.260122 -0.101865 -1.11781
v 0.212474 -0.08638 -1.1635
v 0.212291 -0.105749 -1.16971
v 0.239533 -0.103596 -1.17722
v 0.239716 -0.084227 -1.17101
v 0.245255 -0.211794 -0.937667
v 0.23564 -0.203772 -0.970252
v 0.239644 -0.243118 -0.967006
v 0.247582 -0.250332 -0.938814
v 0.20904 -0.218297 -0.924812
v 0.199926 -0.212656 -0.95554
v 0.202827 -0.242012 -0.953432
v 0.211233 -0.248682 -0.925568
v 0.23797 -0.250875 -0.931151
v 0.227883 -0.243486 -0.96328
v 0.22403 -0.205538 -0.966375
v 0.235306 -0.213245 -0.930024
v 0.228892 -0.223387 -0.888623
v 0.230462 -0.247719 -0.889906
v 0.247651 -0.24687 -0.894579
v 0.246456 -0.221472 -0.89286
v 0.239437 -0.222641 -0.868515
v 0.241043 -0.247531 -0.869827
v 0.256136 -0.245131 -0.875942
v 0.256357 -0.221304 -0.873179
v 0.211074 -0.263639 -0.953702
v 0.213693 -0.287969 -0.951236
v 0.220098 -0.290426 -0.927654
v 0.217767 -0.267981 -0.929448
v 0.244401 -0.260805 -0.898326
v 0.246352 -0.279833 -0.896941
v 0.22605 -0.263629 -0.895257
v 0.227699 -0.279716 -0.894086
v 0.244023 -0.258082 -0.877504
v 0.245361 -0.271127 -0.876555
v 0.231216 -0.259837 -0.875381
v 0.232387 -0.271258 -0.87455
v 0.242235 -0.234909 -0.865645
v 0.25077 -0.246182 -0.869083
v 0.249798 -0.221958 -0.8673
v 0.258332 -0.233231 -0.870738
v 0.250591 -0.234249 -0.867948
v 0.340336 -0.064822 -0.814251
v 0.289619 -0.068389 -0.800918
v 0.27575 -0.028073 -0.848984
v 0.323192 -0.025853 -0.859801
v 0.347259 -0.086137 -0.809994
v 0.288925 -0.090417 -0.7944
v 0.323713 -0.063998 -0.876764
v 0.271488 -0.066639 -0.864561
v 0.30779 -0.003466 -0.90206
v 0.269355 -0.005186 -0.893491
v 0.305922 -0.036948 -0.917187
v 0.267487 -0.038668 -0.908618
v 0.290951 0.010285 -0.945364
v 0.264889 0.009062 -0.939487
v 0.289769 -0.012563 -0.955362
v 0.263707 -0.013786 -0.949485
v 0.389423 -0.241181 -0.511183
v 0.42824 -0.238113 -0.521883
v 0.390542 -0.278589 -0.508273
v 0.434238 -0.348579 -0.541377
v 0.42824 -0.370001 -0.559701
v 0.389423 -0.373069 -0.549002
v 0.390542 -0.352032 -0.529332
v 0.390542 -0.318275 -0.519653
v 0.434238 -0.275136 -0.520317
v 0.434238 -0.314821 -0.531697
v 0.616718 -0.481384 0.244553
v 0.655534 -0.478316 0.233854
v 0.617836 -0.518792 0.247464
v 0.661532 -0.588782 0.21436
v 0.655534 -0.610204 0.196036
v 0.616718 -0.613272 0.206735
v 0.617836 -0.592235 0.226404
v 0.617836 -0.558478 0.236084
v 0.661532 -0.515339 0.23542
v 0.661532 -0.555025 0.22404
vn -0.0693 0.9972 0.0269
vn 0.9795 0.1687 -0.1100
vn 0.1060 0.7854 0.6098
vn 0.9604 0.1984 -0.1956
vn 0.0434 -0.9929 -0.1105
vn -0.8879 -0.3691 0.2745
vn -0.9967 0.0312 0.0753
vn 0.0064 -0.9769 -0.2137
vn -0.9784 0.0912 0.1858
vn 0.8684 -0.1187 -0.4815
vn 0.9200 0.1044 -0.3777
vn -0.9872 -0.0075 0.1595
vn -0.2347 -0.2040 -0.9504
vn -0.9357 -0.1073 0.3360
vn 0.9709 0.0660 -0.2301
vn 0.9798 0.0546 -0.1923
vn -0.9451 -0.0305 0.3255
vn 0.9660 0.0680 -0.2495
vn 0.9317 -0.2088 -0.2973
vn -0.9522 0.0661 0.2984
vn 0.0031 -0.9814 -0.1918
vn 0.2293 0.2657 0.9364
vn -0.9558 -0.0825 0.2822
vn 0.9496 0.2172 -0.2261
vn -0.9345 -0.2676 0.2347
vn -0.9114 0.0193 0.4112
vn 0.9246 0.2310 -0.3028
vn -0.9916 -0.0052 0.1295
vn -0.0507 -0.8928 -0.4476
vn 0.9804 0.0441 -0.1921
vn 0.9662 0.0724 -0.2475
vn -0.8929 -0.3210 0.3158
vn 0.9471 -0.2199 -0.2338
vn -0.2380 -0.1521 -0.9593
vn -0.0758 -0.9889 -0.1279
vn 0.8868 0.0460 -0.4598
vn -0.9364 -0.0930 0.3384
vn 0.9710 0.0651 -0.2302
vn 0.9384 0.0922 -0.3330
vn -0.0060 0.9668 0.2556
vn -0.0315 -0.9247 -0.3794
vn 0.9551 0.1199 -0.2708
vn -0.0139 -0.9467 -0.3219
vn -0.0064 -0.9548 -0.2971
vn -0.0263 0.9821 0.1863
vn -0.9867 -0.0495 0.1545
vn -0.2753 0.2158 -0.9368
vn -0.0418 0.9903 0.1324
vn -0.9862 -0.0511 0.1575
vn 0.9240 0.0999 -0.3690
vn 0.0107 0.9502 0.3113
vn 0.9467 0.0724 -0.3140
vn -0.9982 -0.0057 0.0600
vn -0.0179 0.9765 0.2149
vn -0.0382 -0.9153 -0.4010
vn -0.0324 -0.9235 -0.3822
vn 0.9461 0.0908 -0.3108
vn -0.9804 -0.0518 0.1901
vn -0.2755 0.2962 -0.9145
vn 0.9396 0.0966 -0.3284
vn -0.9782 -0.0550 0.2002
vn 0.0106 0.9503 0.3110
vn -0.1254 -0.9738 -0.1895
vn -0.6568 -0.1481 -0.7394
vn -0.7727 0.5638 0.2916
vn -0.9713 -0.2191 0.0929
vn -0.9596 -0.0757 0.2710
vn -0.3749 -0.1088 -0.9207
vn -0.0133 -0.9972 0.0739
vn -0.1558 0.9587 0.2381
vn -0.0228 0.9732 0.2290
vn 0.6151 0.0168 0.7883
vn -0.2986 -0.1081 -0.9482
vn -0.0725 -0.9741 -0.2141
vn -0.8802 -0.0814 0.4676
vn -0.8777 -0.0780 0.4729
vn 0.9610 0.0709 -0.2674
vn -0.1065 0.9694 0.2210
vn 0.0508 0.0974 0.9940
vn 0.8971 0.0564 -0.4382
vn 0.1038 -0.9946 -0.0036
vn -0.0866 0.9960 0.0233
vn -0.9643 -0.0790 0.2528
vn 0.9671 0.2076 0.1470
vn -0.2769 0.9267 0.2540
vn -0.3354 -0.1588 -0.9286
vn 0.0602 -0.9190 0.3896
vn -0.2317 0.9724 -0.0259
vn -0.0314 -0.9363 0.3497
vn -0.9663 -0.0810 0.2445
vn 0.1512 0.0872 0.9846
vn 0.9947 0.1023 0.0047
vn -0.1663 0.9766 -0.1368
vn -0.9610 -0.0793 0.2649
vn 0.1076 -0.2146 0.9707
vn 0.5991 -0.2528 0.7597
vn 0.5042 0.1209 0.8551
vn 0.1072 0.7759 0.6216
vn 0.9524 0.1729 -0.2510
vn -0.9908 0.0279 0.1323
vn -0.9608 0.0375 0.2747
vn -0.9580 0.0734 0.2771
vn -0.2526 0.2577 -0.9326
vn 0.9434 0.2219 -0.2465
vn 0.2349 0.2579 0.9372
vn -0.9951 0.0098 0.0989
vn 0.0606 0.8911 0.4497
vn 0.9440 0.1199 -0.3073
vn -0.0806 -0.8446 -0.5293
vn -0.2194 0.4006 -0.8896
vn 0.0223 0.9555 0.2943
vn -0.0760 -0.8547 -0.5136
vn 0.9376 0.0981 -0.3337
vn 0.0075 0.9536 0.3008
vn 0.9613 0.0760 -0.2650
vn -0.0075 -0.9536 -0.3008
vn 0.9560 -0.0171 -0.2929
vn -0.9502 -0.0859 0.2995
vn -0.9502 -0.0868 0.2994
vn 0.0106 0.9504 0.3108
vn 0.0057 -0.9665 -0.2566
vn -0.9431 0.0480 0.3290
vn 0.9511 -0.1186 -0.2851
vn 0.2462 -0.6689 0.7014
vn 0.2756 -0.2650 0.9240
vn 0.2587 0.0826 0.9624
vn -0.9613 -0.0760 0.2650
vn -0.9574 -0.1683 0.2345
vn -0.9582 -0.0064 0.2861
vn 0.9593 0.1452 -0.2424
vt 0.625000 0.250000
vt 0.625000 0.000000
vt 0.625000 0.250000
vt 0.375000 0.929303
vt 0.625000 0.929303
vt 0.625000 1.000000
vt 0.375000 1.000000
vt 0.375000 0.000000
vt 0.375000 0.250000
vt 0.375000 0.500000
vt 0.625000 0.500000
vt 0.625000 0.750000
vt 0.375000 0.750000
vt 0.375000 0.449616
vt 0.625000 0.449616
vt 0.625000 0.320697
vt 0.625000 0.800385
vt 0.625000 0.800384
vt 0.625000 0.929303
vt 0.625000 0.858607
vt 0.625000 0.858607
vt 0.625000 0.929303
vt 0.625000 0.449616
vt 0.625000 0.391393
vt 0.675385 0.500000
vt 0.733607 0.500000
vt 0.733607 0.750000
vt 0.675384 0.750000
vt 0.375000 0.320697
vt 0.375000 0.391393
vt 0.375000 0.800384
vt 0.375000 0.858607
vt 0.625000 0.250000
vt 0.804303 0.750000
vt 0.804303 0.500000
vt 0.875000 0.500000
vt 0.875000 0.750000
vt 0.625000 0.420504
vt 0.625000 1.000000
vt 0.625000 0.250000
vt 0.324616 0.500000
vt 0.324616 0.750000
vt 0.195697 0.500000
vt 0.266393 0.500000
vt 0.266393 0.750000
vt 0.195697 0.750000
vt 0.125000 0.500000
vt 0.125000 0.750000
s 0
usemtl Material
f 20/1/1 19/2/1 10/2/1 12/3/1
f 28/4/2 26/5/2 7/6/2 8/7/2
f 8/8/3 7/2/3 5/3/3 6/9/3
f 28/4/4 8/7/4 119/7/4 126/4/4
f 2/10/5 1/11/5 3/12/5 4/13/5
f 36/14/6 34/15/6 1/11/6 2/10/6
f 30/16/7 12/3/7 43/3/7 44/16/7
f 22/12/8 21/11/8 11/11/8 9/12/8
f 32/16/9 20/1/9 12/3/9 30/16/9
f 40/17/10 22/12/10 9/12/10 38/18/10
f 31/19/11 23/20/11 17/21/11 27/22/11
f 39/23/12 24/24/12 65/24/12 68/23/12
f 35/25/13 18/26/13 17/27/13 38/28/13
f 25/29/14 29/16/14 16/24/14 13/30/14
f 33/31/15 15/32/15 127/32/15 121/31/15
f 33/31/16 37/17/16 14/21/16 15/32/16
f 34/15/17 16/24/17 24/24/17 39/23/17
f 26/5/18 14/21/18 23/20/18 31/19/18
f 37/17/19 3/12/19 22/12/19 40/17/19
f 29/16/20 5/3/20 20/1/20 32/16/20
f 3/12/21 1/11/21 21/11/21 22/12/21
f 107/33/22 106/2/22 102/2/22 103/3/22
f 16/24/23 29/16/23 32/16/23 24/24/23
f 7/6/24 26/5/24 31/19/24 19/6/24
f 36/14/25 2/10/25 123/10/25 124/14/25
f 6/9/26 5/3/26 29/16/26 25/29/26
f 19/6/27 31/19/27 27/22/27 10/6/27
f 24/24/28 32/16/28 30/16/28 18/24/28
f 17/27/29 18/26/29 54/26/29 55/27/29
f 15/32/30 14/21/30 26/5/30 28/4/30
f 14/21/31 37/17/31 40/17/31 23/20/31
f 1/11/32 34/15/32 39/23/32 21/11/32
f 4/13/33 3/12/33 37/17/33 33/31/33
f 11/11/34 35/25/34 38/28/34 9/12/34
f 11/11/35 21/11/35 87/11/35 86/11/35
f 23/20/36 40/17/36 38/18/36 17/21/36
f 13/30/37 16/24/37 34/15/37 36/14/37
f 15/32/38 28/4/38 126/4/38 127/32/38
f 42/6/39 41/22/39 45/22/39 46/6/39
f 12/3/40 10/2/40 42/2/40 43/3/40
f 27/34/41 30/35/41 44/35/41 41/34/41
f 10/6/42 27/22/42 41/22/42 42/6/42
f 45/34/43 48/35/43 52/35/43 49/34/43
f 41/34/44 44/35/44 48/35/44 45/34/44
f 43/3/45 42/2/45 46/2/45 47/3/45
f 44/16/46 43/3/46 47/3/46 48/16/46
f 52/35/47 51/36/47 50/37/47 49/34/47
f 47/3/48 46/2/48 50/2/48 51/3/48
f 48/16/49 47/3/49 51/3/49 52/16/49
f 46/6/50 45/22/50 49/22/50 50/6/50
f 53/35/51 56/34/51 60/34/51 57/35/51
f 27/22/52 17/21/52 55/21/52 56/22/52
f 18/24/53 30/16/53 53/16/53 54/24/53
f 30/35/54 27/34/54 56/34/54 53/35/54
f 59/27/55 58/26/55 62/26/55 63/27/55
f 55/27/56 54/26/56 58/26/56 59/27/56
f 56/22/57 55/21/57 59/21/57 60/22/57
f 54/24/58 53/16/58 57/16/58 58/24/58
f 62/26/59 61/35/59 64/34/59 63/27/59
f 60/22/60 59/21/60 63/21/60 64/22/60
f 58/24/61 57/16/61 61/16/61 62/24/61
f 57/35/62 60/34/62 64/34/62 61/35/62
f 74/15/63 73/23/63 72/23/63 71/15/63
f 18/26/64 35/25/64 67/25/64 66/26/64
f 24/24/65 18/24/65 66/24/65 65/24/65
f 35/15/66 39/23/66 68/23/66 67/15/66
f 72/23/67 69/24/67 70/24/67 71/15/67
f 75/26/68 74/25/68 71/25/68 70/26/68
f 72/23/69 73/23/69 79/23/69 78/23/69
f 76/24/70 75/24/70 70/24/70 69/24/70
f 65/24/71 66/24/71 75/24/71 76/24/71
f 68/23/72 65/24/72 76/24/72 73/23/72
f 66/26/73 67/25/73 74/25/73 75/26/73
f 67/15/74 68/23/74 73/23/74 74/15/74
f 77/24/75 78/23/75 82/23/75 97/38/75 81/24/75
f 69/24/76 72/23/76 78/23/76 77/24/76
f 73/23/77 76/24/77 80/24/77 79/23/77
f 76/24/78 69/24/78 77/24/78 80/24/78
f 101/38/79 99/24/79 81/24/79 97/38/79
f 79/23/80 80/24/80 84/24/80 100/38/80 83/23/80
f 78/23/81 79/23/81 83/23/81 98/23/81 82/23/81
f 80/24/82 77/24/82 81/24/82 99/24/82 84/24/82
f 87/11/83 88/23/83 85/15/83 86/11/83
f 21/11/84 39/23/84 89/23/84 90/11/84
f 39/23/85 35/15/85 85/15/85 88/23/85
f 35/25/86 11/11/86 86/11/86 85/25/86
f 92/11/87 90/11/87 94/11/87 96/11/87
f 39/23/88 88/23/88 91/23/88 89/23/88
f 87/11/89 21/11/89 90/11/89 92/11/89
f 88/23/90 87/11/90 92/11/90 91/23/90
f 94/11/91 93/23/91 95/23/91 96/11/91
f 90/11/92 89/23/92 93/23/92 94/11/92
f 89/23/93 91/23/93 95/23/93 93/23/93
f 91/23/94 92/11/94 96/11/94 95/23/94
f 98/23/95 101/38/95 97/38/95 82/23/95
f 83/23/96 100/38/96 101/38/96 98/23/96
f 100/38/97 84/24/97 99/24/97 101/38/97
f 103/3/98 102/2/98 105/2/98 104/1/98
f 106/39/99 108/6/99 105/6/99 102/6/99
f 109/40/100 104/1/100 111/1/100 113/40/100
f 109/40/101 107/33/101 103/3/101 104/1/101
f 20/1/102 5/3/102 107/33/102 109/40/102
f 19/2/103 20/1/103 109/40/103 108/2/103
f 7/6/104 19/6/104 108/6/104 106/39/104
f 5/3/105 7/2/105 106/2/105 107/33/105
f 113/40/106 111/1/106 115/1/106 117/40/106
f 104/1/107 105/2/107 110/2/107 111/1/107
f 105/6/108 108/6/108 112/6/108 110/6/108
f 108/2/109 109/40/109 113/40/109 112/2/109
f 116/2/110 117/40/110 115/1/110 114/2/110
f 111/1/111 110/2/111 114/2/111 115/1/111
f 112/2/112 113/40/112 117/40/112 116/2/112
f 110/6/113 112/6/113 116/6/113 114/6/113
f 119/8/114 118/9/114 128/9/114 129/8/114
f 121/31/115 127/32/115 137/32/115 131/31/115
f 123/10/116 122/13/116 132/13/116 133/10/116
f 122/13/117 121/31/117 131/31/117 132/13/117
f 13/30/118 36/14/118 124/14/118 125/30/118
f 25/29/119 13/30/119 125/30/119 120/29/119
f 8/8/120 6/9/120 118/9/120 119/8/120
f 2/10/121 4/13/121 122/13/121 123/10/121
f 6/9/122 25/29/122 120/29/122 118/9/122
f 4/13/123 33/31/123 121/31/123 122/13/123
f 134/41/124 133/10/124 132/13/124 131/42/124
f 130/43/125 135/44/125 137/45/125 136/46/125
f 128/47/126 130/43/126 136/46/126 129/48/126
f 135/44/125 134/41/125 131/42/125 137/45/125
f 120/29/127 125/30/127 135/30/127 130/29/127
f 125/30/127 124/14/127 134/14/127 135/30/127
f 124/14/128 123/10/128 133/10/128 134/14/128
f 118/9/129 120/29/129 130/29/129 128/9/129
f 126/4/130 119/7/130 129/7/130 136/4/130
f 127/32/115 126/4/115 136/4/115 137/32/115

BIN
assets/fingergun.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 218 KiB

612
assets/human.obj Normal file
View File

@@ -0,0 +1,612 @@
# Blender 3.6.4
# www.blender.org
mtllib human.mtl
o Cube
v 0.000000 1.096552 0.046445
v 0.000000 0.889451 0.075384
v 0.000000 1.115286 -0.108617
v 0.000000 0.869687 -0.104453
v -0.180548 1.111717 -0.017414
v -0.111752 0.883886 0.021620
v -0.185078 1.107266 -0.078906
v -0.119727 0.880731 -0.089652
v -0.113113 0.901238 0.004425
v -0.119191 0.863347 -0.060317
v 0.000000 0.586646 0.082459
v 0.000000 0.680490 -0.100339
v -0.138114 0.663711 0.049467
v -0.138587 0.663308 -0.075376
v -0.128084 0.703346 0.048918
v -0.138936 0.663857 -0.074824
v 0.000000 0.586646 0.082459
v 0.000000 0.680490 -0.100339
v -0.138114 0.663711 0.049467
v -0.138587 0.663308 -0.075376
v -0.138936 0.663857 -0.074824
v 0.000000 0.633606 0.062970
v 0.000000 0.680489 -0.091701
v -0.138114 0.663711 0.049467
v -0.138587 0.663308 -0.075376
v -0.138936 0.663857 -0.074824
v 0.000000 0.593050 0.063683
v 0.000000 0.677601 -0.092874
v -0.138114 0.663711 0.049467
v -0.138587 0.663308 -0.075376
v -0.138936 0.663857 -0.074824
v -0.069100 0.324785 0.031864
v -0.069974 0.349583 -0.105590
v -0.178168 0.333615 0.001983
v -0.176367 0.332529 -0.079971
v -0.176661 0.332851 -0.079619
v -0.078182 0.060565 -0.038352
v -0.100391 0.066316 -0.116765
v -0.161400 0.061971 -0.059044
v -0.154590 0.057629 -0.103715
v -0.154739 0.057792 -0.103535
v 0.000000 1.008557 0.072589
v -0.141948 1.013588 -0.077902
v 0.000000 0.962634 -0.106029
v -0.142827 1.021350 -0.002643
v -0.207545 1.041885 -0.083794
v -0.193677 1.102421 -0.079812
v -0.188428 1.103945 -0.018320
v -0.208865 1.048599 -0.008441
v -0.141948 1.013588 -0.077902
v -0.142827 1.021350 -0.002643
v -0.207545 1.041885 -0.083794
v -0.208865 1.048599 -0.008441
v -0.235837 0.598081 -0.011834
v -0.238964 0.602158 0.027134
v -0.272812 0.599277 -0.016077
v -0.275955 0.602764 0.022947
v -0.248917 0.533886 -0.005790
v -0.250356 0.537962 0.033178
v -0.265930 0.535082 -0.010034
v -0.267377 0.538568 0.028991
v -0.251597 0.852753 -0.055310
v -0.198231 0.836037 -0.050122
v -0.200071 0.842224 0.009630
v -0.253697 0.858088 0.004520
v -0.081324 0.011252 -0.048924
v -0.103533 0.017003 -0.127338
v -0.164542 0.012658 -0.069616
v -0.157732 0.008315 -0.114287
v -0.157881 0.008479 -0.114108
v -0.099701 0.028161 0.049506
v -0.154886 0.035284 0.046596
v -0.096329 0.004370 0.044705
v -0.164542 0.012658 0.030254
v -0.165478 0.195079 -0.091843
v -0.144114 0.077886 -0.060395
v -0.103904 0.081048 -0.098625
v -0.090656 0.076731 -0.047003
v -0.165700 0.195321 -0.091577
v -0.160220 0.126557 -0.097556
v -0.157480 0.092175 -0.100546
v -0.158850 0.109366 -0.099051
v 0.000000 1.162288 -0.069621
v -0.042130 1.159910 -0.042350
v 0.000000 1.163101 0.001170
v -0.041746 1.160373 -0.012683
v 0.000000 1.218953 -0.082666
v -0.054340 1.216575 -0.055394
v 0.000000 1.203799 0.005752
v -0.053956 1.217038 -0.025727
v 0.000000 1.265359 -0.105607
v -0.055992 1.262981 -0.078336
v -0.056859 1.263444 -0.026306
v 0.000000 1.324387 -0.095129
v -0.048669 1.313749 -0.071148
v 0.000000 1.329979 -0.010151
v -0.048314 1.315816 -0.019151
v -0.044592 1.234672 0.013774
v 0.000000 1.236440 0.022752
v -0.046473 1.264750 0.013399
v 0.000000 1.266518 0.022377
v -0.047524 1.291874 0.015141
v 0.000000 1.307387 0.019786
v -0.045451 1.198253 -0.045035
v -0.044363 1.199189 -0.035255
v 0.000000 1.199480 -0.067041
v 0.000000 1.198633 -0.039855
v -0.123594 0.736939 0.058421
v -0.118219 0.758177 0.058127
v 0.000000 0.711181 0.072811
v -0.124034 0.737017 -0.065871
v -0.123847 0.736723 -0.066167
v 0.000000 0.737698 -0.107365
v -0.119073 0.864514 -0.058899
v -0.119191 0.863347 -0.060317
v -0.119073 0.864514 -0.058899
v 0.180548 1.111717 -0.017414
v 0.111752 0.883886 0.021620
v 0.185078 1.107266 -0.078906
v 0.119727 0.880731 -0.089652
v 0.113113 0.901238 0.004425
v 0.119191 0.863347 -0.060317
v 0.138114 0.663711 0.049467
v 0.138587 0.663308 -0.075376
v 0.128084 0.703346 0.048918
v 0.138936 0.663857 -0.074824
v 0.138114 0.663711 0.049467
v 0.138587 0.663308 -0.075376
v 0.138936 0.663857 -0.074824
v 0.138114 0.663711 0.049467
v 0.138587 0.663308 -0.075376
v 0.138936 0.663857 -0.074824
v 0.138114 0.663711 0.049467
v 0.138587 0.663308 -0.075376
v 0.138936 0.663857 -0.074824
v 0.069100 0.324785 0.031864
v 0.069974 0.349583 -0.105590
v 0.178168 0.333615 0.001983
v 0.176367 0.332529 -0.079971
v 0.176661 0.332851 -0.079619
v 0.078182 0.060565 -0.038352
v 0.100391 0.066316 -0.116765
v 0.161400 0.061971 -0.059044
v 0.154590 0.057629 -0.103715
v 0.154739 0.057792 -0.103535
v 0.141948 1.013588 -0.077902
v 0.142827 1.021350 -0.002643
v 0.207545 1.041885 -0.083794
v 0.193677 1.102421 -0.079812
v 0.188428 1.103945 -0.018320
v 0.208865 1.048599 -0.008441
v 0.141948 1.013588 -0.077902
v 0.142827 1.021350 -0.002643
v 0.207545 1.041885 -0.083794
v 0.208865 1.048599 -0.008441
v 0.235837 0.598081 -0.011834
v 0.238964 0.602158 0.027134
v 0.272812 0.599277 -0.016077
v 0.275955 0.602764 0.022947
v 0.248917 0.533886 -0.005790
v 0.250356 0.537962 0.033178
v 0.265930 0.535082 -0.010034
v 0.267377 0.538568 0.028991
v 0.251597 0.852753 -0.055310
v 0.198231 0.836037 -0.050122
v 0.200071 0.842224 0.009630
v 0.253697 0.858088 0.004520
v 0.081324 0.011252 -0.048924
v 0.103533 0.017003 -0.127338
v 0.164542 0.012658 -0.069616
v 0.157732 0.008315 -0.114287
v 0.157881 0.008479 -0.114108
v 0.099701 0.028161 0.049506
v 0.154886 0.035284 0.046596
v 0.096329 0.004370 0.044705
v 0.164542 0.012658 0.030254
v 0.165478 0.195079 -0.091843
v 0.144114 0.077886 -0.060395
v 0.103904 0.081048 -0.098625
v 0.090656 0.076731 -0.047003
v 0.165700 0.195321 -0.091577
v 0.160220 0.126557 -0.097556
v 0.157480 0.092175 -0.100546
v 0.158850 0.109366 -0.099051
v 0.042130 1.159910 -0.042350
v 0.041746 1.160373 -0.012683
v 0.054340 1.216575 -0.055394
v 0.053956 1.217038 -0.025727
v 0.055992 1.262981 -0.078336
v 0.056859 1.263444 -0.026306
v 0.048669 1.313749 -0.071148
v 0.048314 1.315816 -0.019151
v 0.044592 1.234672 0.013774
v 0.046473 1.264750 0.013399
v 0.047524 1.291874 0.015141
v 0.045451 1.198253 -0.045035
v 0.044363 1.199189 -0.035255
v 0.123594 0.736939 0.058421
v 0.118219 0.758177 0.058127
v 0.124034 0.737017 -0.065871
v 0.123847 0.736723 -0.066167
v 0.119073 0.864514 -0.058899
v 0.119191 0.863347 -0.060317
v 0.119073 0.864514 -0.058899
vn -0.0000 0.3474 0.9377
vn -0.0000 0.6149 0.7886
vn -0.4110 0.6925 0.5929
vn -0.4320 0.7175 0.5464
vn -0.0000 -0.0003 -1.0000
vn -0.4191 0.5177 -0.7458
vn -0.3645 0.6539 -0.6630
vn -0.0000 0.3983 -0.9172
vn -0.6186 0.4665 -0.6322
vn -0.6252 0.5101 0.5906
vn -0.8604 0.2027 0.4676
vn -0.4420 0.8027 0.4004
vn -0.0000 0.8362 0.5484
vn -0.0000 0.0586 0.9983
vn -0.9877 0.0416 -0.1505
vn -0.9616 0.2180 -0.1664
vn -0.5097 0.5588 0.6542
vn -0.0000 0.0881 0.9961
vn -0.0000 0.7046 -0.7096
vn -0.0000 1.0000 -0.0000
vn 0.0307 0.9995 -0.0000
vn -0.3101 0.8961 -0.3175
vn -0.8450 0.4761 -0.2434
vn -0.9912 0.1128 -0.0693
vn -0.0000 -0.0138 -0.9999
vn -0.5899 0.0904 -0.8024
vn 0.0024 0.9430 -0.3328
vn -0.0530 0.9976 0.0439
vn 0.8147 -0.5718 0.0958
vn -0.0000 0.7793 -0.6266
vn 0.1907 -0.2058 0.9598
vn 0.2826 0.1425 -0.9486
vn 0.4249 -0.5707 -0.7027
vn -0.0088 0.9652 -0.2615
vn -0.5228 0.5757 -0.6286
vn -0.7857 0.0343 -0.6176
vn -0.7675 0.0673 -0.6375
vn -0.3728 0.8745 -0.3101
vn -0.4913 0.4473 0.7473
vn -0.7768 -0.0183 -0.6294
vn -0.7324 0.1168 -0.6707
vn -0.9076 0.3512 0.2302
vn -0.6250 0.0208 0.7803
vn -0.7855 -0.0935 0.6118
vn 0.5856 -0.0775 -0.8069
vn 0.5796 -0.2771 0.7663
vn -0.6304 -0.4047 -0.6625
vn -0.6562 0.1979 -0.7282
vn -0.7442 0.0494 -0.6662
vn 0.6276 0.2792 0.7268
vn 0.8159 0.5308 0.2294
vn 0.4741 0.2089 -0.8553
vn 0.7393 0.2500 -0.6252
vn -0.7704 -0.0060 -0.6375
vn -0.9047 -0.0229 0.4254
vn -0.0000 0.0799 0.9968
vn -0.6755 -0.0692 -0.7341
vn -0.0000 -0.0232 -0.9997
vn -0.2838 0.8657 -0.4122
vn -0.3393 0.8667 0.3657
vn -0.3718 0.8498 -0.3735
vn -0.3839 0.8664 0.3193
vn 0.6971 -0.2700 -0.6641
vn 0.7610 -0.2061 -0.6151
vn -0.6774 -0.1085 -0.7275
vn -0.6868 -0.0003 -0.7269
vn 0.4602 0.7430 -0.4860
vn 0.3826 0.7883 0.4820
vn -0.7861 0.0431 0.6165
vn -0.6088 -0.5555 0.5664
vn 0.4413 -0.5512 0.7081
vn 0.6370 -0.0566 0.7687
vn 0.6275 -0.0968 0.7726
vn -0.7511 0.1648 0.6393
vn -0.5008 -0.6210 -0.6030
vn 0.5382 -0.7171 -0.4429
vn -0.7709 -0.6324 -0.0756
vn 0.3871 -0.4729 -0.7916
vn 0.7385 -0.6708 -0.0681
vn 0.4595 0.2915 0.8390
vn 0.4668 -0.7203 0.5131
vn -0.5133 0.3853 0.7668
vn -0.7382 -0.5785 0.3470
vn -0.8419 -0.3694 0.3934
vn -0.8355 -0.4752 0.2760
vn -0.8065 -0.4050 -0.4306
vn -0.8282 -0.3596 -0.4299
vn -0.6220 0.5978 -0.5058
vn -0.0000 0.4750 -0.8800
vn -0.0000 -0.8236 0.5672
vn -0.0000 -0.3557 0.9346
vn -0.6195 -0.3078 0.7221
vn -0.0000 -0.5241 -0.8517
vn -0.0000 -0.3802 -0.9249
vn -0.0000 -0.2207 0.9753
vn -0.9946 0.0314 0.0993
vn -0.7148 0.6699 0.2008
vn -0.7088 0.5820 -0.3985
vn -0.8127 -0.0671 -0.5788
vn -0.0000 -0.1189 -0.9929
vn -0.0000 0.9539 0.3001
vn -0.0000 0.7097 -0.7045
vn -0.6498 0.3028 0.6972
vn -0.0000 0.5110 0.8596
vn -0.0000 0.0083 1.0000
vn -0.6999 0.0109 0.7142
vn -0.9231 0.3828 0.0375
vn -0.9990 0.0257 -0.0356
vn 0.4320 0.7175 0.5464
vn 0.4110 0.6925 0.5929
vn 0.3645 0.6539 -0.6630
vn 0.4191 0.5177 -0.7458
vn 0.6252 0.5101 0.5906
vn 0.6186 0.4665 -0.6322
vn 0.8604 0.2027 0.4676
vn 0.4420 0.8027 0.4004
vn 0.9877 0.0416 -0.1505
vn 0.9616 0.2180 -0.1664
vn 0.5097 0.5588 0.6542
vn 0.3101 0.8961 -0.3175
vn -0.0307 0.9995 -0.0000
vn 0.8450 0.4761 -0.2434
vn 0.9912 0.1128 -0.0693
vn 0.5899 0.0904 -0.8024
vn -0.0024 0.9430 -0.3328
vn 0.0530 0.9976 0.0439
vn 0.0088 0.9652 -0.2615
vn 0.5228 0.5757 -0.6286
vn 0.3728 0.8745 -0.3101
vn 0.7675 0.0673 -0.6375
vn 0.7857 0.0343 -0.6176
vn 0.4913 0.4473 0.7473
vn 0.7855 -0.0935 0.6118
vn 0.6250 0.0208 0.7803
vn 0.9076 0.3512 0.2302
vn 0.7325 0.1168 -0.6707
vn 0.7768 -0.0183 -0.6294
vn -0.5856 -0.0775 -0.8069
vn -0.5796 -0.2771 0.7663
vn 0.7442 0.0494 -0.6662
vn 0.6562 0.1979 -0.7282
vn 0.6304 -0.4047 -0.6625
vn -0.6276 0.2792 0.7268
vn -0.7393 0.2500 -0.6252
vn -0.4741 0.2089 -0.8553
vn -0.8159 0.5308 0.2294
vn 0.7704 -0.0060 -0.6375
vn 0.9047 -0.0229 0.4254
vn 0.6755 -0.0692 -0.7341
vn 0.2838 0.8657 -0.4122
vn 0.3393 0.8667 0.3657
vn 0.3839 0.8664 0.3193
vn 0.3718 0.8498 -0.3735
vn -0.6971 -0.2700 -0.6641
vn 0.6868 -0.0003 -0.7269
vn 0.6774 -0.1085 -0.7275
vn -0.7610 -0.2061 -0.6151
vn -0.4602 0.7430 -0.4860
vn -0.3826 0.7883 0.4820
vn 0.7861 0.0431 0.6165
vn -0.6370 -0.0566 0.7687
vn -0.4413 -0.5512 0.7081
vn 0.6088 -0.5555 0.5664
vn -0.6275 -0.0968 0.7726
vn 0.7511 0.1648 0.6393
vn -0.5382 -0.7171 -0.4429
vn 0.5008 -0.6210 -0.6030
vn 0.7709 -0.6324 -0.0756
vn -0.7385 -0.6708 -0.0681
vn -0.3871 -0.4729 -0.7916
vn -0.4668 -0.7203 0.5131
vn -0.4595 0.2915 0.8390
vn 0.5133 0.3853 0.7668
vn 0.7382 -0.5785 0.3470
vn 0.8419 -0.3694 0.3934
vn 0.8282 -0.3596 -0.4299
vn 0.8065 -0.4050 -0.4306
vn 0.8355 -0.4752 0.2760
vn 0.6220 0.5978 -0.5058
vn 0.6195 -0.3078 0.7221
vn 0.9946 0.0314 0.0993
vn 0.8127 -0.0671 -0.5788
vn 0.7088 0.5820 -0.3985
vn 0.7148 0.6699 0.2008
vn 0.6498 0.3028 0.6972
vn 0.6999 0.0109 0.7142
vn 0.9231 0.3828 0.0375
vn 0.9990 0.0257 -0.0356
vt 0.625000 0.533594
vt 0.625000 0.250000
vt 0.469613 0.750000
vt 0.469613 1.089323
vt 0.625000 1.089323
vt 0.625000 0.750000
vt 0.964323 0.750000
vt 0.964323 0.500000
vt 0.375000 0.250000
vt 0.375000 0.500000
vt 0.000000 0.000000
vt 0.469613 0.250000
vt 0.469613 0.500000
vt 0.375000 0.750000
vt 0.375000 1.089323
vt 0.375000 0.000000
vt 0.375000 1.090001
vt 0.375000 0.247735
vt 0.375000 0.250000
vt 0.375000 0.500000
vt 0.369133 -0.068032
vt 0.469613 0.000000
vt 0.375000 1.125950
vt 0.625000 0.000000
vt 0.469613 0.250000
vt 0.469613 0.250000
vt 0.035677 0.500000
vt 0.035677 0.750000
vt 0.964323 0.750000
s 1
usemtl Material
f 1/1/1 85/1/2 86/2/3 5/2/4
f 44/3/5 43/4/6 7/5/7 3/6/8
f 7/7/7 47/7/9 48/8/10 5/8/4
f 108/9/11 13/9/12 11/10/13 110/10/14
f 109/11/15 15/11/16 13/11/12 108/11/11
f 45/12/17 42/13/18 1/1/1 5/2/4
f 12/14/19 18/14/20 20/15/21 14/15/22
f 13/9/12 15/9/16 16/16/23 14/16/22
f 111/11/24 16/11/23 15/11/16 109/11/15
f 113/14/25 12/14/19 14/15/22 112/15/26
f 112/11/26 14/11/22 16/11/23 111/11/24
f 19/9/27 24/9/28 22/10/29 17/10/30
f 14/16/22 20/16/21 19/9/27 13/9/12
f 14/16/22 20/16/21 21/16/20 16/16/23
f 13/9/12 19/9/27 17/10/30 11/10/13
f 22/11/29 27/11/31 28/11/32 23/11/33
f 20/15/21 25/15/34 26/17/20 21/17/20
f 18/14/20 23/14/33 25/15/34 20/15/21
f 20/18/21 25/18/34 24/9/28 19/9/27
f 30/16/35 35/16/36 36/16/37 31/16/38
f 24/11/28 29/11/39 27/11/31 22/11/29
f 25/16/34 30/16/35 31/16/38 26/16/20
f 23/14/33 28/14/32 30/15/35 25/15/34
f 25/11/34 30/11/35 29/11/39 24/11/28
f 35/16/36 75/16/40 40/16/41 39/9/42 76/19/43 34/9/44
f 28/14/32 33/14/45 35/15/36 30/15/35
f 30/16/35 35/16/36 34/9/44 29/9/39
f 27/11/31 32/11/46 33/11/45 28/11/32
f 29/9/39 34/9/44 32/10/46 27/10/31
f 40/16/41 69/16/47 70/16/48 41/16/49
f 78/11/50 37/11/51 38/11/52 77/11/53
f 76/19/43 39/9/42 37/10/51 78/20/50
f 35/16/36 75/16/40 40/16/41 41/16/49 81/16/54 82/16/54 80/16/54 79/16/54 36/16/37
f 33/14/45 77/14/53 38/14/52 40/15/41 75/15/40 35/15/36
f 6/9/55 2/10/56 42/13/18 45/12/17
f 8/21/57 6/9/55 45/12/17 43/22/6
f 4/14/58 8/23/57 43/4/6 44/3/5
f 46/22/59 49/12/60 48/2/10 47/24/9
f 43/4/6 46/4/59 47/5/9 7/5/7
f 46/22/59 52/22/61 53/12/62 49/12/60
f 5/2/4 48/2/10 49/12/60 45/12/17
f 63/4/63 54/4/64 56/4/65 62/4/66
f 43/4/6 50/4/67 52/4/61 46/4/59
f 45/12/17 51/12/68 50/22/67 43/22/6
f 49/12/60 53/12/62 51/12/68 45/12/17
f 57/12/69 61/12/70 59/12/71 55/12/72
f 64/25/73 55/12/72 54/22/64 63/22/63
f 65/26/74 57/12/69 55/12/72 64/25/73
f 62/22/66 56/22/65 57/12/69 65/26/74
f 59/12/71 61/12/70 60/22/75 58/22/76
f 56/22/65 60/22/75 61/12/70 57/12/69
f 54/4/64 58/4/76 60/4/75 56/4/65
f 55/12/72 59/12/71 58/22/76 54/22/64
f 52/22/61 62/22/66 65/26/74 53/12/62
f 53/12/62 65/26/74 64/25/73 51/12/68
f 51/12/68 64/25/73 63/22/63 50/22/67
f 50/4/67 63/4/63 62/4/66 52/4/61
f 68/27/77 69/28/47 67/14/78 66/10/79
f 38/14/52 67/14/78 69/15/47 40/15/41
f 40/16/41 69/16/47 68/9/77 39/9/42
f 37/11/51 66/11/79 67/11/78 38/11/52
f 37/11/51 71/11/80 73/11/81 66/11/79
f 72/9/82 74/9/83 73/10/81 71/10/80
f 66/10/79 73/10/81 74/27/83 68/27/77
f 39/9/42 72/9/82 71/10/80 37/10/51
f 68/9/77 74/9/83 72/9/82 39/9/42
f 34/9/44 76/19/43 78/20/50 32/10/46
f 32/11/46 78/11/50 77/11/53 33/11/45
f 105/8/84 90/8/85 88/7/86 104/29/87
f 7/5/7 84/5/88 83/6/89 3/6/8
f 5/8/4 86/8/3 84/7/88 7/7/7
f 89/1/90 99/1/91 98/2/92 90/2/85
f 104/5/87 88/5/86 87/6/93 106/6/94
f 107/1/95 89/1/90 90/2/85 105/2/84
f 93/8/96 97/8/97 95/7/98 92/7/99
f 90/8/85 93/8/96 92/7/99 88/7/86
f 88/5/86 92/5/99 91/6/100 87/6/93
f 96/1/101 94/6/102 95/7/98 97/8/97
f 92/5/99 95/5/98 94/6/102 91/6/100
f 97/8/97 102/8/103 103/1/104 96/1/101
f 99/1/91 101/1/105 100/2/106 98/2/92
f 101/1/105 103/1/104 102/2/103 100/2/106
f 90/8/85 98/8/92 100/8/106 93/8/96
f 93/8/96 100/8/106 102/8/103 97/8/97
f 85/1/2 107/1/95 105/2/84 86/2/3
f 84/5/88 104/5/87 106/6/94 83/6/89
f 86/8/3 105/8/84 104/29/87 84/7/88
f 8/11/57 112/11/26 111/11/24 10/11/107
f 4/14/58 113/14/25 112/15/26 8/23/57
f 10/11/107 111/11/24 109/11/15 9/11/108
f 9/11/108 109/11/15 108/11/11 6/11/55
f 6/9/55 108/9/11 110/10/14 2/10/56
f 10/11/107 114/11/20 116/11/20 115/11/20
f 1/1/1 117/2/109 186/2/110 85/1/2
f 44/3/5 3/6/8 119/5/111 146/4/112
f 119/7/111 117/8/109 150/8/113 149/7/114
f 198/9/115 110/10/14 11/10/13 123/9/116
f 199/11/117 198/11/115 123/11/116 125/11/118
f 147/12/119 117/2/109 1/1/1 42/13/18
f 12/14/19 124/15/120 128/15/121 18/14/20
f 123/9/116 124/16/120 126/16/122 125/9/118
f 200/11/123 199/11/117 125/11/118 126/11/122
f 113/14/25 201/15/124 124/15/120 12/14/19
f 201/11/124 200/11/123 126/11/122 124/11/120
f 127/9/125 17/10/30 22/10/29 130/9/126
f 124/16/120 123/9/116 127/9/125 128/16/121
f 124/16/120 126/16/122 129/16/20 128/16/121
f 123/9/116 11/10/13 17/10/30 127/9/125
f 128/15/121 129/17/20 132/17/20 131/15/127
f 18/14/20 128/15/121 131/15/127 23/14/33
f 128/18/121 127/9/125 130/9/126 131/18/127
f 134/16/128 135/16/129 140/16/130 139/16/131
f 130/11/126 22/11/29 27/11/31 133/11/132
f 131/16/127 132/16/20 135/16/129 134/16/128
f 23/14/33 131/15/127 134/15/128 28/14/32
f 131/11/127 130/11/126 133/11/132 134/11/128
f 139/16/131 138/9/133 178/19/134 143/9/135 144/16/136 177/16/137
f 28/14/32 134/15/128 139/15/131 137/14/138
f 134/16/128 133/9/132 138/9/133 139/16/131
f 27/11/31 28/11/32 137/11/138 136/11/139
f 133/9/132 27/10/31 136/10/139 138/9/133
f 144/16/136 145/16/140 172/16/141 171/16/142
f 180/11/143 179/11/144 142/11/145 141/11/146
f 178/19/134 180/20/143 141/10/146 143/9/135
f 139/16/131 140/16/130 181/16/147 182/16/147 184/16/147 183/16/147 145/16/140 144/16/136 177/16/137
f 137/14/138 139/15/131 177/15/137 144/15/136 142/14/145 179/14/144
f 118/9/148 147/12/119 42/13/18 2/10/56
f 120/21/149 146/22/112 147/12/119 118/9/148
f 4/14/58 44/3/5 146/4/112 120/23/149
f 148/22/150 149/24/114 150/2/113 151/12/151
f 146/4/112 119/5/111 149/5/114 148/4/150
f 148/22/150 151/12/151 155/12/152 154/22/153
f 117/2/109 147/12/119 151/12/151 150/2/113
f 165/4/154 164/4/155 158/4/156 156/4/157
f 146/4/112 148/4/150 154/4/153 152/4/158
f 147/12/119 146/22/112 152/22/158 153/12/159
f 151/12/151 147/12/119 153/12/159 155/12/152
f 159/12/160 157/12/161 161/12/162 163/12/163
f 166/25/164 165/22/154 156/22/157 157/12/161
f 167/26/165 166/25/164 157/12/161 159/12/160
f 164/22/155 167/26/165 159/12/160 158/22/156
f 161/12/162 160/22/166 162/22/167 163/12/163
f 158/22/156 159/12/160 163/12/163 162/22/167
f 156/4/157 158/4/156 162/4/167 160/4/166
f 157/12/161 156/22/157 160/22/166 161/12/162
f 154/22/153 155/12/152 167/26/165 164/22/155
f 155/12/152 153/12/159 166/25/164 167/26/165
f 153/12/159 152/22/158 165/22/154 166/25/164
f 152/4/158 154/4/153 164/4/155 165/4/154
f 170/27/168 168/10/169 169/14/170 171/28/142
f 142/14/145 144/15/136 171/15/142 169/14/170
f 144/16/136 143/9/135 170/9/168 171/16/142
f 141/11/146 142/11/145 169/11/170 168/11/169
f 141/11/146 168/11/169 175/11/171 173/11/172
f 174/9/173 173/10/172 175/10/171 176/9/174
f 168/10/169 170/27/168 176/27/174 175/10/171
f 143/9/135 141/10/146 173/10/172 174/9/173
f 170/9/168 143/9/135 174/9/173 176/9/174
f 138/9/133 136/10/139 180/20/143 178/19/134
f 136/11/139 137/11/138 179/11/144 180/11/143
f 197/8/175 196/29/176 187/7/177 188/8/178
f 119/5/111 3/6/8 83/6/89 185/5/179
f 117/8/109 119/7/111 185/7/179 186/8/110
f 89/1/90 188/2/178 193/2/180 99/1/91
f 196/5/176 106/6/94 87/6/93 187/5/177
f 107/1/95 197/2/175 188/2/178 89/1/90
f 190/8/181 189/7/182 191/7/183 192/8/184
f 188/8/178 187/7/177 189/7/182 190/8/181
f 187/5/177 87/6/93 91/6/100 189/5/182
f 96/1/101 192/8/184 191/7/183 94/6/102
f 189/5/182 91/6/100 94/6/102 191/5/183
f 192/8/184 96/1/101 103/1/104 195/8/185
f 99/1/91 193/2/180 194/2/186 101/1/105
f 101/1/105 194/2/186 195/2/185 103/1/104
f 188/8/178 190/8/181 194/8/186 193/8/180
f 190/8/181 192/8/184 195/8/185 194/8/186
f 85/1/2 186/2/110 197/2/175 107/1/95
f 185/5/179 83/6/89 106/6/94 196/5/176
f 186/8/110 185/7/179 196/29/176 197/8/175
f 120/11/149 122/11/187 200/11/123 201/11/124
f 4/14/58 120/23/149 201/15/124 113/14/25
f 122/11/187 121/11/188 199/11/117 200/11/123
f 121/11/188 118/11/148 198/11/115 199/11/117
f 118/9/148 2/10/56 110/10/14 198/9/115
f 122/11/187 203/11/20 204/11/20 202/11/20

BIN
assets/jp.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 78 KiB

View File

@@ -1,40 +0,0 @@
# Blender 3.6.4
# www.blender.org
mtllib untitled.mtl
o Cube
v 1.000000 3.829521 -1.000000
v 1.000000 -1.000000 -1.000000
v 1.000000 3.829521 1.000000
v 1.000000 -1.000000 1.000000
v -1.000000 3.829521 -1.000000
v -1.000000 -1.000000 -1.000000
v -1.000000 3.829521 1.000000
v -1.000000 -1.000000 1.000000
vn -0.0000 1.0000 -0.0000
vn -0.0000 -0.0000 1.0000
vn -1.0000 -0.0000 -0.0000
vn -0.0000 -1.0000 -0.0000
vn 1.0000 -0.0000 -0.0000
vn -0.0000 -0.0000 -1.0000
vt 0.625000 0.500000
vt 0.875000 0.500000
vt 0.875000 0.750000
vt 0.625000 0.750000
vt 0.375000 0.750000
vt 0.625000 1.000000
vt 0.375000 1.000000
vt 0.375000 0.000000
vt 0.625000 0.000000
vt 0.625000 0.250000
vt 0.375000 0.250000
vt 0.125000 0.500000
vt 0.375000 0.500000
vt 0.125000 0.750000
s 0
usemtl Material
f 1/1/1 5/2/1 7/3/1 3/4/1
f 4/5/2 3/4/2 7/6/2 8/7/2
f 8/8/3 7/9/3 5/10/3 6/11/3
f 6/12/4 2/13/4 4/5/4 8/14/4
f 2/13/5 1/1/5 3/4/5 4/5/5
f 6/11/6 5/10/6 1/1/6 2/13/6

2737
doxyfile Normal file

File diff suppressed because it is too large Load Diff

21
doxygen/footer.html Normal file
View File

@@ -0,0 +1,21 @@
<!-- HTML footer for doxygen 1.9.1-->
<!-- start footer part -->
<!--BEGIN GENERATE_TREEVIEW-->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
<ul>
$navpath
<li class="footer">$generatedby <a href="https://www.doxygen.org/index.html"><img class="footer"
src="$relpath^doxygen.svg" width="104" height="31" alt="doxygen" /></a> $doxygenversion </li>
</ul>
</div>
<!--END GENERATE_TREEVIEW-->
<!--BEGIN !GENERATE_TREEVIEW-->
<hr class="footer" />
<address class="footer"><small>
$generatedby&#160;<a href="https://www.doxygen.org/index.html"><img class="footer" src="$relpath^doxygen.svg"
width="104" height="31" alt="doxygen" /></a> $doxygenversion
</small></address>
<!--END !GENERATE_TREEVIEW-->
</body>
</html>

66
doxygen/header.html Normal file
View File

@@ -0,0 +1,66 @@
<!-- HTML header for doxygen 1.9.1-->
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=9" />
<meta name="generator" content="Doxygen $doxygenversion" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<!--BEGIN PROJECT_NAME-->
<title>$projectname: $title</title><!--END PROJECT_NAME-->
<!--BEGIN !PROJECT_NAME-->
<title>$title</title><!--END !PROJECT_NAME-->
<link href="$relpath^tabs.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="$relpath^jquery.js"></script>
<script type="text/javascript" src="$relpath^dynsections.js"></script>
$treeview
$search
$mathjax
<link href="$relpath^$stylesheet" rel="stylesheet" type="text/css" />
$extrastylesheet
<script type="text/javascript" src="$relpath^doxygen-awesome-darkmode-toggle.js"></script>
<script type="text/javascript">
DoxygenAwesomeDarkModeToggle.init()
</script>
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<!--BEGIN TITLEAREA-->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
<tbody>
<tr style="height: 56px;">
<!--BEGIN PROJECT_LOGO-->
<td id="projectlogo"><img alt="Logo" src="$relpath^$projectlogo" /></td>
<!--END PROJECT_LOGO-->
<!--BEGIN PROJECT_NAME-->
<td id="projectalign" style="padding-left: 0.5em;">
<div id="projectname">$projectname
<!--BEGIN PROJECT_NUMBER-->&#160;<span id="projectnumber">$projectnumber</span><!--END PROJECT_NUMBER-->
</div>
<!--BEGIN PROJECT_BRIEF-->
<div id="projectbrief">$projectbrief</div><!--END PROJECT_BRIEF-->
</td>
<!--END PROJECT_NAME-->
<!--BEGIN !PROJECT_NAME-->
<!--BEGIN PROJECT_BRIEF-->
<td style="padding-left: 0.5em;">
<div id="projectbrief">$projectbrief</div>
</td>
<!--END PROJECT_BRIEF-->
<!--END !PROJECT_NAME-->
<!--BEGIN DISABLE_INDEX-->
<!--BEGIN SEARCHENGINE-->
<td>$searchbox</td>
<!--END SEARCHENGINE-->
<!--END DISABLE_INDEX-->
</tr>
</tbody>
</table>
</div>
<!--END TITLEAREA-->
<!-- end header part -->

5
doxygen/stylesheet.css Normal file
View File

@@ -0,0 +1,5 @@
/* The standard CSS for doxygen 1.9.1 */
body, table, div, p, dl {
font: 400 14px/22px Roboto,sans-serif;
}

View File

@@ -1,11 +0,0 @@
#pragma once
#include <cstdint>
namespace blitz {
#define REMOVE_COPY(className) \
className(const className&) = delete; \
className& operator=(const className&) = delete
} // namespace blitz

View File

@@ -1,13 +1,23 @@
#pragma once
/**
* \file DataBuffer.h
* \brief File containing the blitz::DataBuffer class
*/
#include <algorithm>
#include <cassert>
#include <cstring>
#include <string>
#include <vector>
#include <cstdint>
namespace blitz {
/**
* \class DataBuffer
* \brief Class used to manipulate memory
*/
class DataBuffer {
private:
typedef std::vector<std::uint8_t> Data;
@@ -44,9 +54,9 @@ class DataBuffer {
return *this;
}
// don't use it for binary data !
DataBuffer& operator<<(const std::string& str) {
// including null character
std::size_t strlen = str.length() + 1;
std::size_t strlen = str.length() + 1; // including null character
Resize(GetSize() + strlen);
std::memcpy(m_Buffer.data() + GetSize() - strlen, str.data(), strlen);
return *this;
@@ -77,6 +87,7 @@ class DataBuffer {
return *this;
}
// Don't use it for binary data !
DataBuffer& operator>>(std::string& str) {
std::size_t stringSize =
strlen(reinterpret_cast<const char*>(m_Buffer.data()) + m_ReadOffset) + 1; // including null character
@@ -118,13 +129,6 @@ class DataBuffer {
m_ReadOffset += amount;
}
void ReadSome(std::string& buffer, std::size_t amount) {
assert(m_ReadOffset + amount <= GetSize());
buffer.resize(amount);
std::copy_n(m_Buffer.begin() + static_cast<difference_type>(m_ReadOffset), amount, buffer.begin());
m_ReadOffset += amount;
}
void Resize(std::size_t size) {
m_Buffer.resize(size);
}
@@ -161,7 +165,6 @@ class DataBuffer {
void SetReadOffset(std::size_t pos);
std::size_t GetSize() const;
std::string ToString() const;
std::size_t GetRemaining() const;
iterator begin();
@@ -171,6 +174,17 @@ class DataBuffer {
bool ReadFile(const std::string& fileName);
bool WriteFile(const std::string& fileName);
// Don't forget to free the data !
std::uint8_t* HeapAllocatedData() const {
std::uint8_t* newBuffer = new std::uint8_t[GetSize()];
std::memcpy(newBuffer, data(), GetSize());
return newBuffer;
}
bool operator==(const DataBuffer& other) const{
return m_Buffer == other.m_Buffer;
}
};
std::ostream& operator<<(std::ostream& os, const DataBuffer& buffer);

View File

@@ -0,0 +1,20 @@
#pragma once
/**
* \file Defines.h
* \brief File containing constants and typedefs
*/
#include <cstdint>
namespace blitz {
namespace game {
/**
* \typedef PlayerID
* \brief Represents the identifier of a Player
*/
typedef std::uint8_t PlayerID;
} // namespace game
} // namespace blitz

View File

@@ -0,0 +1,15 @@
#pragma once
namespace blitz {
class NonCopyable {
public:
NonCopyable(const NonCopyable&) = delete;
NonCopyable& operator=(const NonCopyable&) = delete;
protected:
NonCopyable() {}
~NonCopyable() {}
};
} // namespace blitz

View File

@@ -0,0 +1,19 @@
#pragma once
namespace blitz {
class EMASmoother {
private:
float Alpha;
public:
float Current;
EMASmoother();
void TickUnitT(float target);
void Tick(float target, float delta);
float GetAlpha();
void SetAlpha(float alpha);
void SetSmoothingTime(float t);
};
} // namespace blitz

View File

@@ -0,0 +1,28 @@
#pragma once
#include <cstddef>
#include <cstdint>
namespace blitz {
class DataBuffer;
class VarInt {
private:
std::uint64_t m_Value;
public:
VarInt() : m_Value(0) {}
VarInt(std::uint64_t value) : m_Value(value) {}
std::uint64_t GetValue() const {
return m_Value;
}
std::size_t GetSerializedLength() const;
friend DataBuffer& operator<<(DataBuffer& out, const VarInt& var);
friend DataBuffer& operator>>(DataBuffer& in, VarInt& var);
};
} // namespace blitz

View File

@@ -1,6 +1,7 @@
#pragma once
#include "Player.h"
#include "blitz/misc/Time.h"
#include <map>
namespace blitz {
@@ -8,12 +9,30 @@ namespace game {
typedef std::map<PlayerID, Player> PlayerMap;
enum GameState : std::uint8_t {
gsNone = 0,
gsWaiting,
gsPreparing,
gsGame,
gsEnd,
};
struct GameConfig {
float Gravity;
int FiringRate;
};
class Game {
private:
protected:
PlayerMap m_Players;
GameState m_GameState;
utils::Timer m_GameTimer;
GameConfig m_Config;
public:
Game() {}
Game() : m_GameState(gsNone) {}
virtual void Tick(std::uint64_t delta) = 0;
Player* GetPlayerById(PlayerID id);
const Player* GetPlayerById(PlayerID id) const;
@@ -25,6 +44,25 @@ class Game {
const PlayerMap& GetPlayers() const {
return m_Players;
}
GameState GetGameState() const {
return m_GameState;
}
void LoadConfig(const GameConfig& config) {
m_Config = config;
}
const game::GameConfig& GetGameConfig() const {
return m_Config;
}
virtual void AddPlayer(PlayerID player, const std::string& name);
virtual void RemovePlayer(PlayerID player);
std::uint64_t GetGameStateRemainingTime() const {
return m_GameTimer.GetTimeRemaining();
}
};

View File

@@ -0,0 +1,25 @@
#pragma once
#include "blitz/game/Player.h"
#include <vector>
namespace blitz {
namespace game {
class LeaderBoard {
private:
std::vector<Player*> m_Players;
public:
void AddPlayer(Player* player);
void RemovePlayer(PlayerID player);
void Update();
const std::vector<Player*>& GetPlayers() const {
return m_Players;
}
};
} // namespace game
} // namespace blitz

View File

@@ -0,0 +1,34 @@
#pragma once
#include "blitz/common/Defines.h"
#include "blitz/maths/Vector.h"
#include <vector>
namespace blitz {
namespace protocol {
struct ColoredPart;
typedef std::vector<ColoredPart> ColoredText;
} // namespace protocol
namespace game {
class PlayerInputListener {
public:
virtual void OnLocalPlayerJump() {}
virtual void OnLocalPlayerShoot(const Vec3f& position, float yaw, float pitch) {}
};
class ClientListener {
public:
virtual void OnTextChatReceived(const protocol::ColoredText& text) {}
virtual void OnSpectatorChange(game::PlayerID player) {}
virtual void OnPlayerShoot(PlayerID player, const Vec3f& position, float yaw, float pitch) {}
virtual void OnGameConfigUpdate() {}
};
} // namespace game
} // namespace blitz

View File

@@ -1,20 +1,34 @@
#pragma once
#include "blitz/common/Defines.h"
#include "blitz/maths/Vector.h"
#include <cstdint>
#include <string>
namespace blitz {
namespace game {
typedef std::uint8_t PlayerID;
struct PlayerStats {
std::uint16_t m_Deaths;
std::uint16_t m_Kills;
std::uint32_t m_ShootCount;
std::uint32_t m_ShootSuccessCount;
};
class Player {
private:
PlayerID m_ID;
std::string m_Name;
Vec3f m_Position;
Vec3f m_Velocity;
float m_Yaw;
float m_Pitch;
float m_HP;
bool m_IsBot;
public:
Player(PlayerID id) : m_ID(id) {}
Player(PlayerID id) : m_ID(id), m_Yaw(0), m_Pitch(0), m_HP(100), m_IsBot(false) {}
PlayerStats m_Stats{};
PlayerID GetID() const {
return m_ID;
@@ -27,6 +41,78 @@ class Player {
void SetName(const std::string& name) {
m_Name = name;
}
const Vec3f& GetPosition() const {
return m_Position;
}
void SetPosition(const Vec3f& newPos) {
m_Position = newPos;
}
void AddPosition(const Vec3f& dPos) {
m_Position += dPos;
}
const Vec3f& GetVelocity() const {
return m_Velocity;
}
void SetVelocity(const Vec3f& newVelocity) {
m_Velocity = newVelocity;
}
float GetYaw() const {
return m_Yaw;
}
void SetYaw(float yaw) {
m_Yaw = yaw;
}
void AddYaw(float dYaw) {
m_Yaw += dYaw;
}
float GetPitch() const {
return m_Pitch;
}
void SetPitch(float pitch) {
m_Pitch = pitch;
}
void AddPitch(float dPitch) {
m_Pitch += dPitch;
}
float GetHP() const {
return m_HP;
}
void SetHP(float hp) {
m_HP = hp;
}
bool IsBot() const {
return m_IsBot;
}
void SetBot() {
m_IsBot = true;
}
const PlayerStats& GetStats() const {
return m_Stats;
}
PlayerStats& GetStats() {
return m_Stats;
}
void SetStats(const PlayerStats& stats) {
m_Stats = stats;
}
};

249
include/blitz/maths/Maths.h Normal file
View File

@@ -0,0 +1,249 @@
#pragma once
#include "blitz/maths/Vector.h"
#include <cmath>
namespace blitz {
namespace maths {
static constexpr float PI = 3.141592653f;
template <typename T>
/**
* @brief returns the amount of overlap between the ranges [a1 ; b1] and [a2 ; b2]
*/
T RangesOverlap(T& a1, T& b1, T& a2, T& b2) {
return std::min(std::max(a1, b1), std::max(a2, b2)) - std::max(std::min(a1, b1), std::min(a2, b2));
}
template <typename T>
/**
* @brief returns whether the ranges [a1 ; b1] and [a2 ; b2] overlap
*/
bool RangesOverlapping(T& a1, T& b1, T& a2, T& b2) {
return RangesOverlap(a1, a2, b1, b2) >= 0;
}
//////////////////////////////////////////////////////////////////
// Vectors //
//////////////////////////////////////////////////////////////////
template <typename T>
T Length(const Vec3<T>& vect) {
return std::sqrt(vect.x * vect.x + vect.y * vect.y + vect.z * vect.z);
}
template <typename T>
Vec3<T> Normalize(const Vec3<T>& vect) {
T length = Length(vect);
return {vect.x / length, vect.y / length, vect.z / length};
}
template <typename T>
Vec4<T> Normalize(const Vec4<T>& vect) {
T length = std::sqrt(vect.x * vect.x + vect.y * vect.y + vect.z * vect.z + vect.w * vect.w);
return {vect.x / length, vect.y / length, vect.z / length, vect.w / length};
}
template <typename T>
T Dot(const Vec3<T>& vect, const Vec3<T>& other) {
return vect.x * other.x + vect.y * other.y + vect.z * other.z;
}
template <typename T>
Vec3<T> Cross(const Vec3<T>& vect, const Vec3<T>& other) {
return {
vect.y * other.z - vect.z * other.y,
vect.z * other.x - vect.x * other.z,
vect.x * other.y - vect.y * other.x,
};
}
template <typename T>
T Dot(const Vec4<T>& vect, const Vec4<T>& other) {
return vect.x * other.x + vect.y * other.y + vect.z * other.z + vect.w * other.w;
}
template <typename T>
T Distance(const Vec3<T>& vect, const Vec3<T>& other) {
return Length(vect - other);
}
// it seems that `std::{min, max}`'s behavior conflicts with that of `cmath`'s `f{min, max}[f]`
// Why? Like I fucking know dude
template <typename T>
T ReduceMin(const Vec3<T>& vect) {
return std::min(std::min(vect.x, vect.y), vect.z);
}
template <typename T>
T ReduceMax(const Vec3<T>& vect) {
return std::max(std::max(vect.x, vect.y), vect.z);
}
/**
* @brief returns the (signed) minimal coordinate of the vector
*
* @param v
* @return constexpr T
*/
template <>
inline float ReduceMin<float>(const Vec3f& v) {
return std::fminf(std::fminf(v.x, v.y), v.z);
}
/**
* @brief returns the (signed) maximal coordinate of the vector
*
* @param v
* @return constexpr T
*/
template <>
inline float ReduceMax<float>(const Vec3f& v) {
return std::fmaxf(std::fmaxf(v.x, v.y), v.z);
}
/**
* @brief returns the (signed) minimal coordinate of the vector
*
* @param v
* @return constexpr T
*/
template <>
inline double ReduceMin<double>(const Vec3d& v) {
return std::fmin(std::fmin(v.x, v.y), v.z);
}
/**
* @brief returns the (signed) maximal coordinate of the vector
*
* @param v
* @return constexpr T
*/
template <>
inline double ReduceMax<double>(const Vec3d& v) {
return std::fmax(std::fmax(v.x, v.y), v.z);
}
/**
* @brief returns the coordinate-wise minimum of the given vectors,
* where a coordinate in the returned vector is NAN iff any of the two compared ones are NAN
*
* @tparam T
* @param self
* @param other
* @return constexpr Vec3f
*/
template <typename T>
constexpr Vec3<T> Min(const Vec3<T>& self, const Vec3<T>& other) {
return {
std::min(self.x, other.x),
std::min(self.y, other.y),
std::min(self.z, other.z),
};
}
/**
* @brief returns the coordinate-wise maximum of the given vectors,
* where a coordinate in the returned vector is NAN iff any of the two compared ones are NAN
*
* @tparam T
* @param self
* @param other
* @return constexpr Vec3f
*/
template <typename T>
constexpr Vec3<T> Max(const Vec3<T>& self, const Vec3<T>& other) {
return {
std::max(self.x, other.x),
std::max(self.y, other.y),
std::max(self.z, other.z),
};
}
//////////////////////////////////////////////////////////////////
// Matricies //
//////////////////////////////////////////////////////////////////
template <typename T>
Vec4<T> Dot(const Mat4<T>& mat, const Vec4<T>& vect) {
return {mat.x0 * vect.x + mat.x1 * vect.y + mat.x2 * vect.z + mat.x3 * vect.w,
mat.y0 * vect.x + mat.y1 * vect.y + mat.y2 * vect.z + mat.y3 * vect.w,
mat.z0 * vect.x + mat.z1 * vect.y + mat.z2 * vect.z + mat.z3 * vect.w,
mat.w0 * vect.x + mat.w1 * vect.y + mat.w2 * vect.z + mat.w3 * vect.w};
}
template <typename T>
Mat4<T> Dot(const Mat4<T>& mat, const Mat4<T>& other) {
Mat4<T> result{};
for (std::size_t i = 0; i < Mat4<T>::MATRIX_SIZE; i++) {
for (std::size_t j = 0; j < Mat4<T>::MATRIX_SIZE; j++) {
for (std::size_t k = 0; k < Mat4<T>::MATRIX_SIZE; k++) {
result.at(i, j) += mat.at(i, k) * other.at(k, j);
}
}
}
return result;
}
template <typename T>
Mat4<T> Identity() {
Mat4<T> result{};
result.x0 = static_cast<T>(1);
result.y1 = static_cast<T>(1);
result.z2 = static_cast<T>(1);
result.w3 = static_cast<T>(1);
return result;
}
template <typename T>
Mat4<T> Transpose(const Mat4<T>& mat) {
Mat4<T> result;
result.x1 = mat.y0;
result.x2 = mat.z0;
result.x3 = mat.w0;
result.y0 = mat.x1;
result.y2 = mat.z1;
result.y3 = mat.w1;
result.z0 = mat.x2;
result.z1 = mat.y2;
result.z3 = mat.w2;
result.w0 = mat.x3;
result.w1 = mat.y3;
result.w2 = mat.z3;
result.x0 = mat.x0;
result.y1 = mat.y1;
result.z2 = mat.z2;
result.w3 = mat.w3;
return result;
}
Mat4f Perspective(float fovY, float aspectRatio, float zNear, float zFar);
Mat4f Look(const Vec3f& eyePos, const Vec3f& front, const Vec3f& up);
Mat4f Inverse(const Mat4f& mat);
Mat4f Translate(const Vec3f& translation);
Mat4f Scale(const Vec3f& axisFactor);
Mat4f RotateX(float angle);
Mat4f RotateY(float angle);
Mat4f RotateZ(float angle);
Mat4f Rotate(const Vec3f& angles);
Mat4f Rotate(float angle, Vec3f axis);
} // namespace maths
} // namespace blitz

View File

@@ -0,0 +1,30 @@
#pragma once
#include "blitz/maths/Vector.h"
namespace blitz {
namespace maths {
struct Ray {
Vec3f origin;
Vec3f direction;
};
struct AABB {
Vec3f from;
Vec3f to;
};
inline AABB operator+(const AABB& aabb, const Vec3f& offset) {
AABB result = aabb;
result.from += offset;
result.to += offset;
return result;
}
float Distance(const Ray& ray, const AABB& aabb);
bool Intersects(const Ray& ray, const AABB& aabb);
} // namespace maths
} // namespace blitz

View File

@@ -0,0 +1,322 @@
#pragma once
#include <algorithm>
#include <cmath>
#include <cstddef>
namespace blitz {
//////////////////////////////////////////////////////////////////
// Vector //
//////////////////////////////////////////////////////////////////
template <typename T>
struct Vec2 {
union {
T x;
T r;
};
union {
T y;
T g;
};
constexpr Vec2(T X = 0, T Y = 0) : x(X), y(Y) {}
};
template <typename T>
struct Vec3 {
union {
T x;
T r;
};
union {
T y;
T g;
};
union {
T z;
T b;
};
constexpr Vec3(T X = 0, T Y = 0, T Z = 0) : x(X), y(Y), z(Z) {}
};
template <typename T>
struct Vec4 {
union {
T x;
T r;
};
union {
T y;
T g;
};
union {
T z;
T b;
};
union {
T w;
T a;
};
constexpr Vec4(Vec3<T> vec, T W = 1) : x(vec.x), y(vec.y), z(vec.z), w(W) {}
constexpr Vec4(T X = 0, T Y = 0, T Z = 0, T W = 0) : x(X), y(Y), z(Z), w(W) {}
};
using Vec2uc = Vec2<unsigned char>;
using Vec2i = Vec2<int>;
using Vec2u = Vec2<unsigned int>;
using Vec2f = Vec2<float>;
using Vec2d = Vec2<double>;
using Vec3uc = Vec3<unsigned char>;
using Vec3i = Vec3<int>;
using Vec3u = Vec3<unsigned int>;
using Vec3f = Vec3<float>;
using Vec3d = Vec3<double>;
using Vec4uc = Vec4<unsigned char>;
using Vec4i = Vec4<int>;
using Vec4u = Vec4<unsigned int>;
using Vec4f = Vec4<float>;
using Vec4d = Vec4<double>;
using Color = Vec3uc;
// Vec2
template <typename T>
constexpr bool operator==(const Vec2<T>& vec2, const Vec2<T>& other) {
return vec2.x == other.x && vec2.y == other.y;
}
template <typename T>
constexpr Vec2<T> operator+(const Vec2<T>& vect, const Vec2<T>& other) {
return {vect.x + other.x, vect.y + other.y};
}
template <typename T>
Vec2<T>& operator+=(Vec2<T>& vect, const Vec2<T>& other) {
vect = vect + other;
return vect;
}
template <typename T>
constexpr Vec2<T> operator-(const Vec2<T>& vect) {
return {-vect.x, -vect.y};
}
template <typename T>
constexpr Vec2<T> operator-(const Vec2<T>& vect, const Vec2<T>& other) {
return {vect.x - other.x, vect.y - other.y};
}
template <typename T>
Vec2<T>& operator-=(Vec2<T>& vect, const Vec2<T>& other) {
vect = vect - other;
return vect;
}
template <typename T>
constexpr Vec2<T> operator*(const Vec2<T>& vect, T mult) {
return {vect.x * mult, vect.y * mult};
}
template <typename T>
constexpr Vec2<T> operator*(T mult, const Vec2<T>& vect) {
return vect * mult;
}
// Vec3
template <typename T>
constexpr bool operator==(const Vec3<T>& vec3, const Vec3<T>& other) {
return vec3.x == other.x && vec3.y == other.y && vec3.z == other.z;
}
template <typename T>
constexpr Vec3<T> operator-(const Vec3<T>& vect) {
return {-vect.x, -vect.y, -vect.z};
}
template <typename T>
constexpr Vec3<T> operator+(const Vec3<T>& vect, const Vec3<T>& other) {
return {vect.x + other.x, vect.y + other.y, vect.z + other.z};
}
template <typename T>
Vec3<T>& operator+=(Vec3<T>& vect, const Vec3<T>& other) {
vect = vect + other;
return vect;
}
template <typename T>
constexpr Vec3<T> operator-(const Vec3<T>& vect, const Vec3<T>& other) {
return {vect.x - other.x, vect.y - other.y, vect.z - other.z};
}
template <typename T>
Vec3<T>& operator-=(Vec3<T>& vect, const Vec3<T>& other) {
vect = vect - other;
return vect;
}
template <typename T>
constexpr Vec3<T> operator*(const Vec3<T>& vect, T mult) {
return {vect.x * mult, vect.y * mult, vect.z * mult};
}
template <typename T>
constexpr Vec3<T> operator*(T mult, const Vec3<T>& vect) {
return vect * mult;
}
template <typename T>
constexpr Vec3<T> operator*=(const Vec3<T>& vect, T mult) {
vect = vect * mult;
return vect;
}
template <typename T>
constexpr Vec3<T> operator*=(T mult, const Vec3<T>& vect) {
vect = vect * mult;
return vect;
}
template <typename T>
constexpr Vec3<T> operator*(const Vec3<T>& vect, const Vec3<T>& other) {
return {vect.x * other.x, vect.y * other.y, vect.z * other.z};
}
template <typename T>
Vec3<T>& operator*=(Vec3<T>& vect, const Vec3<T>& other) {
vect = vect * other;
return vect;
}
template <typename T>
constexpr Vec3<T> operator/(const Vec3<T>& vect, const Vec3<T>& other) {
return {vect.x / other.x, vect.y / other.y, vect.z / other.z};
}
template <typename T>
Vec3<T>& operator/=(Vec3<T>& vect, const Vec3<T>& other) {
vect = vect / other;
return vect;
}
template <typename T>
constexpr bool operator<(const Vec3<T>& vec3, const Vec3<T>& other) {
return vec3.x < other.x && vec3.y < other.y && vec3.z < other.z;
}
// Vec4
template <typename T>
constexpr bool operator==(const Vec4<T>& vec4, const Vec4<T>& other) {
return vec4.x == other.x && vec4.y == other.y && vec4.z == other.z && vec4.w == other.w;
}
template <typename T>
constexpr Vec4<T> operator-(const Vec4<T>& vect) {
return {-vect.x, -vect.y, -vect.z, -vect.w};
}
template <typename T>
constexpr Vec4<T> operator+(const Vec4<T>& vect, const Vec4<T>& other) {
return {vect.x + other.x, vect.y + other.y, vect.z + other.z, vect.w + other.w};
}
template <typename T>
Vec4<T>& operator+=(Vec4<T>& vect, const Vec4<T>& other) {
vect = vect + other;
return vect;
}
template <typename T>
constexpr Vec4<T> operator-(const Vec4<T>& vect, const Vec4<T>& other) {
return {vect.x - other.x, vect.y - other.y, vect.z - other.z, vect.w - other.w};
}
template <typename T>
Vec4<T>& operator-=(Vec4<T>& vect, const Vec4<T>& other) {
vect = vect - other;
return vect;
}
template <typename T>
constexpr Vec4<T> operator*(const Vec4<T>& vect, T mult) {
return {vect.x * mult, vect.y * mult, vect.z * mult, vect.w * mult};
}
template <typename T>
constexpr Vec4<T> operator*(T mult, const Vec4<T>& vect) {
return vect * mult;
}
//////////////////////////////////////////////////////////////////
// Matrix //
//////////////////////////////////////////////////////////////////
template <typename T>
struct Mat4 {
static const std::size_t MATRIX_SIZE = 4;
T x0, x1, x2, x3;
T y0, y1, y2, y3;
T z0, z1, z2, z3;
T w0, w1, w2, w3;
T operator[](std::size_t offset) const {
return reinterpret_cast<const T*>(this)[offset];
}
T& operator[](std::size_t offset) {
return reinterpret_cast<T*>(this)[offset];
}
T* data() {
return reinterpret_cast<T*>(this);
}
const T* data() const {
return reinterpret_cast<const T*>(this);
}
T at(std::size_t row, std::size_t column) const {
return operator[](row * MATRIX_SIZE + column);
}
T& at(std::size_t row, std::size_t column) {
return operator[](row * MATRIX_SIZE + column);
}
};
typedef Mat4<float> Mat4f;
typedef Mat4<int> Mat4i;
typedef Mat4<double> Mat4d;
template <typename T>
bool operator==(const Mat4<T>& mat, const Mat4<T>& other) {
return mat.x0 == other.x0 && mat.y0 == other.y0 && mat.z0 == other.z0 && mat.w0 == other.w0 && mat.x1 == other.x1 &&
mat.y1 == other.y1 && mat.z1 == other.z1 && mat.w1 == other.w1 && mat.x2 == other.x2 && mat.y2 == other.y2 &&
mat.z2 == other.z2 && mat.w2 == other.w2 && mat.x3 == other.x3 && mat.y3 == other.y3 && mat.z3 == other.z3 &&
mat.w3 == other.w3;
}
} // namespace blitz

View File

@@ -1,13 +1,36 @@
#pragma once
#include "DataBuffer.h"
/**
* \file Compression.h
* \brief File containing compress utilities
*/
#include "blitz/common/DataBuffer.h"
#include <cstdint>
namespace blitz {
namespace utils {
/**
* \brief Compress some data
* \param buffer the data to compress
* \return the compressed data
*/
DataBuffer Compress(const DataBuffer& buffer);
/**
* \brief Reads the packet lenght and uncompress it
* \param buffer the data to uncompress
* \return the uncompressed data
*/
DataBuffer Decompress(DataBuffer& buffer);
/**
* \brief Uncompress some data
* \param buffer the data to uncompress
* \param packetLength lenght of data
* \return the uncompressed data
*/
DataBuffer Decompress(DataBuffer& buffer, std::uint64_t packetLength);
} // namespace utils

View File

@@ -1,348 +0,0 @@
#pragma once
#include <cmath>
namespace blitz {
static constexpr float PI = 3.141592653f;
template <typename T>
struct Vec2 {
union {
T x;
T r;
};
union {
T y;
T g;
};
constexpr Vec2(T X = 0, T Y = 0) : x(X), y(Y) {}
};
template <typename T>
inline bool operator==(const Vec2<T>& vec2, const Vec2<T>& other) {
return vec2.x == other.x && vec2.y == other.y;
}
template <typename T>
struct Vec3 {
union {
T x;
T r;
};
union {
T y;
T g;
};
union {
T z;
T b;
};
constexpr Vec3(T X = 0, T Y = 0, T Z = 0) : x(X), y(Y), z(Z) {}
};
template <typename T>
inline bool operator==(const Vec3<T>& vec3, const Vec3<T>& other) {
return vec3.x == other.x && vec3.y == other.y && vec3.z == other.z;
}
template <typename T>
struct Vec4 {
union {
T x;
T r;
};
union {
T y;
T g;
};
union {
T z;
T b;
};
union {
T w;
T a;
};
constexpr Vec4(Vec3<T> vec, T W = 1) : x(vec.x), y(vec.y), z(vec.z), w(W) {}
constexpr Vec4(T X = 0, T Y = 0, T Z = 0, T W = 0) : x(X), y(Y), z(Z), w(W) {}
};
template <typename T>
inline bool operator==(const Vec4<T>& vec4, const Vec4<T>& other) {
return vec4.x == other.x && vec4.y == other.y && vec4.z == other.z && vec4.w = other.w;
}
using Vec2uc = Vec2<unsigned int>;
using Vec2i = Vec2<int>;
using Vec2u = Vec2<unsigned int>;
using Vec2f = Vec2<float>;
using Vec2d = Vec2<double>;
using Vec3uc = Vec3<unsigned int>;
using Vec3i = Vec3<int>;
using Vec3u = Vec3<unsigned int>;
using Vec3f = Vec3<float>;
using Vec3d = Vec3<double>;
using Vec4uc = Vec4<unsigned int>;
using Vec4i = Vec4<int>;
using Vec4u = Vec4<unsigned int>;
using Vec4f = Vec4<float>;
using Vec4d = Vec4<double>;
using Color = Vec3<unsigned char>;
template <typename T>
struct Mat4 {
static const std::size_t MATRIX_SIZE = 4;
T x0, x1, x2, x3;
T y0, y1, y2, y3;
T z0, z1, z2, z3;
T w0, w1, w2, w3;
T operator[](std::size_t offset) const {
return reinterpret_cast<const T*>(this)[offset];
}
T& operator[](std::size_t offset) {
return reinterpret_cast<T*>(this)[offset];
}
T* data() {
return reinterpret_cast<T*>(this);
}
const T* data() const {
return reinterpret_cast<const T*>(this);
}
T at(std::size_t row, std::size_t column) const {
return operator[](row* MATRIX_SIZE + column);
}
T& at(std::size_t row, std::size_t column) {
return operator[](row* MATRIX_SIZE + column);
}
};
typedef Mat4<float> Mat4f;
typedef Mat4<int> Mat4i;
typedef Mat4<double> Mat4d;
template <typename T>
inline bool operator==(const Mat4<T>& mat, const Mat4<T>& other) {
return mat.x0 == other.x0 && mat.y0 == other.y0 && mat.z0 == other.z0 && mat.w0 == other.w0 && mat.x1 == other.x1 &&
mat.y1 == other.y1 && mat.z1 == other.z1 && mat.w1 == other.w1 && mat.x2 == other.x2 && mat.y2 == other.y2 &&
mat.z2 == other.z2 && mat.w2 == other.w2 && mat.x3 == other.x3 && mat.y3 == other.y3 && mat.z3 == other.z3 &&
mat.w3 == other.w3;
}
//////////////////////////////////////////////////////////////////
// Operators //
//////////////////////////////////////////////////////////////////
template <typename T>
Vec2<T> operator+(const Vec2<T>& vect, const Vec2<T>& other) {
return {vect.x + other.x, vect.y + other.y};
}
template <typename T>
void operator+=(Vec2<T>& vect, const Vec2<T>& other) {
vect = vect + other;
}
template <typename T>
Vec2<T> operator-(const Vec2<T>& vect) {
return {-vect.x, -vect.y};
}
template <typename T>
Vec2<T> operator-(const Vec2<T>& vect, const Vec2<T>& other) {
return vect + (-other);
}
template <typename T>
void operator-=(Vec2<T>& vect, const Vec2<T>& other) {
vect = vect - other;
}
template <typename T>
Vec3<T> operator-(const Vec3<T>& vect) {
return {-vect.x, -vect.y, -vect.z};
}
template <typename T>
Vec3<T> operator+(const Vec3<T>& vect, const Vec3<T>& other) {
return {vect.x + other.x, vect.y + other.y, vect.z + other.y};
}
template <typename T>
void operator+=(Vec3<T>& vect, const Vec3<T>& other) {
vect = vect + other;
}
template <typename T>
Vec3<T> operator-(const Vec3<T>& vect, const Vec3<T>& other) {
return vect + (-other);
}
template <typename T>
void operator-=(Vec3<T>& vect, const Vec3<T>& other) {
vect = vect - other;
}
template <typename T>
Vec4<T> operator-(const Vec4<T>& vect) {
return {-vect.x, -vect.y, -vect.z, -vect.w};
}
template <typename T>
Vec4<T> operator+(const Vec4<T>& vect, const Vec4<T>& other) {
return {vect.x + other.x, vect.y + other.y, vect.z + other.y, vect.w + other.w};
}
template <typename T>
Vec4<T> operator+=(Vec4<T>& vect, const Vec4<T>& other) {
vect = vect + other;
}
template <typename T>
Vec4<T> operator-(const Vec4<T>& vect, const Vec4<T>& other) {
return vect + (-other);
}
template <typename T>
Vec4<T> operator-=(Vec4<T>& vect, const Vec4<T>& other) {
vect = vect - other;
}
//////////////////////////////////////////////////////////////////
// Vectors //
//////////////////////////////////////////////////////////////////
namespace maths {
template <typename T>
T Length(const Vec3<T>& vect) {
return std::sqrt(vect.x * vect.x + vect.y * vect.y + vect.z * vect.z);
}
template <typename T>
Vec3<T> Normalize(const Vec3<T>& vect) {
T length = Length(vect);
return {vect.x / length, vect.y / length, vect.z / length};
}
template <typename T>
Vec4<T> Normalize(const Vec4<T>& vect) {
T length = std::sqrt(vect.x * vect.x + vect.y * vect.y + vect.z * vect.z + vect.w * vect.w);
return {vect.x / length, vect.y / length, vect.z / length, vect.w / length};
}
template <typename T>
T Dot(const Vec3<T>& vect, const Vec3<T>& other) {
return vect.x * other.x + vect.y * other.y + vect.z * other.z;
}
template <typename T>
Vec3<T> Cross(const Vec3<T>& vect, const Vec3<T>& other) {
return {
vect.y * other.z - vect.z * other.y,
vect.z * other.x - vect.x * other.z,
vect.x * other.y - vect.y * other.x,
};
}
template <typename T>
T Dot(const Vec4<T>& vect, const Vec4<T>& other) {
return vect.x * other.x + vect.y * other.y + vect.z * other.z + vect.w * other.w;
}
template <typename T>
T Distance(const Vec3<T>& vect, const Vec3<T>& other) {
return Length(vect - other);
}
//////////////////////////////////////////////////////////////////
// Matricies //
//////////////////////////////////////////////////////////////////
template <typename T>
Vec4<T> Dot(const Mat4<T>& mat, const Vec4<T>& vect) {
return {mat.x0 * vect.x + mat.x1 * vect.y + mat.x2 * vect.z + mat.x3 * vect.w,
mat.y0 * vect.x + mat.y1 * vect.y + mat.y2 * vect.z + mat.y3 * vect.w,
mat.z0 * vect.x + mat.z1 * vect.y + mat.z2 * vect.z + mat.z3 * vect.w,
mat.w0 * vect.x + mat.w1 * vect.y + mat.w2 * vect.z + mat.w3 * vect.w};
}
template <typename T>
Mat4<T> Dot(const Mat4<T>& mat, const Mat4<T>& other) {
Mat4<T> result{};
for (std::size_t i = 0; i < Mat4<T>::MATRIX_SIZE; i++) {
for (std::size_t j = 0; j < Mat4<T>::MATRIX_SIZE; j++) {
for (std::size_t k = 0; k < Mat4<T>::MATRIX_SIZE; k++) {
result.at(i, j) += mat.at(i, k) * other.at(k, j);
}
}
}
return result;
}
template <typename T>
Mat4<T> Identity() {
Mat4<T> result{};
result.x0 = static_cast<T>(1);
result.y1 = static_cast<T>(1);
result.z2 = static_cast<T>(1);
result.w3 = static_cast<T>(1);
return result;
}
template <typename T>
Mat4<T> Transpose(const Mat4<T>& mat) {
Mat4<T> result;
result.x1 = mat.y0;
result.x2 = mat.z0;
result.x3 = mat.w0;
result.y0 = mat.x1;
result.y2 = mat.z1;
result.y3 = mat.w1;
result.z0 = mat.x2;
result.z1 = mat.y2;
result.z3 = mat.w2;
result.w0 = mat.x3;
result.w1 = mat.y3;
result.w2 = mat.z3;
result.x0 = mat.x0;
result.y1 = mat.y1;
result.z2 = mat.z2;
result.w3 = mat.w3;
return result;
}
Mat4f Perspective(float fovY, float aspectRatio, float zNear, float zFar);
Mat4f Look(const Vec3f& eyePos, const Vec3f& front, const Vec3f& up);
Mat4f Inverse(const Mat4f& mat);
} // namespace maths
} // namespace blitz

View File

@@ -0,0 +1,25 @@
#pragma once
#include "blitz/maths/Vector.h"
#include <string>
namespace blitz {
namespace utils {
namespace TextColor {
const static Vec3uc AQUA = {0, 255, 255};
const static Vec3uc BLUE = {0, 0, 255};
const static Vec3uc GREEN = {0, 255, 0};
const static Vec3uc PURPLE = {255, 0, 255};
const static Vec3uc RED = {255, 0, 0};
const static Vec3uc WHITE = {255, 255, 255};
const static Vec3uc YELLOW = {255, 255, 0};
} // namespace TextColor
std::string GetTextColor(Vec3uc color);
std::string GetTextColorReset();
} // namespace utils
} // namespace blitz

58
include/blitz/misc/Test.h Normal file
View File

@@ -0,0 +1,58 @@
#pragma once
/**
* \file Test.h
* \brief File containing unit testing utilities
*/
#include <cstdlib>
namespace blitz {
namespace utils {
#define BLITZ_TEST_SUCCESSFUL 0
#define BLITZ_TEST_FAILED 1
#ifndef __FUNCTION_NAME__
#ifdef _WIN32
#define __FUNCTION_NAME__ __FUNCTION__
#else
#define __FUNCTION_NAME__ __PRETTY_FUNCTION__
#endif
#endif
/**
* \def blitz_test_assert
* \param ... The expression to evaluate
* \brief Evaluates the expression and exits the program if not valid
*/
#define blitz_test_assert(...) \
if (!static_cast<bool>(__VA_ARGS__)) { \
blitz::utils::LOGAssert(#__VA_ARGS__, __FILE__, __LINE__, __FUNCTION_NAME__); \
std::exit(BLITZ_TEST_FAILED); \
}
/**
* \def blitz_debug_assert
* \param ... The expression to execute
* \brief Assertion without checks in release mode
*/
#ifdef NDEBUG
#define blitz_debug_assert(...) __VA_ARGS__
#else
#define blitz_debug_assert blitz_test_assert
#endif
/**
* \brief Prints an error message associated with a failed assertion
* \param expression The expression that was tested
* \param file The file in which the assertion failed
* \param line The line in the file in which the assertion failed
* \param function The function in which the assertion failed
*/
void LOGAssert(const char* expression, const char* file, int line, const char* function);
} // namespace utils
} // namespace blitz

View File

@@ -59,6 +59,15 @@ class Timer {
bool Update(std::uint64_t delta);
void Reset();
// void ResetSoft(); // don't trigger the timer
std::uint64_t GetTimeRemaining() const {
return m_Interval - m_InternalTime;
}
std::uint64_t GetTimeElapsed() const {
return m_InternalTime;
}
void SetInterval(std::uint64_t newInterval) {
m_Interval = newInterval;
@@ -70,29 +79,74 @@ class Timer {
};
// utililty class to trigger update at regular period of time with a cooldown
template <typename T>
class CooldownTimer {
private:
std::uint64_t m_Cooldown; // in millis
std::uint64_t m_CooldownTime;
T m_Cooldown;
T m_CooldownTime;
public:
CooldownTimer() : m_Cooldown(0), m_CooldownTime(0) {}
CooldownTimer(std::uint64_t cooldown) : m_Cooldown(0), m_CooldownTime(cooldown) {}
CooldownTimer(T cooldown) : m_Cooldown(0), m_CooldownTime(cooldown) {}
bool Update(std::uint64_t delta);
bool Update(T delta) {
if (m_Cooldown > 0) {
m_Cooldown = std::max<T>(static_cast<T>(0), static_cast<T>(m_Cooldown - delta));
}
return m_Cooldown == 0;
}
void ApplyCooldown();
void ApplyCooldown() {
m_Cooldown = m_CooldownTime;
}
void Reset();
void Reset() {
m_Cooldown = 0;
}
void SetCooldown(std::uint64_t newCooldown) {
void SetCooldown(T newCooldown) {
m_CooldownTime = newCooldown;
}
std::uint64_t GetCooldown() const {
T GetCooldown() const {
return m_CooldownTime;
}
};
// utililty class to trigger update at regular period of time with a cooldown
template <typename T>
class DelayTimer {
private:
T m_DelayTime;
T m_InternalTime;
public:
DelayTimer() : m_DelayTime(0), m_InternalTime(0) {}
DelayTimer(T delay) : m_DelayTime(delay), m_InternalTime(delay) {}
/**
* \brief Returns true whether the delay has been passed.
*/
bool Update(T delta) {
m_InternalTime = std::max<T>(static_cast<T>(0), static_cast<T>(m_InternalTime - delta));
return m_InternalTime == 0;
}
/**
* \brief Resets the timer
*/
void Reset() {
m_InternalTime = m_DelayTime;
}
void SetDelay(T newDelay) {
m_DelayTime = newDelay;
}
T GetDelay() const {
return m_DelayTime;
}
};
} // namespace utils
} // namespace blitz

View File

@@ -1,5 +1,10 @@
#pragma once
/**
* \file Connexion.h
* \brief File containing the blitz::network::Connexion class
*/
#include "TCPSocket.h"
#include "blitz/protocol/PacketDispatcher.h"
#include "blitz/protocol/PacketHandler.h"
@@ -7,7 +12,11 @@
namespace blitz {
namespace network {
class Connexion : public protocol::PacketHandler {
/**
* \class Connexion
* \brief Represents a network connexion
*/
class Connexion : public protocol::PacketHandler, private NonCopyable {
protected:
protocol::PacketDispatcher m_Dispatcher;
@@ -15,24 +24,54 @@ class Connexion : public protocol::PacketHandler {
TCPSocket m_Socket;
public:
/**
* \brief Constructs with an empty socket
*/
Connexion(protocol::PacketDispatcher* dispatcher);
/**
* \brief Constructs with an already connected socket
*/
Connexion(protocol::PacketDispatcher* dispatcher, TCPSocket& socket);
/**
* \brief Move constructor
*/
Connexion(Connexion&& move);
/**
* \brief Default destructor
*/
virtual ~Connexion();
/**
* \brief Reads socket and process a Packet, if any
*/
virtual bool UpdateSocket();
/**
* \brief Closes the connexion
*/
void CloseConnection();
/**
* \brief Tries to connect the socket at the specified address and port
* \return Wether this action was succesfull
*/
virtual bool Connect(const std::string& address, std::uint16_t port);
/**
* \brief Returns the TCPSocket::Status of the internal socket
*/
TCPSocket::Status GetSocketStatus() const {
return m_Socket.GetStatus();
}
/**
* \brief Sends the protocol::Packet over the network to the remote
* \param packet The protocol::Packet to send
*/
void SendPacket(const protocol::Packet* packet);
REMOVE_COPY(Connexion);
};
} // namespace network

View File

@@ -1,51 +0,0 @@
#pragma once
#include <string>
#include <vector>
namespace blitz {
namespace network {
/* IPv4 address */
class IPAddress {
private:
std::uint32_t m_Address;
bool m_Valid;
public:
/* Create an invalid address */
IPAddress() noexcept;
/* Initialize by string IP */
IPAddress(const std::string& str);
/* Initialize by octets */
IPAddress(std::uint8_t octet1, std::uint8_t octet2, std::uint8_t octet3, std::uint8_t octet4) noexcept;
/* Get the specific octet. 1-4 */
std::uint8_t GetOctet(std::uint8_t num) const;
/* Set the specific octet. 1-4 */
void SetOctet(std::uint8_t num, std::uint8_t value);
/* Make sure the IP is valid. It will be invalid if the host wasn't found. */
bool IsValid() const noexcept {
return m_Valid;
}
std::string ToString() const;
static IPAddress LocalAddress();
bool operator==(const IPAddress& right);
bool operator!=(const IPAddress& right);
bool operator==(bool b);
};
typedef std::vector<IPAddress> IPAddresses;
std::ostream& operator<<(std::ostream& os, const IPAddress& addr);
std::wostream& operator<<(std::wostream& os, const IPAddress& addr);
} // namespace network
} // namespace blitz

View File

@@ -1,25 +1,36 @@
#pragma once
#ifdef _WIN32
#include <ws2tcpip.h>
#else
#include <arpa/inet.h>
#include <fcntl.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <unistd.h>
#endif
/**
* \file Network.h
* \brief File containing the blitz::network::NetworkInitializer class
*/
#include "IPAddress.h"
#include "TCPSocket.h"
namespace blitz {
/**
* \namespace blitz::network
* \brief Namespace containing all classes related to networking
*/
namespace network {
class Dns {
/**
* \class NetworkInitializer
* \brief Class used to initialize the network (only does something on Windows).
* \note This class is meant to be created only once in your program. \n
* The easiest thing to do is to create an instance of this class at the top of your **main.cpp**.
*/
class NetworkInitializer : private NonCopyable {
public:
static IPAddresses Resolve(const std::string& host);
/**
* \brief Creates the networking context
*/
NetworkInitializer();
/**
* \brief Destroys the networking context
*/
~NetworkInitializer();
};
} // namespace network

View File

@@ -1,36 +1,84 @@
#pragma once
/**
* \file TCPListener.h
* \brief File containing the blitz::network::TCPListener class
*/
#include "TCPSocket.h"
#include "blitz/Defines.h"
namespace blitz {
namespace network {
class TCPListener {
int m_Handle;
/**
* \class TCPListener
* \brief Cross platform abstraction of a TCP socket server
*/
class TCPListener : private NonCopyable {
private:
SocketHandle m_Handle;
std::uint16_t m_Port;
int m_MaxConnections;
public:
/**
* \brief Default constructor
*/
TCPListener();
/**
* \brief Default destructor
*/
~TCPListener();
bool Listen(std::uint16_t port, int maxConnections);
/**
* \brief Starts listening for guests to connect
* \param port The port to listen to
* \param maxConnexions The maximum amount of connexion that can happen at the same time. \n
* Every other guests will be kicked if this amount is reached.
* \return Wether this action was succesfull
*/
bool Listen(std::uint16_t port, int maxConnexions);
/**
* \brief Tries to accept an incoming request to connect
* \param newSocket the empty socket to put the result to
* \return true if a new connexion was accepted
*/
bool Accept(TCPSocket& newSocket);
/**
* \brief Destroys the socket
*/
void Destroy();
/**
* \brief Closes transmissions
* \return true if this action was succesfull
*/
bool Close();
/**
* \brief Allows to set the socket in non blocking/blocking mode
* \param block If set to true, every call to Read will wait until the socket receives something
* \return true if the operation was successful
*/
bool SetBlocking(bool blocking);
/**
* \brief Getter of the m_Port member
* \return The port which the socket listen to
*/
std::uint16_t GetListeningPort() const {
return m_Port;
}
/**
* \brief Getter of the m_MaxConnections member
* \return The maximum amount of connexions that can happen at the same time.
*/
int GetMaximumConnections() const {
return m_MaxConnections;
}
REMOVE_COPY(TCPListener);
};
} // namespace network

View File

@@ -1,13 +1,7 @@
#pragma once
#include <memory>
#include <string>
#include <vector>
#include "IPAddress.h"
#include "blitz/Defines.h"
#include "blitz/misc/DataBuffer.h"
#include "blitz/common/DataBuffer.h"
#include "blitz/common/NonCopyable.h"
#ifdef _WIN32
#include <winsock2.h>
@@ -28,60 +22,146 @@
#define INVALID_SOCKET -1
#endif
/**
* \file TCPSocket.h
* \brief File containing the blitz::network::TCPSocket class
*/
namespace blitz {
namespace network {
class IPAddress;
/**
* \typedef SocketHandle
* \brief Represents a native socket
*/
typedef int SocketHandle;
class TCPSocket {
/**
* \class TCPSocket
* \brief Cross platform abstraction of a TCP socket
*/
class TCPSocket : private NonCopyable {
public:
enum class Status { Connected, Disconnected, Error };
/**
* \enum Status
* \brief Describes the state of a socket
*/
enum class Status {
/** The socket is connected */
Connected,
/** The socket is not connected */
Disconnected,
/** Something bad happened */
Error,
};
private:
bool m_Blocking;
Status m_Status;
SocketHandle m_Handle;
IPAddress m_RemoteIP;
std::uint16_t m_Port;
sockaddr m_RemoteAddr;
public:
/**
* \brief Default constructor
*/
TCPSocket();
TCPSocket(TCPSocket&&);
/**
* \brief Default destructor
*/
virtual ~TCPSocket();
/**
* \brief Move constructor
*/
TCPSocket(TCPSocket&&);
/**
* \brief Sets the TCPSocket::Status of the socket
* \param status The TCPSocket::Status to apply
*/
void SetStatus(Status status);
/**
* \brief Allows to set the socket in non blocking/blocking mode
* \param block If set to true, every call to Read will wait until the socket receives something
* \return true if the operation was successful
*/
bool SetBlocking(bool block);
bool IsBlocking() const noexcept;
Status GetStatus() const noexcept;
SocketHandle GetHandle() const noexcept;
/**
* \brief Checks if the socket is in blocking mode
* \return Whether the socket is in blocking mode
*/
bool IsBlocking() const;
bool Connect(const std::string& ip, std::uint16_t port);
bool Connect(const IPAddress& address, std::uint16_t port);
/**
* \brief Getter of the m_Status member
* \return The TCPSocket::Status of this socket
*/
Status GetStatus() const;
/**
* \brief Tries to connect to the host at the given port
* \param host The host to connect to. Can be a hostname or an ip address.
* \param port The port to connect to.
* \return Whether this action was successfull
*/
bool Connect(const std::string& host, std::uint16_t port);
/**
* \brief Disconnects the socket from the remote
* \note Does nothing if the socket is not connected. \n
* This function is also called by the destructor.
*/
void Disconnect();
std::size_t Send(const std::string& data);
/**
* \brief Sends some data
* \param buffer The data to send
* \note Simply returns 0 if the socket is not connected
* \return The amount of data sent. It should be the size of the buffer in theory.
*/
std::size_t Send(DataBuffer& buffer);
std::size_t Send(const uint8_t* data, std::size_t size);
/**
* \brief Sends some data
* \param data The data to send
* \param size The amount of data to send
* \note Simply returns 0 if the socket is not connected
* \return The amount of data sent. It should be equal to the size param in theory
*/
std::size_t Send(const std::uint8_t* data, std::size_t size);
/**
* \brief Reads some data
* \param amount The amount of data to read
* \return The buffer containing the data that have been received
* \note If no data is available, an empty DataBuffer is returned
*/
DataBuffer Receive(std::size_t amount);
/**
* \brief Reads some data
* \param buffer The buffer to write into
* \param amount The amount of data to read
* \return The amount of data read
* \note If no data is available, 0 is returned
*/
std::size_t Receive(DataBuffer& buffer, std::size_t amount);
REMOVE_COPY(TCPSocket);
friend class TCPListener;
};
/**
* \brief Compress the data and send it to the socket
* \param data The data to send
* \param socket The socket to send to
*/
void SendPacket(const DataBuffer& data, network::TCPSocket& socket);
typedef std::shared_ptr<TCPSocket> SocketPtr;
} // namespace network
} // namespace blitz

View File

@@ -3,7 +3,6 @@
#include "blitz/protocol/Protocol.h"
#include <map>
#include <vector>
namespace blitz {
namespace protocol {
@@ -22,7 +21,7 @@ class PacketDispatcher {
PacketDispatcher(PacketDispatcher&& rhs) = delete;
PacketDispatcher& operator=(PacketDispatcher&& rhs) = delete;
void Dispatch(const PacketPtr& packet);
void Dispatch(const Packet* packet);
void RegisterHandler(PacketType type, PacketHandler* handler);
void UnregisterHandler(PacketType type, PacketHandler* handler);

View File

@@ -6,7 +6,7 @@ namespace blitz {
namespace protocol {
namespace PacketFactory {
PacketPtr CreatePacket(PacketType type, DataBuffer& buffer);
const Packet* CreatePacket(PacketType type, DataBuffer& buffer);
}
} // namespace protocol

View File

@@ -28,7 +28,13 @@ class PacketHandler {
virtual void HandlePacket(const PlayerLeavePacket* packet) {}
virtual void HandlePacket(const PlayerListPacket* packet) {}
virtual void HandlePacket(const PlayerLoginPacket* packet) {}
virtual void HandlePacket(const PlayerPositionAndRotationPacket* packet) {}
virtual void HandlePacket(const PlayerShootPacket* packet) {}
virtual void HandlePacket(const PlayerStatsPacket* packet) {}
virtual void HandlePacket(const ServerConfigPacket* packet) {}
virtual void HandlePacket(const ServerTpsPacket* packet) {}
virtual void HandlePacket(const UpdateGameStatePacket* packet) {}
virtual void HandlePacket(const UpdateHealthPacket* packet) {}
};
} // namespace protocol

View File

@@ -1,9 +1,15 @@
#include "packets/ChatPacket.h"
#include "packets/ConnectionInfoPacket.h"
#include "packets/ConnexionInfoPacket.h"
#include "packets/DisconnectPacket.h"
#include "packets/KeepAlivePacket.h"
#include "packets/PlayerJoinPacket.h"
#include "packets/PlayerLeavePacket.h"
#include "packets/PlayerListPacket.h"
#include "packets/PlayerLoginPacket.h"
#include "packets/ServerTpsPacket.h"
#include "packets/PlayerPositionAndRotationPacket.h"
#include "packets/PlayerShootPacket.h"
#include "packets/PlayerStatsPacket.h"
#include "packets/ServerConfigPacket.h"
#include "packets/ServerTpsPacket.h"
#include "packets/UpdateGameStatePacket.h"
#include "packets/UpdateHealthPacket.h"

View File

@@ -11,7 +11,13 @@ class PlayerJoinPacket;
class PlayerLeavePacket;
class PlayerListPacket;
class PlayerLoginPacket;
class PlayerPositionAndRotationPacket;
class PlayerShootPacket;
class PlayerStatsPacket;
class ServerConfigPacket;
class ServerTpsPacket;
class UpdateGameStatePacket;
class UpdateHealthPacket;
} // namespace protocol
} // namespace blitz

View File

@@ -1,66 +1,103 @@
#pragma once
#include "blitz/misc/DataBuffer.h"
/**
* \file Protocol.h
* \brief File describing protocol
*/
#include <memory>
#include "blitz/common/DataBuffer.h"
namespace blitz {
namespace protocol {
class PacketHandler;
/////////////////////////////////////////////
// Packet Structure //
/////////////////////////////////////////////
// /// //
// PacketID /// PacketData //
// /// //
/////////////////////////////////////////////
// /// //
// 1 byte /// varying size //
// /// //
/////////////////////////////////////////////
/**
* \enum PacketType
* \brief Map the packets name to their ID
*/
enum class PacketType : std::uint8_t {
// client --> server
PlayerLogin = 0,
PlayerLogin = 0, /**< Corresponds to PlayerLoginPacket */
UpdateHealth, /**< Corresponds to UpdateHealthPacket */
// client <-- server
ConnectionInfo,
PlayerJoin,
PlayerLeave,
PlayerList,
ServerTps,
ConnexionInfo, /**< Corresponds to ConnexionInfoPacket */
PlayerJoin, /**< Corresponds to PlayerJoinPacket */
PlayerLeave, /**< Corresponds to PlayerLeavePacket */
PlayerList, /**< Corresponds to PlayerListPacket */
PlayerStats, /**< Corresponds to PlayerStatsPacket */
ServerConfig, /**< Corresponds to ServerConfigPacket*/
ServerTps, /**< Corresponds to ServerTpsPacket */
UpdateGameState, /**< Corresponds to UpdateGameStatePacket */
// client <--> server
KeepAlive,
Disconnect,
Chat,
KeepAlive, /**< Corresponds to KeepAlivePacket */
Disconnect, /**< Corresponds to DisconnectPacket */
Chat, /**< Corresponds to ChatPacket */
PlayerPositionAndRotation, /**< Corresponds to PlayerPositionAndRotationPacket */
PlayerShoot, /**< Corresponds to PlayerShootPacket */
PACKET_COUNT
};
/**
* \class Packet
* \brief Represents a network packet <br/>
* %Packet data structure :
*| Field Name | Field Type | Notes |
*|---------------------|---------------|-------------------------------|
*| Length | Long | Length of whole Packet |
*| Uncompressed Length | VarInt | Length of Packet ID + Data |
*| Packet ID | Byte | Represents the #PacketType |
*| Data | Byte Array | Depends on the packet ID |
*/
class Packet {
public:
Packet() {}
virtual ~Packet() {}
/**
* \brief Serialize the Packet into a DataBuffer to be sent over the network
* \param packetID Set to false if you don't want to write the Packet ID for some reason
* \returns A DataBuffer filled with the serialized Packet
*/
virtual DataBuffer Serialize(bool packetID = true) const = 0;
/**
* \brief Deserialize the DataBuffer into a Packet to be read by the client/server
* \param data The DataBuffer containing the data from the network
*/
virtual void Deserialize(DataBuffer& data) = 0;
/**
* \brief Dispatches the Packet
* \param handler The class to dispatch the Packet to
*/
virtual void Dispatch(PacketHandler* handler) const = 0;
/**
* \brief Writes the Packet ID into a buffer
* \param data The DataBuffer to write to
* \param packetID If set to false, this function does nothing
*/
void WritePacketID(DataBuffer& data, bool packetID) const;
/**
* \returns The type of the Packet
*/
virtual PacketType GetType() const = 0;
/**
* \returns The Packet ID corresponding to the PacketType of this Packet
*/
std::uint8_t GetID() const {
return static_cast<std::uint8_t>(GetType());
}
};
typedef std::unique_ptr<Packet> PacketPtr;
} // namespace protocol
} // namespace blitz

View File

@@ -1,6 +1,6 @@
#pragma once
#include "blitz/misc/Maths.h"
#include "blitz/maths/Vector.h"
#include "blitz/protocol/Protocol.h"
#include <vector>
@@ -32,13 +32,13 @@ class ChatPacket : public Packet {
return m_Message;
}
static std::string GetTextColor(Vec3uc color);
static ColoredText ColorizeText(const std::string& text);
static std::string GetColoredTextString(const ColoredText& text);
virtual PacketType GetType() const {
return PacketType::Chat;
}
static std::string GetTextColor(Vec3uc color);
static ColoredText ColorizeText(const std::string& text);
static std::string GetColoredTextString(const ColoredText& text);
};
const static Vec3uc AQUA = {0, 255, 255};

View File

@@ -23,7 +23,7 @@ class ConnexionInfoPacket : public Packet {
}
virtual PacketType GetType() const {
return PacketType::ConnectionInfo;
return PacketType::ConnexionInfo;
}
};

View File

@@ -1,13 +1,33 @@
#pragma once
/**
* \file KeepAlivePacket.h
* \brief File containing the blitz::protocol::KeepAlivePacket class
*/
#include "blitz/common/VarInt.h"
#include "blitz/protocol/Protocol.h"
namespace blitz {
namespace protocol {
/**
* \class KeepAlivePacket
* \brief %Packet sent to measure the health of a connexion. \n
* The client must respond with the same alive ID. Else, the connexion will be closed. \n
* %Packet structure :
* | PacketType |
* |------------------------|
* | PacketType::KeepAlive |
*
* | Field Name | Field Type | Notes |
* |--------------------|---------------|---------------------------------------------------------------------------|
* | Keep Alive ID | VarInt | The server generates a random ID, the client must respond with the same |
*
*/
class KeepAlivePacket : public Packet {
private:
std::uint64_t m_AliveID;
VarInt m_AliveID;
public:
KeepAlivePacket() {}
@@ -18,8 +38,12 @@ class KeepAlivePacket : public Packet {
virtual void Deserialize(DataBuffer& data);
virtual void Dispatch(PacketHandler* handler) const;
/**
* \brief Getter of the alive ID
* \return The alive ID
*/
std::uint64_t GetAliveID() const {
return m_AliveID;
return m_AliveID.GetValue();
}
virtual PacketType GetType() const {

View File

@@ -1,28 +1,56 @@
#pragma once
/**
* \file PlayerJoinPacket.h
* \brief File containing the blitz::protocol::PlayerJoinPacket class
*/
#include "blitz/common/Defines.h"
#include "blitz/protocol/Protocol.h"
namespace blitz {
namespace protocol {
/**
* \class PlayerJoinPacket
* \brief %Packet sent when a new player joins the game \n
* %Packet structure :
* | PacketType |
* |------------------------|
* | PacketType::PlayerJoin |
*
* | Field Name | Field Type | Notes |
* |--------------------|-------------------|-------------------------------|
* | Player ID | game::PlayerID | Id of the player who joined |
* | Player Name | std::string | Name of the player who joined |
*
*/
class PlayerJoinPacket : public Packet {
private:
std::uint8_t m_PlayerID;
game::PlayerID m_PlayerID;
std::string m_PlayerName;
public:
PlayerJoinPacket() {}
PlayerJoinPacket(std::uint8_t playerID, const std::string& playerName) : m_PlayerID(playerID), m_PlayerName(playerName) {}
PlayerJoinPacket(game::PlayerID playerID, const std::string& playerName) : m_PlayerID(playerID), m_PlayerName(playerName) {}
virtual ~PlayerJoinPacket() {}
virtual DataBuffer Serialize(bool packetID = true) const;
virtual void Deserialize(DataBuffer& data);
virtual void Dispatch(PacketHandler* handler) const;
std::uint8_t GetPlayerID() const {
/**
* \brief Getter of the player id
* \return The ID of the player
*/
game::PlayerID GetPlayerID() const {
return m_PlayerID;
}
/**
* \brief Getter of the player name
* \return The name of the player
*/
const std::string& GetPlayerName() const {
return m_PlayerName;
}

View File

@@ -0,0 +1,49 @@
#pragma once
#include "blitz/common/Defines.h"
#include "blitz/maths/Vector.h"
#include "blitz/protocol/Protocol.h"
namespace blitz {
namespace protocol {
class PlayerPositionAndRotationPacket : public Packet {
private:
game::PlayerID m_Player; // only used when sent to client
Vec3f m_Position;
float m_Yaw, m_Pitch;
public:
PlayerPositionAndRotationPacket() {}
PlayerPositionAndRotationPacket(const Vec3f& position, float yaw, float pitch, game::PlayerID player = 0) :
m_Player(player), m_Position(position), m_Yaw(yaw), m_Pitch(pitch) {}
virtual ~PlayerPositionAndRotationPacket() {}
virtual DataBuffer Serialize(bool packetID = true) const;
virtual void Deserialize(DataBuffer& data);
virtual void Dispatch(PacketHandler* handler) const;
const Vec3f& GetPosition() const {
return m_Position;
}
float GetYaw() const {
return m_Yaw;
}
float GetPitch() const {
return m_Pitch;
}
game::PlayerID GetPlayer() const {
return m_Player;
}
virtual PacketType GetType() const {
return PacketType::PlayerPositionAndRotation;
}
};
} // namespace protocol
} // namespace blitz

View File

@@ -0,0 +1,47 @@
#pragma once
#include "blitz/game/Player.h"
#include "blitz/protocol/Protocol.h"
namespace blitz {
namespace protocol {
class PlayerShootPacket : public Packet {
private:
game::PlayerID m_Player; // only used when sent to client
Vec3f m_Position;
float m_Yaw, m_Pitch;
public:
PlayerShootPacket() {}
PlayerShootPacket(Vec3f position, float yaw, float pitch, game::PlayerID player = 0) :
m_Player(player), m_Position(position), m_Yaw(yaw), m_Pitch(pitch) {}
virtual ~PlayerShootPacket() {}
virtual DataBuffer Serialize(bool packetID = true) const;
virtual void Deserialize(DataBuffer& data);
virtual void Dispatch(PacketHandler* handler) const;
const Vec3f& GetPosition() const {
return m_Position;
}
float GetYaw() const {
return m_Yaw;
}
float GetPitch() const {
return m_Pitch;
}
game::PlayerID GetPlayer() const {
return m_Player;
}
virtual PacketType GetType() const {
return PacketType::PlayerShoot;
}
};
} // namespace protocol
} // namespace blitz

View File

@@ -0,0 +1,46 @@
#pragma once
#include "blitz/common/Defines.h"
#include "blitz/game/Player.h"
#include "blitz/protocol/Protocol.h"
namespace blitz {
namespace protocol {
class PlayerStatsPacket : public Packet {
private:
game::PlayerID m_PlayerID;
game::PlayerStats m_PlayerStats;
public:
PlayerStatsPacket() {}
PlayerStatsPacket(game::PlayerID playerID, const game::PlayerStats& stats) : m_PlayerID(playerID), m_PlayerStats(stats) {}
virtual ~PlayerStatsPacket() {}
virtual DataBuffer Serialize(bool packetID = true) const;
virtual void Deserialize(DataBuffer& data);
virtual void Dispatch(PacketHandler* handler) const;
/**
* \brief Getter of the player id
* \return The ID of the player
*/
game::PlayerID GetPlayerID() const {
return m_PlayerID;
}
/**
* \brief Getter of the player stats
* \return The stats of the player
*/
const game::PlayerStats& GetPlayerStats() const {
return m_PlayerStats;
}
virtual PacketType GetType() const {
return PacketType::PlayerStats;
}
};
} // namespace protocol
} // namespace blitz

View File

@@ -0,0 +1,32 @@
#pragma once
#include "blitz/game/Game.h"
#include "blitz/protocol/Protocol.h"
namespace blitz {
namespace protocol {
class ServerConfigPacket : public Packet {
private:
game::GameConfig m_GameConfig;
public:
ServerConfigPacket() {}
ServerConfigPacket(const game::GameConfig& GameConfig) : m_GameConfig(GameConfig) {}
virtual ~ServerConfigPacket() {}
virtual DataBuffer Serialize(bool packetID = true) const;
virtual void Deserialize(DataBuffer& data);
virtual void Dispatch(PacketHandler* handler) const;
game::GameConfig GetGameConfig() const {
return m_GameConfig;
}
virtual PacketType GetType() const {
return PacketType::ServerConfig;
}
};
} // namespace protocol
} // namespace blitz

View File

@@ -0,0 +1,38 @@
#pragma once
#include "blitz/game/Game.h"
#include "blitz/protocol/Protocol.h"
namespace blitz {
namespace protocol {
class UpdateGameStatePacket : public Packet {
private:
game::GameState m_GameState;
std::uint64_t m_TimeRemaining;
public:
UpdateGameStatePacket() {}
UpdateGameStatePacket(game::GameState a_GameState, std::uint64_t a_TimeRemaining = 0) :
m_GameState(a_GameState), m_TimeRemaining(a_TimeRemaining) {}
virtual ~UpdateGameStatePacket() {}
virtual DataBuffer Serialize(bool packetID = true) const;
virtual void Deserialize(DataBuffer& data);
virtual void Dispatch(PacketHandler* handler) const;
game::GameState GetGameState() const {
return m_GameState;
}
std::uint64_t GetTimeRemaining() const {
return m_TimeRemaining;
}
virtual PacketType GetType() const {
return PacketType::UpdateGameState;
}
};
} // namespace protocol
} // namespace blitz

View File

@@ -0,0 +1,31 @@
#pragma once
#include "blitz/protocol/Protocol.h"
namespace blitz {
namespace protocol {
class UpdateHealthPacket : public Packet {
private:
float m_NewHealth;
public:
UpdateHealthPacket() {}
UpdateHealthPacket(float newHealth) : m_NewHealth(newHealth) {}
virtual ~UpdateHealthPacket() {}
virtual DataBuffer Serialize(bool packetID = true) const;
virtual void Deserialize(DataBuffer& data);
virtual void Dispatch(PacketHandler* handler) const;
float GetNewHealth() const {
return m_NewHealth;
}
virtual PacketType GetType() const {
return PacketType::UpdateHealth;
}
};
} // namespace protocol
} // namespace blitz

View File

@@ -0,0 +1,13 @@
#pragma once
#include "blitz/common/DataBuffer.h"
namespace blitz {
namespace utils {
namespace AssetsManager {
DataBuffer GetAsset(const std::string& fileName);
} // namespace AssetsManager
} // namespace utils
} // namespace blitz

View File

@@ -1,31 +1,38 @@
#pragma once
#include "blitz/common/Defines.h"
#include "blitz/game/Listeners.h"
#include "blitz/misc/ObjectNotifier.h"
#include "blitz/misc/Time.h"
#include "blitz/protocol/packets/ChatPacket.h"
#include "client/config/BlitzConfig.h"
#include <cstdint>
#include <memory>
#include <string>
namespace blitz {
static const int PlayerUpdatePosRate = 50;
namespace client {
class ClientConnexion;
class ClientGame;
} // namespace client
namespace server {
class Server;
} // namespace server
class ChatListener {
public:
virtual void OnTextChatReceived(const protocol::ColoredText& text) {}
};
// Singleton
class Client : public utils::ObjectNotifier<ChatListener> {
class Client : public utils::ObjectNotifier<game::ClientListener>, public game::PlayerInputListener {
private:
std::unique_ptr<server::Server> m_Server;
std::unique_ptr<client::ClientConnexion> m_Connexion;
std::unique_ptr<client::ClientGame> m_Game;
utils::Timer m_UpdatePosTimer{PlayerUpdatePosRate};
BlitzConfig m_Config;
public:
Client();
@@ -38,8 +45,37 @@ class Client : public utils::ObjectNotifier<ChatListener> {
bool JoinGame(const std::string& pseudo, const std::string& address, std::uint16_t port);
bool CreateGame(std::uint16_t port, const std::string& pseudo);
void Disconnect();
void SendChatText(const std::string& text);
void ChatTextReceived(const protocol::ColoredText& text);
void SendPlayerPosAndLook(const Vec3f& position, float yaw, float pitch);
virtual void OnLocalPlayerShoot(const Vec3f& position, float yaw, float pitch) override;
game::PlayerID GetPlayerID() const;
client::ClientGame* GetGame() {
return m_Game.get();
}
BlitzConfig* GetConfig() {
return &m_Config;
}
bool IsAdmin() const;
server::Server* GetServer() {
return m_Server.get();
}
void UpdateServerConfig();
private:
void Reset();
void UpdatePosition(std::uint64_t delta);
};
} // namespace blitz

View File

@@ -1,7 +1,7 @@
#pragma once
#include "blitz/common/Defines.h"
#include "blitz/network/Connexion.h"
#include "blitz/protocol/PacketsForward.h"
namespace blitz {
@@ -12,16 +12,24 @@ namespace client {
class ClientConnexion : public network::Connexion {
private:
Client* m_Client;
std::string m_PlayerName;
game::PlayerID m_PlayerID;
public:
ClientConnexion(Client* client);
virtual ~ClientConnexion();
virtual void HandlePacket(const protocol::DisconnectPacket* packet) override;
virtual void HandlePacket(const protocol::KeepAlivePacket* packet) override;
virtual void HandlePacket(const protocol::ChatPacket* packet) override;
virtual void HandlePacket(const protocol::ConnexionInfoPacket* packet) override;
virtual bool Connect(const std::string& pseudo, const std::string& address, std::uint16_t port);
game::PlayerID GetPlayerID() const {
return m_PlayerID;
}
private:
void Login(const std::string& pseudo);
void RegisterHandlers();

View File

@@ -0,0 +1,75 @@
#pragma once
#include "blitz/game/Game.h"
#include <array>
#include <string>
namespace blitz {
enum KeyAction {
kaAvancer = 0,
kaReculer,
kaDroite,
kaGauche,
kaFenetreAdmin,
kaMax,
};
typedef std::array<int, kaMax> Keybinds;
class BlitzConfig {
private:
std::array<char, 256> m_Pseudo;
game::GameConfig m_ServerConfig;
bool m_VSync;
bool m_DisplayFps;
Keybinds m_Keybinds{};
float m_MouseSpeed;
public:
BlitzConfig();
~BlitzConfig();
std::array<char, 256>& GetPseudo() {
return m_Pseudo;
}
bool IsVSyncEnabled() const {
return m_VSync;
}
void SetVSync(bool vsync) {
m_VSync = vsync;
}
bool IsFPSDisplayEnabled() const {
return m_DisplayFps;
}
void SetFPSDisplay(bool display) {
m_DisplayFps = display;
}
Keybinds& GetKeys() {
return m_Keybinds;
}
float GetMouseSpeed() const {
return m_MouseSpeed;
}
void SetMouseSpeed(float MouseSpeed) {
m_MouseSpeed = MouseSpeed;
}
game::GameConfig& GetServerConfig() {
return m_ServerConfig;
}
private:
void LoadConfig();
void LoadDefaultConfig();
void SaveConfig();
};
} // namespace blitz

View File

@@ -0,0 +1,19 @@
#pragma once
#include <SDL2/SDL_events.h>
#include <functional>
namespace blitz {
namespace InputManager {
typedef std::function<void(int)> KeyDownCallback;
typedef std::function<void(int, int)> MouseMoveCallback;
void BindKeyDownCallback(const KeyDownCallback&);
void BindMouseMoveCallback(const MouseMoveCallback&);
void ProcessEvent(SDL_Event& event);
void GrabMouse(bool grabInput);
bool MouseGrabbed();
} // namespace InputManager
} // namespace blitz

View File

@@ -0,0 +1,56 @@
#pragma once
#include "blitz/common/Smoothing.h"
#include "blitz/game/Listeners.h"
#include "blitz/misc/ObjectNotifier.h"
#include "blitz/misc/Time.h"
namespace blitz {
class Client;
namespace game {
class Player;
} // namespace game
namespace input {
class PlayerController : public utils::ObjectNotifier<game::PlayerInputListener>, game::ClientListener {
private:
game::Player* m_Player;
Client* m_Client;
utils::CooldownTimer<float> m_ShootTimer{1.0f};
EMASmoother m_DxSmoother;
EMASmoother m_DySmoother;
// current (target) velocity
Vec3f m_Velocity;
/// maximum x-axis velocity
Vec3f m_MaxVelocity;
/// this is reset when the player touches the ground
bool m_OnGround;
public:
PlayerController(Client* client);
void Update(float delta);
virtual void OnGameConfigUpdate() override;
void SetAttachedPlayer(game::Player* a_Player) {
m_Player = a_Player;
}
game::Player* GetAttachedPlayer() {
return m_Player;
}
private:
void UpdateShootTimer(int bpm);
void MouseMotionEvent(int, int);
void UpdatePosition(float delta);
};
} // namespace input
} // namespace blitz

View File

@@ -0,0 +1,47 @@
#pragma once
#include "blitz/game/Game.h"
#include "blitz/game/LeaderBoard.h"
#include "blitz/protocol/PacketHandler.h"
#include <vector>
namespace blitz {
class Client;
namespace client {
class ClientGame : public game::Game, public protocol::PacketHandler {
private:
Client* m_Client;
game::LeaderBoard m_LeaderBoard;
public:
ClientGame(Client* client, protocol::PacketDispatcher* dispatcher);
virtual ~ClientGame();
void Tick(std::uint64_t delta) override;
virtual void HandlePacket(const protocol::PlayerJoinPacket* packet) override;
virtual void HandlePacket(const protocol::PlayerLeavePacket* packet) override;
virtual void HandlePacket(const protocol::PlayerListPacket* packet) override;
virtual void HandlePacket(const protocol::PlayerPositionAndRotationPacket* packet) override;
virtual void HandlePacket(const protocol::PlayerShootPacket* packet) override;
virtual void HandlePacket(const protocol::UpdateHealthPacket* packet) override;
virtual void HandlePacket(const protocol::PlayerStatsPacket* packet) override;
virtual void HandlePacket(const protocol::UpdateGameStatePacket* packet) override;
virtual void HandlePacket(const protocol::ServerConfigPacket* packet) override;
virtual void AddPlayer(game::PlayerID player, const std::string& name);
virtual void RemovePlayer(game::PlayerID player);
const game::LeaderBoard& GetLeaderBoard() const {
return m_LeaderBoard;
}
private:
void RegisterHandlers();
};
} // namespace client
} // namespace blitz

View File

@@ -1,6 +1,5 @@
#pragma once
#include "blitz/misc/Maths.h"
#include "blitz/protocol/packets/ChatPacket.h"
#include <string>

View File

@@ -0,0 +1,19 @@
#pragma once
#include "GuiWidget.h"
namespace blitz {
namespace gui {
class CrossHair : public GuiWidget {
private:
std::uint64_t m_CrossHairTexture;
public:
CrossHair(Client* client);
virtual void Render() override;
};
} // namespace gui
} // namespace blitz

View File

@@ -9,12 +9,15 @@ namespace blitz {
namespace gui {
class GameChatGui : public GuiWidget, ChatListener {
class GameChatGui : public GuiWidget, game::ClientListener {
private:
char InputBuf[256];
std::vector<protocol::ColoredText> m_Lines;
std::vector<protocol::ColoredText> m_TempLines;
bool m_FocusRequested = false;
int HistoryPos; // -1: new line, 0..History.Size-1 browsing history.
bool ScrollToBottom = false;
bool AutoScroll = true;
float m_ChatDisplay = 0;

View File

@@ -3,7 +3,7 @@
#include <memory>
#include <vector>
#include "blitz/Defines.h"
#include "blitz/common/Defines.h"
namespace blitz {

33
include/client/gui/Hud.h Normal file
View File

@@ -0,0 +1,33 @@
#pragma once
#include "GuiWidget.h"
#include "client/Client.h"
namespace blitz {
class Client;
namespace game {
class Player;
} // namespace game
namespace gui {
class Hud : public GuiWidget {
private:
std::uint64_t m_GunTexture;
std::uint64_t m_JPTexture;
utils::DelayTimer<float> m_Timer{5.0f};
public:
Hud(GuiWidget* parent, Client* client);
virtual void Render() override;
private:
std::string FormatString();
void Draw(const char* title, bool* p_open);
void DrawFinishScreen(bool win);
void RenderTime(float, float);
};
} // namespace gui
} // namespace blitz

View File

@@ -0,0 +1,22 @@
#pragma once
#include "GuiWidget.h"
#include "client/Client.h"
namespace blitz {
namespace gui {
class LeaderBoardGui : public GuiWidget {
private:
void Draw(const char* title, bool* p_open);
utils::DelayTimer<float> m_Timer{5.0f};
public:
LeaderBoardGui(GuiWidget* parent, Client* client);
~LeaderBoardGui();
virtual void Render() override;
};
} // namespace gui
} // namespace blitz

View File

@@ -1,6 +1,10 @@
#pragma once
#include "GuiWidget.h"
#include "blitz/misc/Time.h"
#include "client/config/BlitzConfig.h"
#include <array>
#include <string>
namespace blitz {
@@ -9,10 +13,25 @@ class Client;
namespace gui {
class OptionsMenu : public GuiWidget {
private:
bool m_ShowFPS;
bool m_VSync;
bool m_IsKeyPopupOpen;
bool m_KeyPopupShouldClose;
utils::Timer m_Timer{100};
KeyAction m_CurrentAction;
public:
OptionsMenu(GuiWidget* parent, Client* client);
virtual void Render() override;
void OnKeyEvent(int key);
private:
std::string GetKeyActionCodeName(KeyAction);
void HotkeyBindingButton();
void HotkeyBindingPopUp();
};
} // namespace gui

View File

@@ -0,0 +1,16 @@
#pragma once
#include "GuiWidget.h"
namespace blitz {
namespace gui {
class ServerGui : public GuiWidget {
public:
ServerGui(GuiWidget* parent, Client* client);
virtual void Render() override;
};
} // namespace gui
} // namespace blitz

View File

@@ -0,0 +1,44 @@
#pragma once
#include "blitz/maths/Vector.h"
#include "client/render/loader/ModelLoader.h"
#include <memory>
#include <vector>
namespace blitz {
namespace shader {
class BulletShader;
} // namespace shader
namespace render {
class Camera;
struct Trail {
Mat4f m_Transform;
float m_Decay;
};
class BulletRenderer {
private:
std::vector<Trail> m_Trails;
ModelLoader::Model m_BulletModel;
std::unique_ptr<shader::BulletShader> m_Shader;
unsigned int m_Vbo;
const Camera& m_Camera;
public:
BulletRenderer(const Camera& cam);
~BulletRenderer();
void AddBullet(const Vec3f& origin, float yaw, float pitch, bool firstPersson);
void Update(float delta);
void Render();
};
} // namespace render
} // namespace blitz

View File

@@ -1,6 +1,7 @@
#pragma once
#include "blitz/misc/Maths.h"
#include "blitz/game/Player.h"
#include "blitz/maths/Vector.h"
#include <cstdint>
namespace blitz {
@@ -8,26 +9,31 @@ namespace render {
class Camera {
private:
float m_Yaw, m_Pitch;
Vec3f m_Position;
game::Player* m_Player;
Mat4f m_PerspectiveMatrix;
Vec2i m_LastWindowSize;
public:
Camera() : m_Yaw(-PI / 2.0f), m_Pitch(0), m_Position(10, 1, 10) {}
Camera() : m_Player(nullptr) {}
~Camera() {}
void Update(std::uint64_t delta);
void Update(float delta);
static float GetPlayerEyeHeight();
void SetAttachedPlayer(game::Player* a_Player) {
m_Player = a_Player;
}
const game::Player* GetAttachedPlayer() const {
return m_Player;
}
Mat4f GetViewMatrix() const;
const Mat4f& GetPerspectiveMatrix() const {
return m_PerspectiveMatrix;
}
const Vec3f& GetPosition() const {
return m_Position;
}
};
} // namespace render

View File

@@ -1,39 +1,60 @@
#pragma once
#include "client/Client.h"
#include "client/display/PlayerController.h"
#include "client/render/BulletRenderer.h"
#include "client/render/Camera.h"
#include "client/render/loader/GLLoader.h"
#include <memory>
#include "client/render/loader/ModelLoader.h"
namespace blitz {
namespace shader {
class EntityShader;
class WorldShader;
class GunShader;
} // namespace shader
class Client;
namespace render {
class MainRenderer {
class MainRenderer : public game::ClientListener, public game::PlayerInputListener {
private:
Client* m_Client;
std::unique_ptr<GL::VertexArray> m_Vao;
std::unique_ptr<shader::EntityShader> m_Shader;
ModelLoader::Model m_PlayerModel;
ModelLoader::Model m_WorldModel;
ModelLoader::Model m_GunModel;
std::unique_ptr<shader::EntityShader> m_EntityShader;
std::unique_ptr<shader::WorldShader> m_WorldShader;
std::unique_ptr<shader::GunShader> m_GunShader;
input::PlayerController m_PlayerController;
unsigned int m_Texture;
float m_ShootTime;
Camera m_Camera;
BulletRenderer m_BulletRenderer;
public:
MainRenderer(Client* client);
~MainRenderer();
virtual void OnSpectatorChange(game::PlayerID player) override;
virtual void OnPlayerShoot(game::PlayerID player, const Vec3f& position, float yaw, float pitch) override;
virtual void OnLocalPlayerShoot(const Vec3f& position, float yaw, float pitch) override;
virtual void OnGameConfigUpdate() override;
void Update();
void Render();
void Render(const GL::VertexArray& vao);
void RenderEntity(const GL::VertexArray& vao, const Vec3f& position, float yaw);
void RenderWorld(const GL::VertexArray& vao);
void RenderGun();
private:
void LoadModel();
void LoadModels();
void RenderPlayers();
void RenderWorld();
};
} // namespace render

View File

@@ -0,0 +1,8 @@
#pragma once
#ifndef BLITZ_GL_LOADER_GLBNIDING
#include <GL/glew.h>
#else
#include <glbinding/gl/gl.h>
using namespace gl;
#endif

View File

@@ -1,6 +1,6 @@
#pragma once
#include "blitz/Defines.h"
#include "blitz/common/NonCopyable.h"
#include <vector>
@@ -13,9 +13,9 @@ struct VertexAttribPointer {
unsigned int m_Offset;
};
class ElementBuffer {
class ElementBuffer : private NonCopyable {
private:
unsigned int m_ID;
unsigned int m_ID = 0;
std::size_t m_TriangleCount;
public:
@@ -33,11 +33,9 @@ class ElementBuffer {
std::size_t GetTriangleCount() const {
return m_TriangleCount;
}
REMOVE_COPY(ElementBuffer);
};
class VertexBuffer {
class VertexBuffer : private NonCopyable {
private:
unsigned int m_ID = 0, m_DataStride;
std::vector<VertexAttribPointer> m_VertexAttribs;
@@ -56,11 +54,9 @@ class VertexBuffer {
void Unbind() const;
void AddVertexAttribPointer(unsigned int index, unsigned int coordinateSize, unsigned int offset);
void BindVertexAttribs() const;
REMOVE_COPY(VertexBuffer);
};
class VertexArray {
class VertexArray : private NonCopyable {
private:
unsigned int m_ID = 0;
ElementBuffer m_ElementBuffer;
@@ -74,7 +70,7 @@ class VertexArray {
VertexArray(ElementBuffer&& indicies);
~VertexArray();
unsigned int GetVertexCount() const {
std::size_t GetVertexCount() const {
return m_ElementBuffer.GetTriangleCount();
}
@@ -82,8 +78,6 @@ class VertexArray {
void Bind() const;
void Unbind() const;
REMOVE_COPY(VertexArray);
private:
void BindElementArrayBuffer();
};

View File

@@ -0,0 +1,20 @@
#pragma once
#include "client/render/loader/GLLoader.h"
#include <memory>
#include <string>
#include <vector>
namespace blitz {
namespace ModelLoader {
typedef std::unique_ptr<GL::VertexArray> VaoPtr;
struct Model {
std::vector<VaoPtr> mVaos;
};
Model LoadModel(const std::string& fileName);
} // namespace ModelLoader
} // namespace blitz

View File

@@ -0,0 +1,30 @@
#pragma once
#include "ShaderProgram.h"
namespace blitz {
namespace shader {
class BulletShader : public ShaderProgram {
private:
unsigned int m_LocationProjectionMatrix = 0;
unsigned int m_LocationViewMatrix = 0;
unsigned int m_LocationAlpha = 0;
unsigned int m_LocationTransform = 0;
protected:
virtual void GetAllUniformLocation() override;
public:
BulletShader();
bool LoadShader();
void SetProjectionMatrix(const Mat4f& proj) const;
void SetViewMatrix(const Mat4f& view) const;
void SetTransform(const Mat4f& trans) const;
void SetDecay(float decay) const;
};
} // namespace shader
} // namespace blitz

View File

@@ -9,21 +9,19 @@ class EntityShader : public ShaderProgram {
private:
unsigned int m_LocationProjectionMatrix = 0;
unsigned int m_LocationViewMatrix = 0;
unsigned int m_LocationPosition = 0;
unsigned int m_LocationColorEffect = 0;
unsigned int m_LocationTransform = 0;
protected:
virtual void GetAllUniformLocation();
virtual void GetAllUniformLocation() override;
public:
EntityShader();
void LoadShader();
bool LoadShader();
void SetColorEffect(const Vec3f& color);
void SetProjectionMatrix(const Mat4f& proj) const;
void SetViewMatrix(const Mat4f& view) const;
void SetModelPos(const Vec3f& pos) const;
void SetModelTransform(const Mat4f& transform) const;
};
} // namespace shader

View File

@@ -0,0 +1,26 @@
#pragma once
#include "ShaderProgram.h"
namespace blitz {
namespace shader {
class GunShader : public ShaderProgram {
private:
unsigned int m_LocationProjection = 0;
unsigned int m_LocationTransform = 0;
protected:
void GetAllUniformLocation() override;
public:
GunShader();
bool LoadShader();
void SetProjectionMatrix(const Mat4f& proj) const;
void SetModelTransform(const Mat4f& trans) const;
};
} // namespace shader
} // namespace blitz

View File

@@ -1,6 +1,7 @@
#pragma once
#include "blitz/misc/Maths.h"
#include "blitz/maths/Vector.h"
#include "client/render/OpenGL.h"
#include <string>
namespace blitz {
@@ -14,8 +15,9 @@ class ShaderProgram {
void Start() const;
void Stop() const;
void LoadProgramFile(const std::string& vertexFile, const std::string& fragmentFile);
void LoadProgram(const std::string& vertexSource, const std::string& fragmentSource);
bool LoadProgram(const std::string& vertexSource, const std::string& fragmentSource);
static std::string GetShaderHeader();
protected:
virtual void GetAllUniformLocation() = 0;
@@ -34,8 +36,7 @@ class ShaderProgram {
unsigned int m_VertexShaderID;
unsigned int m_FragmentShaderID;
unsigned int LoadShaderFromFile(const std::string& file, unsigned int type);
unsigned int LoadShader(const std::string& source, unsigned int type);
int LoadShader(const std::string& source, GLenum type);
};
} // namespace shader

View File

@@ -7,17 +7,19 @@ namespace shader {
class WorldShader : public ShaderProgram {
private:
unsigned int m_LocationProjection = 0, m_LocationView = 0;
unsigned int m_LocationProjection = 0, m_LocationView = 0, m_LocationLight = 0;
protected:
void GetAllUniformLocation();
void GetAllUniformLocation() override;
public:
WorldShader();
void LoadShader();
bool LoadShader();
void SetProjectionMatrix(const Mat4f& proj) const;
void SetViewMatrix(const Mat4f& view) const;
void SetLightPosition(const Vec3f& lightPos) const;
};
} // namespace shader

View File

@@ -5,20 +5,13 @@
#include "blitz/misc/TickCounter.h"
#include "blitz/network/TCPListener.h"
#include "blitz/protocol/PacketDispatcher.h"
#include "blitz/protocol/PacketHandler.h"
#include "blitz/protocol/Protocol.h"
#include "server/ServerConnexion.h"
#include "server/game/ServerGame.h"
#define SERVER_TPS 20
#define SERVER_TICK 1000 / SERVER_TPS
namespace blitz {
namespace game {
class Game;
} // namespace game
namespace server {
typedef std::map<std::uint8_t, std::unique_ptr<ServerConnexion>> ConnexionMap;
@@ -29,7 +22,7 @@ class Server {
ConnexionMap m_Connections;
utils::TickCounter m_TickCounter;
std::unique_ptr<game::Game> m_Game;
ServerGame m_Game;
std::thread m_Thread;
bool m_ServerRunning;
@@ -43,6 +36,8 @@ class Server {
void Restart();
void AddBot();
void RemoveConnexion(std::uint8_t connexionID);
void BroadcastPacket(const protocol::Packet* packet);
@@ -68,12 +63,14 @@ class Server {
return m_Connections;
}
game::Game* GetGame() {
return m_Game.get();
ServerGame& GetGame() {
return m_Game;
}
std::uint16_t GetListeningPort();
game::PlayerID GetNewPlayerID();
private:
void Accept();
void UpdateSockets();

View File

@@ -1,9 +1,6 @@
#pragma once
#include "blitz/network/Connexion.h"
#include "blitz/network/TCPSocket.h"
#include "blitz/protocol/PacketDispatcher.h"
#include "blitz/protocol/PacketHandler.h"
namespace blitz {
@@ -44,6 +41,8 @@ class ServerConnexion : public network::Connexion {
virtual void HandlePacket(const protocol::KeepAlivePacket* packet) override;
virtual void HandlePacket(const protocol::DisconnectPacket* packet) override;
virtual void HandlePacket(const protocol::ChatPacket* packet) override;
virtual void HandlePacket(const protocol::PlayerPositionAndRotationPacket* packet) override;
virtual void HandlePacket(const protocol::PlayerShootPacket* packet) override;
std::uint8_t GetID() const {
return m_ID;
@@ -51,14 +50,15 @@ class ServerConnexion : public network::Connexion {
virtual bool UpdateSocket();
REMOVE_COPY(ServerConnexion);
private:
void RegisterHandlers();
void CheckKeepAlive();
void SendKeepAlive();
void InitConnection();
void InitPlayerChatColor();
void SendPlayers();
void SendGameState();
void SendServerConfig();
};
} // namespace server

View File

@@ -0,0 +1,52 @@
#pragma once
#include "blitz/game/Game.h"
namespace blitz {
namespace server {
struct ServerDuration {
std::uint64_t m_GameDuration = 1000 * 3 * 60;
std::uint64_t m_PrepDuration = 1000 * 10;
std::uint64_t m_EndDuration = 1000 * 30;
};
class Server;
class ServerGame : public game::Game {
private:
Server* m_Server;
utils::Timer m_PositionTimer;
ServerDuration m_ServerDuration;
public:
ServerGame(Server* server);
virtual ~ServerGame();
void CheckShoot(game::PlayerID player, Vec3f position, float yaw, float pitch);
void AddPlayer(game::PlayerID player, const std::string& name) override;
void RemovePlayer(game::PlayerID player) override;
void Tick(std::uint64_t delta) override;
void SetGameState(game::GameState gameState, std::uint64_t duration);
ServerDuration& GetServerDuration() {
return m_ServerDuration;
}
void SendServerConfig();
private:
void SendPlayerPositions();
void DamagePlayer(game::Player& player, game::Player& shooter);
void UpdateHP(game::Player& player, float newHP);
void UpdatePlayerStats();
void StartGame(); // when at least 2 players joined
void CancelGame(); // when not enough players are left
void ResetPlayerStats();
};
} // namespace server
} // namespace blitz

21
libs/imgui/LICENSE.txt Normal file
View File

@@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) 2014-2023 Omar Cornut
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.

View File

@@ -0,0 +1,942 @@
// 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 identifier as void*/ImTextureID. Read the FAQ about ImTextureID!
// [x] Renderer: Large meshes support (64k+ vertices) with 16-bit indices (Desktop OpenGL only).
// 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.
// If you are new to Dear ImGui, read documentation from the docs/ folder + read the top of imgui.cpp.
// Read online: https://github.com/ocornut/imgui/tree/master/docs
// CHANGELOG
// (minor and older changes stripped away, please see git history for details)
// 2023-06-20: OpenGL: Fixed erroneous use glGetIntegerv(GL_CONTEXT_PROFILE_MASK) on contexts lower than 3.2. (#6539, #6333)
// 2023-05-09: OpenGL: Support for glBindSampler() backup/restore on ES3. (#6375)
// 2023-04-18: OpenGL: Restore front and back polygon mode separately when supported by context. (#6333)
// 2023-03-23: OpenGL: Properly restoring "no shader program bound" if it was the case prior to running the rendering function. (#6267, #6220, #6224)
// 2023-03-15: OpenGL: Fixed GL loader crash when GL_VERSION returns NULL. (#6154, #4445, #3530)
// 2023-03-06: OpenGL: Fixed restoration of a potentially deleted OpenGL program, by calling glIsProgram(). (#6220, #6224)
// 2022-11-09: OpenGL: Reverted use of glBufferSubData(), too many corruptions issues + old issues seemingly can't be reproed with Intel drivers nowadays (revert 2021-12-15 and 2022-05-23 changes).
// 2022-10-11: Using 'nullptr' instead of 'NULL' as per our switch to C++11.
// 2022-09-27: OpenGL: Added ability to '#define IMGUI_IMPL_OPENGL_DEBUG'.
// 2022-05-23: OpenGL: Reworking 2021-12-15 "Using buffer orphaning" so it only happens on Intel GPU, seems to cause problems otherwise. (#4468, #4825, #4832, #5127).
// 2022-05-13: OpenGL: Fixed state corruption on OpenGL ES 2.0 due to not preserving GL_ELEMENT_ARRAY_BUFFER_BINDING and vertex attribute states.
// 2021-12-15: OpenGL: Using buffer orphaning + glBufferSubData(), seems to fix leaks with multi-viewports with some Intel HD drivers.
// 2021-08-23: OpenGL: Fixed ES 3.0 shader ("#version 300 es") use normal precision floats to avoid wobbly rendering at HD resolutions.
// 2021-08-19: OpenGL: Embed and use our own minimal GL loader (imgui_impl_opengl3_loader.h), removing requirement and support for third-party loader.
// 2021-06-29: Reorganized backend to pull data from a single structure to facilitate usage with multiple-contexts (all g_XXXX access changed to bd->XXXX).
// 2021-06-25: OpenGL: Use OES_vertex_array extension on Emscripten + backup/restore current state.
// 2021-06-21: OpenGL: Destroy individual vertex/fragment shader objects right after they are linked into the main shader.
// 2021-05-24: OpenGL: Access GL_CLIP_ORIGIN when "GL_ARB_clip_control" extension is detected, inside of just OpenGL 4.5 version.
// 2021-05-19: OpenGL: Replaced direct access to ImDrawCmd::TextureId with a call to ImDrawCmd::GetTexID(). (will become a requirement)
// 2021-04-06: OpenGL: Don't try to read GL_CLIP_ORIGIN unless we're OpenGL 4.5 or greater.
// 2021-02-18: OpenGL: Change blending equation to preserve alpha in output buffer.
// 2021-01-03: OpenGL: Backup, setup and restore GL_STENCIL_TEST state.
// 2020-10-23: OpenGL: Backup, setup and restore GL_PRIMITIVE_RESTART state.
// 2020-10-15: OpenGL: Use glGetString(GL_VERSION) instead of glGetIntegerv(GL_MAJOR_VERSION, ...) when the later returns zero (e.g. Desktop GL 2.x)
// 2020-09-17: OpenGL: Fix to avoid compiling/calling glBindSampler() on ES or pre 3.3 context which have the defines set by a loader.
// 2020-07-10: OpenGL: Added support for glad2 OpenGL loader.
// 2020-05-08: OpenGL: Made default GLSL version 150 (instead of 130) on OSX.
// 2020-04-21: OpenGL: Fixed handling of glClipControl(GL_UPPER_LEFT) by inverting projection matrix.
// 2020-04-12: OpenGL: Fixed context version check mistakenly testing for 4.0+ instead of 3.2+ to enable ImGuiBackendFlags_RendererHasVtxOffset.
// 2020-03-24: OpenGL: Added support for glbinding 2.x OpenGL loader.
// 2020-01-07: OpenGL: Added support for glbinding 3.x OpenGL loader.
// 2019-10-25: OpenGL: Using a combination of GL define and runtime GL version to decide whether to use glDrawElementsBaseVertex(). Fix building with pre-3.2 GL loaders.
// 2019-09-22: OpenGL: Detect default GL loader using __has_include compiler facility.
// 2019-09-16: OpenGL: Tweak initialization code to allow application calling ImGui_ImplOpenGL3_CreateFontsTexture() before the first NewFrame() call.
// 2019-05-29: OpenGL: Desktop GL only: Added support for large mesh (64K+ vertices), enable ImGuiBackendFlags_RendererHasVtxOffset flag.
// 2019-04-30: OpenGL: Added support for special ImDrawCallback_ResetRenderState callback to reset render state.
// 2019-03-29: OpenGL: Not calling glBindBuffer more than necessary in the render loop.
// 2019-03-15: OpenGL: Added a GL call + comments in ImGui_ImplOpenGL3_Init() to detect uninitialized GL function loaders early.
// 2019-03-03: OpenGL: Fix support for ES 2.0 (WebGL 1.0).
// 2019-02-20: OpenGL: Fix for OSX not supporting OpenGL 4.5, we don't try to read GL_CLIP_ORIGIN even if defined by the headers/loader.
// 2019-02-11: OpenGL: Projecting clipping rectangles correctly using draw_data->FramebufferScale to allow multi-viewports for retina display.
// 2019-02-01: OpenGL: Using GLSL 410 shaders for any version over 410 (e.g. 430, 450).
// 2018-11-30: Misc: Setting up io.BackendRendererName so it can be displayed in the About Window.
// 2018-11-13: OpenGL: Support for GL 4.5's glClipControl(GL_UPPER_LEFT) / GL_CLIP_ORIGIN.
// 2018-08-29: OpenGL: Added support for more OpenGL loaders: glew and glad, with comments indicative that any loader can be used.
// 2018-08-09: OpenGL: Default to OpenGL ES 3 on iOS and Android. GLSL version default to "#version 300 ES".
// 2018-07-30: OpenGL: Support for GLSL 300 ES and 410 core. Fixes for Emscripten compilation.
// 2018-07-10: OpenGL: Support for more GLSL versions (based on the GLSL version string). Added error output when shaders fail to compile/link.
// 2018-06-08: Misc: Extracted imgui_impl_opengl3.cpp/.h away from the old combined GLFW/SDL+OpenGL3 examples.
// 2018-06-08: OpenGL: Use draw_data->DisplayPos and draw_data->DisplaySize to setup projection matrix and clipping rectangle.
// 2018-05-25: OpenGL: Removed unnecessary backup/restore of GL_ELEMENT_ARRAY_BUFFER_BINDING since this is part of the VAO state.
// 2018-05-14: OpenGL: Making the call to glBindSampler() optional so 3.2 context won't fail if the function is a nullptr pointer.
// 2018-03-06: OpenGL: Added const char* glsl_version parameter to ImGui_ImplOpenGL3_Init() so user can override the GLSL version e.g. "#version 150".
// 2018-02-23: OpenGL: Create the VAO in the render function so the setup can more easily be used with multiple shared GL context.
// 2018-02-16: Misc: Obsoleted the io.RenderDrawListsFn callback and exposed ImGui_ImplSdlGL3_RenderDrawData() in the .h file so you can call it yourself.
// 2018-01-07: OpenGL: Changed GLSL shader version from 330 to 150.
// 2017-09-01: OpenGL: Save and restore current bound sampler. Save and restore current polygon mode.
// 2017-05-01: OpenGL: Fixed save and restore of current blend func state.
// 2017-05-01: OpenGL: Fixed save and restore of current GL_ACTIVE_TEXTURE.
// 2016-09-05: OpenGL: Fixed save and restore of current scissor rectangle.
// 2016-07-29: OpenGL: Explicitly setting GL_UNPACK_ROW_LENGTH to reduce issues because SDL changes it. (#752)
//----------------------------------------
// OpenGL GLSL GLSL
// version version string
//----------------------------------------
// 2.0 110 "#version 110"
// 2.1 120 "#version 120"
// 3.0 130 "#version 130"
// 3.1 140 "#version 140"
// 3.2 150 "#version 150"
// 3.3 330 "#version 330 core"
// 4.0 400 "#version 400 core"
// 4.1 410 "#version 410 core"
// 4.2 420 "#version 410 core"
// 4.3 430 "#version 430 core"
// ES 2.0 100 "#version 100" = WebGL 1.0
// ES 3.0 300 "#version 300 es" = WebGL 2.0
//----------------------------------------
#if defined(_MSC_VER) && !defined(_CRT_SECURE_NO_WARNINGS)
#define _CRT_SECURE_NO_WARNINGS
#endif
#include "imgui.h"
#ifndef IMGUI_DISABLE
#include "imgui_impl_opengl3.h"
#include <stdio.h>
#include <stdint.h> // intptr_t
#if defined(__APPLE__)
#include <TargetConditionals.h>
#endif
// Clang/GCC 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 "-Wsign-conversion" // warning: implicit conversion changes signedness
#pragma clang diagnostic ignored "-Wunused-macros" // warning: macro is not used
#pragma clang diagnostic ignored "-Wnonportable-system-include-path"
#pragma clang diagnostic ignored "-Wcast-function-type" // warning: cast between incompatible function types (for loader)
#endif
#if defined(__GNUC__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wpragmas" // warning: unknown option after '#pragma GCC diagnostic' kind
#pragma GCC diagnostic ignored "-Wunknown-warning-option" // warning: unknown warning group 'xxx'
#pragma GCC diagnostic ignored "-Wcast-function-type" // warning: cast between incompatible function types (for loader)
#endif
// GL includes
#if defined(IMGUI_IMPL_OPENGL_ES2)
#if (defined(__APPLE__) && (TARGET_OS_IOS || TARGET_OS_TV))
#include <OpenGLES/ES2/gl.h> // Use GL ES 2
#else
#include <GLES2/gl2.h> // Use GL ES 2
#endif
#if defined(__EMSCRIPTEN__)
#ifndef GL_GLEXT_PROTOTYPES
#define GL_GLEXT_PROTOTYPES
#endif
#include <GLES2/gl2ext.h>
#endif
#elif defined(IMGUI_IMPL_OPENGL_ES3)
#if (defined(__APPLE__) && (TARGET_OS_IOS || TARGET_OS_TV))
#include <OpenGLES/ES3/gl.h> // Use GL ES 3
#else
#include <GLES3/gl3.h> // Use GL ES 3
#endif
#elif !defined(IMGUI_IMPL_OPENGL_LOADER_CUSTOM)
// Modern desktop OpenGL doesn't have a standard portable header file to load OpenGL function pointers.
// Helper libraries are often used for this purpose! Here we are using our own minimal custom loader based on gl3w.
// In the rest of your app/engine, you can use another loader of your choice (gl3w, glew, glad, glbinding, glext, glLoadGen, etc.).
// If you happen to be developing a new feature for this backend (imgui_impl_opengl3.cpp):
// - You may need to regenerate imgui_impl_opengl3_loader.h to add new symbols. See https://github.com/dearimgui/gl3w_stripped
// - You can temporarily use an unstripped version. See https://github.com/dearimgui/gl3w_stripped/releases
// Changes to this backend using new APIs should be accompanied by a regenerated stripped loader version.
#define IMGL3W_IMPL
#include "imgui_impl_opengl3_loader.h"
#endif
// Vertex arrays are not supported on ES2/WebGL1 unless Emscripten which uses an extension
#ifndef IMGUI_IMPL_OPENGL_ES2
#define IMGUI_IMPL_OPENGL_USE_VERTEX_ARRAY
#elif defined(__EMSCRIPTEN__)
#define IMGUI_IMPL_OPENGL_USE_VERTEX_ARRAY
#define glBindVertexArray glBindVertexArrayOES
#define glGenVertexArrays glGenVertexArraysOES
#define glDeleteVertexArrays glDeleteVertexArraysOES
#define GL_VERTEX_ARRAY_BINDING GL_VERTEX_ARRAY_BINDING_OES
#endif
// Desktop GL 2.0+ has glPolygonMode() which GL ES and WebGL don't have.
#ifdef GL_POLYGON_MODE
#define IMGUI_IMPL_HAS_POLYGON_MODE
#endif
// Desktop GL 3.2+ has glDrawElementsBaseVertex() which GL ES and WebGL don't have.
#if !defined(IMGUI_IMPL_OPENGL_ES2) && !defined(IMGUI_IMPL_OPENGL_ES3) && defined(GL_VERSION_3_2)
#define IMGUI_IMPL_OPENGL_MAY_HAVE_VTX_OFFSET
#endif
// Desktop GL 3.3+ and GL ES 3.0+ have glBindSampler()
#if !defined(IMGUI_IMPL_OPENGL_ES2) && (defined(IMGUI_IMPL_OPENGL_ES3) || defined(GL_VERSION_3_3))
#define IMGUI_IMPL_OPENGL_MAY_HAVE_BIND_SAMPLER
#endif
// Desktop GL 3.1+ has GL_PRIMITIVE_RESTART state
#if !defined(IMGUI_IMPL_OPENGL_ES2) && !defined(IMGUI_IMPL_OPENGL_ES3) && defined(GL_VERSION_3_1)
#define IMGUI_IMPL_OPENGL_MAY_HAVE_PRIMITIVE_RESTART
#endif
// Desktop GL use extension detection
#if !defined(IMGUI_IMPL_OPENGL_ES2) && !defined(IMGUI_IMPL_OPENGL_ES3)
#define IMGUI_IMPL_OPENGL_MAY_HAVE_EXTENSIONS
#endif
// [Debugging]
//#define IMGUI_IMPL_OPENGL_DEBUG
#ifdef IMGUI_IMPL_OPENGL_DEBUG
#include <stdio.h>
#define GL_CALL(_CALL) do { _CALL; GLenum gl_err = glGetError(); if (gl_err != 0) fprintf(stderr, "GL error 0x%x returned from '%s'.\n", gl_err, #_CALL); } while (0) // Call with error check
#else
#define GL_CALL(_CALL) _CALL // Call without error check
#endif
// OpenGL Data
struct ImGui_ImplOpenGL3_Data
{
GLuint GlVersion; // Extracted at runtime using GL_MAJOR_VERSION, GL_MINOR_VERSION queries (e.g. 320 for GL 3.2)
char GlslVersionString[32]; // Specified by user or detected based on compile time GL settings.
bool GlProfileIsES2;
bool GlProfileIsES3;
bool GlProfileIsCompat;
GLint GlProfileMask;
GLuint FontTexture;
GLuint ShaderHandle;
GLint AttribLocationTex; // Uniforms location
GLint AttribLocationProjMtx;
GLuint AttribLocationVtxPos; // Vertex attributes location
GLuint AttribLocationVtxUV;
GLuint AttribLocationVtxColor;
unsigned int VboHandle, ElementsHandle;
GLsizeiptr VertexBufferSize;
GLsizeiptr IndexBufferSize;
bool HasClipOrigin;
bool UseBufferSubData;
ImGui_ImplOpenGL3_Data() { memset((void*)this, 0, sizeof(*this)); }
};
// Backend data stored in io.BackendRendererUserData 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.
static ImGui_ImplOpenGL3_Data* ImGui_ImplOpenGL3_GetBackendData()
{
return ImGui::GetCurrentContext() ? (ImGui_ImplOpenGL3_Data*)ImGui::GetIO().BackendRendererUserData : nullptr;
}
// OpenGL vertex attribute state (for ES 1.0 and ES 2.0 only)
#ifndef IMGUI_IMPL_OPENGL_USE_VERTEX_ARRAY
struct ImGui_ImplOpenGL3_VtxAttribState
{
GLint Enabled, Size, Type, Normalized, Stride;
GLvoid* Ptr;
void GetState(GLint index)
{
glGetVertexAttribiv(index, GL_VERTEX_ATTRIB_ARRAY_ENABLED, &Enabled);
glGetVertexAttribiv(index, GL_VERTEX_ATTRIB_ARRAY_SIZE, &Size);
glGetVertexAttribiv(index, GL_VERTEX_ATTRIB_ARRAY_TYPE, &Type);
glGetVertexAttribiv(index, GL_VERTEX_ATTRIB_ARRAY_NORMALIZED, &Normalized);
glGetVertexAttribiv(index, GL_VERTEX_ATTRIB_ARRAY_STRIDE, &Stride);
glGetVertexAttribPointerv(index, GL_VERTEX_ATTRIB_ARRAY_POINTER, &Ptr);
}
void SetState(GLint index)
{
glVertexAttribPointer(index, Size, Type, (GLboolean)Normalized, Stride, Ptr);
if (Enabled) glEnableVertexAttribArray(index); else glDisableVertexAttribArray(index);
}
};
#endif
// Functions
bool ImGui_ImplOpenGL3_Init(const char* glsl_version)
{
ImGuiIO& io = ImGui::GetIO();
IM_ASSERT(io.BackendRendererUserData == nullptr && "Already initialized a renderer backend!");
// Initialize our loader
#if !defined(IMGUI_IMPL_OPENGL_ES2) && !defined(IMGUI_IMPL_OPENGL_ES3) && !defined(IMGUI_IMPL_OPENGL_LOADER_CUSTOM)
if (imgl3wInit() != 0)
{
fprintf(stderr, "Failed to initialize OpenGL loader!\n");
return false;
}
#endif
// Setup backend capabilities flags
ImGui_ImplOpenGL3_Data* bd = IM_NEW(ImGui_ImplOpenGL3_Data)();
io.BackendRendererUserData = (void*)bd;
io.BackendRendererName = "imgui_impl_opengl3";
// Query for GL version (e.g. 320 for GL 3.2)
#if defined(IMGUI_IMPL_OPENGL_ES2)
// GLES 2
bd->GlVersion = 200;
bd->GlProfileIsES2 = true;
#else
// Desktop or GLES 3
GLint major = 0;
GLint minor = 0;
glGetIntegerv(GL_MAJOR_VERSION, &major);
glGetIntegerv(GL_MINOR_VERSION, &minor);
if (major == 0 && minor == 0)
{
// Query GL_VERSION in desktop GL 2.x, the string will start with "<major>.<minor>"
const char* gl_version = (const char*)glGetString(GL_VERSION);
sscanf(gl_version, "%d.%d", &major, &minor);
}
bd->GlVersion = (GLuint)(major * 100 + minor * 10);
#if defined(GL_CONTEXT_PROFILE_MASK)
if (bd->GlVersion >= 320)
glGetIntegerv(GL_CONTEXT_PROFILE_MASK, &bd->GlProfileMask);
bd->GlProfileIsCompat = (bd->GlProfileMask & GL_CONTEXT_COMPATIBILITY_PROFILE_BIT) != 0;
#endif
#if defined(IMGUI_IMPL_OPENGL_ES3)
bd->GlProfileIsES3 = true;
#endif
bd->UseBufferSubData = false;
/*
// Query vendor to enable glBufferSubData kludge
#ifdef _WIN32
if (const char* vendor = (const char*)glGetString(GL_VENDOR))
if (strncmp(vendor, "Intel", 5) == 0)
bd->UseBufferSubData = true;
#endif
*/
#endif
#ifdef IMGUI_IMPL_OPENGL_DEBUG
printf("GlVersion = %d\nGlProfileIsCompat = %d\nGlProfileMask = 0x%X\nGlProfileIsES2 = %d, GlProfileIsES3 = %d\nGL_VENDOR = '%s'\nGL_RENDERER = '%s'\n", bd->GlVersion, bd->GlProfileIsCompat, bd->GlProfileMask, bd->GlProfileIsES2, bd->GlProfileIsES3, (const char*)glGetString(GL_VENDOR), (const char*)glGetString(GL_RENDERER)); // [DEBUG]
#endif
#ifdef IMGUI_IMPL_OPENGL_MAY_HAVE_VTX_OFFSET
if (bd->GlVersion >= 320)
io.BackendFlags |= ImGuiBackendFlags_RendererHasVtxOffset; // We can honor the ImDrawCmd::VtxOffset field, allowing for large meshes.
#endif
// Store GLSL version string so we can refer to it later in case we recreate shaders.
// Note: GLSL version is NOT the same as GL version. Leave this to nullptr if unsure.
if (glsl_version == nullptr)
{
#if defined(IMGUI_IMPL_OPENGL_ES2)
glsl_version = "#version 100";
#elif defined(IMGUI_IMPL_OPENGL_ES3)
glsl_version = "#version 300 es";
#elif defined(__APPLE__)
glsl_version = "#version 150";
#else
glsl_version = "#version 130";
#endif
}
IM_ASSERT((int)strlen(glsl_version) + 2 < IM_ARRAYSIZE(bd->GlslVersionString));
strcpy(bd->GlslVersionString, glsl_version);
strcat(bd->GlslVersionString, "\n");
// Make an arbitrary GL call (we don't actually need the result)
// IF YOU GET A CRASH HERE: it probably means the OpenGL function loader didn't do its job. Let us know!
GLint current_texture;
glGetIntegerv(GL_TEXTURE_BINDING_2D, &current_texture);
// Detect extensions we support
bd->HasClipOrigin = (bd->GlVersion >= 450);
#ifdef IMGUI_IMPL_OPENGL_MAY_HAVE_EXTENSIONS
GLint num_extensions = 0;
glGetIntegerv(GL_NUM_EXTENSIONS, &num_extensions);
for (GLint i = 0; i < num_extensions; i++)
{
const char* extension = (const char*)glGetStringi(GL_EXTENSIONS, i);
if (extension != nullptr && strcmp(extension, "GL_ARB_clip_control") == 0)
bd->HasClipOrigin = true;
}
#endif
return true;
}
void ImGui_ImplOpenGL3_Shutdown()
{
ImGui_ImplOpenGL3_Data* bd = ImGui_ImplOpenGL3_GetBackendData();
IM_ASSERT(bd != nullptr && "No renderer backend to shutdown, or already shutdown?");
ImGuiIO& io = ImGui::GetIO();
ImGui_ImplOpenGL3_DestroyDeviceObjects();
io.BackendRendererName = nullptr;
io.BackendRendererUserData = nullptr;
io.BackendFlags &= ~ImGuiBackendFlags_RendererHasVtxOffset;
IM_DELETE(bd);
}
void ImGui_ImplOpenGL3_NewFrame()
{
ImGui_ImplOpenGL3_Data* bd = ImGui_ImplOpenGL3_GetBackendData();
IM_ASSERT(bd != nullptr && "Did you call ImGui_ImplOpenGL3_Init()?");
if (!bd->ShaderHandle)
ImGui_ImplOpenGL3_CreateDeviceObjects();
}
static void ImGui_ImplOpenGL3_SetupRenderState(ImDrawData* draw_data, int fb_width, int fb_height, GLuint vertex_array_object)
{
ImGui_ImplOpenGL3_Data* bd = ImGui_ImplOpenGL3_GetBackendData();
// Setup render state: alpha-blending enabled, no face culling, no depth testing, scissor enabled, polygon fill
glEnable(GL_BLEND);
glBlendEquation(GL_FUNC_ADD);
glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
glDisable(GL_CULL_FACE);
glDisable(GL_DEPTH_TEST);
glDisable(GL_STENCIL_TEST);
glEnable(GL_SCISSOR_TEST);
#ifdef IMGUI_IMPL_OPENGL_MAY_HAVE_PRIMITIVE_RESTART
if (bd->GlVersion >= 310)
glDisable(GL_PRIMITIVE_RESTART);
#endif
#ifdef IMGUI_IMPL_HAS_POLYGON_MODE
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
#endif
// Support for GL 4.5 rarely used glClipControl(GL_UPPER_LEFT)
#if defined(GL_CLIP_ORIGIN)
bool clip_origin_lower_left = true;
if (bd->HasClipOrigin)
{
GLenum current_clip_origin = 0; glGetIntegerv(GL_CLIP_ORIGIN, (GLint*)&current_clip_origin);
if (current_clip_origin == GL_UPPER_LEFT)
clip_origin_lower_left = false;
}
#endif
// Setup viewport, orthographic projection matrix
// Our visible imgui space lies from draw_data->DisplayPos (top left) to draw_data->DisplayPos+data_data->DisplaySize (bottom right). DisplayPos is (0,0) for single viewport apps.
GL_CALL(glViewport(0, 0, (GLsizei)fb_width, (GLsizei)fb_height));
float L = draw_data->DisplayPos.x;
float R = draw_data->DisplayPos.x + draw_data->DisplaySize.x;
float T = draw_data->DisplayPos.y;
float B = draw_data->DisplayPos.y + draw_data->DisplaySize.y;
#if defined(GL_CLIP_ORIGIN)
if (!clip_origin_lower_left) { float tmp = T; T = B; B = tmp; } // Swap top and bottom if origin is upper left
#endif
const float ortho_projection[4][4] =
{
{ 2.0f/(R-L), 0.0f, 0.0f, 0.0f },
{ 0.0f, 2.0f/(T-B), 0.0f, 0.0f },
{ 0.0f, 0.0f, -1.0f, 0.0f },
{ (R+L)/(L-R), (T+B)/(B-T), 0.0f, 1.0f },
};
glUseProgram(bd->ShaderHandle);
glUniform1i(bd->AttribLocationTex, 0);
glUniformMatrix4fv(bd->AttribLocationProjMtx, 1, GL_FALSE, &ortho_projection[0][0]);
#ifdef IMGUI_IMPL_OPENGL_MAY_HAVE_BIND_SAMPLER
if (bd->GlVersion >= 330 || bd->GlProfileIsES3)
glBindSampler(0, 0); // We use combined texture/sampler state. Applications using GL 3.3 and GL ES 3.0 may set that otherwise.
#endif
(void)vertex_array_object;
#ifdef IMGUI_IMPL_OPENGL_USE_VERTEX_ARRAY
glBindVertexArray(vertex_array_object);
#endif
// Bind vertex/index buffers and setup attributes for ImDrawVert
GL_CALL(glBindBuffer(GL_ARRAY_BUFFER, bd->VboHandle));
GL_CALL(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, bd->ElementsHandle));
GL_CALL(glEnableVertexAttribArray(bd->AttribLocationVtxPos));
GL_CALL(glEnableVertexAttribArray(bd->AttribLocationVtxUV));
GL_CALL(glEnableVertexAttribArray(bd->AttribLocationVtxColor));
GL_CALL(glVertexAttribPointer(bd->AttribLocationVtxPos, 2, GL_FLOAT, GL_FALSE, sizeof(ImDrawVert), (GLvoid*)IM_OFFSETOF(ImDrawVert, pos)));
GL_CALL(glVertexAttribPointer(bd->AttribLocationVtxUV, 2, GL_FLOAT, GL_FALSE, sizeof(ImDrawVert), (GLvoid*)IM_OFFSETOF(ImDrawVert, uv)));
GL_CALL(glVertexAttribPointer(bd->AttribLocationVtxColor, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(ImDrawVert), (GLvoid*)IM_OFFSETOF(ImDrawVert, col)));
}
// OpenGL3 Render function.
// Note that this implementation is little overcomplicated because we are saving/setting up/restoring every OpenGL state explicitly.
// This is in order to be able to run within an OpenGL engine that doesn't do so.
void ImGui_ImplOpenGL3_RenderDrawData(ImDrawData* draw_data)
{
// Avoid rendering when minimized, scale coordinates for retina displays (screen coordinates != framebuffer coordinates)
int fb_width = (int)(draw_data->DisplaySize.x * draw_data->FramebufferScale.x);
int fb_height = (int)(draw_data->DisplaySize.y * draw_data->FramebufferScale.y);
if (fb_width <= 0 || fb_height <= 0)
return;
ImGui_ImplOpenGL3_Data* bd = ImGui_ImplOpenGL3_GetBackendData();
// Backup GL state
GLenum last_active_texture; glGetIntegerv(GL_ACTIVE_TEXTURE, (GLint*)&last_active_texture);
glActiveTexture(GL_TEXTURE0);
GLuint last_program; glGetIntegerv(GL_CURRENT_PROGRAM, (GLint*)&last_program);
GLuint last_texture; glGetIntegerv(GL_TEXTURE_BINDING_2D, (GLint*)&last_texture);
#ifdef IMGUI_IMPL_OPENGL_MAY_HAVE_BIND_SAMPLER
GLuint last_sampler; if (bd->GlVersion >= 330 || bd->GlProfileIsES3) { glGetIntegerv(GL_SAMPLER_BINDING, (GLint*)&last_sampler); } else { last_sampler = 0; }
#endif
GLuint last_array_buffer; glGetIntegerv(GL_ARRAY_BUFFER_BINDING, (GLint*)&last_array_buffer);
#ifndef IMGUI_IMPL_OPENGL_USE_VERTEX_ARRAY
// This is part of VAO on OpenGL 3.0+ and OpenGL ES 3.0+.
GLint last_element_array_buffer; glGetIntegerv(GL_ELEMENT_ARRAY_BUFFER_BINDING, &last_element_array_buffer);
ImGui_ImplOpenGL3_VtxAttribState last_vtx_attrib_state_pos; last_vtx_attrib_state_pos.GetState(bd->AttribLocationVtxPos);
ImGui_ImplOpenGL3_VtxAttribState last_vtx_attrib_state_uv; last_vtx_attrib_state_uv.GetState(bd->AttribLocationVtxUV);
ImGui_ImplOpenGL3_VtxAttribState last_vtx_attrib_state_color; last_vtx_attrib_state_color.GetState(bd->AttribLocationVtxColor);
#endif
#ifdef IMGUI_IMPL_OPENGL_USE_VERTEX_ARRAY
GLuint last_vertex_array_object; glGetIntegerv(GL_VERTEX_ARRAY_BINDING, (GLint*)&last_vertex_array_object);
#endif
#ifdef IMGUI_IMPL_HAS_POLYGON_MODE
GLint last_polygon_mode[2]; glGetIntegerv(GL_POLYGON_MODE, last_polygon_mode);
#endif
GLint last_viewport[4]; glGetIntegerv(GL_VIEWPORT, last_viewport);
GLint last_scissor_box[4]; glGetIntegerv(GL_SCISSOR_BOX, last_scissor_box);
GLenum last_blend_src_rgb; glGetIntegerv(GL_BLEND_SRC_RGB, (GLint*)&last_blend_src_rgb);
GLenum last_blend_dst_rgb; glGetIntegerv(GL_BLEND_DST_RGB, (GLint*)&last_blend_dst_rgb);
GLenum last_blend_src_alpha; glGetIntegerv(GL_BLEND_SRC_ALPHA, (GLint*)&last_blend_src_alpha);
GLenum last_blend_dst_alpha; glGetIntegerv(GL_BLEND_DST_ALPHA, (GLint*)&last_blend_dst_alpha);
GLenum last_blend_equation_rgb; glGetIntegerv(GL_BLEND_EQUATION_RGB, (GLint*)&last_blend_equation_rgb);
GLenum last_blend_equation_alpha; glGetIntegerv(GL_BLEND_EQUATION_ALPHA, (GLint*)&last_blend_equation_alpha);
GLboolean last_enable_blend = glIsEnabled(GL_BLEND);
GLboolean last_enable_cull_face = glIsEnabled(GL_CULL_FACE);
GLboolean last_enable_depth_test = glIsEnabled(GL_DEPTH_TEST);
GLboolean last_enable_stencil_test = glIsEnabled(GL_STENCIL_TEST);
GLboolean last_enable_scissor_test = glIsEnabled(GL_SCISSOR_TEST);
#ifdef IMGUI_IMPL_OPENGL_MAY_HAVE_PRIMITIVE_RESTART
GLboolean last_enable_primitive_restart = (bd->GlVersion >= 310) ? glIsEnabled(GL_PRIMITIVE_RESTART) : GL_FALSE;
#endif
// Setup desired GL state
// Recreate the VAO every time (this is to easily allow multiple GL contexts to be rendered to. VAO are not shared among GL contexts)
// The renderer would actually work without any VAO bound, but then our VertexAttrib calls would overwrite the default one currently bound.
GLuint vertex_array_object = 0;
#ifdef IMGUI_IMPL_OPENGL_USE_VERTEX_ARRAY
GL_CALL(glGenVertexArrays(1, &vertex_array_object));
#endif
ImGui_ImplOpenGL3_SetupRenderState(draw_data, fb_width, fb_height, vertex_array_object);
// Will project scissor/clipping rectangles into framebuffer space
ImVec2 clip_off = draw_data->DisplayPos; // (0,0) unless using multi-viewports
ImVec2 clip_scale = draw_data->FramebufferScale; // (1,1) unless using retina display which are often (2,2)
// Render command lists
for (int n = 0; n < draw_data->CmdListsCount; n++)
{
const ImDrawList* cmd_list = draw_data->CmdLists[n];
// Upload vertex/index buffers
// - OpenGL drivers are in a very sorry state nowadays....
// During 2021 we attempted to switch from glBufferData() to orphaning+glBufferSubData() following reports
// of leaks on Intel GPU when using multi-viewports on Windows.
// - After this we kept hearing of various display corruptions issues. We started disabling on non-Intel GPU, but issues still got reported on Intel.
// - We are now back to using exclusively glBufferData(). So bd->UseBufferSubData IS ALWAYS FALSE in this code.
// We are keeping the old code path for a while in case people finding new issues may want to test the bd->UseBufferSubData path.
// - See https://github.com/ocornut/imgui/issues/4468 and please report any corruption issues.
const GLsizeiptr vtx_buffer_size = (GLsizeiptr)cmd_list->VtxBuffer.Size * (int)sizeof(ImDrawVert);
const GLsizeiptr idx_buffer_size = (GLsizeiptr)cmd_list->IdxBuffer.Size * (int)sizeof(ImDrawIdx);
if (bd->UseBufferSubData)
{
if (bd->VertexBufferSize < vtx_buffer_size)
{
bd->VertexBufferSize = vtx_buffer_size;
GL_CALL(glBufferData(GL_ARRAY_BUFFER, bd->VertexBufferSize, nullptr, GL_STREAM_DRAW));
}
if (bd->IndexBufferSize < idx_buffer_size)
{
bd->IndexBufferSize = idx_buffer_size;
GL_CALL(glBufferData(GL_ELEMENT_ARRAY_BUFFER, bd->IndexBufferSize, nullptr, GL_STREAM_DRAW));
}
GL_CALL(glBufferSubData(GL_ARRAY_BUFFER, 0, vtx_buffer_size, (const GLvoid*)cmd_list->VtxBuffer.Data));
GL_CALL(glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, 0, idx_buffer_size, (const GLvoid*)cmd_list->IdxBuffer.Data));
}
else
{
GL_CALL(glBufferData(GL_ARRAY_BUFFER, vtx_buffer_size, (const GLvoid*)cmd_list->VtxBuffer.Data, GL_STREAM_DRAW));
GL_CALL(glBufferData(GL_ELEMENT_ARRAY_BUFFER, idx_buffer_size, (const GLvoid*)cmd_list->IdxBuffer.Data, GL_STREAM_DRAW));
}
for (int cmd_i = 0; cmd_i < cmd_list->CmdBuffer.Size; cmd_i++)
{
const ImDrawCmd* pcmd = &cmd_list->CmdBuffer[cmd_i];
if (pcmd->UserCallback != nullptr)
{
// User callback, registered via ImDrawList::AddCallback()
// (ImDrawCallback_ResetRenderState is a special callback value used by the user to request the renderer to reset render state.)
if (pcmd->UserCallback == ImDrawCallback_ResetRenderState)
ImGui_ImplOpenGL3_SetupRenderState(draw_data, fb_width, fb_height, vertex_array_object);
else
pcmd->UserCallback(cmd_list, pcmd);
}
else
{
// Project scissor/clipping rectangles into framebuffer space
ImVec2 clip_min((pcmd->ClipRect.x - clip_off.x) * clip_scale.x, (pcmd->ClipRect.y - clip_off.y) * clip_scale.y);
ImVec2 clip_max((pcmd->ClipRect.z - clip_off.x) * clip_scale.x, (pcmd->ClipRect.w - clip_off.y) * clip_scale.y);
if (clip_max.x <= clip_min.x || clip_max.y <= clip_min.y)
continue;
// Apply scissor/clipping rectangle (Y is inverted in OpenGL)
GL_CALL(glScissor((int)clip_min.x, (int)((float)fb_height - clip_max.y), (int)(clip_max.x - clip_min.x), (int)(clip_max.y - clip_min.y)));
// Bind texture, Draw
GL_CALL(glBindTexture(GL_TEXTURE_2D, (GLuint)(intptr_t)pcmd->GetTexID()));
#ifdef IMGUI_IMPL_OPENGL_MAY_HAVE_VTX_OFFSET
if (bd->GlVersion >= 320)
GL_CALL(glDrawElementsBaseVertex(GL_TRIANGLES, (GLsizei)pcmd->ElemCount, sizeof(ImDrawIdx) == 2 ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT, (void*)(intptr_t)(pcmd->IdxOffset * sizeof(ImDrawIdx)), (GLint)pcmd->VtxOffset));
else
#endif
GL_CALL(glDrawElements(GL_TRIANGLES, (GLsizei)pcmd->ElemCount, sizeof(ImDrawIdx) == 2 ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT, (void*)(intptr_t)(pcmd->IdxOffset * sizeof(ImDrawIdx))));
}
}
}
// Destroy the temporary VAO
#ifdef IMGUI_IMPL_OPENGL_USE_VERTEX_ARRAY
GL_CALL(glDeleteVertexArrays(1, &vertex_array_object));
#endif
// Restore modified GL state
// This "glIsProgram()" check is required because if the program is "pending deletion" at the time of binding backup, it will have been deleted by now and will cause an OpenGL error. See #6220.
if (last_program == 0 || glIsProgram(last_program)) glUseProgram(last_program);
glBindTexture(GL_TEXTURE_2D, last_texture);
#ifdef IMGUI_IMPL_OPENGL_MAY_HAVE_BIND_SAMPLER
if (bd->GlVersion >= 330 || bd->GlProfileIsES3)
glBindSampler(0, last_sampler);
#endif
glActiveTexture(last_active_texture);
#ifdef IMGUI_IMPL_OPENGL_USE_VERTEX_ARRAY
glBindVertexArray(last_vertex_array_object);
#endif
glBindBuffer(GL_ARRAY_BUFFER, last_array_buffer);
#ifndef IMGUI_IMPL_OPENGL_USE_VERTEX_ARRAY
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, last_element_array_buffer);
last_vtx_attrib_state_pos.SetState(bd->AttribLocationVtxPos);
last_vtx_attrib_state_uv.SetState(bd->AttribLocationVtxUV);
last_vtx_attrib_state_color.SetState(bd->AttribLocationVtxColor);
#endif
glBlendEquationSeparate(last_blend_equation_rgb, last_blend_equation_alpha);
glBlendFuncSeparate(last_blend_src_rgb, last_blend_dst_rgb, last_blend_src_alpha, last_blend_dst_alpha);
if (last_enable_blend) glEnable(GL_BLEND); else glDisable(GL_BLEND);
if (last_enable_cull_face) glEnable(GL_CULL_FACE); else glDisable(GL_CULL_FACE);
if (last_enable_depth_test) glEnable(GL_DEPTH_TEST); else glDisable(GL_DEPTH_TEST);
if (last_enable_stencil_test) glEnable(GL_STENCIL_TEST); else glDisable(GL_STENCIL_TEST);
if (last_enable_scissor_test) glEnable(GL_SCISSOR_TEST); else glDisable(GL_SCISSOR_TEST);
#ifdef IMGUI_IMPL_OPENGL_MAY_HAVE_PRIMITIVE_RESTART
if (bd->GlVersion >= 310) { if (last_enable_primitive_restart) glEnable(GL_PRIMITIVE_RESTART); else glDisable(GL_PRIMITIVE_RESTART); }
#endif
#ifdef IMGUI_IMPL_HAS_POLYGON_MODE
// Desktop OpenGL 3.0 and OpenGL 3.1 had separate polygon draw modes for front-facing and back-facing faces of polygons
if (bd->GlVersion <= 310 || bd->GlProfileIsCompat)
{
glPolygonMode(GL_FRONT, (GLenum)last_polygon_mode[0]);
glPolygonMode(GL_BACK, (GLenum)last_polygon_mode[1]);
}
else
{
glPolygonMode(GL_FRONT_AND_BACK, (GLenum)last_polygon_mode[0]);
}
#endif // IMGUI_IMPL_HAS_POLYGON_MODE
glViewport(last_viewport[0], last_viewport[1], (GLsizei)last_viewport[2], (GLsizei)last_viewport[3]);
glScissor(last_scissor_box[0], last_scissor_box[1], (GLsizei)last_scissor_box[2], (GLsizei)last_scissor_box[3]);
(void)bd; // Not all compilation paths use this
}
bool ImGui_ImplOpenGL3_CreateFontsTexture()
{
ImGuiIO& io = ImGui::GetIO();
ImGui_ImplOpenGL3_Data* bd = ImGui_ImplOpenGL3_GetBackendData();
// Build texture atlas
unsigned char* pixels;
int width, height;
io.Fonts->GetTexDataAsRGBA32(&pixels, &width, &height); // Load as RGBA 32-bit (75% of the memory is wasted, but default font is so small) because it is more likely to be compatible with user's existing shaders. If your ImTextureId represent a higher-level concept than just a GL texture id, consider calling GetTexDataAsAlpha8() instead to save on GPU memory.
// Upload texture to graphics system
// (Bilinear sampling is required by default. Set 'io.Fonts->Flags |= ImFontAtlasFlags_NoBakedLines' or 'style.AntiAliasedLinesUseTex = false' to allow point/nearest sampling)
GLint last_texture;
GL_CALL(glGetIntegerv(GL_TEXTURE_BINDING_2D, &last_texture));
GL_CALL(glGenTextures(1, &bd->FontTexture));
GL_CALL(glBindTexture(GL_TEXTURE_2D, bd->FontTexture));
GL_CALL(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR));
GL_CALL(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR));
#ifdef GL_UNPACK_ROW_LENGTH // Not on WebGL/ES
GL_CALL(glPixelStorei(GL_UNPACK_ROW_LENGTH, 0));
#endif
GL_CALL(glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels));
// Store our identifier
io.Fonts->SetTexID((ImTextureID)(intptr_t)bd->FontTexture);
// Restore state
GL_CALL(glBindTexture(GL_TEXTURE_2D, last_texture));
return true;
}
void ImGui_ImplOpenGL3_DestroyFontsTexture()
{
ImGuiIO& io = ImGui::GetIO();
ImGui_ImplOpenGL3_Data* bd = ImGui_ImplOpenGL3_GetBackendData();
if (bd->FontTexture)
{
glDeleteTextures(1, &bd->FontTexture);
io.Fonts->SetTexID(0);
bd->FontTexture = 0;
}
}
// If you get an error please report on github. You may try different GL context version or GLSL version. See GL<>GLSL version table at the top of this file.
static bool CheckShader(GLuint handle, const char* desc)
{
ImGui_ImplOpenGL3_Data* bd = ImGui_ImplOpenGL3_GetBackendData();
GLint status = 0, log_length = 0;
glGetShaderiv(handle, GL_COMPILE_STATUS, &status);
glGetShaderiv(handle, GL_INFO_LOG_LENGTH, &log_length);
if ((GLboolean)status == GL_FALSE)
fprintf(stderr, "ERROR: ImGui_ImplOpenGL3_CreateDeviceObjects: failed to compile %s! With GLSL: %s\n", desc, bd->GlslVersionString);
if (log_length > 1)
{
ImVector<char> buf;
buf.resize((int)(log_length + 1));
glGetShaderInfoLog(handle, log_length, nullptr, (GLchar*)buf.begin());
fprintf(stderr, "%s\n", buf.begin());
}
return (GLboolean)status == GL_TRUE;
}
// If you get an error please report on GitHub. You may try different GL context version or GLSL version.
static bool CheckProgram(GLuint handle, const char* desc)
{
ImGui_ImplOpenGL3_Data* bd = ImGui_ImplOpenGL3_GetBackendData();
GLint status = 0, log_length = 0;
glGetProgramiv(handle, GL_LINK_STATUS, &status);
glGetProgramiv(handle, GL_INFO_LOG_LENGTH, &log_length);
if ((GLboolean)status == GL_FALSE)
fprintf(stderr, "ERROR: ImGui_ImplOpenGL3_CreateDeviceObjects: failed to link %s! With GLSL %s\n", desc, bd->GlslVersionString);
if (log_length > 1)
{
ImVector<char> buf;
buf.resize((int)(log_length + 1));
glGetProgramInfoLog(handle, log_length, nullptr, (GLchar*)buf.begin());
fprintf(stderr, "%s\n", buf.begin());
}
return (GLboolean)status == GL_TRUE;
}
bool ImGui_ImplOpenGL3_CreateDeviceObjects()
{
ImGui_ImplOpenGL3_Data* bd = ImGui_ImplOpenGL3_GetBackendData();
// Backup GL state
GLint last_texture, last_array_buffer;
glGetIntegerv(GL_TEXTURE_BINDING_2D, &last_texture);
glGetIntegerv(GL_ARRAY_BUFFER_BINDING, &last_array_buffer);
#ifdef IMGUI_IMPL_OPENGL_USE_VERTEX_ARRAY
GLint last_vertex_array;
glGetIntegerv(GL_VERTEX_ARRAY_BINDING, &last_vertex_array);
#endif
// Parse GLSL version string
int glsl_version = 130;
sscanf(bd->GlslVersionString, "#version %d", &glsl_version);
const GLchar* vertex_shader_glsl_120 =
"uniform mat4 ProjMtx;\n"
"attribute vec2 Position;\n"
"attribute vec2 UV;\n"
"attribute vec4 Color;\n"
"varying vec2 Frag_UV;\n"
"varying vec4 Frag_Color;\n"
"void main()\n"
"{\n"
" Frag_UV = UV;\n"
" Frag_Color = Color;\n"
" gl_Position = ProjMtx * vec4(Position.xy,0,1);\n"
"}\n";
const GLchar* vertex_shader_glsl_130 =
"uniform mat4 ProjMtx;\n"
"in vec2 Position;\n"
"in vec2 UV;\n"
"in vec4 Color;\n"
"out vec2 Frag_UV;\n"
"out vec4 Frag_Color;\n"
"void main()\n"
"{\n"
" Frag_UV = UV;\n"
" Frag_Color = Color;\n"
" gl_Position = ProjMtx * vec4(Position.xy,0,1);\n"
"}\n";
const GLchar* vertex_shader_glsl_300_es =
"precision highp float;\n"
"layout (location = 0) in vec2 Position;\n"
"layout (location = 1) in vec2 UV;\n"
"layout (location = 2) in vec4 Color;\n"
"uniform mat4 ProjMtx;\n"
"out vec2 Frag_UV;\n"
"out vec4 Frag_Color;\n"
"void main()\n"
"{\n"
" Frag_UV = UV;\n"
" Frag_Color = Color;\n"
" gl_Position = ProjMtx * vec4(Position.xy,0,1);\n"
"}\n";
const GLchar* vertex_shader_glsl_410_core =
"layout (location = 0) in vec2 Position;\n"
"layout (location = 1) in vec2 UV;\n"
"layout (location = 2) in vec4 Color;\n"
"uniform mat4 ProjMtx;\n"
"out vec2 Frag_UV;\n"
"out vec4 Frag_Color;\n"
"void main()\n"
"{\n"
" Frag_UV = UV;\n"
" Frag_Color = Color;\n"
" gl_Position = ProjMtx * vec4(Position.xy,0,1);\n"
"}\n";
const GLchar* fragment_shader_glsl_120 =
"#ifdef GL_ES\n"
" precision mediump float;\n"
"#endif\n"
"uniform sampler2D Texture;\n"
"varying vec2 Frag_UV;\n"
"varying vec4 Frag_Color;\n"
"void main()\n"
"{\n"
" gl_FragColor = Frag_Color * texture2D(Texture, Frag_UV.st);\n"
"}\n";
const GLchar* fragment_shader_glsl_130 =
"uniform sampler2D Texture;\n"
"in vec2 Frag_UV;\n"
"in vec4 Frag_Color;\n"
"out vec4 Out_Color;\n"
"void main()\n"
"{\n"
" Out_Color = Frag_Color * texture(Texture, Frag_UV.st);\n"
"}\n";
const GLchar* fragment_shader_glsl_300_es =
"precision mediump float;\n"
"uniform sampler2D Texture;\n"
"in vec2 Frag_UV;\n"
"in vec4 Frag_Color;\n"
"layout (location = 0) out vec4 Out_Color;\n"
"void main()\n"
"{\n"
" Out_Color = Frag_Color * texture(Texture, Frag_UV.st);\n"
"}\n";
const GLchar* fragment_shader_glsl_410_core =
"in vec2 Frag_UV;\n"
"in vec4 Frag_Color;\n"
"uniform sampler2D Texture;\n"
"layout (location = 0) out vec4 Out_Color;\n"
"void main()\n"
"{\n"
" Out_Color = Frag_Color * texture(Texture, Frag_UV.st);\n"
"}\n";
// Select shaders matching our GLSL versions
const GLchar* vertex_shader = nullptr;
const GLchar* fragment_shader = nullptr;
if (glsl_version < 130)
{
vertex_shader = vertex_shader_glsl_120;
fragment_shader = fragment_shader_glsl_120;
}
else if (glsl_version >= 410)
{
vertex_shader = vertex_shader_glsl_410_core;
fragment_shader = fragment_shader_glsl_410_core;
}
else if (glsl_version == 300)
{
vertex_shader = vertex_shader_glsl_300_es;
fragment_shader = fragment_shader_glsl_300_es;
}
else
{
vertex_shader = vertex_shader_glsl_130;
fragment_shader = fragment_shader_glsl_130;
}
// Create shaders
const GLchar* vertex_shader_with_version[2] = { bd->GlslVersionString, vertex_shader };
GLuint vert_handle = glCreateShader(GL_VERTEX_SHADER);
glShaderSource(vert_handle, 2, vertex_shader_with_version, nullptr);
glCompileShader(vert_handle);
CheckShader(vert_handle, "vertex shader");
const GLchar* fragment_shader_with_version[2] = { bd->GlslVersionString, fragment_shader };
GLuint frag_handle = glCreateShader(GL_FRAGMENT_SHADER);
glShaderSource(frag_handle, 2, fragment_shader_with_version, nullptr);
glCompileShader(frag_handle);
CheckShader(frag_handle, "fragment shader");
// Link
bd->ShaderHandle = glCreateProgram();
glAttachShader(bd->ShaderHandle, vert_handle);
glAttachShader(bd->ShaderHandle, frag_handle);
glLinkProgram(bd->ShaderHandle);
CheckProgram(bd->ShaderHandle, "shader program");
glDetachShader(bd->ShaderHandle, vert_handle);
glDetachShader(bd->ShaderHandle, frag_handle);
glDeleteShader(vert_handle);
glDeleteShader(frag_handle);
bd->AttribLocationTex = glGetUniformLocation(bd->ShaderHandle, "Texture");
bd->AttribLocationProjMtx = glGetUniformLocation(bd->ShaderHandle, "ProjMtx");
bd->AttribLocationVtxPos = (GLuint)glGetAttribLocation(bd->ShaderHandle, "Position");
bd->AttribLocationVtxUV = (GLuint)glGetAttribLocation(bd->ShaderHandle, "UV");
bd->AttribLocationVtxColor = (GLuint)glGetAttribLocation(bd->ShaderHandle, "Color");
// Create buffers
glGenBuffers(1, &bd->VboHandle);
glGenBuffers(1, &bd->ElementsHandle);
ImGui_ImplOpenGL3_CreateFontsTexture();
// Restore modified GL state
glBindTexture(GL_TEXTURE_2D, last_texture);
glBindBuffer(GL_ARRAY_BUFFER, last_array_buffer);
#ifdef IMGUI_IMPL_OPENGL_USE_VERTEX_ARRAY
glBindVertexArray(last_vertex_array);
#endif
return true;
}
void ImGui_ImplOpenGL3_DestroyDeviceObjects()
{
ImGui_ImplOpenGL3_Data* bd = ImGui_ImplOpenGL3_GetBackendData();
if (bd->VboHandle) { glDeleteBuffers(1, &bd->VboHandle); bd->VboHandle = 0; }
if (bd->ElementsHandle) { glDeleteBuffers(1, &bd->ElementsHandle); bd->ElementsHandle = 0; }
if (bd->ShaderHandle) { glDeleteProgram(bd->ShaderHandle); bd->ShaderHandle = 0; }
ImGui_ImplOpenGL3_DestroyFontsTexture();
}
//-----------------------------------------------------------------------------
#if defined(__GNUC__)
#pragma GCC diagnostic pop
#endif
#if defined(__clang__)
#pragma clang diagnostic pop
#endif
#endif // #ifndef IMGUI_DISABLE

View File

@@ -0,0 +1,63 @@
// 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 identifier as void*/ImTextureID. Read the FAQ about ImTextureID!
// [x] Renderer: Large meshes support (64k+ vertices) with 16-bit indices (Desktop OpenGL only).
// 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.
// If you are new to Dear ImGui, read documentation from the docs/ folder + read the top of imgui.cpp.
// Read online: https://github.com/ocornut/imgui/tree/master/docs
// 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
// Backend API
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_CreateFontsTexture();
IMGUI_IMPL_API void ImGui_ImplOpenGL3_DestroyFontsTexture();
IMGUI_IMPL_API bool ImGui_ImplOpenGL3_CreateDeviceObjects();
IMGUI_IMPL_API void ImGui_ImplOpenGL3_DestroyDeviceObjects();
// Specific OpenGL ES versions
//#define IMGUI_IMPL_OPENGL_ES2 // Auto-detected on Emscripten
//#define IMGUI_IMPL_OPENGL_ES3 // 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

View File

@@ -0,0 +1,809 @@
//-----------------------------------------------------------------------------
// 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 INCUDING '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:
// python 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_PACK_ALIGNMENT 0x0D05
#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
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 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 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_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_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 int imgl3wIsSupported(int major, int minor);
GL3W_API GL3WglProc imgl3wGetProcAddress(const char *proc);
/* gl3w internal state */
union GL3WProcs {
GL3WglProc ptr[59];
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;
PFNGLUNIFORM1IPROC Uniform1i;
PFNGLUNIFORMMATRIX4FVPROC UniformMatrix4fv;
PFNGLUSEPROGRAMPROC UseProgram;
PFNGLVERTEXATTRIBPOINTERPROC VertexAttribPointer;
PFNGLVIEWPORTPROC Viewport;
} gl;
};
GL3W_API extern union GL3WProcs 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 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 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;
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); }
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;
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); }
static GL3WglProc get_proc(const char *proc)
{
GL3WglProc res;
*(void **)(&res) = dlsym(libgl, proc);
return res;
}
#else
#include <dlfcn.h>
static void *libgl;
static GL3WglProc (*glx_get_proc_address)(const GLubyte *);
static int open_libgl(void)
{
libgl = dlopen("libGL.so.1", RTLD_LAZY | RTLD_LOCAL);
if (!libgl)
return GL3W_ERROR_LIBRARY_OPEN;
*(void **)(&glx_get_proc_address) = dlsym(libgl, "glXGetProcAddressARB");
return GL3W_OK;
}
static void close_libgl(void) { dlclose(libgl); }
static GL3WglProc get_proc(const char *proc)
{
GL3WglProc res;
res = glx_get_proc_address((const GLubyte *)proc);
if (!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();
}
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",
"glUniform1i",
"glUniformMatrix4fv",
"glUseProgram",
"glVertexAttribPointer",
"glViewport",
};
GL3W_API union GL3WProcs imgl3wProcs;
static void load_procs(GL3WGetProcAddressProc proc)
{
size_t i;
for (i = 0; i < ARRAY_SIZE(proc_names); i++)
imgl3wProcs.ptr[i] = proc(proc_names[i]);
}
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -0,0 +1,656 @@
// dear imgui: Platform Backend for SDL2
// This needs to be used along with a Renderer (e.g. DirectX11, OpenGL3, Vulkan..)
// (Info: SDL2 is a cross-platform general purpose library for handling windows, inputs, graphics context creation, etc.)
// (Prefer SDL 2.0.5+ for full feature support.)
// 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 will also be supported unless IMGUI_DISABLE_OBSOLETE_KEYIO is set]
// [X] Platform: Gamepad support. Enabled with 'io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad'.
// [X] Platform: Mouse cursor shape and visibility. Disable with 'io.ConfigFlags |= ImGuiConfigFlags_NoMouseCursorChange'.
// [X] Platform: Basic IME support. App needs to call 'SDL_SetHint(SDL_HINT_IME_SHOW_UI, "1");' before SDL_CreateWindow()!.
// 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.
// If you are new to Dear ImGui, read documentation from the docs/ folder + read the top of imgui.cpp.
// Read online: https://github.com/ocornut/imgui/tree/master/docs
// CHANGELOG
// (minor and older changes stripped away, please see git history for details)
// 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: Implement IME handler (io.SetPlatformImeDataFn will call SDL_SetTextInputRect()/SDL_StartTextInput()).
// 2023-02-07: *BREAKING CHANGE* Renamed this backend file from imgui_impl_sdl.cpp/.h to imgui_impl_sdl2.cpp/.h in prevision for the future release of SDL3.
// 2023-02-02: Avoid calling SDL_SetCursor() when cursor has not changed, as the function is surprisingly costly on Mac with latest SDL (may be fixed in next SDL version).
// 2023-02-02: Added support for SDL 2.0.18+ preciseX/preciseY mouse wheel data for smooth scrolling + Scaling X value on Emscripten (bug?). (#4019, #6096)
// 2023-02-02: Removed SDL_MOUSEWHEEL value clamping, as values seem correct in latest Emscripten. (#4019)
// 2023-02-01: Flipping SDL_MOUSEWHEEL 'wheel.x' value to match other backends and offer consistent horizontal scrolling direction. (#4019, #6096, #1463)
// 2022-10-11: Using 'nullptr' instead of 'NULL' as per our switch to C++11.
// 2022-09-26: Inputs: Disable SDL 2.0.22 new "auto capture" (SDL_HINT_MOUSE_AUTO_CAPTURE) which prevents drag and drop across windows for multi-viewport support + don't capture when drag and dropping. (#5710)
// 2022-09-26: Inputs: Renamed ImGuiKey_ModXXX introduced in 1.87 to ImGuiMod_XXX (old names still supported).
// 2022-03-22: Inputs: Fix mouse position issues when dragging outside of boundaries. SDL_CaptureMouse() erroneously still gives out LEAVE events when hovering OS decorations.
// 2022-03-22: Inputs: Added support for extra mouse buttons (SDL_BUTTON_X1/SDL_BUTTON_X2).
// 2022-02-04: Added SDL_Renderer* parameter to ImGui_ImplSDL2_InitForSDLRenderer(), so we can use SDL_GetRendererOutputSize() instead of SDL_GL_GetDrawableSize() when bound to a SDL_Renderer.
// 2022-01-26: Inputs: replaced short-lived io.AddKeyModsEvent() (added two weeks ago) with io.AddKeyEvent() using ImGuiKey_ModXXX flags. Sorry for the confusion.
// 2021-01-20: Inputs: calling new io.AddKeyAnalogEvent() for gamepad support, instead of writing directly to io.NavInputs[].
// 2022-01-17: Inputs: calling new io.AddMousePosEvent(), io.AddMouseButtonEvent(), io.AddMouseWheelEvent() API (1.87+).
// 2022-01-17: Inputs: always update key mods next and before key event (not in NewFrame) to fix input queue with very low framerates.
// 2022-01-12: Update mouse inputs using SDL_MOUSEMOTION/SDL_WINDOWEVENT_LEAVE + fallback to provide it when focused but not hovered/captured. More standard and will allow us to pass it to future input queue API.
// 2022-01-12: Maintain our own copy of MouseButtonsDown mask instead of using ImGui::IsAnyMouseDown() which will be obsoleted.
// 2022-01-10: Inputs: calling new io.AddKeyEvent(), io.AddKeyModsEvent() + io.SetKeyEventNativeData() API (1.87+). Support for full ImGuiKey range.
// 2021-08-17: Calling io.AddFocusEvent() on SDL_WINDOWEVENT_FOCUS_GAINED/SDL_WINDOWEVENT_FOCUS_LOST.
// 2021-07-29: Inputs: MousePos is correctly reported when the host platform window is hovered but not focused (using SDL_GetMouseFocus() + SDL_HINT_MOUSE_FOCUS_CLICKTHROUGH, requires SDL 2.0.5+)
// 2021-06-29: *BREAKING CHANGE* Removed 'SDL_Window* window' parameter to ImGui_ImplSDL2_NewFrame() which was unnecessary.
// 2021-06-29: Reorganized backend to pull data from a single structure to facilitate usage with multiple-contexts (all g_XXXX access changed to bd->XXXX).
// 2021-03-22: Rework global mouse pos availability check listing supported platforms explicitly, effectively fixing mouse access on Raspberry Pi. (#2837, #3950)
// 2020-05-25: Misc: Report a zero display-size when window is minimized, to be consistent with other backends.
// 2020-02-20: Inputs: Fixed mapping for ImGuiKey_KeyPadEnter (using SDL_SCANCODE_KP_ENTER instead of SDL_SCANCODE_RETURN2).
// 2019-12-17: Inputs: On Wayland, use SDL_GetMouseState (because there is no global mouse state).
// 2019-12-05: Inputs: Added support for ImGuiMouseCursor_NotAllowed mouse cursor.
// 2019-07-21: Inputs: Added mapping for ImGuiKey_KeyPadEnter.
// 2019-04-23: Inputs: Added support for SDL_GameController (if ImGuiConfigFlags_NavEnableGamepad is set by user application).
// 2019-03-12: Misc: Preserve DisplayFramebufferScale when main window is minimized.
// 2018-12-21: Inputs: Workaround for Android/iOS which don't seem to handle focus related calls.
// 2018-11-30: Misc: Setting up io.BackendPlatformName so it can be displayed in the About Window.
// 2018-11-14: Changed the signature of ImGui_ImplSDL2_ProcessEvent() to take a 'const SDL_Event*'.
// 2018-08-01: Inputs: Workaround for Emscripten which doesn't seem to handle focus related calls.
// 2018-06-29: Inputs: Added support for the ImGuiMouseCursor_Hand cursor.
// 2018-06-08: Misc: Extracted imgui_impl_sdl.cpp/.h away from the old combined SDL2+OpenGL/Vulkan examples.
// 2018-06-08: Misc: ImGui_ImplSDL2_InitForOpenGL() now takes a SDL_GLContext parameter.
// 2018-05-09: Misc: Fixed clipboard paste memory leak (we didn't call SDL_FreeMemory on the data returned by SDL_GetClipboardText).
// 2018-03-20: Misc: Setup io.BackendFlags ImGuiBackendFlags_HasMouseCursors flag + honor ImGuiConfigFlags_NoMouseCursorChange flag.
// 2018-02-16: Inputs: Added support for mouse cursors, honoring ImGui::GetMouseCursor() value.
// 2018-02-06: Misc: Removed call to ImGui::Shutdown() which is not available from 1.60 WIP, user needs to call CreateContext/DestroyContext themselves.
// 2018-02-06: Inputs: Added mapping for ImGuiKey_Space.
// 2018-02-05: Misc: Using SDL_GetPerformanceCounter() instead of SDL_GetTicks() to be able to handle very high framerate (1000+ FPS).
// 2018-02-05: Inputs: Keyboard mapping is using scancodes everywhere instead of a confusing mixture of keycodes and scancodes.
// 2018-01-20: Inputs: Added Horizontal Mouse Wheel support.
// 2018-01-19: Inputs: When available (SDL 2.0.4+) using SDL_CaptureMouse() to retrieve coordinates outside of client area when dragging. Otherwise (SDL 2.0.3 and before) testing for SDL_WINDOW_INPUT_FOCUS instead of SDL_WINDOW_MOUSE_FOCUS.
// 2018-01-18: Inputs: Added mapping for ImGuiKey_Insert.
// 2017-08-25: Inputs: MousePos set to -FLT_MAX,-FLT_MAX when mouse is unavailable/missing (instead of -1,-1).
// 2016-10-15: Misc: Added a void* user_data parameter to Clipboard function handlers.
#include "imgui.h"
#ifndef IMGUI_DISABLE
#include "imgui_impl_sdl2.h"
// Clang warnings with -Weverything
#if defined(__clang__)
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wimplicit-int-float-conversion" // warning: implicit conversion from 'xxx' to 'float' may lose precision
#endif
// SDL
#include <SDL2/SDL.h>
#include <SDL2/SDL_syswm.h>
#if defined(__APPLE__)
#include <TargetConditionals.h>
#endif
#if SDL_VERSION_ATLEAST(2,0,4) && !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
#define SDL_HAS_VULKAN SDL_VERSION_ATLEAST(2,0,6)
// SDL Data
struct ImGui_ImplSDL2_Data
{
SDL_Window* Window;
SDL_Renderer* Renderer;
Uint64 Time;
Uint32 MouseWindowID;
int MouseButtonsDown;
SDL_Cursor* MouseCursors[ImGuiMouseCursor_COUNT];
SDL_Cursor* LastMouseCursor;
int PendingMouseLeaveFrame;
char* ClipboardTextData;
bool MouseCanUseGlobalState;
ImGui_ImplSDL2_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_ImplSDL2_Data* ImGui_ImplSDL2_GetBackendData()
{
return ImGui::GetCurrentContext() ? (ImGui_ImplSDL2_Data*)ImGui::GetIO().BackendPlatformUserData : nullptr;
}
// Functions
static const char* ImGui_ImplSDL2_GetClipboardText(void*)
{
ImGui_ImplSDL2_Data* bd = ImGui_ImplSDL2_GetBackendData();
if (bd->ClipboardTextData)
SDL_free(bd->ClipboardTextData);
bd->ClipboardTextData = SDL_GetClipboardText();
return bd->ClipboardTextData;
}
static void ImGui_ImplSDL2_SetClipboardText(void*, const char* text)
{
SDL_SetClipboardText(text);
}
// Note: native IME will only display if user calls SDL_SetHint(SDL_HINT_IME_SHOW_UI, "1") _before_ SDL_CreateWindow().
static void ImGui_ImplSDL2_SetPlatformImeData(ImGuiViewport*, ImGuiPlatformImeData* data)
{
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_SetTextInputRect(&r);
}
}
static ImGuiKey ImGui_ImplSDL2_KeycodeToImGuiKey(int keycode)
{
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_QUOTE: 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_BACKQUOTE: 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_KP_0: return ImGuiKey_Keypad0;
case SDLK_KP_1: return ImGuiKey_Keypad1;
case SDLK_KP_2: return ImGuiKey_Keypad2;
case SDLK_KP_3: return ImGuiKey_Keypad3;
case SDLK_KP_4: return ImGuiKey_Keypad4;
case SDLK_KP_5: return ImGuiKey_Keypad5;
case SDLK_KP_6: return ImGuiKey_Keypad6;
case SDLK_KP_7: return ImGuiKey_Keypad7;
case SDLK_KP_8: return ImGuiKey_Keypad8;
case SDLK_KP_9: return ImGuiKey_Keypad9;
case SDLK_KP_PERIOD: return ImGuiKey_KeypadDecimal;
case SDLK_KP_DIVIDE: return ImGuiKey_KeypadDivide;
case SDLK_KP_MULTIPLY: return ImGuiKey_KeypadMultiply;
case SDLK_KP_MINUS: return ImGuiKey_KeypadSubtract;
case SDLK_KP_PLUS: return ImGuiKey_KeypadAdd;
case SDLK_KP_ENTER: return ImGuiKey_KeypadEnter;
case SDLK_KP_EQUALS: return ImGuiKey_KeypadEqual;
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;
}
return ImGuiKey_None;
}
static void ImGui_ImplSDL2_UpdateKeyModifiers(SDL_Keymod sdl_key_mods)
{
ImGuiIO& io = ImGui::GetIO();
io.AddKeyEvent(ImGuiMod_Ctrl, (sdl_key_mods & KMOD_CTRL) != 0);
io.AddKeyEvent(ImGuiMod_Shift, (sdl_key_mods & KMOD_SHIFT) != 0);
io.AddKeyEvent(ImGuiMod_Alt, (sdl_key_mods & KMOD_ALT) != 0);
io.AddKeyEvent(ImGuiMod_Super, (sdl_key_mods & KMOD_GUI) != 0);
}
// 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_ImplSDL2_ProcessEvent(const SDL_Event* event)
{
ImGuiIO& io = ImGui::GetIO();
ImGui_ImplSDL2_Data* bd = ImGui_ImplSDL2_GetBackendData();
switch (event->type)
{
case SDL_MOUSEMOTION:
{
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_MOUSEWHEEL:
{
//IMGUI_DEBUG_LOG("wheel %.2f %.2f, precise %.2f %.2f\n", (float)event->wheel.x, (float)event->wheel.y, event->wheel.preciseX, event->wheel.preciseY);
#if SDL_VERSION_ATLEAST(2,0,18) // If this fails to compile on Emscripten: update to latest Emscripten!
float wheel_x = -event->wheel.preciseX;
float wheel_y = event->wheel.preciseY;
#else
float wheel_x = -(float)event->wheel.x;
float wheel_y = (float)event->wheel.y;
#endif
#ifdef __EMSCRIPTEN__
wheel_x /= 100.0f;
#endif
io.AddMouseSourceEvent(event->wheel.which == SDL_TOUCH_MOUSEID ? ImGuiMouseSource_TouchScreen : ImGuiMouseSource_Mouse);
io.AddMouseWheelEvent(wheel_x, wheel_y);
return true;
}
case SDL_MOUSEBUTTONDOWN:
case SDL_MOUSEBUTTONUP:
{
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_MOUSEBUTTONDOWN));
bd->MouseButtonsDown = (event->type == SDL_MOUSEBUTTONDOWN) ? (bd->MouseButtonsDown | (1 << mouse_button)) : (bd->MouseButtonsDown & ~(1 << mouse_button));
return true;
}
case SDL_TEXTINPUT:
{
io.AddInputCharactersUTF8(event->text.text);
return true;
}
case SDL_KEYDOWN:
case SDL_KEYUP:
{
ImGui_ImplSDL2_UpdateKeyModifiers((SDL_Keymod)event->key.keysym.mod);
ImGuiKey key = ImGui_ImplSDL2_KeycodeToImGuiKey(event->key.keysym.sym);
io.AddKeyEvent(key, (event->type == SDL_KEYDOWN));
io.SetKeyEventNativeData(key, event->key.keysym.sym, event->key.keysym.scancode, event->key.keysym.scancode); // To support legacy indexing (<1.87 user code). Legacy backend uses SDLK_*** as indices to IsKeyXXX() functions.
return true;
}
case SDL_WINDOWEVENT:
{
// - When capturing mouse, SDL will send a bunch of conflicting LEAVE/ENTER event on every mouse move, but the final ENTER tends to be right.
// - However we won't get a correct LEAVE event for a captured window.
// - 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.
Uint8 window_event = event->window.event;
if (window_event == SDL_WINDOWEVENT_ENTER)
{
bd->MouseWindowID = event->window.windowID;
bd->PendingMouseLeaveFrame = 0;
}
if (window_event == SDL_WINDOWEVENT_LEAVE)
bd->PendingMouseLeaveFrame = ImGui::GetFrameCount() + 1;
if (window_event == SDL_WINDOWEVENT_FOCUS_GAINED)
io.AddFocusEvent(true);
else if (event->window.event == SDL_WINDOWEVENT_FOCUS_LOST)
io.AddFocusEvent(false);
return true;
}
}
return false;
}
static bool ImGui_ImplSDL2_Init(SDL_Window* window, SDL_Renderer* renderer)
{
ImGuiIO& io = ImGui::GetIO();
IM_ASSERT(io.BackendPlatformUserData == nullptr && "Already initialized a platform backend!");
// Check and store if we are on a SDL backend that supports global mouse position
// ("wayland" and "rpi" don't support it, but we chose to use a white-list instead of a black-list)
bool mouse_can_use_global_state = false;
#if SDL_HAS_CAPTURE_AND_GLOBAL_MOUSE
const char* sdl_backend = SDL_GetCurrentVideoDriver();
const char* global_mouse_whitelist[] = { "windows", "cocoa", "x11", "DIVE", "VMAN" };
for (int n = 0; n < IM_ARRAYSIZE(global_mouse_whitelist); n++)
if (strncmp(sdl_backend, global_mouse_whitelist[n], strlen(global_mouse_whitelist[n])) == 0)
mouse_can_use_global_state = true;
#endif
// Setup backend capabilities flags
ImGui_ImplSDL2_Data* bd = IM_NEW(ImGui_ImplSDL2_Data)();
io.BackendPlatformUserData = (void*)bd;
io.BackendPlatformName = "imgui_impl_sdl2";
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->Renderer = renderer;
bd->MouseCanUseGlobalState = mouse_can_use_global_state;
io.SetClipboardTextFn = ImGui_ImplSDL2_SetClipboardText;
io.GetClipboardTextFn = ImGui_ImplSDL2_GetClipboardText;
io.ClipboardUserData = nullptr;
io.SetPlatformImeDataFn = ImGui_ImplSDL2_SetPlatformImeData;
// Load mouse cursors
bd->MouseCursors[ImGuiMouseCursor_Arrow] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_ARROW);
bd->MouseCursors[ImGuiMouseCursor_TextInput] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_IBEAM);
bd->MouseCursors[ImGuiMouseCursor_ResizeAll] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_SIZEALL);
bd->MouseCursors[ImGuiMouseCursor_ResizeNS] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_SIZENS);
bd->MouseCursors[ImGuiMouseCursor_ResizeEW] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_SIZEWE);
bd->MouseCursors[ImGuiMouseCursor_ResizeNESW] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_SIZENESW);
bd->MouseCursors[ImGuiMouseCursor_ResizeNWSE] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_SIZENWSE);
bd->MouseCursors[ImGuiMouseCursor_Hand] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_HAND);
bd->MouseCursors[ImGuiMouseCursor_NotAllowed] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_NO);
// Set platform dependent data in viewport
// Our mouse update function expect PlatformHandle to be filled for the main viewport
ImGuiViewport* main_viewport = ImGui::GetMainViewport();
main_viewport->PlatformHandleRaw = nullptr;
SDL_SysWMinfo info;
SDL_VERSION(&info.version);
if (SDL_GetWindowWMInfo(window, &info))
{
#if defined(SDL_VIDEO_DRIVER_WINDOWS)
main_viewport->PlatformHandleRaw = (void*)info.info.win.window;
#elif defined(__APPLE__) && defined(SDL_VIDEO_DRIVER_COCOA)
main_viewport->PlatformHandleRaw = (void*)info.info.cocoa.window;
#endif
}
// 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_MOUSEBUTTONDOWN 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.18: Enable native IME.
// IMPORTANT: This is used at the time of SDL_CreateWindow() so this will only affects secondary windows, if any.
// For the main window to be affected, your application needs to call this manually before calling SDL_CreateWindow().
#ifdef SDL_HINT_IME_SHOW_UI
SDL_SetHint(SDL_HINT_IME_SHOW_UI, "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_ImplSDL2_InitForOpenGL(SDL_Window* window, void* sdl_gl_context)
{
IM_UNUSED(sdl_gl_context); // Viewport branch will need this.
return ImGui_ImplSDL2_Init(window, nullptr);
}
bool ImGui_ImplSDL2_InitForVulkan(SDL_Window* window)
{
#if !SDL_HAS_VULKAN
IM_ASSERT(0 && "Unsupported");
#endif
return ImGui_ImplSDL2_Init(window, nullptr);
}
bool ImGui_ImplSDL2_InitForD3D(SDL_Window* window)
{
#if !defined(_WIN32)
IM_ASSERT(0 && "Unsupported");
#endif
return ImGui_ImplSDL2_Init(window, nullptr);
}
bool ImGui_ImplSDL2_InitForMetal(SDL_Window* window)
{
return ImGui_ImplSDL2_Init(window, nullptr);
}
bool ImGui_ImplSDL2_InitForSDLRenderer(SDL_Window* window, SDL_Renderer* renderer)
{
return ImGui_ImplSDL2_Init(window, renderer);
}
bool ImGui_ImplSDL2_InitForOther(SDL_Window* window)
{
return ImGui_ImplSDL2_Init(window, nullptr);
}
void ImGui_ImplSDL2_Shutdown()
{
ImGui_ImplSDL2_Data* bd = ImGui_ImplSDL2_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_FreeCursor(bd->MouseCursors[cursor_n]);
bd->LastMouseCursor = nullptr;
io.BackendPlatformName = nullptr;
io.BackendPlatformUserData = nullptr;
io.BackendFlags &= ~(ImGuiBackendFlags_HasMouseCursors | ImGuiBackendFlags_HasSetMousePos | ImGuiBackendFlags_HasGamepad);
IM_DELETE(bd);
}
static void ImGui_ImplSDL2_UpdateMouseData()
{
ImGui_ImplSDL2_Data* bd = ImGui_ImplSDL2_GetBackendData();
ImGuiIO& io = ImGui::GetIO();
// We forward mouse input when hovered or captured (via SDL_MOUSEMOTION) or when focused (below)
#if SDL_HAS_CAPTURE_AND_GLOBAL_MOUSE
// SDL_CaptureMouse() let the OS know e.g. that our imgui drag outside the SDL window boundaries shouldn't e.g. trigger other operations outside
SDL_CaptureMouse((bd->MouseButtonsDown != 0) ? SDL_TRUE : SDL_FALSE);
SDL_Window* focused_window = SDL_GetKeyboardFocus();
const bool is_app_focused = (bd->Window == focused_window);
#else
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 ImGuiConfigFlags_NavEnableSetMousePos is enabled by user)
if (io.WantSetMousePos)
SDL_WarpMouseInWindow(bd->Window, (int)io.MousePos.x, (int)io.MousePos.y);
// (Optional) Fallback to provide mouse position when focused (SDL_MOUSEMOTION already provides this when hovered or captured)
if (bd->MouseCanUseGlobalState && bd->MouseButtonsDown == 0)
{
int window_x, window_y, mouse_x_global, mouse_y_global;
SDL_GetGlobalMouseState(&mouse_x_global, &mouse_y_global);
SDL_GetWindowPosition(bd->Window, &window_x, &window_y);
io.AddMousePosEvent((float)(mouse_x_global - window_x), (float)(mouse_y_global - window_y));
}
}
}
static void ImGui_ImplSDL2_UpdateMouseCursor()
{
ImGuiIO& io = ImGui::GetIO();
if (io.ConfigFlags & ImGuiConfigFlags_NoMouseCursorChange)
return;
ImGui_ImplSDL2_Data* bd = ImGui_ImplSDL2_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_ShowCursor(SDL_FALSE);
}
else
{
// Show OS mouse cursor
SDL_Cursor* expected_cursor = bd->MouseCursors[imgui_cursor] ? bd->MouseCursors[imgui_cursor] : bd->MouseCursors[ImGuiMouseCursor_Arrow];
if (bd->LastMouseCursor != expected_cursor)
{
SDL_SetCursor(expected_cursor); // SDL function doesn't have an early out (see #6113)
bd->LastMouseCursor = expected_cursor;
}
SDL_ShowCursor(SDL_TRUE);
}
}
static void ImGui_ImplSDL2_UpdateGamepads()
{
ImGuiIO& io = ImGui::GetIO();
if ((io.ConfigFlags & ImGuiConfigFlags_NavEnableGamepad) == 0) // FIXME: Technically feeding gamepad shouldn't depend on this now that they are regular inputs.
return;
// Get gamepad
io.BackendFlags &= ~ImGuiBackendFlags_HasGamepad;
SDL_GameController* game_controller = SDL_GameControllerOpen(0);
if (!game_controller)
return;
io.BackendFlags |= ImGuiBackendFlags_HasGamepad;
// Update gamepad inputs
#define IM_SATURATE(V) (V < 0.0f ? 0.0f : V > 1.0f ? 1.0f : V)
#define MAP_BUTTON(KEY_NO, BUTTON_NO) { io.AddKeyEvent(KEY_NO, SDL_GameControllerGetButton(game_controller, BUTTON_NO) != 0); }
#define MAP_ANALOG(KEY_NO, AXIS_NO, V0, V1) { float vn = (float)(SDL_GameControllerGetAxis(game_controller, AXIS_NO) - V0) / (float)(V1 - V0); vn = IM_SATURATE(vn); io.AddKeyAnalogEvent(KEY_NO, vn > 0.1f, vn); }
const int thumb_dead_zone = 8000; // SDL_gamecontroller.h suggests using this value.
MAP_BUTTON(ImGuiKey_GamepadStart, SDL_CONTROLLER_BUTTON_START);
MAP_BUTTON(ImGuiKey_GamepadBack, SDL_CONTROLLER_BUTTON_BACK);
MAP_BUTTON(ImGuiKey_GamepadFaceLeft, SDL_CONTROLLER_BUTTON_X); // Xbox X, PS Square
MAP_BUTTON(ImGuiKey_GamepadFaceRight, SDL_CONTROLLER_BUTTON_B); // Xbox B, PS Circle
MAP_BUTTON(ImGuiKey_GamepadFaceUp, SDL_CONTROLLER_BUTTON_Y); // Xbox Y, PS Triangle
MAP_BUTTON(ImGuiKey_GamepadFaceDown, SDL_CONTROLLER_BUTTON_A); // Xbox A, PS Cross
MAP_BUTTON(ImGuiKey_GamepadDpadLeft, SDL_CONTROLLER_BUTTON_DPAD_LEFT);
MAP_BUTTON(ImGuiKey_GamepadDpadRight, SDL_CONTROLLER_BUTTON_DPAD_RIGHT);
MAP_BUTTON(ImGuiKey_GamepadDpadUp, SDL_CONTROLLER_BUTTON_DPAD_UP);
MAP_BUTTON(ImGuiKey_GamepadDpadDown, SDL_CONTROLLER_BUTTON_DPAD_DOWN);
MAP_BUTTON(ImGuiKey_GamepadL1, SDL_CONTROLLER_BUTTON_LEFTSHOULDER);
MAP_BUTTON(ImGuiKey_GamepadR1, SDL_CONTROLLER_BUTTON_RIGHTSHOULDER);
MAP_ANALOG(ImGuiKey_GamepadL2, SDL_CONTROLLER_AXIS_TRIGGERLEFT, 0.0f, 32767);
MAP_ANALOG(ImGuiKey_GamepadR2, SDL_CONTROLLER_AXIS_TRIGGERRIGHT, 0.0f, 32767);
MAP_BUTTON(ImGuiKey_GamepadL3, SDL_CONTROLLER_BUTTON_LEFTSTICK);
MAP_BUTTON(ImGuiKey_GamepadR3, SDL_CONTROLLER_BUTTON_RIGHTSTICK);
MAP_ANALOG(ImGuiKey_GamepadLStickLeft, SDL_CONTROLLER_AXIS_LEFTX, -thumb_dead_zone, -32768);
MAP_ANALOG(ImGuiKey_GamepadLStickRight, SDL_CONTROLLER_AXIS_LEFTX, +thumb_dead_zone, +32767);
MAP_ANALOG(ImGuiKey_GamepadLStickUp, SDL_CONTROLLER_AXIS_LEFTY, -thumb_dead_zone, -32768);
MAP_ANALOG(ImGuiKey_GamepadLStickDown, SDL_CONTROLLER_AXIS_LEFTY, +thumb_dead_zone, +32767);
MAP_ANALOG(ImGuiKey_GamepadRStickLeft, SDL_CONTROLLER_AXIS_RIGHTX, -thumb_dead_zone, -32768);
MAP_ANALOG(ImGuiKey_GamepadRStickRight, SDL_CONTROLLER_AXIS_RIGHTX, +thumb_dead_zone, +32767);
MAP_ANALOG(ImGuiKey_GamepadRStickUp, SDL_CONTROLLER_AXIS_RIGHTY, -thumb_dead_zone, -32768);
MAP_ANALOG(ImGuiKey_GamepadRStickDown, SDL_CONTROLLER_AXIS_RIGHTY, +thumb_dead_zone, +32767);
#undef MAP_BUTTON
#undef MAP_ANALOG
}
void ImGui_ImplSDL2_NewFrame()
{
ImGui_ImplSDL2_Data* bd = ImGui_ImplSDL2_GetBackendData();
IM_ASSERT(bd != nullptr && "Did you call ImGui_ImplSDL2_Init()?");
ImGuiIO& io = ImGui::GetIO();
// Setup display size (every frame to accommodate for window resizing)
int w, h;
int display_w, display_h;
SDL_GetWindowSize(bd->Window, &w, &h);
if (SDL_GetWindowFlags(bd->Window) & SDL_WINDOW_MINIMIZED)
w = h = 0;
if (bd->Renderer != nullptr)
SDL_GetRendererOutputSize(bd->Renderer, &display_w, &display_h);
else
SDL_GL_GetDrawableSize(bd->Window, &display_w, &display_h);
io.DisplaySize = ImVec2((float)w, (float)h);
if (w > 0 && h > 0)
io.DisplayFramebufferScale = ImVec2((float)display_w / w, (float)display_h / h);
// Setup time step (we don't use SDL_GetTicks() because it is using millisecond resolution)
// (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->PendingMouseLeaveFrame && bd->PendingMouseLeaveFrame >= ImGui::GetFrameCount() && bd->MouseButtonsDown == 0)
{
bd->MouseWindowID = 0;
bd->PendingMouseLeaveFrame = 0;
io.AddMousePosEvent(-FLT_MAX, -FLT_MAX);
}
ImGui_ImplSDL2_UpdateMouseData();
ImGui_ImplSDL2_UpdateMouseCursor();
// Update game controllers (if enabled and available)
ImGui_ImplSDL2_UpdateGamepads();
}
//-----------------------------------------------------------------------------
#if defined(__clang__)
#pragma clang diagnostic pop
#endif
#endif // #ifndef IMGUI_DISABLE

View File

@@ -0,0 +1,40 @@
// dear imgui: Platform Backend for SDL2
// This needs to be used along with a Renderer (e.g. DirectX11, OpenGL3, Vulkan..)
// (Info: SDL2 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 will also be supported unless IMGUI_DISABLE_OBSOLETE_KEYIO is set]
// [X] Platform: Gamepad support. Enabled with 'io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad'.
// [X] Platform: Mouse cursor shape and visibility. Disable with 'io.ConfigFlags |= ImGuiConfigFlags_NoMouseCursorChange'.
// [X] Platform: Basic IME support. App needs to call 'SDL_SetHint(SDL_HINT_IME_SHOW_UI, "1");' before SDL_CreateWindow()!.
// 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.
// If you are new to Dear ImGui, read documentation from the docs/ folder + read the top of imgui.cpp.
// Read online: https://github.com/ocornut/imgui/tree/master/docs
#pragma once
#include "imgui.h" // IMGUI_IMPL_API
#ifndef IMGUI_DISABLE
class SDL_Window;
struct SDL_Renderer;
typedef union SDL_Event SDL_Event;
IMGUI_IMPL_API bool ImGui_ImplSDL2_InitForOpenGL(SDL_Window* window, void* sdl_gl_context);
IMGUI_IMPL_API bool ImGui_ImplSDL2_InitForVulkan(SDL_Window* window);
IMGUI_IMPL_API bool ImGui_ImplSDL2_InitForD3D(SDL_Window* window);
IMGUI_IMPL_API bool ImGui_ImplSDL2_InitForMetal(SDL_Window* window);
IMGUI_IMPL_API bool ImGui_ImplSDL2_InitForSDLRenderer(SDL_Window* window, SDL_Renderer* renderer);
IMGUI_IMPL_API bool ImGui_ImplSDL2_InitForOther(SDL_Window* window);
IMGUI_IMPL_API void ImGui_ImplSDL2_Shutdown();
IMGUI_IMPL_API void ImGui_ImplSDL2_NewFrame();
IMGUI_IMPL_API bool ImGui_ImplSDL2_ProcessEvent(const SDL_Event* event);
#ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS
static inline void ImGui_ImplSDL2_NewFrame(SDL_Window*) { ImGui_ImplSDL2_NewFrame(); } // 1.84: removed unnecessary parameter
#endif
#endif // #ifndef IMGUI_DISABLE

129
libs/imgui/imconfig.h Normal file
View File

@@ -0,0 +1,129 @@
//-----------------------------------------------------------------------------
// 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.
// 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 )
//#define IMGUI_API __declspec( dllimport )
//---- 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
//#define IMGUI_DISABLE_OBSOLETE_KEYIO // 1.87: disable legacy io.KeyMap[]+io.KeysDown[] in favor io.AddKeyEvent(). This will be folded into IMGUI_DISABLE_OBSOLETE_FUNCTIONS in a few versions.
//---- 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 ShowStackToolWindow() will be empty (this was called IMGUI_DISABLE_METRICS_WINDOW before 1.88).
//---- 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_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_SSE // Disable use of SSE intrinsics even if available
//---- Include imgui_user.h at the end of imgui.h as a convenience
//#define IMGUI_INCLUDE_IMGUI_USER_H
//---- Pack colors to BGRA8 instead of RGBA8 (to avoid converting from one to another)
//#define IMGUI_USE_BGRA_PACKED_COLOR
//---- 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+lunasvg library to render OpenType SVG fonts (SVGinOT)
// Requires lunasvg headers to be available in the include path + program to be linked with the lunasvg library (not provided).
// Only works in combination with IMGUI_ENABLE_FREETYPE.
// (implementation is based on Freetype's rsvg-port.c which is licensed under CeCILL-C Free Software License Agreement)
//#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 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);
}
*/

14984
libs/imgui/imgui.cpp Normal file

File diff suppressed because it is too large Load Diff

3214
libs/imgui/imgui.h Normal file

File diff suppressed because it is too large Load Diff

8257
libs/imgui/imgui_demo.cpp Normal file

File diff suppressed because it is too large Load Diff

6247
libs/imgui/imgui_draw.cpp Normal file

File diff suppressed because it is too large Load Diff

Some files were not shown because too many files have changed in this diff Show More