# “RuntimeError: Validation failure (0)” using shaders

I'm trying to move away from using glVertex() in my game code because it doesn't seem to work well with a large quantity of vertices. At the moment I'm trying to make code that uses Shaders, but when compiling with shaders.compileProgram, it gives me the error shown in the title, with no explanation as to what is wrong.

Code so far:

import OpenGL
from OpenGL.GL import *
from OpenGL.arrays import vbo

import math
import pygame
from pygame.locals import *

#version 120
void main() {
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
}

#version 120
void main() {
gl_FragColor = vec4( 0, 1, 0, 1 );
}



The full error message:

Traceback (most recent call last):
File "PyOpenGl shader test from scratch.py", line 24, in <module>
File "/home/[my name]/.local/lib/python2.7/site-packages/OpenGL    /GL/shaders.py", line 196, in compileProgram
program.check_validate()
File "/home/[my name]/.local/lib/python2.7/site-packages/OpenGL/GL/shaders.py", line 108, in check_validate
glGetProgramInfoLog( self ),
RuntimeError: Validation failure (0):


Is there a line I need to add for it to tell me what is wrong?

• What is the result of the call to glGetProgramInfoLog()? Does anything change if you change the values in the fragment shader to (0.0, 1.0, 0.0, 1.0)? I've sometimes had issues with implicit casts in glsl. – user1118321 Jul 18 '18 at 2:36
• Don't use gl_ModelViewProjectionMatrix if you want to move away from GL1 stuff – Bálint Jul 18 '18 at 2:45
• Usually calling glGetShaderInfoLog(yourShader), glGetProgramInfoLog(yourProgram) or glGetError() solves your problem – Bálint Jul 18 '18 at 2:48
• gl_ModelViewProjectionMatrix is compatible with Glsl 120. There's a bad habit in OpenGL circles of focusing on use of old stuff rather than answering the question. It might have been helpful to say what to use instead. – Maximus Minimus Jul 18 '18 at 3:05
• @MaximusMinimus Thank you for that, for the record I get errors trying to use GLSL 330 in PyOpenGL. (But not C++ OpenGL for some reason?) – C1ff Jul 18 '18 at 16:12

Well, it turns out that I've just completely missed the fact that this tutorial uses a special library specifically for the tutorial. (I hate when a tutorial does this... How am I supposed to do anything without the tutorial module?)

This is the tutorial in question.

It doesn't even appear that the problem was with the shaders, I was just missing functions from an inherited class.

This often happens also if you do not specify the context before compiling the shaders. For example, for QT Widgets (pytqt) you should have your shaders compiled when the gl context is enabled, for example in the initializeGL function. So in the case of using QT you can do something like:

class MyQtWidget(QOpenGLWidget, QWidget):
def __init__(self, directory):
super(MyQtWidget, self).__init__()
...

def initializeGL(self):
"""
Initializes openGL context and scenery
"""

So in here we have this glfw.make_context_current function.