glGetShaderiv shows false in compile status

Hi,

I got some trouble when I compile my first GLSL program, the code snippet is shown below


        /* read shader file */
	char* vSource = readShaderSource(vShaderFile);
	char* fSource = readShaderSource(fShaderFile);


	/* created program and shader objects */
	vShader = glCreateShader(GL_VERTEX_SHADER);
	fShader = glCreateShader(GL_FRAGMENT_SHADER);
	program = glCreateProgramObjectARB();

	/* attach shaders to the program object */
	glAttachShader(program, vShader);
	glAttachShader(program, fShader);

	/* read shaders */
	glShaderSource(vShader, 1, &vSource, NULL);
	glShaderSource(fShader, 1, &fSource, NULL);

	/* compile shaders */
	glCompileShader(vShader);
	glCompileShader(fShader);

	glGetShaderiv(vShader, GL_COMPILE_STATUS, &success);
	if (!success)
	{
		GLchar infoLog[MAX_INFO_LOG_SIZE];
		glGetShaderInfoLog(vShader, MAX_INFO_LOG_SIZE, NULL, infoLog);
		fprintf(stderr, "Error in vertex shader compilation!
");
		fprintf(stderr, "Info log: %s
", infoLog);
	}

variable success is 0, and infoLog shows “ERROR: 1 compilation errors. No code generated”, is this problem caused by incompatibility of ATI and GLSL?

BTW, my laptop video card is ATI 1350, version of OpenGL is 2.0

Thanks in advance!

Leo

variable success is 0, and infoLog shows “ERROR: 1 compilation errors. No code generated”, is this problem caused by incompatibility of ATI and GLSL?

Considering the age of your card/driver, this is entirely possible. However, it could be because your shader code is simply not compiling.

Wouldn’t it be better to first compile the vertex shader, then check if it was successful, thenattach to the program object?

You have fprintf(stderr, "Error in vertex shader compilation!
");
which doesn’t make any sense. How do you know the problem is the VS?

You have fprintf(stderr, "Error in vertex shader compilation!
");
which doesn’t make any sense. How do you know the problem is the VS?

Because the compile status is not like glError; it is a part of each shader object’s state. And he’s checking the compile status in the vertex shader object, so he’s getting the compile status for the vertex shader.

here is the vertex shader:


void main(void)
{
	gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
	gl_FrontColor = gl_Color;
}

and it’s the running image below

http://cid-310862c298a827bc.spaces.live.com/default.aspx

anybody knows what’s wrong with this program? thanks

Leo

Ah yes, he has vShader. For some reason I thought it was his program object.

Maybe your vSource string is not null char terminated.

First of all the code style you quote is far from perfect. Instead of duplicating each call for every shader and checking everything in the end a far better practice is to move the common code to a separate function or at least a loop.
Secondly why are you mixing for example glCreateShader with glCreateProgramObjectARB() ?
And lastly just run your program on a decent videocard that in addition to the note that the shader does not compile would give you the actual compilation error.

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