tags:

views:

213

answers:

4

Hi,

I have a problem with glut, I would like to have a callback to know when the user is moving the window of my application, and I didn't found anything in glut.

My goal is to make an application only on windows, is it possible to do this with MFC keeping my glut code?

Thanks in advance

+2  A: 

I couldn't find a call back function but you could do it by hand with glutGet:

int glutGet(GLenum state);

An example of what you might do is:

bool window_change(void)
{
  int init_x = glutGet(GLUT_INIT_WINDOW_X);
  int init_y = glutGet(GLUT_INIT_WINDOW_Y);
  int pos_x = glutGet(GLUT_WINDOW_X);
  int pos_y = glutGet(GLUT_WINDOW_Y);

  return (init_x != pos_x || init_y != pos_y);
}

This will return true if it's moved from it's initial spot. If you want to see if it's moved since the last check, try:

bool window_change(void)
{
  static int init_x = glutGet(GLUT_INIT_WINDOW_X);
  static int init_y = glutGet(GLUT_INIT_WINDOW_Y);
  int pos_x = glutGet(GLUT_WINDOW_X);
  int pos_y = glutGet(GLUT_WINDOW_Y);

  bool result = init_x != pos_x || init_y != pos_y;

  init_x = pos_x; 
  init_y = pos_y;

  return result;
}

You can set the window position by using the function: glutPositionWindow

void glutPositionWindow(int x, int y);
Bruce
thanks for your suggestion, but this code can't work because when you drag the window with glut, your program is freezed. Maybe creating a thread just for this? But the code will not work if you only click on the program window bar (i don't remember the correct term) without moving the window.
penpen
Ya I've checked and there's no way to check if the window is moving with glut, as far as I know. You'll have to make a thread.
Bruce
A: 

the idea from Bruce is very good. i think there is not another option while using GLUT. i think this scenario is something that GLUT was not developed for. GLUT is a toolkit for OpenGL, which wraps window- and input-management across platforms. it has a lot of uses, but why should it care, when its window is dragged? i think if you (or your program) care, then you should implement your own window- and input-management anyway.

which leads me to your second question. you can use OpenGL with MFC (although my recommendation strongly depends on what you are planing). you should not use GLUT then, because MFC has its own way of handling input, windows, event management, rendering/drawing ...

if you really want to do it: http://www.codeproject.com/KB/openGL/OpenGL%5FMFC%5FAppWizard.aspx

didito
Thanks for you help. It seems that I have no choice and I will have to do what you suggest. That's frustrating because everything works with glut, but there is only this problem....
penpen
A: 
manifest
A: 

GLUT is actually fairly limited, and does not expose all window events to the client. However it does provide a lot of boiler code plate for WGL (on Windows) and GLX (on X11) that is probably not worth rewriting.

When I had a hobby project that was using GL, and there were certain events that I couldn't handle via GLUT, what I did is fork the open source freeglut. That is, download the tarball, and edit the library's WindowProc (Windows) or XGetEvent() loop (on X) and simply add the missing callbacks to the library.

You'll have a dependency on your own GLUT modifications, but it'll work, and you won't have to write as much boiler-plate code as if you were targeting WGL or GLX directly.

You'll probably want to link it statically so it doesn't conflict with any other freeglut.

asveikau