Mouse questions

Hi SDL users,

I have some question about the mouse. A mouse has 4 buttons (left, scroll, scroll click , right).

openGL has his own event handler for the mouse. I want to use the SDL mouse eventhandler that do the same thing as the opengl mouse event handler.

my question is how to define those 4 buttons in sdl and how to overload the opengl event handler?

regards

btang

— btang at planet.nl wrote:

Hi SDL users,

I have some question about the mouse. A mouse has 4
buttons (left, scroll, scroll click , right).

At first this confused me, you are counting scrolling
as one “button.” Just clarifying this for anyone else
who reads it.

openGL has his own event handler for the mouse. I
want to use the SDL mouse eventhandler that do the
same thing as the opengl mouse event handler.

I don’t know much about OpenGL, but I am studying
beginner OpenGL programming from "Analog Annelid,"
which I eventually got to build on Panther. I read his
code, and he handles mice just using the ordinary
SDL_PollEvent just like in non-OpenGL SDL
applications. His code works on Windows and Linux
according to his website. And I don’t think it would
be platform-specific anyhow.>

my question is how to define those 4 buttons in sdl
and how to overload the opengl event handler?

regards

btang


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl


Do you Yahoo!?
Friends. Fun. Try the all-new Yahoo! Messenger.

Actually such mouse (2 buttons + scroll) has 5 buttons.
They usually are like this:
button0: left button
button1: right button
button3: scroll button
button4: scroll up
button5: scroll down

But anyway to use the mouse handler in SDL, this is a very short c++ example
to get you on the right way:
#include
#include // for std::atexit
#include <SDL.h>

int main(int argc, char* argv[])
{
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
std::cerr << “failed to initialize SDL” << std::endl;
return -1;
}
std::atexit(SDL_Quit);

if (!SDL_SetVideoMode(640, 480, 0, 0)) {
std::cerr << SDL_GetError() << std::endl;
return -1;
}

bool done = false;
SDL_Event event;
do {
while (SDL_PollEvent(&event)) {
switch (event.type) {
case SDL_MOUSEBUTTONDOWN:
std::cout << “Button " << (int)event.button.button << " is down” <<
std::endl;
break;
case SDL_MOUSEBUTTONUP:
std::cout << “Button " << (int)event.button.button << " is up” << std::endl;
break;

  case SDL_MOUSEMOTION:
std::cout << "Mouse moved from (" << (event.motion.x+event.motion.xrel) << 

“,” << (event.motion.y+event.motion.yrel) << “) to (” << event.motion.x <<
"," << event.motion.y << “)” << std::endl;
break;

  case SDL_QUIT: done = true; break;

  default: break;
  }
}

}
while (!done);
return 0;
}

btw, OpenGL doesn’t have a mouse event handler.

// Alexander BussmanOn Friday 28 May 2004 17:56, btang at planet.nl wrote:

Hi SDL users,

I have some question about the mouse. A mouse has 4 buttons (left, scroll,
scroll click , right).

btang at planet.nl wrote:

openGL has his own event handler for the mouse. I want to use the SDL mouse eventhandler that do the same thing as the opengl mouse event handler.

Yeh, OpenGL doesn’t have mouse handling stuff as far as I know. GLUT
(GL Utility Toolkit) certainly does, because it’s designed as a
cross-platform , uh, utility toolkit for making OpenGL programs without
operating system-specific code, same as SDL. You simply use SDL’s code,
and don’t use GLUT. Stick to GL and GLU, and you’ll be fine. I’ve been
so far… :slight_smile:

–Scott