PDA

View Full Version : Create HGLRC on Remote desktop



iron1103
04-30-2010, 05:44 AM
Hi, every one! I'm a new guy here, I check all the posts with the keyword "Remote Desktop", but I still can't find the answer.

I have a simple OpenGL Application, it just create a opengl context by calling wglCreateContext, but i want it run on both local machine(WinXP SP3) and remote desktop.

So I declare two pfd, one used by local machine and another one used by remote desktop, I'll post my pseudo code below.

When I run this on local machine, no matter bSoftware is true or false, everything works fine.
When I run this on remote desktop, I set bSoftware to true, make it use PFD_GENERIC_FORMAT, but the GLCreateSoftware always return NULL, because SetPixelFormat always failure, and GetLastError() will be ERROR_INVALID_FUNCTION.

The point is I wanna create a HGLRC on remote desktop, any reply will be appreciated. Thanks.

iron1103
04-30-2010, 05:46 AM
Here is my pseudo code:
void GLCreate(bool bSoftware)
{
HWND hwnd = CreateWindow(,WS_CLIPSIBLINGS|WS_CLIPCHILDREN,);
HDC hdc = GetDC(hwnd);
m_hDC = CreateCompatibleDC(hdc);
m_hBmp = CreateCompatibleBitmap(hdc, cx, cy);
SelectObject(m_hDC, m_hBmp);
if( ! bSoftware )
m_hRC = GLCreateHardware(&m_hDC);
else
m_hRC = GLCreateSoftware(&m_hDC);
}

HGLRC GLCreateHardware(HDC *hDC, HGLRC *hRC)
{
HGLRC glrc = NULL;
PIXELFORMATDESCRIPTOR pfd;
memset(&pfd, 0, sizeof(PIXELFORMATDESCRIPTOR));
pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR);
pfd.nVersion = 1;
//dwFlags is the difference between HW and SW
pfd.dwFlags = PFD_SUPPORT_OPENGL|PFD_DRAW_TO_BITMAP;
pfd.iPixelType = PFD_TYPE_RGBA;
pfd.cColorBits = 32;
pfd.cAlphaBits = 8;
pfd.iLayerType = PFD_MAIN_PLANE;

int pixelformat = ChoosePixelFormat(*hDC, &pfd);
if( SetPixelFormat(*hDC, pixelformat, &pfd) )
{
glrc = wglCreateContext(*hDC);
wglMakeCurrent(*hDC, glrc);
}
return glrc;
}

HGLRC GLCreateSoftware(HDC *hDC, HGLRC *hRC)
{
HGLRC glrc = NULL;
PIXELFORMATDESCRIPTOR pfd;
memset(&pfd, 0, sizeof(PIXELFORMATDESCRIPTOR));
pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR);
pfd.nVersion = 1;
//dwFlags is the difference between HW and SW
pfd.dwFlags = PFD_SUPPORT_OPENGL|PFD_DRAW_TO_BITMAP|PFD_GENERIC_ FORMAT|PFD_SUPPORT_GDI;
pfd.iPixelType = PFD_TYPE_RGBA;
pfd.cColorBits = 32;
pfd.cAlphaBits = 8;
pfd.iLayerType = PFD_MAIN_PLANE;

int pixelformat = ChoosePixelFormat(*hDC, &pfd);
if( SetPixelFormat(*hDC, pixelformat, &pfd) )
{
glrc = wglCreateContext(*hDC);
wglMakeCurrent(*hDC, glrc);
}
return glrc;
}

Alfonse Reinheart
04-30-2010, 10:07 AM
The point is I wanna create a HGLRC on remote desktop, any reply will be appreciated. Thanks.

Is this actually possible on Windows? How do you even get a HWND to a remote desktop window?

Shinta
05-04-2010, 02:44 AM
I think the problem is, that (at least all systems I've tested) remote connections don't have a pixelformat with the requested settings.


|Color|Alpha|Depth|Accum|Stncl| AUX |Doubl|Spprt|Draw2|Draw2|Spprt|Spprt| OGL |Need |Need |Pixel|Swap |Swap |oLays|Spprt
# |Bits |Bits |Bits |Bits |Bits |Bufs |Bufs |Stere|Windw|BitMp| GDI | OGL | Typ | Pal |S.Pal| Typ |Methd|Layer|uLays| DD
-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----
1 | 24 | 0 | 32 | 64 | 8 | 0 | no | no | yes | yes | yes | yes | GDI | no | no | RGB |Undef| no | 0/ 0| no
2 | 24 | 0 | 16 | 64 | 8 | 0 | no | no | yes | yes | yes | yes | GDI | no | no | RGB |Undef| no | 0/ 0| no
3 | 24 | 0 | 32 | 64 | 8 | 0 | yes | no | yes | no | no | yes | GDI | no | no | RGB |Copy | no | 0/ 0| no
4 | 24 | 0 | 16 | 64 | 8 | 0 | yes | no | yes | no | no | yes | GDI | no | no | RGB |Copy | no | 0/ 0| no
5 | 24 | 8 | 32 | 64 | 8 | 0 | no | no | yes | yes | yes | yes | GDI | no | no | RGB |Undef| no | 0/ 0| no
6 | 24 | 8 | 16 | 64 | 8 | 0 | no | no | yes | yes | yes | yes | GDI | no | no | RGB |Undef| no | 0/ 0| no
7 | 24 | 8 | 32 | 64 | 8 | 0 | yes | no | yes | no | no | yes | GDI | no | no | RGB |Copy | no | 0/ 0| no
8 | 24 | 8 | 16 | 64 | 8 | 0 | yes | no | yes | no | no | yes | GDI | no | no | RGB |Copy | no | 0/ 0| no
9 | 24 | 0 | 32 | 0 | 8 | 0 | no | no | yes | yes | yes | yes | GDI | no | no |Index|Undef| no | 0/ 0| no
10 | 24 | 0 | 16 | 0 | 8 | 0 | no | no | yes | yes | yes | yes | GDI | no | no |Index|Undef| no | 0/ 0| no
11 | 24 | 0 | 32 | 0 | 8 | 0 | yes | no | yes | no | no | yes | GDI | no | no |Index|Copy | no | 0/ 0| no
12 | 24 | 0 | 16 | 0 | 8 | 0 | yes | no | yes | no | no | yes | GDI | no | no |Index|Copy | no | 0/ 0| no
13 | 32 | 0 | 32 | 64 | 8 | 0 | no | no | no | yes | yes | yes | GDI | no | no | RGB |Undef| no | 0/ 0| no
14 | 32 | 0 | 16 | 64 | 8 | 0 | no | no | no | yes | yes | yes | GDI | no | no | RGB |Undef| no | 0/ 0| no
15 | 32 | 8 | 32 | 64 | 8 | 0 | no | no | no | yes | yes | yes | GDI | no | no | RGB |Undef| no | 0/ 0| no
16 | 32 | 8 | 16 | 64 | 8 | 0 | no | no | no | yes | yes | yes | GDI | no | no | RGB |Undef| no | 0/ 0| no
17 | 32 | 0 | 32 | 0 | 8 | 0 | no | no | no | yes | yes | yes | GDI | no | no |Index|Undef| no | 0/ 0| no
18 | 32 | 0 | 16 | 0 | 8 | 0 | no | no | no | yes | yes | yes | GDI | no | no |Index|Undef| no | 0/ 0| no
19 | 16 | 0 | 32 | 32 | 8 | 0 | no | no | no | yes | yes | yes | GDI | no | no | RGB |Undef| no | 0/ 0| no
20 | 16 | 0 | 16 | 32 | 8 | 0 | no | no | no | yes | yes | yes | GDI | no | no | RGB |Undef| no | 0/ 0| no
21 | 16 | 8 | 32 | 32 | 8 | 0 | no | no | no | yes | yes | yes | GDI | no | no | RGB |Undef| no | 0/ 0| no
22 | 16 | 8 | 16 | 32 | 8 | 0 | no | no | no | yes | yes | yes | GDI | no | no | RGB |Undef| no | 0/ 0| no
23 | 16 | 0 | 32 | 0 | 8 | 0 | no | no | no | yes | yes | yes | GDI | no | no |Index|Undef| no | 0/ 0| no
24 | 16 | 0 | 16 | 0 | 8 | 0 | no | no | no | yes | yes | yes | GDI | no | no |Index|Undef| no | 0/ 0| no
25 | 8 | 0 | 32 | 32 | 8 | 0 | no | no | no | yes | yes | yes | GDI | no | no | RGB |Undef| no | 0/ 0| no
26 | 8 | 0 | 16 | 32 | 8 | 0 | no | no | no | yes | yes | yes | GDI | no | no | RGB |Undef| no | 0/ 0| no
27 | 8 | 8 | 32 | 32 | 8 | 0 | no | no | no | yes | yes | yes | GDI | no | no | RGB |Undef| no | 0/ 0| no
28 | 8 | 8 | 16 | 32 | 8 | 0 | no | no | no | yes | yes | yes | GDI | no | no | RGB |Undef| no | 0/ 0| no
29 | 8 | 0 | 32 | 0 | 8 | 0 | no | no | no | yes | yes | yes | GDI | no | no |Index|Undef| no | 0/ 0| no
30 | 8 | 0 | 16 | 0 | 8 | 0 | no | no | no | yes | yes | yes | GDI | no | no |Index|Undef| no | 0/ 0| no
31 | 4 | 0 | 32 | 16 | 8 | 0 | no | no | no | yes | yes | yes | GDI | no | no | RGB |Undef| no | 0/ 0| no
32 | 4 | 0 | 16 | 16 | 8 | 0 | no | no | no | yes | yes | yes | GDI | no | no | RGB |Undef| no | 0/ 0| no
33 | 4 | 8 | 32 | 16 | 8 | 0 | no | no | no | yes | yes | yes | GDI | no | no | RGB |Undef| no | 0/ 0| no
34 | 4 | 8 | 16 | 16 | 8 | 0 | no | no | no | yes | yes | yes | GDI | no | no | RGB |Undef| no | 0/ 0| no
35 | 4 | 0 | 32 | 0 | 8 | 0 | no | no | no | yes | yes | yes | GDI | no | no |Index|Undef| no | 0/ 0| no
36 | 4 | 0 | 16 | 0 | 8 | 0 | no | no | no | yes | yes | yes | GDI | no | no |Index|Undef| no | 0/ 0| no


You should try 24 color bits instead of 32.

hth,
Shinta