opengl 绘制拉框 不用重新绘制底图的方法

来源:互联网 发布:苹果mac怎么下载 编辑:程序博客网 时间:2024/05/18 00:55


void CSpBsView::DrawDragRect(CRect rect)
{

HGLRC hRC = wglGetCurrentContext();

//GetGlRC(){ return m_hRC; }  函数返回的是当前的OpenGL Rending Context
if( hRC != m_hRC )
{
::wglMakeCurrent(GetGlDC(), GetGlRC());
::glDrawBuffer(GL_FRONT);
}


CRect clntRc; GetClientRect( &clntRc );
::glEnable(GL_COLOR_LOGIC_OP);
::glLogicOp(GL_XOR);
DrawRect(m_DragRect, clntRc, m_DragColor); m_DragRect = rect;
DrawRect(m_DragRect, clntRc, m_DragColor); 
::glDisable(GL_COLOR_LOGIC_OP);


if( hRC != m_hRC ) ::wglMakeCurrent( NULL,NULL );
}
}

inline static void DrawRect(CRect rect, CRect clntRect, COLORREF color)
{
if( !rect.IsRectEmpty() )
{
::glPushMatrix();
::glLoadIdentity();
::glViewport(0, 0, clntRect.right, clntRect.bottom);
::glOrtho(0, clntRect.right, clntRect.bottom, 0, -1, 1);


::glColor3f(GetRValue(color)/255.f,
GetGValue(color)/255.f,
GetBValue(color)/255.f);


::glBegin(GL_LINE_LOOP);
double x[4] = { rect.left, rect.right, rect.right, rect.left };
double y[4] = { rect.bottom, rect.bottom, rect.top, rect.top };
for( int i=0; i<4; i++ ) ::glVertex2d(x[i], y[i]);
::glEnd();


::glPopMatrix();
}
}


0 0