嗨,我正在尝试使用 OpenGL / glut 绘制半透明球体;
我认为最简单的事情是发布代码:这就是我目前所拥有的;
glutInit(&argc, argv);
sf::ContextSettings settings;
settings.depthBits = 32;
settings.stencilBits = 0;
settings.antialiasingLevel = 0;
sf::Window window(sf::VideoMode(800, 600), "insert title", sf::Style::Default, settings);
window.setVerticalSyncEnabled(true);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND);
glClearColor(0.0,0.0,0.0,0.0);
bool running = true;
while(running)
{
sf::Event e;
while(window.pollEvent(e))
{
if(e.type == sf::Event::Closed)
{
running = false;
}
if(e.type == sf::Event::Resized)
{
glViewport(0, 0, e.size.width, e.size.height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0, (double)e.size.width / (double)e.size.height, 0.1, 2000.0);
gluLookAt(0,0,0, 1,0,0, 0,1,0);
glMatrixMode(GL_MODELVIEW);
}
}
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
glColor4d(1.0, 0.0, 0.0, 0.5);
glutWireSphere(0.5, 4, 4);
window.display();
}
在 optirun 和没有 optirun 的情况下运行这个东西......虽然没有透明度!
我在某处读到上下文必须有一个 alpha 缓冲区...... SFML 支持这个吗?