简体   繁体   English

如何在ActiveX控件中正确初始化OpenGL?

[英]How to properly initialize OpenGL in ActiveX controls?

I am trying to create a simple ActiveX control using OpenGL. 我正在尝试使用OpenGL创建一个简单的ActiveX控件。 I add some styles in PreCreateWindow: 我在PreCreateWindow中添加了一些样式:

BOOL CMFCActiveXControl1Ctrl::PreCreateWindow(CREATESTRUCT& cs) {
    cs.style |=  WS_CLIPSIBLINGS | WS_CLIPCHILDREN;
    cs.lpszClass = _T("STATIC");
    return COleControl::PreCreateWindow(cs);
}

Initialization of OpenGL: OpenGL的初始化:

int CMFCActiveXControl1Ctrl::OnCreate(LPCREATESTRUCT lpCreateStruct) {
    PIXELFORMATDESCRIPTOR pfd = { 0 };
    pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR);
    pfd.nVersion = 1;
    pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_DOUBLEBUFFER | PFD_SUPPORT_OPENGL;
    pfd.iPixelType = PFD_TYPE_RGBA;
    pfd.cColorBits = 24;
    pfd.cDepthBits = 16;
    pfd.iLayerType = PFD_MAIN_PLANE;
    hDC = ::GetDC(m_hWnd);
    int format = ChoosePixelFormat(hDC, &pfd);
    SetPixelFormat(hDC, format, &pfd);
    hRC = wglCreateContext(hDC);
    wglMakeCurrent(hDC, hRC);
    return 0;
}

And then I try to clear color buffer with red color, but all I see is just a black square: 然后我尝试用红色清除颜色缓冲区,但我看到的只是一个黑色方块:

void CMFCActiveXControl1Ctrl::OnDraw(
        CDC* pdc, const CRect& rcBounds, const CRect& rcInvalid)
{
    if (!pdc)
       return;
    glClearColor(1, 0, 0, 0);
    SwapBuffers(wglGetCurrentDC());
}

glClearColor (...) does not actually clear the color buffer, it just sets the color that will be used when you call glClear (...) . glClearColor (...)实际上不会清除颜色缓冲区,它只是设置调用glClear (...)时将使用的颜色。

There is a new function in GL3: glClearBuffer (...) that can be used to clear a buffer to an explicit value all in a single call, but ordinarily you are going to need to call glClear (GL_COLOR_BUFFER_BIT) after setting the clear color instead. GL3中有一个新功能: glClearBuffer (...)可用于在一次调用中将缓冲区清除为所有显式值,但是通常情况下,您需要在设置透明颜色后调用glClear (GL_COLOR_BUFFER_BIT)代替。

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

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