sfml 无法链接着色器

问题描述 投票:0回答:1

当我测试 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

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

c++ opengl glsl sfml
1个回答
0
投票

确保

shader.vert
shader.frag
是正确的 ASCII(或 BOM-less UTF-8)文件,而不是像 UTF-16/UCS-2 那样奇怪的东西,其中
NUL
每隔一个字节出现一次。

© www.soinside.com 2019 - 2024. All rights reserved.