3

我有一个应用程序,它以一种相当简单的方式使用 OpenGL 来渲染纹理 QUADS。

它在本地运行时工作正常,但在远程运行(Microsoft 远程桌面)时,它会显示空白的白色窗口。

我想知道我所做的一些配置是否是直接原因,或者它是否是更基本的东西,只能通过另一种方法解决,比如使用显示列表或类似的东西。

我的代码如下。我像这样初始化上下文:

void InitWindow(HWND *hWnd, HDC *hDC, HGLRC *hRC)
{
    *hDC = GetDC(*hWnd);

    // set the pixel format for the DC
    PIXELFORMATDESCRIPTOR pfd;
    ZeroMemory(&pfd, sizeof(pfd));
    pfd.nSize = sizeof(pfd);
    pfd.nVersion = 1;
    pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | 
            PFD_DOUBLEBUFFER;

    pfd.iPixelType = PFD_TYPE_RGBA;
    pfd.cColorBits = 24;
    //      pfd.cRedBits = 8;   
    //      pfd.cGreenBits = 8;
    //      pfd.cBlueBits = 8;
    pfd.cAlphaBits = 0;
    pfd.cDepthBits = 0;
    pfd.iLayerType = PFD_MAIN_PLANE;

    int format = ChoosePixelFormat(*hDC, &pfd);
    SetPixelFormat(*hDC, format, &pfd);

    // create and enable the render context (RC)
    *hRC = wglCreateContext(*hDC);

    // make current context current 
    wglMakeCurrent(*hDC, *hRC);
}

并像这样绘制到屏幕上:

int Render(HWND hWnd, Raster* raster)
{
    Size RasterSize = raster->GetSize();

    HDC hDC = NULL;
    HGLRC hRC = NULL;

    // acquire DC, HGLRC for the window & make current
    InitWindow(&hWnd, &hDC, &hRC);

    GLenum raster_pixel_format = GL_BGRA_EXT;
    GLint internal_format = GL_RGBA;

    if (s_ClearBeforeDraw)
    {
        glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
        glClear(GL_COLOR_BUFFER_BIT);
    }

    GLuint texture;
    // allocate a texture name
    glGenTextures(1, &texture);
    glBindTexture (GL_TEXTURE_2D, texture);

    glPixelStorei (GL_UNPACK_ALIGNMENT, 1);
    glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
    glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
    glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);

    glTexImage2D (GL_TEXTURE_2D, 0, internal_format, 
            RasterSize.width, RasterSize.height,
            0, raster_pixel_format, GL_UNSIGNED_BYTE,
            raster->GetData());

    glBindTexture(GL_TEXTURE_2D, texture);

    RECT wndRect;
    ::GetClientRect(hWnd, &wndRect);
    GLsizei wndWidth = wndRect.right;
    GLsizei wndHeight = wndRect.bottom;

    glEnable(GL_TEXTURE_2D);

    // this is usually stated in window coordinates,
    // but since we know the raster gets its size from 
    // the window - we can use raster coordinates
    glViewport(0, 0, RasterSize.width, RasterSize.height);

    glBegin( GL_QUADS );    

    glTexCoord2d(0.0,0.0); glVertex2d(-1.0,+1.0);
    glTexCoord2d(1.0,0.0); glVertex2d(+1.0,+1.0);
    glTexCoord2d(1.0,1.0); glVertex2d(+1.0,-1.0);
    glTexCoord2d(0.0,1.0); glVertex2d(-1.0,-1.0);

    glEnd();

    glDisable(GL_TEXTURE_2D);

    glBindTexture(GL_TEXTURE_2D, 0);
    glDeleteTextures(1, &texture);

    SwapBuffers(hDC);
    wglMakeCurrent(NULL, NULL);

    // Release the context handles if they aren't cached
    wglDeleteContext(hRC);
    ReleaseDC(hWnd, hDC);

    return SUCCESS;
}
4

1 回答 1

4

在 RDP 中,您通常没有 GPU 加速。我建议您自己获取 MesaGL 软件光栅器的 Windows 版本,并根据您是否在 RDP 连接上设置 PATH 环境变量以使其找到替代 opengl32.dll 以便您拥有一个不错的软件渲染器。

于 2013-09-20T19:31:55.143 回答