Create Shader returns 0

I am trying to add some text an OpenGL context. I found an example on the internet that uses GLEW and GLUT. I need to create three different windows, so I cant use these wrappers. I believe I have correctly integrated the code into my program that draws three windows on three different screens. The screens are just filled with a simple green quad. I want to overlay the text. The text rendering code comes from “OpenGL Programming/Modern OpenGL Tutorial Text Rendering 01” on

I will attach the files.

When I run it, it correctly creates the three windows, the prints out the below output:

$ ./helloglx
CODE is >#version 120

attribute vec4 coord;
varying vec2 texpos;

void main(void) {
  gl_Position = vec4(coord.xy, 0, 1);
  texpos =;
text.v.glsl:printlog: Not a shader or a program

How do I check the shader version that is loaded on my system? Maybe I don’t have this version to use.

Thank you for any help you can provide.

added a check for return on shader. It does return 0, and perror("") prints “Resource temporarily unavailable”

What does that mean?

GLUT can create multiple windows. If you need other features not available in GLUT, I’d suggest using GTK, Qt or wxWidgets rather than trying to use Xlib or XCB directly.

glGetString(GL_VERSION) and glGetString(GL_SHADING_LANGUAGE_VERSION) return the OpenGL and GLSL versions as a string. See glGetString for the syntax.

You’ll need OpenGL 2.0 in order to use shaders or even query the GLSL version. Older versions may support the ARB_shader_objects extension, but there are significant differences between that extension and the shader support in OpenGL 2.0.

[QUOTE=advorak;1267931]added a check for return on shader. It does return 0, and perror("") prints “Resource temporarily unavailable”

What does that mean?[/QUOTE]

glCreateShader() returns zero if there is an error. OpenGL functions don’t generally set errno so perror() is of no use. Call glGetError() to retrieve the OpenGL error status.

added the calls to glGetString for GL_VERSION and GL_SHADING_LANGUAGE_VERSION. see code below

	const GLubyte *version_string = glGetString( GL_VERSION );
	const GLubyte *lang_version_string = glGetString( GL_SHADING_LANGUAGE_VERSION );

	if((res = glCreateShader(type)) == 0)
	  fprintf( stderr, "CreateShader returned 0.
" );
	  error_val = glGetError();
	  fprintf( stderr, "glGetError returned %d.
", error_val );
	  fprintf( stderr, "%s
", version_string );
	  fprintf( stderr, "%s
", lang_version_string );
	  return 0;

output looks like this

CreateShader returned 0.
glGetError returned 0.

Got a call into NVIDIA

I am going to try setting the context to the proper window, and call the init routine for each context. I think this could be an issue.

You’re calling init_resources() before calling glXMakeCurrent(), i.e. there’s no context bound.

Also, you’re creating the contexts with [var]sharelist[/var] set to NULL, so the contexts won’t share anything. You’ll have to create any objects (shaders, buffers, textures etc) separately for each context. You’ll also need to store separate values (program, vbo, etc) for each context.

Even if the contexts are made to share data, not all object types can be shared (e.g. VAOs can’t), so you’ll probably need to end up storing some data on a per-context basis. So you’ll probably want some kind of struct to hold data specific to each window.

The plan is to have a single thread, and only one window will be text intensive. I will look into sharelist to share the shader across contexts. Thank you. I will post any results I get.

made necessary objects arrays, and it now prints to the first two screens, but not the third.

I will look for an index error

all right, im stumped. Cant see any errors in the index passed. It is in a loop, so if it works for the first, it should work for the last.

I am including the latest c file

The monitor type on screen 2 and screen 3 are the same. Could that cause glXChooseVisual to assign the same visual to the two displays? that could cause the glXCreateContext to return the same context for the last two screens.

Just guessing at this point.

glXCreateContext() always creates a new context.

Incidentally, do you actually have 4 screens? Because X numbers screens starting at 0, so if you have 3 screens they would be 0, 1, and 2.

Yes, i do have four screens. one screen for the console on a quadro430 and the rest on a quadro5200.

i think the problem is in the DrawBars function. If I do not execute the line:

gluLookAt(0., 0., 10., 0., 0., 0., 0., 1., 0.);

I must change the background quad from:

  glVertex3f( -1.0, -1.0, 0.0 );
  glVertex3f( -1.0,  1.0, 0.0 );
  glVertex3f(  1.0,  1.0, 0.0 );
  glVertex3f(  1.0, -1.0, 0.0 );


  glVertex3f( -1.0, -1.0, -1.0 );
  glVertex3f( -1.0,  1.0, -1.0 );
  glVertex3f(  1.0,  1.0, -1.0 );
  glVertex3f(  1.0, -1.0, -1.0 );

Otherwise there is no background drawn, but the text appears on all three screens.

When I remove the lookat and change the quad vertex values, the background is shown on all the screens. But the text does not appear on the third screen.

The text shader is a 2D shader, I would think it would be drawn on the Z=0 plane in the 3D context.

What am I missing?

figured out that for some reason the text shader was drawing behind the quad on the third screen. I don’t know why the by-product only showed up on the third screen. I simply changed my ortho projection to:

glOrtho(-1., 1., -1., 1., -1.0, 1.0);

and forced the quad to:

  glVertex3f( -1.0, -1.0, -0.1 );
  glVertex3f( -1.0,  1.0, -0.1 );
  glVertex3f(  1.0,  1.0, -0.1 );
  glVertex3f(  1.0, -1.0, -0.1 );

and everything works out.

I will need to keep this in mind as I go forward. Ultimately, I will be putting video into an underlay frame buffer so I can write text and graphics on top of it.

thank you for you help GClements