Trying to clip the cursor to my window isn't working?
I'm trying to make the windows cursor stay inside my window. I'm using freeglut and C++ Everything is working great so far, except for the part where I try to use ClipCursor to keep the cursor locked in my window, it moves freely like the command wasn't even called. It worked fine in a project I have that doesn't use glut at all, but I wanted to try glut out.
Here's the code that's relevant:
int main(int argc, char* argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA);
glutInitWindowSize(WIDTH,HEIGHT);
glutInitWindowPosition(50,50);
glutCreateWindow("Indie Game开发者_StackOverflow中文版 01");
glewInit();
GLenum err = glewInit();
if(GLEW_OK != err) {
cout << "glewInit failed, aborting." << endl;
exit(1);
}
cout << "Status: Using GLEW " << glewGetString(GLEW_VERSION) << endl;
cout << "OpenGL version " << glGetString(GL_VERSION) << " supported" << endl;
HWND hwnd;
hwnd = FindWindow("GLUT","Indie Game 01");
RECT r;
GetWindowRect(hwnd,&r);
ClipCursor(&r);
init();
glutDisplayFunc(display);
glutMouseFunc(mouse);
glutKeyboardFunc(keyboard);
glutReshapeFunc(reshape);
glutMainLoop();
return 0;
}
I don't get why the ClipCursor isn't working :/ any help is greatly appreciated!
FindWindow must be failing. Try passing 0 as the first parameter.
精彩评论