PDA

View Full Version : writing a shader error checker in C



sandbucket
10-04-2013, 03:47 PM
hi im writing a simple shader error checker in C to check for errors on compilation and link time. im having a big problem with getting the glShaderSource() function to work. i first create space for the code using malloc(codelength * sizeof(char)) then i attach the source to a created shader object with this line glShaderSource(shader, 1, (const char **) &code, NULL);. i belive the problem is with this line. ive even tried changing NULL to the length of the code but to no avail. when i try to get info on the shader it returns zero to glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &compileloglength); and zero to glGetShaderiv(shaders[0], GL_COMPILE_STATUS, &compileloglength); please donbe t point me to a shader error checker that is already out there, unless it has relevant code because i like doing little projects like these. any help would be great. thanks :)

tonyo_au
10-04-2013, 08:14 PM
bool CompileShaderFromMemory(GLuint p_ID, const char* p_ShaderString)
{
glShaderSource( p_ID, 1, (const char **)&p_ShaderString, 0 );
// Compile the shader, and check if there were compilation errors
glCompileShader( p_ID );

GLint compiled = 0;
glGetShaderiv( p_ID, GL_COMPILE_STATUS, &compiled);
// If there were compile errors, we might want to print them out.
if (!compiled)
{
GLint l,l1;
glGetShaderiv(p_ID,GL_INFO_LOG_LENGTH,&l);
GLchar* compilerSpew = new GLchar[l+1];
glGetShaderInfoLog(p_ID, l+1, &l1, compilerSpew);
Util_ErrorLog(compilerSpew);
Util_Warning(_T("Shader compile failed"));
delete [] compilerSpew;
return false;
}


glAttachShader( c_ProgramID, p_ID );
return true;
}

sandbucket
10-05-2013, 08:57 AM
k i figured it out. i didnt realize i had to make an opengl context for the functions to work :)