问题描述
跟随我的,我提供了如下绘制矩形的代码:
following my another question, I have provided the code that draws the rectangle as follows:
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); }
这里的问题是:
红色矩形消失在 OnDraw 返回之后。我的意思是,例如,当您通过按对话框上的按钮或固定缩小进行固定缩放时,红色矩形闪烁,然后立即消失。
或当您使用 OnDraw 运行时(如高速平移),您会得到类似的东西这个:
确定的红色矩形在短时间后被删除(消失)时间,但这个红色矩形的轨迹显示了很短的时间?
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 发生时,如何删除当前的红色矩形? / strong>
How can I make the current red rectangle be rendered on the texture until the next call of OnDraw?
Also how can I make the current red rectangle be deleted as soon as the next call of OnDraw occurs?
如果第二个问题很难回答,请至少回答第一个问题。显然,如果用户以正常速度进行平移,则不会显示矩形轨迹。
If the second question is hard to answer, no problem please at least answer the first. Obviously if the user does panning with a normal speed this track of rectangles won't be shown.
推荐答案
我猜你的问题是涉及双缓冲。
I guess your issue is related to double buffering.
某些设备在交换时不会删除后台缓冲区的内容。我的建议是在开始渲染到新缓冲区之前明确地清除屏幕(glClear)。这应该处理与多个红色矩形相关的问题。
Some devices do not delete the content of the back buffer when it is being swapped. My suggestion would be to clear the screen explicitly (glClear) before you start rendering into the new buffer. This should handle the issue related to multiple red rectangles.
其次我不知道您的代码中是否存在超出必要的缓冲区交换。请检查是否有其他显式或隐式调用Swap缓冲区可能会导致显示错误的缓冲区。 (显示的最终缓冲区可能不是您绘制矩形的缓冲区)。
Secondly I am not sure if there are more than necessary buffer swaps happening in your code. Please check if there other explicit or implicit calls to Swap Buffer which might result in the wrong buffer being displayed. (The final buffer displayed might not be the buffer in which you drew the rectangle).
这篇关于在2D纹理上绘制的红色矩形在绘制后立即消失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!