My shader which works with renderMonkey don't work with my opengl prog (resolved)

EDIT :my info log say this :
Link successful. The GLSL vertex shader will run in hardware. The GLSL fragment shader will run in hardware.

and i have tried with another shader(toon shading) and it works, the problem is for the other shader (per pixel lighting): i have no lighting… even not gouraud.
so i suppose (can it be something else ?) that some variable which are in my shader are not in the opengl program.
i use in my shader “gl_LightSource[0].halfVector”. HalfVector is not present in my opengl program, is it generated by opengl or have i to do something ?if yes what ? in the shader or in the opengl program ?

I haven’t the possibility of letting a link to my program, so i put the code of the lighting part of my opengl program and the shader code (per pixel lighting):(see last post for copy of that message + code)


first original message:
Hi,
I have made a shader which works with renderMonkey, but when i add this shader to my opengl program the model appears in black.
I have used glIntercept and i have these errors :
GL ERROR - Function glAttachShader generated error GL_INVALID_VALUE
GL ERROR - Function glAttachShader generated error GL_INVALID_VALUE
GL ERROR - Function glLinkProgram generated error GL_INVALID_VALUE
GL ERROR - Function glUseProgram generated error GL_INVALID_VALUE

 loadShader::loadShader(char *fileName1, char *fileName2)
{
	
	unsigned int vsh = glCreateShader(GL_VERTEX_SHADER);
	unsigned int fsh = glCreateShader(GL_FRAGMENT_SHADER);
	
	loadStrings(fileName1) ;
	const char *cContent = content ;
	
	ofstream oFile1("sortie shader1.txt");
	oFile1<<content ;
	
	glShaderSource(vsh, 1, &cContent, NULL);
	free((void*)content);


	loadStrings(fileName2) ;
	const char *cContent2 = content ;
	
	ofstream oFile2("sortie shader2.txt");
	oFile2<<content ;
	
	glShaderSource(fsh, 1, &cContent2, NULL);
	free((void*)content);

	glCompileShader(vsh);
	glCompileShader(fsh);

	unsigned short int ph = glCreateProgram();//program handler
	glAttachShader(ph, vsh);
	glAttachShader(ph, fsh);

	glLinkProgram(ph);
	glUseProgram(ph);
	 

Try enabling the “ExtendedErrorLog” option in GLIntercept.

I’m will to bet the “unsigned short int ph” might be causing some problems…(try GLuint ph)

(Esp if you are on ATI as they seem to use very large program handle numbers which would be clamped)

(i have an ATI 9600 SE)
i have changed all unsigned int by GLuint
and now i have this (with ExtendedErrorLog enabled) :

GL ERROR - Function glGetObjectParameterivARB(3435973836,GL_INFO_LOG_LENGTH,0x12fda4) generated error GL_INVALID_VALUE
GLDriver - Shutdown - Current OpenGL context 0x10000?
GLDriver - Shutdown - Outstanding OpenGL context 0x10000 ?

Log End.
do you know what it means ?
the first error comes from that code :

 GLhandleARB obj ;
	glGetObjectParameterivARB(obj, GL_OBJECT_INFO_LOG_LENGTH_ARB, &infologLength);
	
	    if (infologLength > 0)
	    {
			cout<<"shader "<<endl ;
		infoLog = (char *)malloc(infologLength);
		glGetInfoLogARB(obj, infologLength, &charsWritten, infoLog);
		ofstream oFile3("infoLogFile.txt");
		oFile3<<infoLog ;
		free(infoLog);
	    } 

GLint status=0 ;
glGetObjectParameterivARB(fsh, GL_OBJECT_LINK_STATUS_ARB, &status);
cout<<"status "<<dec<<status<<endl ;

this gives me the status equal to 0, so there is a link problem, but can i do ?

EDIT : i would like to make a log info file but this code gives me an empty file :

 
        int infologLength = 0;
	int charsWritten  = 0;
	char *infoLog;

	glGetObjectParameterivARB(vsh, GL_OBJECT_INFO_LOG_LENGTH_ARB, &infologLength);
	
	    if (infologLength > 0)
	    {
			cout<<"shader "<<infologLength<<endl ;
			infoLog = (char *)malloc(infologLength);
			glGetInfoLogARB(vsh, infologLength, &charsWritten, infoLog);
			ofstream oFile3("infoLogFile.txt");
			oFile3<<infoLog ;
			free(infoLog);
	    } 

i have also noticed that infologLength has a lenght of 1…

have used gl intercept and it gives me that :
GL ERROR - Function glUseProgram(2147483649) generated error GL_INVALID_OPERATION
GL ERROR - Function glGetObjectParameterivARB(536870913,GL_LINK_STATUS,0x12fda4) generated error GL_INVALID_ENUM
GLDriver - Shutdown - Current OpenGL context 0x10000?
GLDriver - Shutdown - Outstanding OpenGL context 0x10000 ?

Log End.

i don’t understand what’s wrong with my code… (i reput it here)

 loadShader::loadShader(char *fileName1, char *fileName2)
{
	
	GLuint vsh = glCreateShader(GL_VERTEX_SHADER);
	GLuint fsh = glCreateShader(GL_FRAGMENT_SHADER);
	
	loadStrings(fileName1) ;
	const char *cContent = content ;
	
	ofstream oFile1("sortie shader1.txt");
	oFile1<<content ;
	
	glShaderSource(vsh, 1, &cContent, NULL);
	free((void*)content);


	loadStrings(fileName2) ;
	const char *cContent2 = content ;
	
	ofstream oFile2("sortie shader2.txt");
	oFile2<<content ;
	
	glShaderSource(fsh, 1, &cContent2, NULL);
	free((void*)content);

	glCompileShader(vsh);
	glCompileShader(fsh);

	GLuint ph = glCreateProgram();//program handler
	glAttachShader(ph, vsh);
	glAttachShader(ph, fsh);

	glLinkProgram(ph);
	glUseProgram(ph);
	
	int status=0 ;
	glGetObjectParameterivARB(fsh, GL_OBJECT_LINK_STATUS_ARB, &status);
	cout<<"status "<<dec<<status<<endl ;

	GLint infologLength = 0;
	GLint charsWritten  = 0;
	GLchar *infoLog;

	glGetObjectParameterivARB(vsh, GL_OBJECT_INFO_LOG_LENGTH_ARB, &infologLength);
	
	    if (infologLength > 0)
	    {
			cout<<"shader "<<infologLength<<endl ;
			infoLog = (char *)malloc(infologLength);
			glGetInfoLogARB(vsh, infologLength, &charsWritten, infoLog);
			ofstream oFile3("infoLogFile.txt");
			oFile3<<infoLog ;
			//free(infoLog);
	    } 

Several issues:
a) Don’t mix core OpenGL 2.0 with the ARB extension. It may work but it is dangerious.

b) You are attempting to get the link status of a fragment program ( GL_OBJECT_LINK_STATUS_ARB). Get the link status of the actual program. (Use “ph”)

c) If you going to check for link status, do it before trying to bind the program. (before glUseProgram) because if it failed, It is invalid to “bind it”.

In practice what you should do is:

  • Compile shaders
  • Check compile status and abort on failure
  • Attach shader(s) to a program
  • Link program
  • Check link status and abort on failure
  • If all OK now bind and use program

If you have future problems, it is usually a good idea to post a link to a running app with source. (to make it easier for people to find your problem)

i have tried another program (which works) to load, compile, link,… and i have the same problem : no lighting

somebody have the answer about questions that i’m asking above ? (about half vector)

I tried your shader in the Shader Designer, and it works perfectly, so your problem could be caused mainly for other reasons than the shader code itself. Try checking this: a) you aren’t settig this program active (or it is invalid), b) your mesh doesn’t have the normals correctly computed (or doesn’t have normals at all) c) check the values of the built-in uniforms that you’re using.
That’s all what I say :slight_smile: hope this helps.

Hi,
i have checked with glutSolidTeapot(10); to see if it comes from the normals, and with glutSolidTeapot() it works well with the toon shading from lighthouse web site, but with my shader which i have put above, there is no lighting :-/ i don’t understand

what did you mean by “you aren’t settig this program active (or it is invalid)” ?

how can i check the values of the built-in uniforms that i am using ?

PS : i have kept the light parameters of my loader with glutSolidTeapot(i can’t know the coordinates of the teapot)

i have tried another shader which perform per pixel lighting and it don’t work too(no lighting).
It seems that there is a problem with lighting (the toon shader that work with my program just change the color and just care about light source position)

I think I’ve found your problem. You are setting “1.0” in the quadratic attenuation. This is a very hight value. Try with 0.001f.
If still does not work, download this application I’ve modified it to test that shader (it is my minimal app that I usually use to send bug reports). In my machine works perfectly, so in yours should.
http://www.typhoonlabs.com/~ffelagund/test.zip

ok thanks, i’ll take a look

it works with your program, but not with mine, even by changing the quadratic value of the attenuation :-/

I’m using glut and glew and i call the lighting parameters before the rest of the opengl code, do you think that it may cause a problem ?
i put the code of the main :

int main(int argc, char *argv[])
{
	myLoader= new loader3ds() ;
	glutInit (&argc, argv) ;
	glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH) ;
	glutInitWindowSize (640, 480) ;
	glutInitWindowPosition (250,250) ;
	glutCreateWindow (argv [0]) ;
	glewInit();

	glEnable( GL_DEPTH_TEST );
	glClearColor(0, 0, 1, 0);
	
	myLoader->lighting() ;
	myLoader->loadTextures() ;
	
	glutReshapeFunc (reshape) ;
	
	glutKeyboardFunc (keyboard) ;
	glutDisplayFunc (display) ;
	
	loadShader *myShaderLoader = new loadShader("vertexShader.vert", "fragmentShader.frag");
	//loadShader *myShaderLoader = new loadShader("toon.vert", "toon.frag");
	
	glutMainLoop () ;
	return 0 ;
}  

i’m also not using glew.c, just glew.h and .lib
does it change something ?

Originally posted by airseb:
i’m also not using glew.c, just glew.h and .lib
does it change something ?

No, it doesn’t change anything. I think that your problem is that you are placing the light position too far away to affect the mesh, looking the attenuation that you are using, Try in your program loading 0 in attenuation factors

i have put 0.0 and the model which wasn’t lighted is lighted strangely, polygons appears in white where it is lighted (it’s nearly like it was flat shading).

it was an attenuation error, thanks guys !

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.