(shaderType, shaderFile)
| 13 | # Function that creates and compiles shaders according to the given type (a GL enum value) and |
| 14 | # shader program (a file containing a GLSL program). |
| 15 | def loadShader(shaderType, shaderFile): |
| 16 | # check if file exists, get full path name |
| 17 | strFilename = findFileOrThrow(shaderFile) |
| 18 | shaderData = None |
| 19 | with open(strFilename, 'r') as f: |
| 20 | shaderData = f.read() |
| 21 | |
| 22 | shader = glCreateShader(shaderType) |
| 23 | glShaderSource(shader, shaderData) # note that this is a simpler function call than in C |
| 24 | |
| 25 | # This shader compilation is more explicit than the one used in |
| 26 | # framework.cpp, which relies on a glutil wrapper function. |
| 27 | # This is made explicit here mainly to decrease dependence on pyOpenGL |
| 28 | # utilities and wrappers, which docs caution may change in future versions. |
| 29 | glCompileShader(shader) |
| 30 | |
| 31 | status = glGetShaderiv(shader, GL_COMPILE_STATUS) |
| 32 | if status == GL_FALSE: |
| 33 | # Note that getting the error log is much simpler in Python than in C/C++ |
| 34 | # and does not require explicit handling of the string buffer |
| 35 | strInfoLog = glGetShaderInfoLog(shader) |
| 36 | strShaderType = "" |
| 37 | if shaderType is GL_VERTEX_SHADER: |
| 38 | strShaderType = "vertex" |
| 39 | elif shaderType is GL_GEOMETRY_SHADER: |
| 40 | strShaderType = "geometry" |
| 41 | elif shaderType is GL_FRAGMENT_SHADER: |
| 42 | strShaderType = "fragment" |
| 43 | |
| 44 | print("Compilation failure for " + strShaderType + " shader:\n" + str(strInfoLog)) |
| 45 | |
| 46 | return shader |
| 47 | |
| 48 | |
| 49 | # Function that accepts a list of shaders, compiles them, and returns a handle to the compiled program |
no test coverage detected