PDA

View Full Version : Create Shader returns 0



advorak
06-16-2015, 09:41 AM
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 wikibooks.org

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 = coord.zw;
}<
text.v.glsl:printlog: Not a shader or a program
^C

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.

advorak
06-16-2015, 09:52 AM
added a check for return on shader. It does return 0, and perror("") prints "Resource temporarily unavailable"

What does that mean?

GClements
06-16-2015, 10:09 AM
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.
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.


How do I check the shader version that is loaded on my system? Maybe I don't have this version to use.
glGetString(GL_VERSION) and glGetString(GL_SHADING_LANGUAGE_VERSION) return the OpenGL and GLSL versions as a string. See glGetString (https://www.opengl.org/sdk/docs/man2/xhtml/glGetString.xml) 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.

GClements
06-16-2015, 10:12 AM
added a check for return on shader. It does return 0, and perror("") prints "Resource temporarily unavailable"

What does that mean?

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.

advorak
06-16-2015, 02:41 PM
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.\n" );
error_val = glGetError();
fprintf( stderr, "glGetError returned %d.\n", error_val );
fprintf( stderr, "%s\n", version_string );
fprintf( stderr, "%s\n", lang_version_string );
return 0;
}

output looks like this



CreateShader returned 0.
glGetError returned 0.
(null)
(null)

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.

GClements
06-16-2015, 02:56 PM
You're calling init_resources() before calling glXMakeCurrent(), i.e. there's no context bound.

Also, you're creating the contexts with sharelist 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.

advorak
06-16-2015, 03:46 PM
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.

advorak
06-16-2015, 04:23 PM
made necessary objects arrays, and it now prints to the first two screens, but not the third.

I will look for an index error

advorak
06-16-2015, 04:41 PM
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.

GClements
06-16-2015, 05:04 PM
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.
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.

advorak
06-17-2015, 07:22 AM
Yes, i do have four screens. one screen for the console on a quadro430 and the rest on a quadro5200.

advorak
06-17-2015, 09:19 AM
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 );

to:


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?

advorak
06-17-2015, 10:42 AM
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