简体   繁体   English

OpenGL / SDL2:PC上的模板缓冲位始终为0

[英]OpenGL / SDL2 : stencil buffer bits always 0 on PC

I'm writing an app using SDL2 / OpenGL, and doing some stencil operations. 我正在使用SDL2 / OpenGL编写应用程序,并进行了一些模版操作。

Everything works as expected on Mac, however on PC the stenciling doesn't work. 一切都可以在Mac上正常运行,但是在PC上无法正常工作。

Upon closer inspection I realized that the following code provides different outcomes on my Mac and PC: 经过仔细检查,我意识到以下代码在Mac和PC上提供了不同的结果:

SDL_Init(SDL_INIT_VIDEO); SDL_Init(SDL_INIT_VIDEO);

SDL_GL_SetAttribute( SDL_GL_STENCIL_SIZE, 8 ); SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE,8);

SDL_CreateWindow( ... ); SDL_CreateWindow(...);

SDL_CreateRenderer( ... ) SDL_CreateRenderer(...)

... do stuff ... ... 做东西 ...

When I print out the stencil bits ( SDL_GL_STENCIL_SIZE ) on Mac I get 8. When I do the same on PC, I get 0. 当我在Mac上打印出模版位(SDL_GL_STENCIL_SIZE)时,我得到8。在PC上进行相同的工作时,我得到0。

The same happens whether I run it on an actual PC, or on a PC emulator on the Mac. 无论是在实际PC上还是在Mac上的PC模拟器上运行,都会发生相同的情况。

What am I missing? 我想念什么? How can I force SDL2 to request a context with a stencil buffer? 如何强制SDL2请求带有模板缓冲区的上下文?

It looks to me like the Mac's OpenGL implementation has different defaults than the PC one, so I'm probably forgetting to do something to specifically request a stencil buffer, but I can't find any good information online ... 在我看来,Mac的OpenGL实现与PC的默认设置不同,因此我可能忘记做一些专门请求模版缓冲区的操作,但是我在网上找不到任何有用的信息...

Help ^_^' ? 帮助^ _ ^'吗?

Never mind, I found the answer: 没关系,我找到了答案:

On PC SDL2 was defaulting to Direct3D (which I guess would explain why my opengl stencil buffer was not there ^_^'). 在PC上,SDL2默认为Direct3D(我想这可以解释为什么我的opengl模板缓冲区不存在^ _ ^')。

To force SDL2 to use a specific driver, you can use the second parameter in SDL_CreateRenderer. 要强制SDL2使用特定的驱动程序,可以在SDL_CreateRenderer中使用第二个参数。

Problem solved :D 解决的问题:D

StackOverflow, the biggest rubber duck available... ^-^' StackOverflow,最大的橡皮鸭... ^-^'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM