Better-than-GLUT keyboard/mouse handling

Hey everyone, first post so go easy on me :slight_smile:

I am learning OpenGL to do research at my university and am using GLUT & OpenGL. I’m looking for something that handles keyboard and mouse input better (you know… event polling and such so that you can move multiple directions at once and have better mouse click interation).

I guess I’m looking for a way to read keyboard and mouse input that is as good as game engines I’ve used (SDL, C4, etc.).

And since I want to be working down-and-dirty with OpenGL, it needs to be something that can work alongside or under OpenGL, not something that has some OpenGL bindings built in and such.

Thanks!
Jeff

You could use SDL, especially as you seem familiar with it already. GLFW is a relatively small library that does these things, as well as a bunch of libraries on this page.

I would recommend SDL because it offers a lot of freedom over simpler libraries, such as GLUT, GLFW, etc. For example, it does not use callback functions, that force you into doing things in a certain order, but rather allows you to make calls from anywhere. Also, the user-interaction part of SDL is particularly intuitive to use.

I have been using SDL ever since I discovered it, and I have never looked back! :slight_smile:

Good luck!

thinks: beg to differ, GLFW is very easy, and most of the callbacks functions are optionnal as they have a direct function counterpart. Personnaly, I found it much simpler than SDL to integrate with OpenGL. And the documentation is really good. Only drawback for games, its does not do sounds.

As said above, if you already have experience with SDL, you can stick with it :slight_smile:

Thanks for all of your replies so far.

I’ve only ever done 2D stuff with SDL but it sounds like that’s a good option.

Could I have OpenGL/GLUT be the “main” thing running in my program and just use the input functionality of SDL or GLFW, does anyone know? My ideal situation is that I can use GLUT to set up an OpenGL rendering window and everything and then have only keyboard/mouse event polling running from whatever other library I use. I’d just do DirectInput, but I switched to Mac :slight_smile:

thinks: beg to differ, GLFW is very easy, and most of the callbacks functions are optional as they have a direct function counterpart. Personally, I found it much simpler than SDL to integrate with OpenGL. And the documentation is really good. Only drawback for games, its does not do sounds.

No doubt GLFW is simpler, and it is what I was using before switching to SDL. However, I have found the small extra time invested in SDL very worth my while. Also, is GLFW still being developed? I know that SDL will be adding (if they haven’t already) support for multiple windows, for instance.

Anyway, I’m quite happy to disagree on this. Most important is to be “comfortable” with the choice in the end.

Yes it is, indeed.

Could I have OpenGL/GLUT be the “main” thing running in my program and just use the input functionality of SDL or GLFW, does anyone know?

You are wrong on one important point : you want to use OpenGL, but apparently glut sounds like it is not a good option for you.
So either SDL+OpenGL, or GLFW+OpenGL (later I found simpler to start with, but YMMV).

And it is very simple. Shamelessly taken from the official user documentation http://glfw.sourceforge.net/documentation.html :


#include <GL/glfw.h>
int main( void )
{
int running = GL_TRUE;
// Initialize GLFW
glfwInit();
// Open an OpenGL window
if( !glfwOpenWindow( 300,300, 0,0,0,0,0,0, GLFW_WINDOW ) )
{
glfwTerminate();
return 0;
}
// Main loopGLFW Users Guide API version 2.6 Page 5/40
while( running )
{
// OpenGL rendering goes here...
glClear( GL_COLOR_BUFFER_BIT );
// Swap front and back rendering buffers
glfwSwapBuffers();
// Check if ESC key was pressed or window was closed
running = !glfwGetKey( GLFW_KEY_ESC ) &&
glfwGetWindowParam( GLFW_OPENED );
}
// Close window and terminate GLFW
glfwTerminate();
// Exit program
return 0;
}