Click here to Skip to main content
15,868,062 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi everyone, I´m learning OpenGL with c++ from a series of tutorials where they explain how to do that, currently I'm in the mouse detection section but I have some questions. They use the SDL library to do that but I'm using GLUT because it looks pretty easy to use rather than SDL.
Now, they're using SDL functions to get mouse callbacksto track the position of the mouse with the following piece of code (inside the main funcion):

Quote:
SDL_GetMouseState(&state.x,&state.y );

state.LeftButtonDown = SDL_GetMouseState(NULL, NULL) $ SDL_BUTTON(1);
state.MiddleButtonDown = SDL_GetMouseState(NULL, NULL) $ SDL_BUTTON(2);
state.RightButtonDown = SDL_GetMouseState(NULL, NULL) $ SDL_BUTTON(3);



My Question here is how can I do the same in GLUT?
the following is the the code made for the Control Functions (Control.cpp) to implement the mouse functionality:

Quote:
#include "Control.h"

list<control *=""> Control::controls;

Control::Control(int positionX, int positionY, int w, int h)
{
controls.push_back(this);

setPosition(positionX, positionY);

//posX = positionX;
//posY = positionY;

width = w;
height = h;
}

Control::~Control()
{
controls.remove(this);
}

bool Control::updateControl(MouseState &state)
{
int x = state.x;
int y = state.y;

inside = false;

if(x >= posX && x <= posX + width &&
y >= posY && y <= posY + height )
{
inside = true;
}
return false;
}

void Control::setPosition(int x, int y)
{
posX = x;
posY = y;

}

void Control::setSize(int w, int h)
{
width = w;
height = h;
}

int Control::getWidth(void)
{
return width;
}

int Control::getHeight(void)
{
return height;
}

Control *addControl(Control *control)
{
static int lastX = 5;
static int lastY = 85;

control->setPosition(lastX, lastY);
lastY += control->getHeight() + 5;

return control;
}


Thanks in advance for those who could help me.

What I have tried:

I've tried to look over the internet for tutorials to solve this problem but they are confusing to me since I'm new in this world, so, if you can explain me (if you have a solution) how that solution works in order to understand better what I'm doing that will be appreciated.
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900