glCreateShader returns 0 value?

I have looked at other answers but none seem to fix my problem. I am not sure why but glCreateShader returns 0 on every run. I have read it could be because of context problems but I am checking for EGL_NO_CONTEXT and it returns false. Any idea what could be causing the problem?

System Info: NanoPi M1 Plus with a Mali400 GPU running Linux 3.4.39-h3

Code:

def LoadShader(stype, shaderSrc):
	shader = glCreateShader(stype)
	if(shader == 0):
		print("Error returned 0")
		if(glGetError()!=GL_NO_ERROR):
			print('GLerror')
		return 0
	glShaderSource(shader, shaderSrc)
	glCompileShader(shader)
	print("Shader status: ", glGetShaderiv(shader, GL_COMPILE_STATUS))
	if glGetShaderiv(shader, GL_COMPILE_STATUS) != GL_TRUE:
		raise RuntimeError(glGetShaderInfoLog(shader))
	return shader

display, context, surface = None, None, None

configAttribs =[
	EGL_SURFACE_TYPE, EGL_PBUFFER_BIT,
	EGL_BLUE_SIZE, 8,
	EGL_GREEN_SIZE, 8,
	EGL_RED_SIZE, 8,
	EGL_DEPTH_SIZE, 8,
	EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
	EGL_NONE
]

pbufferAttribs=[
	EGL_WIDTH, 
    1000,
	EGL_HEIGHT, 
    2,
	EGL_NONE
]

contextAttribs=[
	EGL_CONTEXT_CLIENT_VERSION, 2,
	EGL_NONE
]

vertexShaderCode = '''
	attribute vec4 vPosition;
	void main() {
		gl_Position = vPosition;
	}
'''

fragmentShaderCode = {}

fragmentShaderCode[0] = '''
	precision highp float;
	uniform float Aarr[1000];
	uniform float Barr[1000];

	vec4 EncodeRangeV4(float value, float minVal, float maxVal) {
		value        = clamp( (value-minVal) / (maxVal-minVal), 0.0, 1.0 );
		value       *= 0.99999994039;
		vec4 encode  = fract( value * vec4(1.0, 256.0, 65536.0, 16777216.0) );
		return vec4( encode.xyz - encode.yzw / 256.0, encode.w );
	}

	void main() {
		
		int my_index = int(gl_FragCoord[0]);
		float result = Aarr[my_index] + Barr[my_index];

		gl_FragColor = EncodeRangeV4(result, -512.0, 512.0) - (1.0/1300.0);
	}
'''

vertices=(
	-1, -1, 1,
	-1, 1, 1,
	1, 1, 1,
	-1, -1, 1,
	1, 1, 1,
	1, -1, 1)

prog_array = {}

def gpu_init():
	global prog_array, contextAttribs, configAttribs, display, context, surface

	display = eglGetDisplay(EGL_DEFAULT_DISPLAY)
	if(display == EGL_NO_DISPLAY):
		print("Failed to get EGL display! Error: %s", eglGetError())
		exit()

	print("Egl error after display ",eglGetError())

	major,minor = ctypes.c_long(), ctypes.c_long()
	if not eglInitialize( display, major, minor):
		print("Unable to initialize")
		exit()

	print("Egl error after initalize ",eglGetError())

	configAttribs = arrays.GLintArray.asArray(configAttribs)
	num_configs = ctypes.c_long()
	config = (EGLConfig*1)()
	eglChooseConfig(display, configAttribs, config, 1, num_configs)
	print("Egl error after config ",eglGetError())

	eglBindAPI(EGL_OPENGL_ES_API)
	
	pbufferAttribs_list = pbufferAttribs[:]
	pbufferAttribs_list = arrays.GLintArray.asArray(pbufferAttribs_list)
	surface = eglCreatePbufferSurface(display, config[0], pbufferAttribs_list)

	print("Egl error after surface ",eglGetError())

	contextAttribs = arrays.GLintArray.asArray(contextAttribs)
	context = eglCreateContext(display, config[0], EGL_NO_CONTEXT, contextAttribs)
	print("Egl error after context ",eglGetError())

	eglMakeCurrent(display, surface, surface, context)

	print("Egl error after make current ",eglGetError())

	desiredWidth, desiredHeight = pbufferAttribs[1], pbufferAttribs[3]
	glViewport(0, 0, desiredWidth, desiredHeight)
	#viewport = glGetIntegerv(GL_VIEWPORT)

	print("Egl get error",eglGetError())
	if(glGetError()!=GL_NO_ERROR):
		print('GLerror')

	glClearColor(0.0, 0.0, 0.0, 1.0)
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
	if(glGetError()!=GL_NO_ERROR):
		print('GLerror')

	prog_array[0] = glCreateProgram()
	if(glGetError()!=GL_NO_ERROR):
		print('GLerror')
	
	vert = LoadShader(GL_VERTEX_SHADER, vertexShaderCode)
	frag = LoadShader(GL_FRAGMENT_SHADER, fragmentShaderCode[0])

Output: (12288 meaning no error)

Egl error after display 12288

Egl error after initalize 12288

Egl error after config 12288

Egl error after surface 12288

Egl error after context 12288

Egl error after make current 12288

Egl get error 12288

Error returned 0 

Error returned 0
1 Like

There is a lot of chance that your got a syntax error inside you shader.
example 0 rather than 0.0 or some vecx not the right size. and many other ;))

Start with a very simple shader than test it each time you add new line. It is painfull but very efficient spécially at the begining.