GlProgramStringARB calls GL_INVALID_OPERATION .... or Help with Fragment Programs
I am trying to write a fragment program that will take a texture and lock the texels between two values. That is, if the min value is 0.2 and the maximum value is 0.6, any texel less than 0.2 will become 0, any texel greater than 0.6 will become 1.0, and all values ββin between will be displayed from 0 to 1 , 0.
My glProgramStringARB call is calling GL_INVALID_OPERATION. I can't figure out why this is happening. Please, help.
This is my first attempt at writing a shader, so I'm not really sure what I am doing. Here's my code:
String str =
"!!ARBfp1.0\n"+
"TEMP R0;\n"+
"MOV R0.x, fragment.texcoord[1];\n"+
"ADD R0.w, fragment.texcoord[2].x, -R0.x;\n"+
"TEX R0.xyz, fragment.texcoord[0], texture[0], 2D;\n"+
"RCP R0.w, R0.w;\n"+
"ADD R0.xyz, R0, -fragment.texcoord[1].x;\n"+
"MUL_SAT result.color.xyz, R0, R0.w;\n"+
"END\n";
int count = str.Length;
Gl.glEnable(Gl.GL_FRAGMENT_PROGRAM_ARB);
Gl.glGenProgramsARB(1, out mFragProg);
Gl.glBindProgramARB(Gl.GL_FRAGMENT_PROGRAM_ARB, mFragProg);
Gl.glProgramStringARB(Gl.GL_FRAGMENT_PROGRAM_ARB, Gl.GL_PROGRAM_FORMAT_ASCII_ARB, count, str);
GetGLError("glProgramStringARB");
Gl.glDisable(Gl.GL_FRAGMENT_PROGRAM_ARB);
Then, to use it, I do the following:
Gl.glEnable(Gl.GL_FRAGMENT_PROGRAM_ARB);
Gl.glBindProgramARB(Gl.GL_FRAGMENT_PROGRAM_ARB, mFragProg);
float max = (mMiddle + (mRange / 2.0f))/65535.0f;
float min = (mMiddle - (mRange / 2.0f))/65535.0f;
Gl.glMultiTexCoord1f(Gl.GL_TEXTURE1_ARB, min);
Gl.glMultiTexCoord1f(Gl.GL_TEXTURE2_ARB, max);
GetGLError("Enable Program for Drawing");
/*
* Drawing Code
*/
Gl.glDisable(Gl.GL_FRAGMENT_PROGRAM_ARB);
source to share
I haven't programmed any shaders, but maybe the shader compiler doesn't recognize the newline? did you try to put "\ n \ r"?
EDIT:
Another question you can ask yourself is: What language do you use? Strings in UNICODE, i.e. 16 bits / char? I just noticed that the format you pass to glProgramStringARB () is set to ASCII. If the string is indeed UNICODE, it will cause problems.
For example, JAVA and C # strings are in UNICODE. not ASCII.
First: I don't know much about ARB_fragment_program, so I'm kind of guessing here.
Your best bet would be to get the error string (glGetString (GL_PROGRAM_ERROR_STRING_ARB)) and see what that tells you.
Looking at the shader, you seem to be using the wrong number of components on lines 3 and 7 (and probably some more). For example, I don't think you can assign a 4-component vector (.texcoord [1] chunk) to a scalar field (R0.x).
source to share