Using the mouse scrollwheel in GLUT
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?
opengl glut scrollwheel
add a comment |
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?
opengl glut scrollwheel
add a comment |
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?
opengl glut scrollwheel
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?
opengl glut scrollwheel
opengl glut scrollwheel
asked Aug 18 '08 at 9:29
Ashwin NanjappaAshwin Nanjappa
35.4k63178260
35.4k63178260
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
Freeglut's glutMouseWheelFunc callback is version dependant and not reliable in X. Use standard mouse function and test for buttons 3 and 4.
The OpenGlut notes on glutMouseWheelFunc state:
Due to lack of information about the mouse, it is impossible to
implement this correctly on X at this time. Use of this function
limits the portability of your application. (This feature does work on
X, just not reliably.) You are encouraged to use the standard,
reliable mouse-button reporting, rather than wheel events.
Using standard GLUT mouse reporting:
#include <GL/glut.h>
<snip...>
void mouse(int button, int state, int x, int y)
{
// Wheel reports as button 3(scroll up) and button 4(scroll down)
if ((button == 3) || (button == 4)) // It's a wheel event
{
// Each wheel event reports like a button click, GLUT_DOWN then GLUT_UP
if (state == GLUT_UP) return; // Disregard redundant GLUT_UP events
printf("Scroll %s At %d %dn", (button == 3) ? "Up" : "Down", x, y);
}else{ // normal button event
printf("Button %s At %d %dn", (state == GLUT_DOWN) ? "Down" : "Up", x, y);
}
}
<snip...>
glutMouseFunc(mouse);
As the OP stated, it is "dead simple". He was just wrong.
2
Unfortunately using fixed buttons is pretty unreliable as WHICH mouse buttons correspond to the mouse wheel depends on what device you have plugged in. In fact, I think the most common is button 4/5 for up/down, not 3/4. For any usable program, you want to make it easy for the user to modify this.
– Chris Dodd
Jul 29 '12 at 20:00
3
On my Mac with free glut, 3/4 correspond to vertical up and down scrolling and 5/6 correspond to horizontal scrolling (on my trackpad).
– Alec Jacobson
Oct 19 '12 at 8:54
Thanks mate, this solution works perfectly in my testing scenario.
– Maurizio Benedetti
Feb 5 '13 at 17:59
Thank you, this was excellent for my use-case!
– SRG
Oct 14 '17 at 23:23
add a comment |
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!
5
Much to my annoyance, freeGLUT doesn't seem to implement the glutMouseWheelFunc() callback. Rather ironic that posters were complaining about this style of posting, yet the answer you posted for yourself was incorrect.
– Rich
Jan 12 '09 at 20:57
16
Adding to that - even when one uses#include <GL/freeglut.h>
so that the code compiles, glutMouseWheelFunc does not seem to be called (as tested on Ubuntu 10.04 x86_64, which ships freeglut 2.6.0). The solution is to use the regularglutMouseFunc
callback and check forbutton == 3
for wheel up, andbutton == 4
for wheel down.
– Carlos Scheidegger
Jul 14 '10 at 21:13
glutMouseWheelFunc callback is windows specific might not in Linux and MAC systems
– AMCoded
Nov 17 '17 at 8:41
add a comment |
observe case 3 and 4 in the switch statement below in the mouseClick callback
glutMouseFunc(mouseClick);
...
void mouseClick(int btn, int state, int x, int y) {
if (state == GLUT_DOWN) {
switch(btn) {
case GLUT_LEFT_BUTTON:
std::cout << "left click at: (" << x << ", " << y << ")n";
break;
case GLUT_RIGHT_BUTTON:
std::cout << "right click at: (" << x << ", " << y << ")n";
break;
case GLUT_MIDDLE_BUTTON:
std::cout << "middle click at: (" << x << ", " << y << ")n";
break;
case 3: //mouse wheel scrolls
std::cout << "mouse wheel scroll upn";
break;
case 4:
std::cout << "mouse wheel scroll downn";
break;
default:
break;
}
}
glutPostRedisplay();
}
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f14378%2fusing-the-mouse-scrollwheel-in-glut%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
Freeglut's glutMouseWheelFunc callback is version dependant and not reliable in X. Use standard mouse function and test for buttons 3 and 4.
The OpenGlut notes on glutMouseWheelFunc state:
Due to lack of information about the mouse, it is impossible to
implement this correctly on X at this time. Use of this function
limits the portability of your application. (This feature does work on
X, just not reliably.) You are encouraged to use the standard,
reliable mouse-button reporting, rather than wheel events.
Using standard GLUT mouse reporting:
#include <GL/glut.h>
<snip...>
void mouse(int button, int state, int x, int y)
{
// Wheel reports as button 3(scroll up) and button 4(scroll down)
if ((button == 3) || (button == 4)) // It's a wheel event
{
// Each wheel event reports like a button click, GLUT_DOWN then GLUT_UP
if (state == GLUT_UP) return; // Disregard redundant GLUT_UP events
printf("Scroll %s At %d %dn", (button == 3) ? "Up" : "Down", x, y);
}else{ // normal button event
printf("Button %s At %d %dn", (state == GLUT_DOWN) ? "Down" : "Up", x, y);
}
}
<snip...>
glutMouseFunc(mouse);
As the OP stated, it is "dead simple". He was just wrong.
2
Unfortunately using fixed buttons is pretty unreliable as WHICH mouse buttons correspond to the mouse wheel depends on what device you have plugged in. In fact, I think the most common is button 4/5 for up/down, not 3/4. For any usable program, you want to make it easy for the user to modify this.
– Chris Dodd
Jul 29 '12 at 20:00
3
On my Mac with free glut, 3/4 correspond to vertical up and down scrolling and 5/6 correspond to horizontal scrolling (on my trackpad).
– Alec Jacobson
Oct 19 '12 at 8:54
Thanks mate, this solution works perfectly in my testing scenario.
– Maurizio Benedetti
Feb 5 '13 at 17:59
Thank you, this was excellent for my use-case!
– SRG
Oct 14 '17 at 23:23
add a comment |
Freeglut's glutMouseWheelFunc callback is version dependant and not reliable in X. Use standard mouse function and test for buttons 3 and 4.
The OpenGlut notes on glutMouseWheelFunc state:
Due to lack of information about the mouse, it is impossible to
implement this correctly on X at this time. Use of this function
limits the portability of your application. (This feature does work on
X, just not reliably.) You are encouraged to use the standard,
reliable mouse-button reporting, rather than wheel events.
Using standard GLUT mouse reporting:
#include <GL/glut.h>
<snip...>
void mouse(int button, int state, int x, int y)
{
// Wheel reports as button 3(scroll up) and button 4(scroll down)
if ((button == 3) || (button == 4)) // It's a wheel event
{
// Each wheel event reports like a button click, GLUT_DOWN then GLUT_UP
if (state == GLUT_UP) return; // Disregard redundant GLUT_UP events
printf("Scroll %s At %d %dn", (button == 3) ? "Up" : "Down", x, y);
}else{ // normal button event
printf("Button %s At %d %dn", (state == GLUT_DOWN) ? "Down" : "Up", x, y);
}
}
<snip...>
glutMouseFunc(mouse);
As the OP stated, it is "dead simple". He was just wrong.
2
Unfortunately using fixed buttons is pretty unreliable as WHICH mouse buttons correspond to the mouse wheel depends on what device you have plugged in. In fact, I think the most common is button 4/5 for up/down, not 3/4. For any usable program, you want to make it easy for the user to modify this.
– Chris Dodd
Jul 29 '12 at 20:00
3
On my Mac with free glut, 3/4 correspond to vertical up and down scrolling and 5/6 correspond to horizontal scrolling (on my trackpad).
– Alec Jacobson
Oct 19 '12 at 8:54
Thanks mate, this solution works perfectly in my testing scenario.
– Maurizio Benedetti
Feb 5 '13 at 17:59
Thank you, this was excellent for my use-case!
– SRG
Oct 14 '17 at 23:23
add a comment |
Freeglut's glutMouseWheelFunc callback is version dependant and not reliable in X. Use standard mouse function and test for buttons 3 and 4.
The OpenGlut notes on glutMouseWheelFunc state:
Due to lack of information about the mouse, it is impossible to
implement this correctly on X at this time. Use of this function
limits the portability of your application. (This feature does work on
X, just not reliably.) You are encouraged to use the standard,
reliable mouse-button reporting, rather than wheel events.
Using standard GLUT mouse reporting:
#include <GL/glut.h>
<snip...>
void mouse(int button, int state, int x, int y)
{
// Wheel reports as button 3(scroll up) and button 4(scroll down)
if ((button == 3) || (button == 4)) // It's a wheel event
{
// Each wheel event reports like a button click, GLUT_DOWN then GLUT_UP
if (state == GLUT_UP) return; // Disregard redundant GLUT_UP events
printf("Scroll %s At %d %dn", (button == 3) ? "Up" : "Down", x, y);
}else{ // normal button event
printf("Button %s At %d %dn", (state == GLUT_DOWN) ? "Down" : "Up", x, y);
}
}
<snip...>
glutMouseFunc(mouse);
As the OP stated, it is "dead simple". He was just wrong.
Freeglut's glutMouseWheelFunc callback is version dependant and not reliable in X. Use standard mouse function and test for buttons 3 and 4.
The OpenGlut notes on glutMouseWheelFunc state:
Due to lack of information about the mouse, it is impossible to
implement this correctly on X at this time. Use of this function
limits the portability of your application. (This feature does work on
X, just not reliably.) You are encouraged to use the standard,
reliable mouse-button reporting, rather than wheel events.
Using standard GLUT mouse reporting:
#include <GL/glut.h>
<snip...>
void mouse(int button, int state, int x, int y)
{
// Wheel reports as button 3(scroll up) and button 4(scroll down)
if ((button == 3) || (button == 4)) // It's a wheel event
{
// Each wheel event reports like a button click, GLUT_DOWN then GLUT_UP
if (state == GLUT_UP) return; // Disregard redundant GLUT_UP events
printf("Scroll %s At %d %dn", (button == 3) ? "Up" : "Down", x, y);
}else{ // normal button event
printf("Button %s At %d %dn", (state == GLUT_DOWN) ? "Down" : "Up", x, y);
}
}
<snip...>
glutMouseFunc(mouse);
As the OP stated, it is "dead simple". He was just wrong.
edited Mar 23 '15 at 22:40
Colonel Thirty Two
14.6k42455
14.6k42455
answered Oct 25 '11 at 7:08
BentFXBentFX
1,53622027
1,53622027
2
Unfortunately using fixed buttons is pretty unreliable as WHICH mouse buttons correspond to the mouse wheel depends on what device you have plugged in. In fact, I think the most common is button 4/5 for up/down, not 3/4. For any usable program, you want to make it easy for the user to modify this.
– Chris Dodd
Jul 29 '12 at 20:00
3
On my Mac with free glut, 3/4 correspond to vertical up and down scrolling and 5/6 correspond to horizontal scrolling (on my trackpad).
– Alec Jacobson
Oct 19 '12 at 8:54
Thanks mate, this solution works perfectly in my testing scenario.
– Maurizio Benedetti
Feb 5 '13 at 17:59
Thank you, this was excellent for my use-case!
– SRG
Oct 14 '17 at 23:23
add a comment |
2
Unfortunately using fixed buttons is pretty unreliable as WHICH mouse buttons correspond to the mouse wheel depends on what device you have plugged in. In fact, I think the most common is button 4/5 for up/down, not 3/4. For any usable program, you want to make it easy for the user to modify this.
– Chris Dodd
Jul 29 '12 at 20:00
3
On my Mac with free glut, 3/4 correspond to vertical up and down scrolling and 5/6 correspond to horizontal scrolling (on my trackpad).
– Alec Jacobson
Oct 19 '12 at 8:54
Thanks mate, this solution works perfectly in my testing scenario.
– Maurizio Benedetti
Feb 5 '13 at 17:59
Thank you, this was excellent for my use-case!
– SRG
Oct 14 '17 at 23:23
2
2
Unfortunately using fixed buttons is pretty unreliable as WHICH mouse buttons correspond to the mouse wheel depends on what device you have plugged in. In fact, I think the most common is button 4/5 for up/down, not 3/4. For any usable program, you want to make it easy for the user to modify this.
– Chris Dodd
Jul 29 '12 at 20:00
Unfortunately using fixed buttons is pretty unreliable as WHICH mouse buttons correspond to the mouse wheel depends on what device you have plugged in. In fact, I think the most common is button 4/5 for up/down, not 3/4. For any usable program, you want to make it easy for the user to modify this.
– Chris Dodd
Jul 29 '12 at 20:00
3
3
On my Mac with free glut, 3/4 correspond to vertical up and down scrolling and 5/6 correspond to horizontal scrolling (on my trackpad).
– Alec Jacobson
Oct 19 '12 at 8:54
On my Mac with free glut, 3/4 correspond to vertical up and down scrolling and 5/6 correspond to horizontal scrolling (on my trackpad).
– Alec Jacobson
Oct 19 '12 at 8:54
Thanks mate, this solution works perfectly in my testing scenario.
– Maurizio Benedetti
Feb 5 '13 at 17:59
Thanks mate, this solution works perfectly in my testing scenario.
– Maurizio Benedetti
Feb 5 '13 at 17:59
Thank you, this was excellent for my use-case!
– SRG
Oct 14 '17 at 23:23
Thank you, this was excellent for my use-case!
– SRG
Oct 14 '17 at 23:23
add a comment |
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!
5
Much to my annoyance, freeGLUT doesn't seem to implement the glutMouseWheelFunc() callback. Rather ironic that posters were complaining about this style of posting, yet the answer you posted for yourself was incorrect.
– Rich
Jan 12 '09 at 20:57
16
Adding to that - even when one uses#include <GL/freeglut.h>
so that the code compiles, glutMouseWheelFunc does not seem to be called (as tested on Ubuntu 10.04 x86_64, which ships freeglut 2.6.0). The solution is to use the regularglutMouseFunc
callback and check forbutton == 3
for wheel up, andbutton == 4
for wheel down.
– Carlos Scheidegger
Jul 14 '10 at 21:13
glutMouseWheelFunc callback is windows specific might not in Linux and MAC systems
– AMCoded
Nov 17 '17 at 8:41
add a comment |
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!
5
Much to my annoyance, freeGLUT doesn't seem to implement the glutMouseWheelFunc() callback. Rather ironic that posters were complaining about this style of posting, yet the answer you posted for yourself was incorrect.
– Rich
Jan 12 '09 at 20:57
16
Adding to that - even when one uses#include <GL/freeglut.h>
so that the code compiles, glutMouseWheelFunc does not seem to be called (as tested on Ubuntu 10.04 x86_64, which ships freeglut 2.6.0). The solution is to use the regularglutMouseFunc
callback and check forbutton == 3
for wheel up, andbutton == 4
for wheel down.
– Carlos Scheidegger
Jul 14 '10 at 21:13
glutMouseWheelFunc callback is windows specific might not in Linux and MAC systems
– AMCoded
Nov 17 '17 at 8:41
add a comment |
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!
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!
answered Aug 18 '08 at 9:29
Ashwin NanjappaAshwin Nanjappa
35.4k63178260
35.4k63178260
5
Much to my annoyance, freeGLUT doesn't seem to implement the glutMouseWheelFunc() callback. Rather ironic that posters were complaining about this style of posting, yet the answer you posted for yourself was incorrect.
– Rich
Jan 12 '09 at 20:57
16
Adding to that - even when one uses#include <GL/freeglut.h>
so that the code compiles, glutMouseWheelFunc does not seem to be called (as tested on Ubuntu 10.04 x86_64, which ships freeglut 2.6.0). The solution is to use the regularglutMouseFunc
callback and check forbutton == 3
for wheel up, andbutton == 4
for wheel down.
– Carlos Scheidegger
Jul 14 '10 at 21:13
glutMouseWheelFunc callback is windows specific might not in Linux and MAC systems
– AMCoded
Nov 17 '17 at 8:41
add a comment |
5
Much to my annoyance, freeGLUT doesn't seem to implement the glutMouseWheelFunc() callback. Rather ironic that posters were complaining about this style of posting, yet the answer you posted for yourself was incorrect.
– Rich
Jan 12 '09 at 20:57
16
Adding to that - even when one uses#include <GL/freeglut.h>
so that the code compiles, glutMouseWheelFunc does not seem to be called (as tested on Ubuntu 10.04 x86_64, which ships freeglut 2.6.0). The solution is to use the regularglutMouseFunc
callback and check forbutton == 3
for wheel up, andbutton == 4
for wheel down.
– Carlos Scheidegger
Jul 14 '10 at 21:13
glutMouseWheelFunc callback is windows specific might not in Linux and MAC systems
– AMCoded
Nov 17 '17 at 8:41
5
5
Much to my annoyance, freeGLUT doesn't seem to implement the glutMouseWheelFunc() callback. Rather ironic that posters were complaining about this style of posting, yet the answer you posted for yourself was incorrect.
– Rich
Jan 12 '09 at 20:57
Much to my annoyance, freeGLUT doesn't seem to implement the glutMouseWheelFunc() callback. Rather ironic that posters were complaining about this style of posting, yet the answer you posted for yourself was incorrect.
– Rich
Jan 12 '09 at 20:57
16
16
Adding to that - even when one uses
#include <GL/freeglut.h>
so that the code compiles, glutMouseWheelFunc does not seem to be called (as tested on Ubuntu 10.04 x86_64, which ships freeglut 2.6.0). The solution is to use the regular glutMouseFunc
callback and check for button == 3
for wheel up, and button == 4
for wheel down.– Carlos Scheidegger
Jul 14 '10 at 21:13
Adding to that - even when one uses
#include <GL/freeglut.h>
so that the code compiles, glutMouseWheelFunc does not seem to be called (as tested on Ubuntu 10.04 x86_64, which ships freeglut 2.6.0). The solution is to use the regular glutMouseFunc
callback and check for button == 3
for wheel up, and button == 4
for wheel down.– Carlos Scheidegger
Jul 14 '10 at 21:13
glutMouseWheelFunc callback is windows specific might not in Linux and MAC systems
– AMCoded
Nov 17 '17 at 8:41
glutMouseWheelFunc callback is windows specific might not in Linux and MAC systems
– AMCoded
Nov 17 '17 at 8:41
add a comment |
observe case 3 and 4 in the switch statement below in the mouseClick callback
glutMouseFunc(mouseClick);
...
void mouseClick(int btn, int state, int x, int y) {
if (state == GLUT_DOWN) {
switch(btn) {
case GLUT_LEFT_BUTTON:
std::cout << "left click at: (" << x << ", " << y << ")n";
break;
case GLUT_RIGHT_BUTTON:
std::cout << "right click at: (" << x << ", " << y << ")n";
break;
case GLUT_MIDDLE_BUTTON:
std::cout << "middle click at: (" << x << ", " << y << ")n";
break;
case 3: //mouse wheel scrolls
std::cout << "mouse wheel scroll upn";
break;
case 4:
std::cout << "mouse wheel scroll downn";
break;
default:
break;
}
}
glutPostRedisplay();
}
add a comment |
observe case 3 and 4 in the switch statement below in the mouseClick callback
glutMouseFunc(mouseClick);
...
void mouseClick(int btn, int state, int x, int y) {
if (state == GLUT_DOWN) {
switch(btn) {
case GLUT_LEFT_BUTTON:
std::cout << "left click at: (" << x << ", " << y << ")n";
break;
case GLUT_RIGHT_BUTTON:
std::cout << "right click at: (" << x << ", " << y << ")n";
break;
case GLUT_MIDDLE_BUTTON:
std::cout << "middle click at: (" << x << ", " << y << ")n";
break;
case 3: //mouse wheel scrolls
std::cout << "mouse wheel scroll upn";
break;
case 4:
std::cout << "mouse wheel scroll downn";
break;
default:
break;
}
}
glutPostRedisplay();
}
add a comment |
observe case 3 and 4 in the switch statement below in the mouseClick callback
glutMouseFunc(mouseClick);
...
void mouseClick(int btn, int state, int x, int y) {
if (state == GLUT_DOWN) {
switch(btn) {
case GLUT_LEFT_BUTTON:
std::cout << "left click at: (" << x << ", " << y << ")n";
break;
case GLUT_RIGHT_BUTTON:
std::cout << "right click at: (" << x << ", " << y << ")n";
break;
case GLUT_MIDDLE_BUTTON:
std::cout << "middle click at: (" << x << ", " << y << ")n";
break;
case 3: //mouse wheel scrolls
std::cout << "mouse wheel scroll upn";
break;
case 4:
std::cout << "mouse wheel scroll downn";
break;
default:
break;
}
}
glutPostRedisplay();
}
observe case 3 and 4 in the switch statement below in the mouseClick callback
glutMouseFunc(mouseClick);
...
void mouseClick(int btn, int state, int x, int y) {
if (state == GLUT_DOWN) {
switch(btn) {
case GLUT_LEFT_BUTTON:
std::cout << "left click at: (" << x << ", " << y << ")n";
break;
case GLUT_RIGHT_BUTTON:
std::cout << "right click at: (" << x << ", " << y << ")n";
break;
case GLUT_MIDDLE_BUTTON:
std::cout << "middle click at: (" << x << ", " << y << ")n";
break;
case 3: //mouse wheel scrolls
std::cout << "mouse wheel scroll upn";
break;
case 4:
std::cout << "mouse wheel scroll downn";
break;
default:
break;
}
}
glutPostRedisplay();
}
edited Nov 14 '18 at 18:15
answered Nov 14 '18 at 16:41
StackAttackStackAttack
300213
300213
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f14378%2fusing-the-mouse-scrollwheel-in-glut%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown