RDP上的OpenGL渲染

时间:2013-09-20 16:42:22

标签: c++ opengl rdp

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

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

我想知道我所做的一些配置是否是直接原因,或者它是否更为基础,只能通过其他方法解决,例如使用Display Lists或类似的东西。 / p>

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

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;
}

1 个答案:

答案 0 :(得分:3)

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