Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit/AppGameKit Studio Showcase / [Tier2-Template] Template for using ImGui in AppGameKit projects

Author
Message
MadBit
VIP Member
Gold Codemaster
14
Years of Service
User Offline
Joined: 25th Jun 2009
Location: Germany
Posted: 30th May 2023 20:02 Edited at: 1st Jul 2023 07:45
I would like to provide you a small template to use ImGui in tier2 projects.
I don't have much experience with ImGui. Therefore, if you have any questions regarding ImGUI, please consult the documentation of the developer.
https://github.com/ocornut/imgui

I will of course help where I can.

How to use it:
Copy the contents of the zip file into the Tier2/apps directory.
You may need to adjust the library paths, since I created the template based on the GitHub Tier2 code.


UPDATE 2023-07-01:
- 32Bit Template available for download

Download attached
Share your knowledge. It\'s a way to achieve immortality. (Tenzin Gyatso)

Donations are always welcome.

Attachments

Login to view attachments
Yiu435
3
Years of Service
User Offline
Joined: 19th Dec 2020
Location:
Posted: 31st May 2023 09:11
Thank you very much.
Nice work.
Yiu435
3
Years of Service
User Offline
Joined: 19th Dec 2020
Location:
Posted: 31st May 2023 09:28


identifier "cShape" is undefined

How to fix it?
MadBit
VIP Member
Gold Codemaster
14
Years of Service
User Offline
Joined: 25th Jun 2009
Location: Germany
Posted: 31st May 2023 12:26
Oh, sorry that's something I'm working on right now. I thought I had included ImGui without CShape.
I'll have another look at home when I get there.
Share your knowledge. It\'s a way to achieve immortality. (Tenzin Gyatso)

Donations are always welcome.
MadBit
VIP Member
Gold Codemaster
14
Years of Service
User Offline
Joined: 25th Jun 2009
Location: Germany
Posted: 31st May 2023 21:04
I have replaced the download should work now. Is now somewhat larger the download.
However you must take the attached AgkLib the originals of TGC would not work.
Since my Shape class is not yet finished and should be as an extension for AgkSharp, it is actually not yet intended for the public.
Share your knowledge. It\'s a way to achieve immortality. (Tenzin Gyatso)

Donations are always welcome.
Yiu435
3
Years of Service
User Offline
Joined: 19th Dec 2020
Location:
Posted: 1st Jun 2023 02:42
Thanks a lot。
It works for me as well now。
SkinK4ir3
8
Years of Service
User Offline
Joined: 25th Aug 2015
Location:
Posted: 20th Jun 2023 19:17 Edited at: 20th Jun 2023 19:23
I'd like to thank the entire TGC team for being badass and geniuses. I hope to someday get to meet them.
I thank you immensely for your commitment and dedication to the AppGameKit project tools for community, you are a genius ... thank you very much for the help and support you have provided.


I detected a problem: Inputs & Focus -> Mouse Cursors -> hover to see mouse cursors only arrow works .

how could i fix this?
SkinK4ir3
8
Years of Service
User Offline
Joined: 25th Aug 2015
Location:
Posted: 21st Jun 2023 05:34

solved >: we need disable mousecursor native with >: agk::SetRawMouseVisible(0); AND enable Configuration -> Configuration -> General -> io.MouseDrawCursor ( true )

screenshot > https://prnt.sc/xL9MRb7SuvE7

screnshot 1 > https://prnt.sc/2KysUEFdakze
screenshot 2 > https://prnt.sc/pNPuSa49EDOv
MadBit
VIP Member
Gold Codemaster
14
Years of Service
User Offline
Joined: 25th Jun 2009
Location: Germany
Posted: 21st Jun 2023 16:16
Good that you could solve it yourself.
I haven't dealt with ImGui that much yet.
Therefore my experience with it is not very high.
Share your knowledge. It\'s a way to achieve immortality. (Tenzin Gyatso)

Donations are always welcome.
SkinK4ir3
8
Years of Service
User Offline
Joined: 25th Aug 2015
Location:
Posted: 21st Jun 2023 20:39
why is it cutting like this?
screenshot 1 }: https://prnt.sc/2SysxT5lCf-K

on the other side is with the normal cut.
screenshot 2 }: https://prnt.sc/kNop3UrfNoP-

MadBit
VIP Member
Gold Codemaster
14
Years of Service
User Offline
Joined: 25th Jun 2009
Location: Germany
Posted: 22nd Jun 2023 06:10 Edited at: 22nd Jun 2023 06:19
This happens when you resize the window. AppGameKit then crops the display accordingly.
In this case the fault is that the right side is not cropped.
This is because the FrameBuffer is also scaled, which I think is normal for other graphics engines, but AppGameKit handles this a little differently.
You can fix this very easily.
In the ImGui_DeviceAGK:rawData function you can find these lines at the beginning of the function.

[ImGui_DeviceAGK.cpp]


Just remove the multiplication with render_scale there.
That should be it then.
Share your knowledge. It\'s a way to achieve immortality. (Tenzin Gyatso)

Donations are always welcome.
SkinK4ir3
8
Years of Service
User Offline
Joined: 25th Aug 2015
Location:
Posted: 22nd Jun 2023 14:42 Edited at: 22nd Jun 2023 14:44
this way I did it still persists :C

screenshot > https://prnt.sc/7ixSFmg_UFMu
MadBit
VIP Member
Gold Codemaster
14
Years of Service
User Offline
Joined: 25th Jun 2009
Location: Germany
Posted: 22nd Jun 2023 19:43
As I already indicated, only the right side was not cut off.
The typical behavior of AppGameKit is, if the aspect ratio of the back buffer to your current window size is not equal, the screen will be cropped either top and bottom or right and left.
You probably won't be able to display a sprite beyond this limit or a 3d scene.

With the change of the lines you only effect that the UI elements are also cut off correctly on the right side. Just as it is usual with AGK.
Share your knowledge. It\'s a way to achieve immortality. (Tenzin Gyatso)

Donations are always welcome.
SkinK4ir3
8
Years of Service
User Offline
Joined: 25th Aug 2015
Location:
Posted: 22nd Jun 2023 23:20
all right, now i understand
SkinK4ir3
8
Years of Service
User Offline
Joined: 25th Aug 2015
Location:
Posted: 22nd Jun 2023 23:20
I'm trying to create some examples.
would you have any example of how to import an image by appgamekit and use it in imgui?
MadBit
VIP Member
Gold Codemaster
14
Years of Service
User Offline
Joined: 25th Jun 2009
Location: Germany
Posted: 23rd Jun 2023 06:39
If you have load the image in AppGameKit via agk::LoadImage(YOUR_IMAGE_ID, "your_image.png") then you can use



But if you don't want to bother the AppGameKit Image Manager and the image should really only be rendered with ImGui you can also load the image directly via cImage.



then the ImGui line would look like this.

Share your knowledge. It\'s a way to achieve immortality. (Tenzin Gyatso)

Donations are always welcome.
SkinK4ir3
8
Years of Service
User Offline
Joined: 25th Aug 2015
Location:
Posted: 23rd Jun 2023 15:02
wow, thanks for the great support.
I will try to create some interesting examples and post them here.
PartTimeCoder
AGK Tool Maker
9
Years of Service
User Offline
Joined: 9th Mar 2015
Location: London UK
Posted: 28th Jun 2023 02:22
Pretty Awesome MadBit, was browsing for something related to ImGUI and stumbled across this and brought me home.... might have to return to AppGameKit for a wee while now

Have you tested this with the docking branch, by any chance?

The docking feature is really useful I have been using it inside raylib but due to the way its implemented the "pull window out" feature does not work which is a massive let down so started coding a little engine in raw OGL ..... its painful!!

As for the frame buffer issue mentioned above I am sure there are "hidden" functions in the lib to set/update the buffer size, I'll get VS setup to compile the lib source and take a peek, on that front I did notice the interpreter has been added to the repo, that means we can add stuff and run it in basic (locally) I'll have to get my head round the process though.
Open Source plugins
Cl - DnD Plugin
Buy Me A Coffee
MadBit
VIP Member
Gold Codemaster
14
Years of Service
User Offline
Joined: 25th Jun 2009
Location: Germany
Posted: 28th Jun 2023 15:04
Quote: "Have you tested this with the docking branch, by any chance?"


no I have not. I have only run Imgui with Agk.
As I mentioned before, my experience with ImGui is not very high.
Share your knowledge. It\'s a way to achieve immortality. (Tenzin Gyatso)

Donations are always welcome.
PartTimeCoder
AGK Tool Maker
9
Years of Service
User Offline
Joined: 9th Mar 2015
Location: London UK
Posted: 4th Jul 2023 20:27 Edited at: 4th Jul 2023 20:31
OK, I dont really need it right now anyway I'll test it later on if I find time, docking is useful for making editors and such but not for a game or debug related tasks

There is however one small thing i'd like your opinion on regarding the ImGui scaling ...

When the UI is scaled below 1.0f then the ImGui draw area is also scaled down, on large res screens the 1.0f is to large and needs to be scaled down, the below image is at scale 0.8f, is there a way to make the actual draw area always 1.0f even when the scale < 1 ...

Open Source plugins
Cl - DnD Plugin
Buy Me A Coffee

Attachments

Login to view attachments
SkinK4ir3
8
Years of Service
User Offline
Joined: 25th Aug 2015
Location:
Posted: 5th Jul 2023 18:06
this is awesome PartTimeCoder !!
i am learning about ImGui Functions too...
my login screen : https://prnt.sc/5h9TGDpO2K22



How do I make the ImGui windows stay in front of the AppGameKit sprites? in the screenshot below, the sprite loaded by agk always stays in front.
screenshot : https://prnt.sc/J7M3AGRkKU0H

PartTimeCoder
AGK Tool Maker
9
Years of Service
User Offline
Joined: 9th Mar 2015
Location: London UK
Posted: 5th Jul 2023 20:26 Edited at: 5th Jul 2023 21:15
You need to render ImGui after AppGameKit renders, comment out agk::Sync() and replace with this



Red Square is the sprite:


You will need to add Render3D() is using 3D, check here for more info: https://www.appgamekit.com/documentation/Reference/Core/Render.htm

Edit: ... No scrap that it messes with the ability to move the window, put the Update after the Render!

Open Source plugins
Cl - DnD Plugin
Buy Me A Coffee

Attachments

Login to view attachments
SkinK4ir3
8
Years of Service
User Offline
Joined: 25th Aug 2015
Location:
Posted: 6th Jul 2023 02:13
it works, thank you very much
SkinK4ir3
8
Years of Service
User Offline
Joined: 25th Aug 2015
Location:
Posted: 13th Jul 2023 18:05
I'm trying to pass this parameter
in the function:

and I try to close the imgui window, I get the following error:
screenshot : https://prnt.sc/mRR_5hiK2r-Q

if I pass
the close button does not appear.

I have to define a pointer to close the window correctly?
MadBit
VIP Member
Gold Codemaster
14
Years of Service
User Offline
Joined: 25th Jun 2009
Location: Germany
Posted: 14th Jul 2023 05:08
Function description wrote: "Passing 'bool* p_open' displays a Close button on the upper-right corner of the window, the pointed value will be set to false when the button is pressed."

So a reference to a variable is expected and not a value.

This is how it should look.
bool close_button = 1;
ImGui::Begin("List of Messages", &close_button, ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove);
Share your knowledge. It\'s a way to achieve immortality. (Tenzin Gyatso)

Donations are always welcome.
PartTimeCoder
AGK Tool Maker
9
Years of Service
User Offline
Joined: 9th Mar 2015
Location: London UK
Posted: 14th Jul 2023 13:47 Edited at: 14th Jul 2023 13:48
static bool close_button = 1;
ImGui::Begin("List of Messages", &close_button, ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove);
Open Source plugins
Cl - DnD Plugin
Buy Me A Coffee
SkinK4ir3
8
Years of Service
User Offline
Joined: 25th Aug 2015
Location:
Posted: 24th Jul 2023 16:51 Edited at: 24th Jul 2023 16:54
I'm getting hit by the algorithm to center a window...
using this command >
the window is not in the exact center...

solved > it is necessary to divide by the scale factor = (io.DisplaySize.x * 0.5f) / 1.25, (io.DisplaySize.y * 0.5f) / 1.25
SkinK4ir3
8
Years of Service
User Offline
Joined: 25th Aug 2015
Location:
Posted: 2nd Aug 2023 19:24
I ran into a bug, depending on how fast I type, imgui ends up getting some phantom keyboard input over and over, sometimes I have to click in another window or outside the window I was typing in to make it stop, and sometimes it just stops causing the error. Phantom keyboard input when I close and reopen the application...

I tested it on a "blank" project with imgui to see if it really wasn't something I had done, but the problem still persists...
MadBit
VIP Member
Gold Codemaster
14
Years of Service
User Offline
Joined: 25th Jun 2009
Location: Germany
Posted: 2nd Aug 2023 22:24
Try this,
in file ImGui_DeviceAGK.cpp line ~ 245

change this

to this

is it better then?
Share your knowledge. It\'s a way to achieve immortality. (Tenzin Gyatso)

Donations are always welcome.
Divided
FPSC Reloaded TGC Backer
10
Years of Service
User Offline
Joined: 31st Oct 2013
Location:
Posted: 16th Oct 2023 07:27
Hey - this is really cool.

Is it possible to integrate into an existing project or do you need to use the template provided?

If it is possible, I'd love a step-by-step process. I'm very new to C++ and it gets confusing very quick!

Thanks!
Real programmers don't comment their code, because it should be written with readability in mind.
MadBit
VIP Member
Gold Codemaster
14
Years of Service
User Offline
Joined: 25th Jun 2009
Location: Germany
Posted: 18th Oct 2023 19:13
I will try to explain it.
First you should copy the template to the template directory of AppGameKit ({AppGameKit}\T2\apps). Then you can compile and run it.
If it works - it's great. If not - write here what error message appears.

About the integration - I don't know how your project structure looks like.
Basically I can say that you can copy all files of your project into the template directory.
But you should not overwrite any files like main.cpp and core.cpp.

When you open the .sln file with Visual Studio you have to paste the copied files into the project.
Project -> Add existing element

In main.cpp finally the program runs.

in app::Begin(void) comes the initialization which you can overwrite as it is in your project.
Just make sure that IM_NEW(ImGui_DeviceAGK); is called.

Before you can render any window in app::Loop(void). You must call
ImGuiDevice->ProcessInputs(); and ImGuiDevice->NewFrame();.
For final rendering of the windows call ImGuiDevice->Render(); just before agk::Sync().

That should be it.
If something doesn't work, write it here in this thread.

Share your knowledge. It\'s a way to achieve immortality. (Tenzin Gyatso)

Donations are always welcome.
Divided
FPSC Reloaded TGC Backer
10
Years of Service
User Offline
Joined: 31st Oct 2013
Location:
Posted: 19th Oct 2023 01:54 Edited at: 19th Oct 2023 03:31
Thanks,

I should point out I'm using the the the latest AGK Studio build of Tier 2 - not sure if that makes much of a difference. EDIT: I think it does make a difference because the link to the lib file provided looks to be the AppGameKit 2 version so switching to that causes errors in the renderer and the additional things added to include the Vulkan API maybe? I really have no idea but looks like the most probable cause.

I added all the necessary project files aside from *.sln *.vcxproj.* etc...
I added the /include directory to the project.

also I think I added relevant functions to the Wrapper.h (as this needed to be done manually as there seems to be a difference between the AGK2 and Studio Wrapper.h)
I'm assuming the only things that were changed had a "madbit" comment somewhere before.

This is what my Additional Library Directories property in Linker looks like: ..\..\platform\windows\Lib\VisualStudio\Debug64;lib\VS2022\Debug64\;%(AdditionalLibraryDirectories)
EDIT: On the above, I tried both just linking the Lib provided and without.
Without the lib provided causes issues with cShape and few other things not having implementations
With the lib causes errors with the renderer.
Perhaps the fix is to provide a lib that's been compiled using the latest AppGameKit studio version?

Without doing anything else such as calling IM_NEW(ImGui_DeviceAGK); I get compilation errors:







Attached is a screenshot of the relevant files that are added to the proj.

Real programmers don't comment their code, because it should be written with readability in mind.

Attachments

Login to view attachments
MadBit
VIP Member
Gold Codemaster
14
Years of Service
User Offline
Joined: 25th Jun 2009
Location: Germany
Posted: 19th Oct 2023 19:15
Ok. I have to note that the required lib comes with the template. I have developed this lib for my AgkSharp. This can not be exchanged against the Studio version. Therefore you will not be able to use the Vulkan functionality.
My way to render ImGui is using cShape, which I developed for AgkSharp.
Now to use ImGui with the standard studio lib you have to write your own renderer which includes writing the shader accordingly. But this might be too hard for someone who just started with C++.
If you need some tips on this then Preben would be the better person to ask.

Sorry
Share your knowledge. It\'s a way to achieve immortality. (Tenzin Gyatso)

Donations are always welcome.

Login to post a reply

Server time is: 2024-04-23 23:10:24
Your offset time is: 2024-04-23 23:10:24