Python OpenGL.GL.GL_FRAGMENT_SHADER Examples

The following are 6 code examples of OpenGL.GL.GL_FRAGMENT_SHADER(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module OpenGL.GL , or try the search function .
Example #1
Source File: glow.py    From semantic-kitti-api with MIT License 6 votes vote down vote up
def link(self):
    if gl.GL_VERTEX_SHADER not in self.shaders_ or gl.GL_FRAGMENT_SHADER not in self.shaders_:
      raise RuntimeError("program needs at least vertex and fragment shader")

    for shader in self.shaders_.values():
      gl.glAttachShader(self.id_, shader.id)
      for line in shader.code.split("\n"):
        match = re.search(r"uniform\s+(\S+)\s+(\S+)\s*;", line)
        if match:
          self.uniform_types_[match.group(2)] = match.group(1)

    gl.glLinkProgram(self.id_)
    isLinked = bool(gl.glGetProgramiv(self.id_, gl.GL_LINK_STATUS))
    if not isLinked:
      msg = gl.glGetProgramInfoLog(self.id_)

      raise RuntimeError(str(msg.decode("utf-8")))

    # after linking we don't need the source code anymore.
    self.shaders_ = {}
    self.is_linked = True 
Example #2
Source File: fullscreen_quad.py    From dm_control with Apache License 2.0 6 votes vote down vote up
def _init_shaders(self):
    """Initializes the shaders used to render the textures fullscreen quad."""
    vs = shaders.compileShader(_VERTEX_SHADER, GL.GL_VERTEX_SHADER)
    fs = shaders.compileShader(_FRAGMENT_SHADER, GL.GL_FRAGMENT_SHADER)
    self._shader = shaders.compileProgram(vs, fs)

    stride = _FLOATS_PER_VERTEX * _SIZE_OF_FLOAT
    var_position = GL.glGetAttribLocation(self._shader, _VAR_POSITION)
    GL.glVertexAttribPointer(
        var_position, 2, GL.GL_FLOAT, GL.GL_FALSE, stride, None)
    GL.glEnableVertexAttribArray(var_position)

    var_uv = GL.glGetAttribLocation(self._shader, _VAR_UV)
    uv_offset = ctypes.c_void_p(_FLOATS_PER_XY * _SIZE_OF_FLOAT)
    GL.glVertexAttribPointer(
        var_uv, 2, GL.GL_FLOAT, GL.GL_FALSE, stride, uv_offset)
    GL.glEnableVertexAttribArray(var_uv)

    self._var_texture_sampler = GL.glGetUniformLocation(
        self._shader, _VAR_TEXTURE_SAMPLER) 
Example #3
Source File: shaderprogram.py    From renpy-shader with MIT License 5 votes vote down vote up
def __init__(self, vsCode, psCode):
        self.handle = gl.glCreateProgram()
        self.linked = False

        self.createShader(vsCode, gl.GL_VERTEX_SHADER)
        self.createShader(psCode, gl.GL_FRAGMENT_SHADER)

        self.link()

        if not self.linked:
            raise RuntimeError("Shader not linked") 
Example #4
Source File: glhelpers.py    From bluesky with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, vertex_shader, fragment_shader, geom_shader=None):
        self.shaders = []
        self.compile_shader(vertex_shader, gl.GL_VERTEX_SHADER)
        self.compile_shader(fragment_shader, gl.GL_FRAGMENT_SHADER)
        if geom_shader is not None:
            self.compile_shader(geom_shader, gl.GL_GEOMETRY_SHADER)
        self.link() 
Example #5
Source File: glhelpers.py    From bluesky with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, vertex_shader, fragment_shader, geom_shader=None):
        self.shaders = []
        self.compile_shader(vertex_shader, gl.GL_VERTEX_SHADER)
        self.compile_shader(fragment_shader, gl.GL_FRAGMENT_SHADER)
        if geom_shader is not None:
            self.compile_shader(geom_shader, gl.GL_GEOMETRY_SHADER)
        self.link() 
Example #6
Source File: tracked_devices_actor.py    From pyopenvr with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def init_gl(self):
        vertex_shader = compileShader(
            shader_string("""
            layout(location = 0) in vec3 in_Position;
            layout(location = 1) in vec3 in_Normal;
            layout(location = 2) in vec2 in_TexCoord;
            
            layout(location = 0) uniform mat4 projection = mat4(1);
            layout(location = 4) uniform mat4 model_view = mat4(1);
            layout(location = 8) uniform mat4 normal_matrix = mat4(1);
            
            out vec3 color;
            out vec2 fragTexCoord;
            
            void main() {
              gl_Position = projection * model_view * vec4(in_Position, 1.0);
              vec3 normal = normalize((normal_matrix * vec4(in_Normal, 0)).xyz);
              color = (normal + vec3(1,1,1)) * 0.5; // color by normal
              fragTexCoord = in_TexCoord;
              // color = vec3(in_TexCoord, 0.5); // color by texture coordinate
            }
            """),
            GL.GL_VERTEX_SHADER)
        fragment_shader = compileShader(
            shader_string("""
            uniform sampler2D diffuse;
            in vec3 color;
            in vec2 fragTexCoord;
            out vec4 fragColor;
            
            void main() {
              // fragColor = vec4(color, 1.0);
              fragColor = texture(diffuse, fragTexCoord);
            }
            """),
            GL.GL_FRAGMENT_SHADER)
        self.shader = compileProgram(vertex_shader, fragment_shader)
        self._check_devices()
        GL.glEnable(GL.GL_DEPTH_TEST)