Question

I have an application which uses OpenGL in a fairly simple way to render textured QUADS.

It's working fine when running locally, but when running remotely (Microsoft Remote Desktop) it displays blank white windows.

I was wondering if some of the configurations I've made are a direct reason for that, or is it something more fundamental that can only be solved by another approach, like using Display Lists or something like that.

My code follows. I initialize the contexts like this:

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

And draw to the screen like this:

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;
}
Was it helpful?

Solution

In RDP you normally don't have GPU acceleration. I suggest you get yourself a Windows build of the MesaGL software rasterizer and depending on if you're on a RDP connection set the PATH environment variable to make it find that alternative opengl32.dll so that you have a nice software renderer.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top