I want to use the mouse scrollwheel in my OpenGL GLUT program to zoom in and out of a scene? How do I do that?
Note that venerable Nate Robin's GLUT library doesn't support the scrollwheel. But, later implementations of GLUT like FreeGLUT do.
Using the scroll wheel in FreeGLUT is dead simple. Here is how:
Declare a callback function that shall be called whenever the scroll wheel is scrolled. This is the prototype:
void mouseWheel(int, int, int, int);
Register the callback with the (Free)GLUT function glutMouseWheelFunc().
glutMouseWheelFunc(mouseWheel);
Define the callback function. The second parameter gives the direction of the scroll. Values of +1 is forward, -1 is backward.
void mouseWheel(int button, int dir, int x, int y)
{
if (dir > 0)
{
// Zoom in
}
else
{
// Zoom out
}
return;
}
That's it!
Ash, why do you keep asking and answering your own simple OpenGL questions?
I'm sorry if I've misconstrued the intention of Stack Overflow and this behavior is in fact valid, but it appears to me that filling up the front page with these frankly useless questions and answers doesn't do much for the overall quality of the site.
I totally accept that it's valid for someone to find elsewhere a good answer for their question and I agree it makes sense to then follow up on Stack Overflow, but I can't help feeling this isn't the case here.
My assumption would be that you're trying to game the system, hoping that by adding a load of questions with a scatter gun approach that someone will eventually run into something useful and up vote you.
My hope was that Stack Overflow would grow to contain detailed questions and answers about deep, sometimes quite esoteric topics that are not easily solved through a simple Google search. Questions that require real human thought, based upon weighing up differing strategies etc.
The questions you're asking and then magically solving perfectly a few seconds later are trivial. Anyone with enough foresight to have signed up for this beta could easily solve these things with nothing more than a cursory understanding of the language/api and the use of google.
Perhaps I'm wrong, but it feels like these types of question go against the core concept of civility on Stack Overflow?
@Ali Parr: While I agree that StackOverflow has to be a place where deep questions can be asked and discussed, I believe that it should also be a place where newbies can get the answers to their most basic doubts. Many of the questions that I asked (and answered) keep appearing regularly on newsgroups like that of opengl. Once StackOverflow goes public, I hope that the folks with these queries will find the StackOverflow page for that query to be the best place for their answers. I don't know about you, but whenever I try to learn a new language/library and have doubts, Google doesn't usually point me to a single reliable place with solutions. My hope is that with StackOverflow's design of accepting multiple answers to a question, it will be such a destination.
@Ash: Thanks for your response and measured argument. I don't want to start an extended discussion about this as this isn't the place, but I'll respond briefly....
I accept and agree that SO should also be a resource for newbies and agree that it is sometimes difficult to obtain reliable information on the web. However, I think your plan of preempting someone's problem is doomed to fail, as you simply won't be able to cover every nuance and caveat a particular context might present. I still believe these answers about the basic methods contained in an API belong in the documentation for that API (which on the whole ARE reliable).
If a newbie has a problem, they'll ask a question, it'll be specific to their particular situation and the resultant answer will be of more value to them. Chances are even if you already have answered their problem, they won't find your original post anyway and we'll end up with duplicate answers to similar questions.
@Ash:
Please do keep posting these, I am finding them extremely useful. I am upmodding every one, as I am happy to get a nice set of GL questions and answers.
@Ash, assuming these are either real questions that you've seen elsewhere or questions that you yourself were looking for an answer to and had trouble finding, then I think posting these are a good thing to do.
But like Ali Parr says, if you're just trying to make wild guesses what a newbie might have trouble with -- don't do that.