简体   繁体   English

通过opengl(MFC)拖动图像

[英]to drag an image by opengl (MFC)

I am using an openGL to drag an image (loaded bitmap) and wondering if there some methods/function to transform the image on the screen. 我正在使用openGL拖动图像(加载的位图),并且想知道是否存在一些方法/功能来转换屏幕上的图像。

so far i have done this code to load an image: 到目前为止,我已经完成了此代码以加载图像:

void CDisplayControlPanelView::OnDraw(CDC* /*pDC*/)
{
    CDisplayControlPanelDoc* pDoc = GetDocument();
    ASSERT_VALID(pDoc);
    if(!pDoc)
        return;

    wglMakeCurrent(m_hDC , m_hRC);
    RenderScene();
    SwapBuffers(m_hDC);
    wglMakeCurrent(m_hDC,NULL);
}

void CDisplayControlPanelView::RenderScene()
{
    AUX_RGBImageRec* pRGBImage;

    glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
    glClearColor(0.0, 0.0, 0.0, 0.0);

    glClear(GL_COLOR_BUFFER_BIT);
    pRGBImage = auxDIBImageLoadA("D:\\map.bmp");

    glDrawPixels(pRGBImage->sizeX, pRGBImage->sizeY, GL_RGB, GL_UNSIGNED_BYTE, pRGBImage->data);
    glFlush();
}

Use glTranslate . 使用glTranslate There are many other ways but this is the most simple. 还有许多其他方法,但这是最简单的。 Check out some tutorials if you are new to OpenGL, it could help. 如果您不熟悉OpenGL,请查看一些教程,它可能会有所帮助。

The first thing you must understand is, that OpenGL is not a scene graph. 您必须了解的第一件事是,OpenGL不是场景图。 It's a drawing API, very much like Windows GDI. 这是一个绘图API,非常类似于Windows GDI。 The function glDrawPixels is not very unlike a BitBlt from a MemDC. glDrawPixels函数与glDrawPixels的BitBlt非常不同。

Anyway: You shouldn't use glDrawPixels. 无论如何:您不应该使用glDrawPixels。 It's slow and deprecated. 它很慢且已弃用。 The way to draw images in OpenGL is uploading the image into a texture and drawing a textured quad. 在OpenGL中绘制图像的方法是将图像上载到纹理中并绘制带纹理的四边形。 The quad you can freely move around as you like. 您可以根据需要自由移动四边形。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM