Skip to main content
gamedev.net
🔒 Locked

C++/OpenGL/Key Input

Started by Tereth 6 replies 3k views
Original Post
Tereth
Tereth
I'm currently in the process of learning OpenGL in the IDE Microsoft Visual C++.

What is the best keyboard input methods to use with OpenGL in C++? I've done quite a bit of looking and I have found VK_, ncurses and sendkeys. Also, where is a good tutorial or article to learn the input method?

I'm not looking for a cin>> operator, but something that can receive input from a loop and cause the program to redraw the screen.
ApochPiQ
ApochPiQ
Input handling is entirely orthogonal to your choice of graphics API; what makes sense for your input system will depend on the features you need and what platform(s) you intend to support. Using OpenGL is totally irrelevant :-)

You seem to have already discovered a few options, so why not just spend a little time on Google looking for tutorials and comparisons between the three approaches you mentioned?
SiCrane
SiCrane
I'm not really sure those all constitute options. ncurses is designed for use with console windows, which OpenGL programs generally don't use and sendkeys is for sending input to a different window, not for receiving input. It would help if you mentioned which libraries you using/how you are creating your OpenGL window.
Tereth
Tereth

Input handling is entirely orthogonal to your choice of graphics API; what makes sense for your input system will depend on the features you need and what platform(s) you intend to support. Using OpenGL is totally irrelevant :-)

You seem to have already discovered a few options, so why not just spend a little time on Google looking for tutorials and comparisons between the three approaches you mentioned?


I've looked around for tutorials and how-to's, however I wanted to see what others have experienced to be the best. All of them seem to have relatively equivalent learning curves, so I wanted some outside thoughts.
Bregma
Bregma
You might want to consider something like SDL or SFML, which you can use for input (keys, mouse, &c) and OpenGL context creation all at once. And there are copious tutorials out there.
Stephen M. Webb
Professional Free Software Developer
Tereth
Tereth

I'm not really sure those all constitute options. ncurses is designed for use with console windows, which OpenGL programs generally don't use and sendkeys is for sending input to a different window, not for receiving input. It would help if you mentioned which libraries you using/how you are creating your OpenGL window.



Here's what I include in my header file. I'm not actually making a large project, but testing out different functions of OpenGL in the learning process.


#include <stdio.h>
#include <tchar.h>
#include <iostream>
#include <Windows.h>
#include <glut.h>

Creating OpenGL window with this:


glutInit(&iArgc, cppArgv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(750, 600);
glutInitWindowPosition(0, 0);
glutCreateWindow("");
SiCrane
SiCrane
Since you're using GLUT you might as well use the GLUT callbacks for input. For keyboard you probably first want to consider glutKeyboardFunc().
Tereth
Tereth

You might want to consider something like SDL or SFML, which you can use for input (keys, mouse, &c) and OpenGL context creation all at once. And there are copious tutorials out there.




Since you're using GLUT you might as well use the GLUT callbacks for input. For keyboard you probably first want to consider glutKeyboardFunc().


Both of you, thanks alot! I'll look into these options and tell you how they turn out. I had already started messing around with the VK_ functions and was having trouble with the keys sticking. I tell you how these work out.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.