How do I add joystick support into OpenGL? - opengl

I want to add joystick support into an openGL application.
Is there any class that can help me?
Thanks in advance.

OpenGL is a graphics API. It has no notion of input devices.
Need more info for a better answer such as platform. On Windows there are many options for handling input. Depending on what you want to do that is. Google for more info. But a start would be simple input handling via the Win32 API. This all presumes you use Windows of course.

OpenGL does not provide direct access to the joystick as it is only a graphics library.
For joystick support we will need to know what platform you are targeting.
For example, on Windows you would likely use DirectInput.

Some GLUT implementations have: glutJoystickFunc

As mentioned in other answers, OpenGL is only a graphics rendering API. It doesn't even know how to open a window, not to mention how to handle mouse or keyboard input; something else must do it for it.
If you want a cross-platform I/O wrapper for OpenGL which also provides joystick support, take a look at SDL - Simple DirectMedia Layer. It may scare you at first, but it's still easier than writing I/O and windowing stuff for a single platform, not to mention writing a wrapper for each platform out there (SDL covers many of them).
So, take a look at SDL.

Related

Cross platform hardware-native OpenGL library, possibly with multimedia?

I am looking for the ability to open OpenGL contexts and draw native OpenGL in windows, macOS, linux distros with X, android and iOS
I don't want to rely on the "native" device framework for the actual UI, I don't need to use native components, all I want is an OpenGL context to natively draw in OpenGL. Many of the cross platform SDKs like Marmalade and MoSync focus on making use of the native UI components and stuff like that, all I need is an OpenGl context to draw as I intend to, absolutely no native UI functionality is required, however, access to native hardware features like microphone, camera and other sensors is desired if possible, as well as access to audio/video/network.
I don't want to use QT, I want to do something that is closer to the hardware to work on the low level. The general idea is to make a lightweight cross platform hardware accelerated GUI, written on a level low enough to be truly hardware native, without relying on any native software framework. I know for android I may have to use a java wrapper to launch the native code, but the idea is to have this wrapper minimized, with very little modifications needed to deploy the low level and thus hopefully TRULY cross-platform code, that is only dependent on OpenGL hardware and OpenGL context for it to work wit.h
So I need a bare minimum solution to avoid using non-cross platform features as much as possible.
At the time the only library that comes to my mind is SDL, but I am not sure it supports android and iOS property, so besides library recommendations, more information on how SDL handles android and iOS devices and their hardware is welcomed too.
How about:
GLFW
SDL
GLUT (FreeGLUT or OpenGLUT)
Blender's GHOST framework?
Essentially they open a window, create a OpenGL context on it, deliver you the input events and leave the rest up to you.
What you want is nothing more than a platform-specific OpenGL context setup (which is quite simple and well documented: the NeHe OpenGL tutorial provides code for many environments that does just this here (the explanation is Windows specific, scroll down for the code on different OSes).
Once you have the OpenGL context, nothing prevents you from creating a full GUI with all OpenGL elements.
If you want, you could use Qt to only set up an OpenGL context (ie don't use any QWidgets or anything, other than the window showing you your OpenGL scene). It takes care of the whole setup process, but for only that, Qt becomes a huge dependency, as it only really replaces at most 100 lines of code per platform.
With regards to SDL+Android, have you checked the README?
And for iOS check the same file here.

Event Handling API's to Use with OpenGL

I've been looking into input handling for an OpenGL application. I want to handle at least two joysticks, keyboard, and mouse. Outsourcing this to python scripting would be a big bonus, but not required.
I look at freeglut, but it only supports one joystick.
Pygame says it's "input queue is heavily dependent on the pygame display module" so that caused me pause.
I'm not familiar with QT or GTK's joystick input handling, and haven't been able to find any document describing my problem concisely.
SDL's python binding says it handles these things "quite well". (A statement I'm not sure what to think about.)
Is my concern over the Pygame problem a moot point when I get into it? Can QT or GTK provide this functionality without issue? Is there another alternative that solves my problem?
All else fails I think I can go straight SDL, but I don't know much about it's performance.
This question really isn't about OpenGL, as OpenGL has very little to do with input handling.
Qt and wxWidgets are not primarily for dealing with input. Obviously they handle mouse and keyboard, but they're basically GUI libraries. Their input systems are designed and intended for that purpose.
SDL's input component is designed for dealing with input. SFML is also an option. Both of them have Python bindings if that's important for you.
Pygame (which uses SDL, from python) works fine with OpenGL.
Use pygame for input events, window creation, etc... (the cross platform stuff) and OpenGL for rendering to the pygame screen.

Need cross-platform GUI toolkit with OpenGL support

I need a cross-platform GUI toolkit with OpenGL support. I also need to be able to draw on a canvas or panel from an image buffer. The candidates I've chosen so far are FLTK (it can do OpenGL windows -- I don't know about canvases), Qt, and wxWidgets.
Any idea which would be the best?
Thanks!
I would say Qt. But that might be argumentative question...
Hey Deep, XVT support openGL. It's a GUI cross-platform toolkit for C and C++ www.xvt.com
For simple things I would suggest GLUT or something similar. But for anything above a simple window into which you render some OpenGL, I strongly recommend Qt. But as tibur said, its probably a matter of taste.
Checkout the Ecere SDK. It's a feature rich cross-platform GUI toolkit, and it supports a variety of graphics driver (e.g. GDI, X11, OpenGL, Direct3D). It has a built-in 3D engine, but you can mix it with your own OpenGL code as well, there are samples showing you how to do just that. It was originally designed as a GUI system for in-game menus, so it supports full screen mdoe as well as windowed mode, but is now a general purpose SDK.

SDL Alternative with multiple windows and multiple display devices

I'm looking for an alternative to SDL that supports multiple windows on multiple display devices for OpenGL.
Is there any mature library that provides this?
I'm aware taht SDL 1.3 will support this but it seems that's a bit into the future.
SFML is probably what you are looking for.
You should also take a look at OpenSceneGraph. It might seem like overkill, but it really is the best I've come across when it comes to rendering in multiple windows on multiple display devices. It's a complete graphics toolkit/engine, which might not be what you are looking for.
Qt and its QGLWidget might be a good alternative, specially if you want to use a GUI with your OpenGL contexts.

What library to choose to build a user interface for a C++ software that uses SDL

I have a simulation software (C++) that runs on the command line. It is platform independent (currently compiling and running on Windows, MacOS X and Linux). When the simulation ends, I visualize the result with SDL; it is a very basic 2d view, mainly color squares next to each other.
I would like to have a user interface on top of the simulation so that I can start and pause the simulation, and change the parameters on the fly. Something pretty simple I guess. Well, ideally I will also add a grapher somewhere to see the evolution over time of some parameters.
Now, I am wondering what direction I should go.
Should I try to use one of the UI libraries for SDL ?
Or maybe wxwidget in conjunction with SDL ?
Or simply wxwidget and get rid of SDL ?
Do you have any experience with this ?
Thanks in advance
Barth
PS: I tried to use AGAR, a SDL UI library. It seemed very promising but I couldn't get it working. Not even the helloworld.
It may be worth you time to look into Qt. It is generally the most mature free Gui framework available. It is cross platform. And it has hardware accelerated rendering if your drawing needs some speed.
Here is a comparison posted on WxWidgets site.
In the end if your windowing needs are minimal you should choose the framework you are most comfortable with.
Probably using wxWidgets without SDL would be the easiest way to go. SDL is a media layer -- it's supposed to allow cross-platform media application development. As you only need graphical display, you only need wxWidgets -- and it will be a lot easier too!
You would benefit from SDL if:
you'd need very fast blitting of very large amount of surfaces (we're talking the 60fps range here)
you'd use RLE, color keying or other graphics operations
you'd use other media (sound, advanced real-time input, etc)
you'd need to run the software on embedded systems (handheld consoles, etc)
If the answer to all 4 is "no", then you won't benefit from SDL, and using wx alone will be much easier.