gpt4 book ai didi

c++ - SDL_GL_SetAttribute 不设置颜色尺寸

转载 作者:行者123 更新时间:2023-11-30 01:27:19 25 4
gpt4 key购买 nike

我正在尝试更改 *SDL_opengl* 中累积缓冲区颜色分量的大小,但 SetAttribute 命令似乎没有执行任何操作。这是我正在使用的代码。
(为了减少代码大小,我在这里只处理红色组件,但在实际代码中,我将所有 4 个组件都传递给颜色和累积缓冲区,效果是一样的)

#include <iostream>
#include <SDL/SDL.h>
#include <SDL/SDL_opengl.h>

int main(int argc, char *argv[])
{
//Initialize all SDL subsystems
if( SDL_Init( SDL_INIT_EVERYTHING ) < 0 )std::cout << "SDL ERROR!";

// Try to Set the BitSize, while checking for errors
int BitSize = 1; //This number never makes a difference!!
int ErrorCode = 0;
ErrorCode += SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 ) // This one WORKS
+ SDL_GL_SetAttribute( SDL_GL_ACCUM_RED_SIZE, BitSize ) // These ones DON'T
+ SDL_GL_SetAttribute( SDL_GL_RED_SIZE, BitSize )
;

if( ErrorCode < 0 )std::cout << "SDL ERROR!";

// Create the Window
int w = 1000, h = 700;
int bpp = 32;

SDL_Surface* Screen = SDL_SetVideoMode( w, h, bpp, SDL_OPENGL |
SDL_NOFRAME |
SDL_DOUBLEBUF );

if( !Screen )std::cout << "SDL ERROR!";


// Check if BitSize's are correct (they are not)
// I'm using glGetInteger, but SDL_GL_GetAttribute yields the same output.
glGetIntegerv( GL_ACCUM_RED_BITS, &BitSize );
std::cout << "AccumBuffer color component size in bits is " << BitSize << "\n";

glGetIntegerv( GL_RED_BITS, &BitSize );
std::cout << "ColorBuffer color component size in bits is " << BitSize << "\n";

ErrorCode = SDL_GL_GetAttribute( SDL_GL_BUFFER_SIZE, &BitSize );
std::cout << "FrameBuffer BitSize is " << BitSize << "\n";

if( ErrorCode < 0 )std::cout << "SDL ERROR!";
if( glGetError() != GL_NO_ERROR )std::cout << "GL ERROR";

return 0;
}

这个编译很好,并且总是打印以下输出:

AccumBuffer color component size in bits is 16
ColorBuffer color component size in bits is 8
FrameBuffer Bit Size is 32

无论我将 BitSize 变量设置为什么。这就像 SDL_GL_SetAttribute( SDL_GL_*_SIZE, int ) 没有任何效果。我可以理解 Color Buffer 组件可能被限制为 8 位,因为我用 32 bpp 初始化了窗口。但是我不应该能够编辑累积缓冲区颜色分辨率吗?

最佳答案

您设置的属性值只是对您期望的最小值的请求,但是给您更大的值是完全有效的。

顺便说一句:除非您拥有专业级 GPU(FireGL、Quadro),否则累积缓冲区可能不是硬件加速的。请改用帧缓冲区对象。

关于c++ - SDL_GL_SetAttribute 不设置颜色尺寸,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9097692/

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