【发布时间】:2016-12-15 20:57:03
【问题描述】:
我正在尝试在片段着色器中使用原子计数器。 基本上我只显示一个纹理四边形,需要对纹理数据进行计算,并显示未改变的纹理。 我从编写一个简单的直通片段着色器开始,但显示的纹理是纯色的。要么我遗漏了一些东西,我不确定是否也使用顶点着色器,因为我只处理纹理,对我来说似乎已经过时了。
片段着色器代码:
#version 420
uniform vec2 texture_coordinate; uniform sampler2D my_color_texture;
void main() {
gl_FragColor = texture2D(my_color_texture, texture_coordinate);
}
渲染管道 - 使用 shaprGL,但易于阅读:
gl.Enable(OpenGL.GL_TEXTURE_2D);
String s = "my_color_texture"; //name of the texture variable in shader
gl.UseProgram(graycounter); // graycounter is a compiled/linked shader
GLint my_sampler_uniform_location = gl.GetUniformLocation(graycounter, s);
gl.ActiveTexture(OpenGL.GL_TEXTURE0);
gl.BindTexture(OpenGL.GL_TEXTURE_2D, ((dTexture)texture).texture); //texture id, working without shader on
gl.Uniform1ARB(my_sampler_uniform_location, 0);
gl.Begin(OpenGL.GL_QUADS); // show the rectangle
gl.Color(1.0f, 1.0f, 1.0f);
gl.TexCoord(0.0f, 0.0f); gl.Vertex(0.0f, 0.0f, 0.0f); // Bottom Left Of The Texture and Quad
gl.TexCoord(1.0f, 0.0f); gl.Vertex(w, 0.0f, 0.0f); // Bottom Right Of The Texture and Quad
gl.TexCoord(1.0f, 1.0f); gl.Vertex(w, h, 0.0f); // Top Right Of The Texture and Quad
gl.TexCoord(0.0f, 1.0f); gl.Vertex(0.0f, h, 0.0f); // Top Left Of The Texture and Quad
gl.End();
gl.UseProgram(0);
【问题讨论】:
标签: opengl glsl shader fragment-shader