OpenGL无法识别#version指令

时间:2014-05-23 16:20:49

标签: opengl glsl shader vertex-shader

我的GLSL版本出现问题,运行我的程序时收到警告:

  

警告:0:29:只有GLSL版本> 110允许后缀“F”或“f”   浮

这对我来说很奇怪,因为我的两个着色器都指定了#version 330 core,例如我的vertex.vert

#version 330 core

// Input vertex data, different for all executions of this shader.
layout(location = 0) in vec3 squareVertices;
layout(location = 1) in vec4 xyzs; // Position of the center of the particule and size of the square
layout(location = 2) in vec4 color; // Position of the center of the particule and size of the square

// Output data ; will be interpolated for each fragment.
out vec2 UV;
out vec4 particlecolor;

// Values that stay constant for the whole mesh.
uniform vec3 CameraRight_worldspace;
uniform vec3 CameraUp_worldspace;
uniform mat4 VP; // Model-View-Projection matrix, but without the Model (the position is in BillboardPos; the orientation depends on the camera)

void main()
{
    float particleSize = xyzs.w; // because we encoded it this way.
    vec3 particleCenter_wordspace = xyzs.xyz;

    vec3 vertexPosition_worldspace = 
        particleCenter_wordspace
        + CameraRight_worldspace * squareVertices.x * particleSize
        + CameraUp_worldspace * squareVertices.y * particleSize;

    // Output position of the vertex
    gl_Position = VP * vec4(vertexPosition_worldspace, 1.0f);

    // UV of the vertex. No special space for this one.
    UV = squareVertices.xy + vec2(0.5, 0.5);
    particlecolor = color;
}

在SFML中创建窗口

sf::Window window(sf::VideoMode(800,600),   //declare window
        "Particle Simulation"                   //window title
        );                                      //default context settings

我的着色器有问题吗?或者我在如何阅读着色器时会出现问题?

2 个答案:

答案 0 :(得分:3)

检查是否使用正确的版本初始化了实际的OpenGL上下文。如果您使用旧版本初始化上下文,那么着色器所支持的内容并不重要。

答案 1 :(得分:2)

创建上下文时需要指定GL上下文版本。

如果是SFML,它将如下所示:

sf::Window window(sf::VideoMode(800, 600), "OpenGL", 
    sf::Style::Default, sf::ContextSettings(32, 8, 0, 3, 3));

Documentation

如果没有指定其他内容,SFML默认为2.0上下文。