将OpenGL 3.2 / GLSL 150与OpenFrameworks v0.8.3一起使用
我试图在我的程序中实现着色器。我的程序成功加载了正确的frag和vert文件,但是我得到了这个错误的视觉和错误:
[ error ] ofShader: setupShaderFromSource(): GL_FRAGMENT_SHADER shader failed to compile
[ error ] ofShader: GL_FRAGMENT_SHADER shader reports:
ERROR: 0:39: Use of undeclared identifier 'gl_FragColor'
我读了这篇SO answer,解释说GLSL 300不支持gl_FragColor
,但我(很确定我没有)使用该版本。无论如何,当我使用gl_FragColor
var更改outputColor
时,我的屏幕显示为黑色而没有错误。
为什么我的着色器没有按预期显示?我感觉这是我的.vert文件/对着色器中如何绘制形状或版本化问题的基本误解。
我的简化程序:
·H
#pragma once
#include "ofMain.h" //includes all openGL libs/reqs
#include "GL/glew.h"
#include "ofxGLSLSandbox.h" //addon lib for runtime shader editing capability
class ofApp : public ofBaseApp{
public:
void setup();
void draw();
ofxGLSLSandbox *glslSandbox; //an object from the addon lib
};
的.cpp
#include "ofApp.h"
//--------------------------------------------------------------
void ofApp::setup(){
// create new ofxGLSLSandbox instance
glslSandbox = new ofxGLSLSandbox();
// setup shader width and height
glslSandbox->setResolution(800, 480);
// load fragment shader file
glslSandbox->loadFile("shader"); //shorthand for loading both .frag and .vert as they are both named "shader.frag" and "shader.vert" and placed in the correct dir
}
//--------------------------------------------------------------
void ofApp::draw(){
glslSandbox->draw();
}
.vert (只是为了传递......如果有意义的话)
#version 150
uniform mat4 modelViewProjectionMatrix;
in vec4 position;
void main(){
gl_Position = modelViewProjectionMatrix * position;
}
.frag (有关预期结果,请参阅第3个交互式代码块this page)
#version 150
#ifdef GL_ES
precision mediump float;
#endif
out vec4 outputColor;
uniform vec2 u_resolution;
uniform vec2 u_mouse;
uniform float u_time;
float circle(in vec2 _st, in float _radius){
vec2 dist = _st-vec2(0.5);
return 1.-smoothstep(_radius-(_radius*0.01),
_radius+(_radius*0.01),
dot(dist,dist)*4.0);
}
void main(){
vec2 st = gl_FragCoord.xy/u_resolution.xy;
vec3 color = vec3(circle(st,0.9));
outputColor = vec4( color, 1.0 );
}
答案 0 :(得分:0)
我没有看到统一变量在任何地方设置,这意味着它们采用默认值。这意味着您的矩阵全为零。