Jump to content

  • Log In with Google      Sign In   
  • Create Account

Awesome job so far everyone! Please give us your feedback on how our article efforts are going. We still need more finished articles for our May contest theme: Remake the Classics

C++/OpenGL/Key Input


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
7 replies to this topic

#1 DontReferenceMyPointer   Members   -  Reputation: 126

Like
0Likes
Like

Posted 22 June 2011 - 03:49 PM

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.

#2 ApochPiQ   Moderators   -  Reputation: 7557

Like
1Likes
Like

Posted 22 June 2011 - 04:59 PM

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?

#3 SiCrane   Moderators   -  Reputation: 6644

Like
1Likes
Like

Posted 22 June 2011 - 05:34 PM

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.

#4 DontReferenceMyPointer   Members   -  Reputation: 126

Like
0Likes
Like

Posted 22 June 2011 - 05:39 PM

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.

#5 Bregma   Members   -  Reputation: 2762

Like
1Likes
Like

Posted 22 June 2011 - 06:08 PM

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

#6 DontReferenceMyPointer   Members   -  Reputation: 126

Like
0Likes
Like

Posted 22 June 2011 - 06:10 PM

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("");

#7 SiCrane   Moderators   -  Reputation: 6644

Like
2Likes
Like

Posted 22 June 2011 - 06:19 PM

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

#8 DontReferenceMyPointer   Members   -  Reputation: 126

Like
0Likes
Like

Posted 23 June 2011 - 02:03 PM

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.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS