C ++不能统一工作,所有变量都定义

问题描述 投票:-1回答:2
#include <windows.h>  // for MS Windows
#include <GL/glut.h>  // GLUT, include glu.h and gl.h
#include <vector> 

uniform vec2 lightpos;
uniform vec3 lightColor;
uniform float screenHeight;
uniform vec3 lightAttenuation;
uniform float radius;

uniform sampler2D texture;

void main()
{       
    vec2 pixel=gl_FragCoord.xy;     
    pixel.y=screenHeight-pixel.y;   
    vec2 aux=lightpos-pixel;
    float distance=length(aux);
    float attenuation=1.0/(lightAttenuation.x+lightAttenuation.y*distance+lightAttenuation.z*distance*distance);    
    vec4 color=vec4(attenuation,attenuation,attenuation,1.0)*vec4(lightColor,1.0);  
    gl_FragColor = color;//*texture2D(texture,gl_TexCoord[0].st);
}

错误“统一”未命名类型未在此范围内声明“ vec2”未在此范围内声明“ screenHeight”预期的';'在“辅助”之前未在此范围内声明'aux'

我使用Dev C ++和...

projects parameters

/GL/ header subfiles

如果需要任何其他信息,请不要犹豫。我加了我所知道的。我之前完成过opengl项目。但知道我必须像这样YouTube Video, OpenGL 2D lighting using shaders

c++ c++11 opengl glsl glsles
2个回答
0
投票

这是着色器程序,而不是c ++程序。您必须使用着色器编译器对其进行编译。


0
投票

GLSL看起来像C,实际上不是C。代码必须由其他编译器(例如glslc或由OpenGL编译器提供的驱动程序)进行编译,并作为渲染过程的一部分在GPU上运行。

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