跟随我的另一个问题 https://stackoverflow.com/questions/18477291/render-an-outlined-red-rectangle-on-top-a-2d-texture-in-opengl/18478717#18478717,我提供了绘制矩形的代码,如下所示:
void COpenGLControl::DrawRectangleOnTopOfTexture()
{
wglMakeCurrent(hdc, hrc);
glPushAttrib(GL_ENABLE_BIT|GL_CURRENT_BIT);
glDisable(target);
glColor3f(1.0f,0.0f,0.0f);
glBegin(GL_LINE_LOOP);
glVertex2f(RectangleToDraw.at(0),RectangleToDraw.at(1));
glVertex2f(RectangleToDraw.at(0),RectangleToDraw.at(3));
glVertex2f(RectangleToDraw.at(2),RectangleToDraw.at(3));
glVertex2f(RectangleToDraw.at(2),RectangleToDraw.at(1));
glEnd();
glPopAttrib();
SwapBuffers(hdc);
wglMakeCurrent(NULL, NULL);
}
void COpenGLControl::OnDraw(CDC *pDC)
{
// TODO: Camera controls
wglMakeCurrent(hdc,hrc);
glLoadIdentity();
gluLookAt(0,0,1,0,0,0,0,1,0);
glTranslatef(m_fPosX, m_fPosY, 0.0f);
glScalef(m_fZoom,m_fZoom,1.0);
setViewRectangle();
if (WantToDrawRectangle)
DrawRectangleOnTopOfTexture();
wglMakeCurrent(NULL, NULL);
}
the problem here is:
the red rectangle disappears right after the OnDraw
returns. I mean for example when you do a fixed zoom in
or fixed zoom out
by pressing a button on the dialog, a red rectangle flashes and then immediately disappears.
Or when you make the OnDraw
run constanly ( for example you pan with high speed ), you get something like this:
surely red rectangles are deleted(disappeared) after a short time but this track of red rectangles is shown for a short period of time?
如何使当前的红色矩形渲染在纹理上,直到下一次调用OnDraw
?
另外,如何使当前的红色矩形在下次调用时立即删除OnDraw
occurs?
如果第二个问题很难回答,没问题,至少回答第一个问题。显然,如果用户以正常速度平移,则不会显示该矩形轨迹。