def create_shader(self, strings, shader_type):
count = len(strings)
# if we have no source code, ignore this shader
if count < 1:
return
# create the shader handle
shader = glCreateShader(shader_type)
shaderstrings = []
for string in strings:
shaderstrings.append(bytes(string, 'ascii'))
# convert the source strings into a ctypes pointer-to-char array, and
# upload them this is deep, dark, dangerous black magic - don't try
# stuff like this at home!
src = (c_char_p * count)(*shaderstrings)
glShaderSource(shader, count, cast(
pointer(src), POINTER(POINTER(c_char))), None)
# compile the shader
glCompileShader(shader)
temp = c_int(0)
# retrieve the compile status
glGetShaderiv(shader, GL_COMPILE_STATUS, byref(temp))
# if compilation failed, print the log
if not temp:
# retrieve the log length
glGetShaderiv(shader, GL_INFO_LOG_LENGTH, byref(temp))
# create a buffer for the log
buffer = create_string_buffer(temp.value)
# retrieve the log text
glGetShaderInfoLog(shader, temp, None, buffer)
# print the log to the console
print(buffer.value)
else:
# all is well, so attach the shader to the program
glAttachShader(self.handle, shader)
评论列表
文章目录