GLUT mouse detection
When using the glueMouseFunc callback, is there some sort of cursor detection flag you have to enable? Also, do the mouse button states actually have to be changed (ie: MOUSE_DOWN to MOUSE_UP) for the callback to be run?
It's just that I've got a program that should perform transformations according to the mouse position relative to the last, and nothing *EVER* happens when I move the mouse, so I'm starting to think that I've done something wrong with GLUT.
(Would SDL work better for continuous mouse position checking?)
Thanks!
EDIT:
Just read a doc about motion funcs, I'll try them.
EDIT 2:
Ok, neither of them work at all either. (Passive and Active.) Here's the (simple) main file I've been using to test, ignore the commented out stuff.
cameraRotate just applies some transforms, nothing that should cause this to not work.
Thanks again!
EDIT 3 (lol): A little testing has proven that GLUT is not even bothering to call the mouse callback function. Hmm.
It's just that I've got a program that should perform transformations according to the mouse position relative to the last, and nothing *EVER* happens when I move the mouse, so I'm starting to think that I've done something wrong with GLUT.
(Would SDL work better for continuous mouse position checking?)
Thanks!
EDIT:
Just read a doc about motion funcs, I'll try them.
EDIT 2:
Ok, neither of them work at all either. (Passive and Active.) Here's the (simple) main file I've been using to test, ignore the commented out stuff.
Code:
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <cstring>
#include <cmath>
#include "GLUT/glut.h"
#include "q2model.h"
#include "camera_trn.h"
using namespace std;
//MD2 testModel;
//bool succTest;
int firstMouseGet = 1;
int lastMouseX;
int lastMouseY;
void init(void)
{
glClearColor(0.0, 0.0, 0.0, 0.0);
glClearDepth(0.0);
glShadeModel(GL_SMOOTH);
glEnable(GL_TEXTURE_2D);
/*
FILE *bob;
bob = fopen("test.txt", "rb");
if (!bob) {
cout << "CRUNCH!" << endl;
}
succTest = testModel.Open("faerie.md2");
if (!succTest) {
cout << "AHH! FAILURE!" << endl;
}
else {
cout << "Opened ok!" << endl;
}
*/
}
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glColor3f(1.0, 1.0, 1.0);
glLoadIdentity();
/*
succTest = testModel.Render(1, FALSE);
if (!succTest) {
cout << "AHH! FAILURE!" << endl;
}
else {
cout << "Rendered ok!" << endl;
}
unsigned int fred = testModel.getErr();
cout << fred << endl;
*/
glRotatef(36.0, 0.0, 1.0, 0.0);
glTranslatef(0.0, 0.0, -5.0);
glTranslatef(2.0, 0.0, 0.0);
//glRotatef(36.0, 0.0, 1.0, 0.0);
glScalef(1.0, 2.0, 1.0);
glEnable(GL_LINE_STIPPLE);
glLineStipple(1, 0xF0F0);
glutWireCube(1.0);
glFlush();
}
void reshape(int width, int height)
{
glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glFrustum(-1.0, 1.0, -1.0, 1.0, 1.5, 20.0);
glMatrixMode(GL_MODELVIEW);
}
void mouseMove(int x, int y) {
myLabel:
if (firstMouseGet == 1) {
lastMouseX = x;
lastMouseY = y;
firstMouseGet = 0;
goto myLabel;
}
glMatrixMode(GL_MODELVIEW);
cameraRotate(y - lastMouseY, x - lastMouseX, 0.0);
lastMouseX = x;
lastMouseY = y;
}
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGBA);
glutInitWindowSize(320, 240);
glutInitWindowPosition(100, 100);
glutCreateWindow("OpenGL");
init();
glutPassiveMotionFunc(mouseMove);
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutMainLoop();
return(0);
}cameraRotate just applies some transforms, nothing that should cause this to not work.
Thanks again!
EDIT 3 (lol): A little testing has proven that GLUT is not even bothering to call the mouse callback function. Hmm.
What the heck is that random goto doing 
Anyway, glutPassiveMotionFunc will be called when the mouse is waved, glutMotionFunc will be called when the mouse is dragged. You'll often need to register for both -- eg for an FPS.

Anyway, glutPassiveMotionFunc will be called when the mouse is waved, glutMotionFunc will be called when the mouse is dragged. You'll often need to register for both -- eg for an FPS.
Wasn't there a post from one sad cookie a second ago?
Well, yeah the fps demo worked, but when I held the forward key and turned with the mouse it got locked into forwards travel...
That means it's my code sucking.
Can't see how though, it's so simple.
Well, yeah the fps demo worked, but when I held the forward key and turned with the mouse it got locked into forwards travel...
That means it's my code sucking.
Can't see how though, it's so simple.
Sorry, I deleted my post 'cos I realized that app didn't use GLUT after all. You're just too fast for me
This one seems to though: http://onesadcookie.com/~keith/Maze.tar.bz2 (if it's working, the point under your mouse should be hilited)
OneSadCookie Wrote:This one seems to though: http://onesadcookie.com/~keith/Maze.tar.bz2 (if it's working, the point under your mouse should be hilited)
Safari seems unable to load that link, it might just be my Shaw Cable sucking huge though, it does this sometime. It'll work fine for browsing and stuff, but as soon as you want a file other than HTML and such... *LAG*.
I'll try again later.
On a less related note, have you ever tried glTools? The GL superbible, which I just purchased, uses it a lot, is it any good? I'm being lured towards trying it because of it's Frame-Of-Reference system, all done already for me.
But using it would make me feel like I'm cheating.Study of my brain:
Just tried the link again and it's definitely working
Possibly Related Threads...
| Thread: | Author | Replies: | Views: | Last Post | |
| annoying mouse clicks and GLUT problem | WhatMeWorry | 1 | 2,217 |
Nov 6, 2005 01:12 AM Last Post: OneSadCookie |
|

