Compile shader glsl

I have bug under compile shader glsl. When i am include compile shader or don’t include then program it is executed equally. In than can be a problem?

Thanks

Probably. When there’s a problem with a shader or shader setup the OpenGL state remains in fixed-functionality pipeline mode which is what it sounds like is happening. You have to check your info log and OpenGL errors to find out what the problem is with your shader:

// Set up OpenGL shading program system.
// Assumes that all required extensions are present.
// Returns: true if the shading system was successfully initialised.
bool InitialiseShadingSystem()
{
	if (GLEW_ARB_shader_objects) {
		// Create vertex and fragment shader.
		GLhandleARB VertShader = glCreateShaderObjectARB(GL_VERTEX_SHADER_ARB);
		GLhandleARB FragShader = glCreateShaderObjectARB(GL_FRAGMENT_SHADER_ARB);
		ProcessGLErrors();

		// Attach shader source strings.
		extern const GLcharARB *vertStr;
		extern const GLcharARB *fragStr;
		glShaderSourceARB(VertShader, 1, &vertStr, NULL);
		glShaderSourceARB(FragShader, 1, &fragStr, NULL);
		ProcessGLErrors();

		// Compile shaders.
		GLint vertCompiled;
		GLint fragCompiled;
		glCompileShaderARB(VertShader);
		ProcessGLErrors();
		glGetObjectParameterivARB(VertShader, GL_OBJECT_COMPILE_STATUS_ARB, &vertCompiled);
		if (!vertCompiled) {	// Compilation of vertex shader failed.
			InfoLog(VertShader);
			return false;
		}
		glCompileShaderARB(FragShader);
		ProcessGLErrors();
		glGetObjectParameterivARB(FragShader, GL_OBJECT_COMPILE_STATUS_ARB, &fragCompiled);
		if (!fragCompiled) {	// Compilation of fragment shader failed.
			InfoLog(FragShader);
			return false;
		}

		// Create shader program object.
		GLhandleARB ShaderProgram = glCreateProgramObjectARB();
		glAttachObjectARB(ShaderProgram, VertShader);
		glAttachObjectARB(ShaderProgram, FragShader);

		// Link shaders to program.
		GLint linked;
		glLinkProgramARB(ShaderProgram);
		ProcessGLErrors();
		glGetObjectParameterivARB(ShaderProgram, GL_OBJECT_LINK_STATUS_ARB, &linked);
		if (!linked) {	// Linking of shader program failed.
			InfoLog(ShaderProgram);
			return false;
		}

		// Put program into current state.
		glUseProgramObjectARB(ShaderProgram);
		return true;	// It worked!
	}
	return false;	// Shader objects not supported by the GPU.
}

My ProcessGLErrors() just calls glGetError() and prints a MessageBox with the result. My InfoLog is like the Orange book one:

// Handle information logs for GLSL function calls.
// Param: obj is a GLhandleARB for a program object or shader object.
// Returns: void.
void InfoLog(GLhandleARB obj)
{
	if (GLEW_ARB_shader_objects) {
		int logLen(0);
		int strLen(0);
		glGetObjectParameterivARB(obj, GL_OBJECT_INFO_LOG_LENGTH_ARB, &logLen);
		if (logLen > 0) {
			GLcharARB *info = new GLcharARB[logLen];
			glGetInfoLogARB(obj, logLen, &strLen, info);
			MessageBox(NULL, info, "INFO", MB_OK | MB_ICONEXCLAMATION);
			delete [] info;
		}
	}
}

Hope that helps.

ffish
Thanks, but problem exists. If in your code delete block:

glCompileShaderARB(VertShader); ProcessGLErrors(); glGetObjectParameterivARB(VertShader, GL_OBJECT_COMPILE_STATUS_ARB, &vertCompiled); if (!vertCompiled) { // Compilation of vertex shader failed. InfoLog(VertShader); return false; } glCompileShaderARB(FragShader); ProcessGLErrors(); glGetObjectParameterivARB(FragShader, GL_OBJECT_COMPILE_STATUS_ARB, &fragCompiled); if (!fragCompiled) { // Compilation of fragment shader failed. InfoLog(FragShader); return false; }

that all work in the same way either as with this block. I possible stupid - Can be so and must be ?

If you use the InitialiseShadingSystem() function that I posted, it should allow creation of any vertex and fragment shader that you like. If you used that (or similar) with your own *vertStr and *fragStr then it should compile and run fine. If there’s a problem, it should report it. Read the extension registry specification for GL_ARB_shader_objects. It tells what each of the shader setup functions should return and possible error messages reported. Check at each stage of the initialisation process until you find where the error is occurring.

Here’s some more helper code:

// Shut down OpenGL shading program system.
// Assumes that all required extensions are present.
// Returns: void.
void ShutDownShadingSystem()
{
	if (GLEW_ARB_shader_objects) {
		// Current state shader program.
		GLhandleARB ShaderProgram(glGetHandleARB(GL_PROGRAM_OBJECT_ARB));
		// Detach shaders attached to the program.
		GLsizei maxCount(10), count(0);
		GLhandleARB *shaders = new GLhandleARB[maxCount];
		glGetAttachedObjectsARB(ShaderProgram, maxCount, &count, shaders);
		for (GLsizei i(0); i < count; ++i) {
			glDetachObjectARB(ShaderProgram, shaders[i]);
		}
		// Delete the shader program.
        glDeleteObjectARB(ShaderProgram);
	}
}

// Handle OpenGL errors.
// Returns: void.
void ProcessGLErrors()
{
	GLenum err(glGetError());
	switch (err) {
		case GL_NO_ERROR:
			break;
		case GL_INVALID_ENUM:
			MessageBox(NULL, "GL_INVALID_ENUM", "ERROR", MB_OK | MB_ICONEXCLAMATION);
			break;
		case GL_INVALID_VALUE:
			MessageBox(NULL, "GL_INVALID_VALUE", "ERROR", MB_OK | MB_ICONEXCLAMATION);
			break;
		case GL_INVALID_OPERATION:
			MessageBox(NULL, "GL_INVALID_OPERATION", "ERROR", MB_OK | MB_ICONEXCLAMATION);
			break;
		case GL_STACK_OVERFLOW:
			MessageBox(NULL, "GL_STACK_OVERFLOW", "ERROR", MB_OK | MB_ICONEXCLAMATION);
			break;
		case GL_STACK_UNDERFLOW:
			MessageBox(NULL, "GL_STACK_UNDERFLOW", "ERROR", MB_OK | MB_ICONEXCLAMATION);
			break;
		case GL_OUT_OF_MEMORY:
			MessageBox(NULL, "GL_OUT_OF_MEMORY", "ERROR", MB_OK | MB_ICONEXCLAMATION);
			break;
		case GL_TABLE_TOO_LARGE:
			MessageBox(NULL, "GL_TABLE_TOO_LARGE", "ERROR", MB_OK | MB_ICONEXCLAMATION);
			break;
		default:
			MessageBox(NULL, "Unknown GL error.", "ERROR", MB_OK | MB_ICONEXCLAMATION);
			break;
	}
}

Just to clarify what I said before, any errors encountered in InitialiseShadingSystem() will result in OpenGL state remaining in fixed functionality mode. So you can delete any part of ISS() and get the same effect - nothing. Only if the whole function executes correctly will the system go into “shader” mode. So check each of the GL_ARB_shader_objects functions’ return values and what GL_ERRORs they set thoroughly to make sure they’re working correctly to isolate the problem. I.e. there are other error handling mechanisms that I haven’t included in my ISS() that you may have to to find your problem.

Thanks.
I’ll Be read documentation. Possible bugs isn’t in my program. Your code to me helps.

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