( 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:
- 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
[ATTACH=CONFIG]1051[/ATTACH]
- 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, -(nRangeh/w), (nRangeh/w), -(nRange10000.0f), (nRange10000.0f));
else
::glOrtho (-(nRangew/h), (nRangew/h), -nRange, nRange, -(nRange10000.0f), (nRange10000.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…