Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 10 of 11

Thread: Rubberband rectangle and local coordinates with MFC context being removed

Threaded View

  1. #1
    Junior Member Newbie
    Join Date
    Oct 2012
    Posts
    11

    Rubberband selection rectangle and local coordinates

    ( quick why)
    I have a GDI+ rubberband or sweep rectangle that I have been using with OPengl and a MFC application. BUT as some have you already know, if you are using OPengl and GDI+ (which I was/is) .. Win7 aero or Win8 aero Desktop Window Manager (DWM) gets VERY mad at you where the sweept rectangle flickers like crazy if Aero is on.

    So to remove GDI+ I created a opengl rubber band rectangle XOR and front buffer, but that is having 2 issue's:

    Issues:
    1. I cannot get the sweep rectangle to track my mouse curser of the box select , keep in mind I have created a 3d environment. What it wants to do is draw it in client cooridinates inside of OpenGL instead of the client rect of the opengl view. I want it to behave like standard CAD zooming/selection where I can have the 3d environment rotated but it draws to the screen like a standard zoom/selection rectangle

    see picture below
    Attachment 1051

    2. The rubberband rectangle draws with the XOR and I cannot get it to draw just with a standard zoom / selection window color ie white



    LButtonDown : Initialize Sweep rectangle
    MouseMove : SweepingDrawRect
    LButtonUp : De-initilize SweepRectangle

    Code sample:

    void CGLView::InitializeDrawRectangle( int linestyle)
    {
    if(m_bSweepRectInitilized) return;
    //get client rectangle
    CRect rectClient;
    ::GetClientRect(m_hWnd,&rectClient);

    GLsizei w, h;
    w = rectClient.Width();
    h = rectClient.Height();


    // set drawing mode to front-buffer, etc
    glDrawBuffer(GL_FRONT);


    glDisable(GL_DEPTH_TEST);
    glLogicOp(GL_XOR);
    glEnable(GL_COLOR_LOGIC_OP);

    glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
    glDisable(GL_DEPTH_TEST);


    // save the current projection matrix and set up a new convenient projection matrix


    if (h==0)
    h=1;
    if(w==0)
    w=1;


    int viewport[4];

    glGetIntegerv(GL_VIEWPORT, viewport);

    glPushMatrix();
    glMatrixMode(GL_PROJECTION);
    glPushMatrix();
    glLoadIdentity();
    gluOrtho2D(0.0, viewport[2], 0.0, viewport[3]);

    glViewport(0,0,w,h);


    // gluOrtho2D(0, rectClient.Width(), 0, rectClient.Height());*/


    // gluOrtho(0, winWidth, 0, winHeight, -1, 1);
    // gluOrtho2D(0, winWidth, 0, winHeight);
    /* if (w <= h)
    ::glOrtho (-nRange, nRange, -(nRange*h/w), (nRange*h/w), -(nRange*10000.0f), (nRange*10000.0f));
    else
    ::glOrtho (-(nRange*w/h), (nRange*w/h), -nRange, nRange, -(nRange*10000.0f), (nRange*10000.0f));*/



    glMatrixMode (GL_MODELVIEW);
    glLoadIdentity();

    glDisable(GL_LIGHTING); //turn off lighting effects

    // glOrtho(0, rectClient.Width(), 0, rectClient.Height(), -1, 1);
    // gluOrtho2D (0.0, (GLdouble) winWidth, 0.0, (GLdouble) winHeight);
    // glViewport(-1, -1, rectClient.Width() + 2, rectClient.Height() + 2);

    // save the current model view matrix
    m_bSweepRectInitilized=1;

    }



    void CGLView::SweepingDrawRect(HDC hDC, int x1, int y1, int x2, int y2)
    {
    wglMakeCurrent(m_hgldc, m_hrc);

    glDrawBuffer(GL_FRONT);
    glEnable(GL_COLOR_LOGIC_OP);
    glLogicOp(GL_XOR);
    glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
    glDisable(GL_DEPTH_TEST);// make sure you do this to get rid of flicker

    // Perform the logic rendering
    glLineWidth(2.0);
    if(x1 < x2)
    {
    glColor4f(0.0f, 0.0f, 0.0f, 0.5f);
    }
    else
    {
    glColor4f(0.0f, 0.2f, 1.0f, 0.5f);
    }

    // CRect rectClient;
    // ::GetClientRect(m_hWnd,&rectClient);

    int viewport[4];

    glGetIntegerv(GL_VIEWPORT, viewport);

    // OpenGL window coordinates are different from GDI's
    glRectd(x1, viewport[3]-y1,x2, viewport[3]-y2);


    glDisable(GL_COLOR_LOGIC_OP);

    wglMakeCurrent(NULL, NULL);
    glDrawBuffer(GL_BACK);

    glFlush(); // must flush here
    }

    It works pretty good with the exception of the above..
    Last edited by EricMar; 06-09-2013 at 08:27 AM. Reason: I missed something

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •