當前位置: 首頁>>代碼示例>>Python>>正文


Python GL.GL_VERTEX_SHADER屬性代碼示例

本文整理匯總了Python中OpenGL.GL.GL_VERTEX_SHADER屬性的典型用法代碼示例。如果您正苦於以下問題:Python GL.GL_VERTEX_SHADER屬性的具體用法?Python GL.GL_VERTEX_SHADER怎麽用?Python GL.GL_VERTEX_SHADER使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在OpenGL.GL的用法示例。


在下文中一共展示了GL.GL_VERTEX_SHADER屬性的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: link

# 需要導入模塊: from OpenGL import GL [as 別名]
# 或者: from OpenGL.GL import GL_VERTEX_SHADER [as 別名]
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 
開發者ID:PRBonn,項目名稱:semantic-kitti-api,代碼行數:23,代碼來源:glow.py

示例2: _init_shaders

# 需要導入模塊: from OpenGL import GL [as 別名]
# 或者: from OpenGL.GL import GL_VERTEX_SHADER [as 別名]
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) 
開發者ID:deepmind,項目名稱:dm_control,代碼行數:22,代碼來源:fullscreen_quad.py

示例3: __init__

# 需要導入模塊: from OpenGL import GL [as 別名]
# 或者: from OpenGL.GL import GL_VERTEX_SHADER [as 別名]
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") 
開發者ID:bitsawer,項目名稱:renpy-shader,代碼行數:13,代碼來源:shaderprogram.py

示例4: __init__

# 需要導入模塊: from OpenGL import GL [as 別名]
# 或者: from OpenGL.GL import GL_VERTEX_SHADER [as 別名]
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() 
開發者ID:TUDelft-CNS-ATM,項目名稱:bluesky,代碼行數:9,代碼來源:glhelpers.py

示例5: init_gl

# 需要導入模塊: from OpenGL import GL [as 別名]
# 或者: from OpenGL.GL import GL_VERTEX_SHADER [as 別名]
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) 
開發者ID:cmbruns,項目名稱:pyopenvr,代碼行數:41,代碼來源:tracked_devices_actor.py


注:本文中的OpenGL.GL.GL_VERTEX_SHADER屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。