【问题标题】:C++ doesn't work uniform and all variable defines [closed]C ++不能统一工作,所有变量都定义了[关闭]
【发布时间】:2020-05-11 16:42:59
【问题描述】:
#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);
}

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

等等

我使用 Dev C++ 和 ...

projects parameters

/GL/ header subfiles

如果需要任何其他信息,请随时写下。我添加了我所知道的。我之前做过opengl项目。但是知道我必须像这样YouTube Video, OpenGL 2D lighting using shaders

【问题讨论】:

标签: c++ c++11 opengl glsl glsles


【解决方案1】:

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

【讨论】:

  • 我想这样应用光照强度,Dev C++ 编译器错误吗?
  • @caginagirdemir:GLSL 不是 C;您不会像编写 C 代码那样使用 C 编译器编译它。
【解决方案2】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-18
    • 1970-01-01
    • 2021-11-19
    • 2021-12-11
    • 1970-01-01
    相关资源
    最近更新 更多