PDA

View Full Version : my shader which works with renderMonkey don't work with my opengl prog (resolved)



airseb
06-03-2005, 03:27 AM
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, &amp;cContent, NULL);
free((void*)content);


loadStrings(fileName2) ;
const char *cContent2 = content ;

ofstream oFile2("sortie shader2.txt");
oFile2<<content ;

glShaderSource(fsh, 1, &amp;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);

sqrt[-1]
06-03-2005, 05:41 AM
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)

airseb
06-03-2005, 05:56 AM
(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_L ENGTH,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, &amp;infologLength);

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

airseb
06-03-2005, 12:49 PM
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, &amp;infologLength);

if (infologLength > 0)
{
cout<<"shader "<<infologLength<<endl ;
infoLog = (char *)malloc(infologLength);
glGetInfoLogARB(vsh, infologLength, &amp;charsWritten, infoLog);
ofstream oFile3("infoLogFile.txt");
oFile3<<infoLog ;
free(infoLog);
} i have also noticed that infologLength has a lenght of 1...

airseb
06-03-2005, 02:13 PM
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, &amp;cContent, NULL);
free((void*)content);


loadStrings(fileName2) ;
const char *cContent2 = content ;

ofstream oFile2("sortie shader2.txt");
oFile2<<content ;

glShaderSource(fsh, 1, &amp;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, &amp;status);
cout<<"status "<<dec<<status<<endl ;

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

glGetObjectParameterivARB(vsh, GL_OBJECT_INFO_LOG_LENGTH_ARB, &amp;infologLength);

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

sqrt[-1]
06-03-2005, 03:11 PM
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)

airseb
06-04-2005, 09:10 AM
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)

Ffelagund
06-05-2005, 12:53 AM
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 :) hope this helps.

airseb
06-05-2005, 04:37 AM
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)

airseb
06-05-2005, 09:23 AM
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)

Ffelagund
06-06-2005, 12:17 AM
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

airseb
06-06-2005, 04:19 AM
ok thanks, i'll take a look

airseb
06-06-2005, 05:29 AM
it works with your program, but not with mine, even by changing the quadratic value of the attenuation :-/

airseb
06-06-2005, 05:50 AM
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 (&amp;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 ;
}

airseb
06-06-2005, 06:15 AM
i'm also not using glew.c, just glew.h and .lib
does it change something ?

Ffelagund
06-06-2005, 06:35 AM
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

airseb
06-06-2005, 08:45 AM
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).

airseb
06-06-2005, 12:53 PM
it was an attenuation error, thanks guys !