c++ gl_PointSize不影响片段内的点大小

7hiiyaii  于 2022-12-24  发布在  其他
关注(0)|答案(1)|浏览(102)

我想平滑点并使其变大。我尝试过以下方法:

#include <SFML/Graphics.hpp>
#define WIDTH 100
int main() {
    sf::RenderWindow window(sf::VideoMode(WIDTH, WIDTH), "Test");
    sf::Shader shader;
    shader.loadFromMemory(
        "#version 140\n"
        "void main() {\n"
        "gl_PointSize = 10; // Not working\n"
        "gl_Position =  gl_Vertex;\n"
        "}\n",
        "#version 140\n"
        "out vec4 out_Colour;\n"
        "void main(void) {\n"
        "out_Colour = vec4(vec3(1.0), 1.0);\n"
        "}\n"
    );
    sf::VertexArray points(sf::Points, 3);
    points[0].position = sf::Vector2f(0, 0);
    points[1].position = sf::Vector2f(-.1, -.1);
    points[2].position = sf::Vector2f(.1, .1);
    while(window.isOpen()) {
        sf::Event currEvent;
        while(window.pollEvent(currEvent)) {
            switch(currEvent.type) {
                case(sf::Event::Closed): window.close(); break;
            }
        }
        window.clear();
        window.draw(points, &shader);
        window.display();
    }
}

不幸的是,gl_PointSize似乎不起作用:

有什么问题吗?

0g0grzrc

0g0grzrc1#

不幸的是,对于GLSL,GL没有 Package 器来启用这种模式。
您可以添加以下内容:

#include <GL/glew.h>
...
glEnable(GL_PROGRAM_POINT_SIZE)

然后您会得到以下输出:

不要忘记链接库:

g++ main.cpp -lGL -lGLEW -lsfml-graphics -lsfml-window -lsfml-system

相关问题