Sign in to follow this  
cignox1

glUseProgramObjectARB fails and I don't know why

Recommended Posts

cignox1    735
Hi, I've just entered (a couple of hours ago) the wonderful world of shaders. I use the following code to create a shader:
    //Create the shader
    GLhandleARB arb = glCreateShaderObjectARB(GL_VERTEX_SHADER_ARB);

    //Assign the code
    char* source[255];
    int l = LoadShader("shader.vert", source);
    if(!l) return 0;

    glShaderSourceARB(arb, l, (const char**)source, NULL);

    //Compile the source
    glCompileShaderARB(arb);

    //Create a program (container of shaders)
    GLhandleARB prg = glCreateProgramObjectARB();

    //Attach the shader to the program
    glAttachObjectARB(prg, arb);

    //Link the program
    glLinkProgramARB(prg);

    delete[] source;

    return prg;

As far as I know, none of the functions fail (glGetError() always returns GL_NO_ERROR But then I try to activate the shader, and I get a GL_INVALID_OPERATION error. If I try with glValidateProgramARB() and then ask for the GL_OBJECT_VALIDATE_STATUS_ARB state var I get GL_TRUE, and I don't use glBegin() and glEnd() functions. I create the shader just after loading the geometry and just before the start of the main loop of the app (SDL). Any Idea? Thank you

Share this post


Link to post
Share on other sites
MARS_999    1627
Well from what it looks like your code posted looks ok. You might want to take a look at your text file and make sure that the file is terminated correctly with a EOF or NULL char if I remember right and not a bunch of extra characters... Off the top of my head this is what comes to mind...

Share this post


Link to post
Share on other sites
cignox1    735
Thank you, but the error is still there. By the way, this is the shader code:

void main()
{
// Transforming The Vertex
gl_Color = vect4(1.0, 0.0,0.0,1.0);//gl_ModelViewProjectionMatrix * gl_Vertex;
}



Following the reference at 3dlabs site, glUseProgramObjectARB() returns GL_INVALID_OPERATION in the following cases:
Quote:

GL_INVALID_OPERATION is generated if program is not of type GL_PROGRAM_OBJECT_ARB.

GL_INVALID_OPERATION is generated if program could not be made part of current state.

GL_INVALID_OPERATION is generated if glUseProgramObjectARB is executed between the execution of glBegin and the corresponding execution of glEnd.

Ok, what is exactly the first case? I created the program with the posted code, without errors, so I think it is the right type.
I don't know what the second case means.
The third case doesn't apply, since I don't use glBegin() and glEnd() and I'm building the shader at initialization stage.

I load, compile and link the shader without problems. Then I think that only the second case can be the reason, but what does it mean?

Share this post


Link to post
Share on other sites
rick_appleton    864
You mentioned that you check for glErrors, but if I recall correctly, failed linking or similar doesn't return on glError, but on a different function (glGetInfoLogARB). Check that to see if compilation/linking is succesful.

Also, if the code you posted is your vertex shader, then it's invalid. You need to output to gl_Position at the very least (so the GPU can calculate the screenspace coordinate for the vertices).

Share this post


Link to post
Share on other sites
MARS_999    1627
Rick is right. If that is your vertex code its wrong. Also you have this


void main()
{
// Transforming The Vertex
gl_Color = vect4(1.0, 0.0,0.0,1.0);//gl_ModelViewProjectionMatrix * gl_Vertex;
}



No such thing as vect4... vec4 is correct.

Your vertex function at least should look like this


//VS
void main()
{
gl_Position = ftransform();
}

//FS
void main()
{
gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
}


Share this post


Link to post
Share on other sites
cignox1    735
Thank you both: it was a combination of wrong source syntax (lack of final \n) and wrong code (vect4 instead vec4 and so on). Now it works, nothing really interesting, but it works :-)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this