问题描述
我想在MFC中左右键击鼠标时移动并调整opengl方块的大小。我尝试了以下代码移动,但它闪烁。
我尝试过:
void OverlayDisplayDlg :: OnMouseMove(UINT nFlags_i,CPoint cpPoint_i)
{
float nDiffx = float(cpPoint_i.x - m_nXvalue)/ 10;
float nDiffy = float(cpPoint_i.y - m_nYvalue)/ 10;
m_nXvalue = cpPoint_i.x;
m_nYvalue = cpPoint_i.y;
if(MK_LBUTTON == nFlags_i)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //清除颜色缓冲区
glMatrixMode(GL_PROJECTION); //操作模型 - 视图矩阵
glLoadIdentity(); //重置模型视图矩阵
// glPushMatrix();
glColor3f(1.0f,1.0f,0.0f);
glBegin(GL_LINE_LOOP);
glVertex2f(-0.3f + nDiffx, - 0.3f + nDiffy); //以逆时针(CCW)顺序定义顶点
glVertex2f(0.3f + nDiffx,-0.3f + nDiffy); //使正常(正面)面向你
glVertex2f(0.3f + nDiffx,0.3f + nDiffy);
glVertex2f(-0.3f + nDiffx ,0.3f + nDiffy);
glEnd();
// glPopMatrix();
SwapBuffers(m_hDeviceContextDC);
}
CDialogEx :: OnMouseMove(nFlags_i,cpPoint_i);
}
以上代码用于移动,但它无法正常工作。请帮助我。
I want to move and resize an opengl square on left and right button click of mouse in MFC. I tried the below code for moving , but it flickers.
What I have tried:
void OverlayDisplayDlg::OnMouseMove(UINT nFlags_i, CPoint cpPoint_i)
{
float nDiffx = float(cpPoint_i.x - m_nXvalue)/ 10;
float nDiffy = float(cpPoint_i.y - m_nYvalue)/ 10;
m_nXvalue = cpPoint_i.x;
m_nYvalue = cpPoint_i.y;
if(MK_LBUTTON == nFlags_i)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); // Clear the color buffer
glMatrixMode(GL_PROJECTION); // To operate on Model-View matrix
glLoadIdentity(); // Reset the model-view matrix
//glPushMatrix();
glColor3f(1.0f,1.0f,0.0f);
glBegin(GL_LINE_LOOP);
glVertex2f(-0.3f + nDiffx, -0.3f + nDiffy); // Define vertices in counter-clockwise (CCW) order
glVertex2f( 0.3f + nDiffx, -0.3f + nDiffy); // so that the normal (front-face) is facing you
glVertex2f( 0.3f + nDiffx, 0.3f + nDiffy);
glVertex2f(-0.3f + nDiffx, 0.3f + nDiffy);
glEnd();
//glPopMatrix();
SwapBuffers(m_hDeviceContextDC);
}
CDialogEx::OnMouseMove(nFlags_i, cpPoint_i);
}
the above code is for moving, but it does not work properly. Please help me.
推荐答案
这篇关于在MFC中移动opengl 2d对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!