c++ sfml无法链接着色器[已关闭]

4zcjmb1e  于 2023-04-13  发布在  其他
关注(0)|答案(1)|浏览(96)

已关闭,此问题需要更focused,目前不接受回答。
**要改进此问题吗?**更新问题,使其仅关注editing this post的一个问题。

昨天关门了。
Improve this question
当我测试gl着色器时,它不工作。
我试过只加载碎片着色器,在着色器中使用其他代码,但我的经验不允许我这样做
C++代码

#include <SFML/Graphics.hpp>
#define uint unsigned int

uint WIDTH = 1280;
uint HEIGHT = 720;

int main()
{
    sf::RenderWindow window(sf::VideoMode(WIDTH, HEIGHT), "no");
    window.setFramerateLimit(60);

    sf::RenderTexture screenTexture;
    screenTexture.create(WIDTH, HEIGHT);

    sf::Sprite screenSprite(screenTexture.getTexture());

    sf::Shader shader;
    shader.loadFromFile("shaders/shader.vert", "shaders/shader.frag");

    while (window.isOpen())
    {
        sf::Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
                window.close();
            else if (event.type == sf::Event::KeyPressed)
            {
            }
        }

        window.clear();
        window.draw(screenSprite, &shader);
        window.display();
    }

    return 0;
}

shader.frag

#version 330

in vec4 a_color;
in vec2 a_texCoord;
out vec4 f_color;

uniform sampler2D u_texture0;

void main() {
    f_color = a_color * texture(u_texture0,a_texCoord);
}

shader.vert

#version 330 

layout (location = 0) in vec3 v_position;
layout (location = 1) in vec2 v_texCoord;

out vec4 a_color;
out vec2 a_texCoord;

void main(){
    a_color = vec4(1.0f,1.0f,1.0f,1.0f);
    a_texCoord = v_texCoord;
    gl_Position = vec4(v_position, 1.0);
}

错误信息

Failed to link shader:
ERROR: Linking vertex stage: Missing entry point: Each stage requires one entry point
ERROR: Linking fragment stage: Missing entry point: Each stage requires one entry point

我想测试着色器,但它不工作

xhv8bpkk

xhv8bpkk1#

确保shader.vertshader.frag是正确的ASCII(或BOM-少UTF-8)文件,而不是像UTF-16/UCS-2那样每隔一个字节出现一个NUL的奇怪文件。

相关问题