سؤال

I am trying to create a simple ActiveX control using OpenGL. I add some styles in PreCreateWindow:

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

Initialization of 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 (...).

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.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top