在MFC中移动opengl 2d对象 [英] Move opengl 2d object in MFC

查看:49
本文介绍了在MFC中移动opengl 2d对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在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.

推荐答案

请参阅捕获鼠标 [ ^ ]。


您不应该在鼠标移动方法中进行屏幕绘制。您应捕获指示移动或调整大小的每条消息,然后使用 InvalidateRect 告诉Windows您的数据已更新。然后在疼痛方法中重新绘制,处理 WM_PAINT 消息。
You should not do screen painting in the mouse move method. You should capture each message that indicates a move or resize, and then use InvalidateRect to tell Windows that your data has been updated. Then you do the repainting in your pain method that handles the WM_PAINT messages.


这篇关于在MFC中移动opengl 2d对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆