gpt4 book ai didi

c++ - RDP 上的 OpenGL 渲染

转载 作者:太空狗 更新时间:2023-10-29 21:23:09 24 4
gpt4 key购买 nike

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

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

我想知道我所做的一些配置是否是造成这种情况的直接原因,或者它是否是更基本的只能通过其他方法解决的问题,比如使用 Display Lists或类似的东西。

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

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

最佳答案

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

关于c++ - RDP 上的 OpenGL 渲染,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18921800/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com