Results 1 to 4 of 4

Thread: updating window coordinates in real time

  1. #1
    Senior Member Regular Contributor
    Join Date
    Aug 2003
    Posts
    369

    updating window coordinates in real time

    Hi to everyone, today I stumbled upon the following problem, using glut and Windows:
    I have a window on screen for which I store the screen coordinates of the window, like: left, top, right, bottom. I show these coordinates on screen. I'd like to update these coordinates pixel by pixel as the user reshapes or moves the window.
    For reshaping, there is the reshape callback, so no problemo there. But what about moving the window? I tried doing the update in the display callback, but the coordinates update as soon as I release the mouse button.
    Has anyone stumbled upon this before? I thought after that I could use glutMotionFunc or PassiveMotionFunc callbacks, but these require that the mouse is within the window (not in the window border). Thanks for your time.

  2. #2
    Senior Member OpenGL Pro
    Join Date
    May 2001
    Location
    Kristianstad,Skåne,Sweden
    Posts
    1,595

    Re: updating window coordinates in real time

    This is pretty easy to do when using the win32 api, but there is no way to have glut do it for you, so as long as you use glut the answer is no.

    Mikael

  3. #3
    Guest

    Re: updating window coordinates in real time

    well, there is a sneaky way to do it under win32, using window sub-classing. use this code at your own risk

    Code :
    #include <windows.h>
    #include "glut.h"
     
    // for glut's window proc
    WNDPROC oldWndProc;
     
    // our new window proc
    LRESULT CALLBACK newWndProc( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
    {
        RECT* rect;
        switch( uMsg )
        {
            case WM_MOVING:
                // watch out, moving rect!
                rect = (RECT*)lParam;
                break;
        }
        return CallWindowProc( oldWndProc, hwnd, uMsg, wParam, lParam );
    }
     
    int main( int argc, char** argv )
    {
        // typical glut setup here, nothing unusual	
        glutInit( &amp;argc, argv );
        glutInitDisplayMode( ... );
        glutInitWindowSize( ... );
        glutInitWindowPosition( ... );
        glutCreateWindow( argv[0] );
     
        // !!! sneaky part !!!
        // find our window
        // note the name matches the window title
        HWND hWnd = FindWindow( NULL, argv[0] );
        if( hWnd )
        {
            // sub-class the window proc
    	oldWndProc = (WNDPROC)GetWindowLongPtr( hWnd, GWL_WNDPROC );
    	if( oldWndProc )
    	    SetWindowLongPtr( hWnd, GWL_WNDPROC, (LONG)newWndProc );
        }
     
        // and the rest is completely as usual
        // ...

  4. #4
    Senior Member Regular Contributor
    Join Date
    Aug 2003
    Posts
    369

    Re: updating window coordinates in real time

    Thanks guys. I guess I have to think about it because in the end this is supposed to be a beginners program, talking about viewports and windows, so I don't know how much I want to put in win32 api calls in there (it might scare people off). I'll think about it but thanks for the options

Similar Threads

  1. Is this real-time?
    By glfreak in forum OpenGL: General
    Replies: 5
    Last Post: 12-13-2007, 05:46 PM
  2. real-time FUR.
    By DSA in forum OpenGL: Advanced Coding
    Replies: 3
    Last Post: 01-19-2004, 12:51 PM
  3. How to get environment map in real time?
    By in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 10-24-2002, 01:15 AM
  4. Real-time OS Support for OGL
    By lobstah in forum OpenGL: General
    Replies: 0
    Last Post: 02-08-2001, 09:08 AM
  5. Real-Time
    By ZeeBoy in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 01-19-2001, 03:14 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean