Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Freeglut OpenGL2 example #801

Closed
wants to merge 9 commits into from
Closed

Freeglut OpenGL2 example #801

wants to merge 9 commits into from

Conversation

bitxue
Copy link

@bitxue bitxue commented Aug 27, 2016

A simple example on integrating imgui with Freeglut.

screenshot

@MatsumotoJ
Copy link

MatsumotoJ commented May 12, 2017

Hi,

Thank you very much for developping the great glut example! It is really useful because I have many resources using glut.

I would like to ask a question about keyboard input:

  • Are copy and paste shortcuts (Ctrl+C, Ctrl+V, and so on) implemented in the glut example? (in InputText widget)

In my environment (Windows 10 (japanese ver.); Visual C++ 2017), the shortcuts did not work.

I had a similar problem in some special keys (arrow keys, delete key, backspace key, etc) but I could fix it by adding the following code:

bool keyboardEvent(unsigned char nChar, int nX, int nY)
{
	ImGuiIO& io = ImGui::GetIO();

	switch (nChar)
	{
	case 127: // delete
		io.KeysDown[nChar] = true; break;
	case 8: // backspace
		io.KeysDown[nChar] = true; break;
	default:
		io.AddInputCharacter(nChar);
	}
	return true;
}
void KeyboardSpecial(int key, int x, int y)
{
	ImGuiIO& io = ImGui::GetIO();
	//io.AddInputCharacter(key);
	io.KeysDown[key] = true;
}

and corresponding "keyboardup" callbacks.

Could you kindly give me advice about what I need to add for implementing the copy and paste shortcut?

Thank you very much!

@bitxue
Copy link
Author

bitxue commented May 12, 2017

GLFW has glfwSetClipboardString and glfwGetClipboardString funcs which make it easy to binding copy and paste in imgui. It seems glut lacks these funcs. You may need to implemente it yourself. The ctrl+c,ctrl+v key binding can refer to the implentation bellow:

https://gist.github.com/mtao/505986dc247a549016e9a1f2a7e01366#file-imgui_impl_glut-cpp

@MatsumotoJ
Copy link

Hi bitxue,

Thank you very much for the information.
I will try to use window.h functions for copy and paste.

Thank you again!

@lramati
Copy link

lramati commented Dec 11, 2017

Hi!
I'm trying to use this in a project now, and it works with OpenGL 3.3 (in compatibility mode) but I'm also running into the issue where not all the keys are getting picked up. @MatsumotoJ is there any chance you could push your changes somewhere? i tried to implement them locally myself, but unfortunately I'm lost as to the key up events.

Thanks!

@MatsumotoJ
Copy link

MatsumotoJ commented Dec 11, 2017

Hi @lramati

Although I forget what I have done exactly, you can check following my codes recently uploaded on github:

  1. https://github.com/ThreeD-Tracker-FAB/3DTrackerFAB-main/blob/master/imgui/imgui_impl_glut.cpp#L169-L174
  2. https://github.com/ThreeD-Tracker-FAB/3DTrackerFAB-main/blob/master/common/app_common.cpp

The first one corresponds to "imgui_impl_glut.cpp" which I slightly modified keymap as in the link. The second one corresponds to "main.cpp". Check keyboard related functions and clipboard related functions in the code for your information.
Note that the code is not optimized. Some parts may be redundant or unnecessary.

@lramati
Copy link

lramati commented Dec 11, 2017

Thank you!

@Johndeep
Copy link

Johndeep commented Mar 22, 2018

Great to have (at least a potential, but not included yet) freeglut port!
Hope this will get through and will be merged soon.

@ocornut
Copy link
Owner

ocornut commented Mar 22, 2018

I'm just wondering, why this commit is not merged into the imgui library yet, since it was developed years ago? But nevertheless way, great to have (at least a potential, but not included yet) freeglut port!

Mostly because of a lack of time. Maintaining the examples and binding has taken a lot of energy.
The PR also have various visible issues. Coding style is inconsistent with other imgui examples, naming convention and stuff like

#include <iostream>
using namespace std;
io.KeyMap[15] = 25; 
io.KeyMap[16] = 26;

Should at least use the enum on the left side, etc.
Generally if the PR shows a few of those issues it means there are other and it needs to be double-checked.

Now, I've recently been refactoring the example (see https://github.com/ocornut/imgui/tree/viewport) meaning this kind of code will be easier to integrate and maintain. Importing the FreeGlut example was part of my plan for this new branch so I will use this PR for it.

EDIT There's also many bugs in that code, e.g. this is incorrect in the mouse event handler for at least two reason:

    if (state == GLUT_DOWN && (button == GLUT_LEFT_BUTTON))
        io.MouseDown[0] = true;
    else
        io.MouseDown[0] = false;

    if (state == GLUT_DOWN && (button == GLUT_RIGHT_BUTTON))
        io.MouseDown[1] = true;
    else
        io.MouseDown[1] = false;

@ocornut
Copy link
Owner

ocornut commented Jun 11, 2018

@bitxue @MatsumotoJ @lramati @Johndeep
Everyone, I have now pushed a functional FreeGLUT example in the repository

As far as I understand GLUT API doesn't allow distinguishing things like TAB vs CTRL+I, so it is severely constrained. Honestly I would recommend against using FreeGLUT in 2018, but AFAIK everything works now.

The new examples/ architecture will allow you to combine FreeGLUT with a different renderer if needed.

@MatsumotoJ
Copy link

Thank you very much for your kindness!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants