本文整理汇总了Python中OpenGL.GL.shaders.compileProgram方法的典型用法代码示例。如果您正苦于以下问题:Python shaders.compileProgram方法的具体用法?Python shaders.compileProgram怎么用?Python shaders.compileProgram使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OpenGL.GL.shaders
的用法示例。
在下文中一共展示了shaders.compileProgram方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _init_shaders
# 需要导入模块: from OpenGL.GL import shaders [as 别名]
# 或者: from OpenGL.GL.shaders import compileProgram [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)
示例2: program
# 需要导入模块: from OpenGL.GL import shaders [as 别名]
# 或者: from OpenGL.GL.shaders import compileProgram [as 别名]
def program(self):
if self.prog is None:
try:
compiled = [s.shader() for s in self.shaders] ## compile all shaders
self.prog = shaders.compileProgram(*compiled) ## compile program
except:
self.prog = -1
raise
return self.prog
示例3: _load_shaders
# 需要导入模块: from OpenGL.GL import shaders [as 别名]
# 或者: from OpenGL.GL.shaders import compileProgram [as 别名]
def _load_shaders(self, vertex_shader, fragment_shader):
"""Load and compile shaders from strings.
"""
shader = shaders.compileProgram(
shaders.compileShader(vertex_shader, GL_VERTEX_SHADER),
shaders.compileShader(fragment_shader, GL_FRAGMENT_SHADER)
)
return shader
示例4: _add_to_context
# 需要导入模块: from OpenGL.GL import shaders [as 别名]
# 或者: from OpenGL.GL.shaders import compileProgram [as 别名]
def _add_to_context(self):
if self._program_id is not None:
raise ValueError('Shader program already in context')
shader_ids = []
# Load vert shader
shader_ids.append(gl_shader_utils.compileShader(
self._load(self.vertex_shader), GL_VERTEX_SHADER)
)
# Load frag shader
shader_ids.append(gl_shader_utils.compileShader(
self._load(self.fragment_shader), GL_FRAGMENT_SHADER)
)
# Load geometry shader
if self.geometry_shader is not None:
shader_ids.append(gl_shader_utils.compileShader(
self._load(self.geometry_shader), GL_GEOMETRY_SHADER)
)
# Bind empty VAO PYOPENGL BUG
if self._vao_id is None:
self._vao_id = glGenVertexArrays(1)
glBindVertexArray(self._vao_id)
# Compile program
self._program_id = gl_shader_utils.compileProgram(*shader_ids)
# Unbind empty VAO PYOPENGL BUG
glBindVertexArray(0)
示例5: init_gl
# 需要导入模块: from OpenGL.GL import shaders [as 别名]
# 或者: from OpenGL.GL.shaders import compileProgram [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)
示例6: compileShaders
# 需要导入模块: from OpenGL.GL import shaders [as 别名]
# 或者: from OpenGL.GL.shaders import compileProgram [as 别名]
def compileShaders(self):
try:
vertex_shader = shaders.compileShader("""
#extension GL_OES_standard_derivatives : enable
uniform vec4 uColor;
uniform float uTransparency;
varying vec3 N;
varying vec3 v;
varying vec3 vBC;
void main(void)
{
v = vec3(gl_ModelViewMatrix * gl_Vertex);
N = normalize(gl_NormalMatrix * gl_Normal);
vBC = gl_Color.xyz;
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
}
""", GL_VERTEX_SHADER)
fragment_shader = shaders.compileShader("""
uniform vec4 uColor;
uniform float uTransparency;
varying vec3 N;
varying vec3 v;
varying vec3 vBC;
float edgeFactor(){
vec3 d = fwidth(vBC);
vec3 a3 = smoothstep(vec3(0.0), d, vBC);
return min(min(a3.x, a3.y), a3.z);
}
void main(void)
{
vec3 L = normalize(gl_LightSource[0].position.xyz - v);
vec4 Idiff = gl_FrontLightProduct[0].diffuse * max(dot(N,L), 0.)*uColor;
Idiff = clamp(Idiff, 0.0, 1.0);
if (Idiff==vec4(0.))
{
Idiff = (uTransparency > 0. ? gl_FrontLightProduct[0].diffuse : vec4(1., 0., 0., 0.))
* max(dot(-N,L), 0.);
//Idiff = vec4(1., 0., 0., 0.);
Idiff = clamp(Idiff, 0.0, 1.0);
}
gl_FragColor.rgb = mix(vec3(0.0), Idiff.xyz, edgeFactor());
gl_FragColor.a = 1. - uTransparency;
}
""", GL_FRAGMENT_SHADER)
self.shaders = shaders.compileProgram(vertex_shader, fragment_shader)
self.shaders_color_location = glGetUniformLocation(self.shaders, 'uColor')
self.shaders_transp_location = glGetUniformLocation(self.shaders, 'uTransparency')
return True
except WindowsError as e:
return False
示例7: init_gl
# 需要导入模块: from OpenGL.GL import shaders [as 别名]
# 或者: from OpenGL.GL.shaders import compileProgram [as 别名]
def init_gl(self):
vertex_shader = compileShader(dedent(
"""
#version 450 core
#line 563
layout(location = 0) uniform mat4 Projection = mat4(1);
layout(location = 4) uniform mat4 ModelView = mat4(1);
const vec3 FLOOR_QUAD[4] = vec3[4](
vec3(-1, 0, -1),
vec3(-1, 0, +1),
vec3(+1, 0, +1),
vec3(+1, 0, -1)
);
const int FLOOR_INDICES[6] = int[6](
2, 1, 0,
0, 3, 2
);
out vec2 texCoord;
void main() {
int vertexIndex = FLOOR_INDICES[gl_VertexID];
vec3 v = FLOOR_QUAD[vertexIndex];
const float scale = 50; // meters per side
texCoord = scale * v.xz;
gl_Position = Projection * ModelView * vec4(scale * v, 1);
}
"""
), GL_VERTEX_SHADER)
fragment_shader = compileShader(dedent(
"""\
#version 450 core
#line 594
in vec2 texCoord; // Floor texture coordinate in meters
out vec4 FragColor;
float filtered_noise(in vec2 texCoord, in float detail);
void main()
{
// shift texture coordinate so origin artifact is probably far away,
// and shift intensity from range [-1,1] to range [0,1]
float noise = 0.50 * (filtered_noise(texCoord * 2 + vec2(10, 10), 8) + 1.0);
// interpolate final color between brown and green
const vec3 color1 = vec3(0.25, 0.3, 0.15); // green
const vec3 color2 = vec3(0.05, 0.05, 0.0); // dark brown
vec3 color = mix(color2, color1, noise);
FragColor = vec4(color, 1.0);
}
"""),
GL_FRAGMENT_SHADER)
self.shader = compileProgram(vertex_shader, fragment_shader, ProceduralNoiseShader().fragment_shader)
#
self.vao = glGenVertexArrays(1)
glBindVertexArray(self.vao)
glEnable(GL_DEPTH_TEST)