PDA

View Full Version : Problems debugging a GLSL-Shader-containing app



ma_luh
08-02-2010, 01:04 PM
Hi,

as mentioned above, I'm facing a problem debugging a Windows-application containing GLSL-shaders with gdb. In normal operation everything is ok.



glGetShaderiv(handle, GL_INFO_LOG_LENGTH , &loglength);


returns a loglength of 0 and everythinkg looks like I've exptected.
When I'm trying to start my app within gdb, I'm receveing compilation errors:



ERROR: 0:16: '<' : syntax error parse error
ERROR: 0:29: '<' : syntax error parse error


Here is the code I'm using to load my vertex/fragment-shaders from an external file:



enum ShaderType {VERTEX, FRAGMENT};

[...]

void Shader::loadShaderFromFile(const char* path, ShaderType t, int shaderLen)
{
char *program = new char[shaderLen];
const GLcharARB **programPtr=(const GLcharARB **)&amp;program;

char *ptr = program;
int len = 0;
std::ifstream input(path);

while (!input.eof())
{
input.getline(ptr,255);
len=strlen(ptr);
ptr[len]='\n';
ptr+=len+1;
}

if(t == VERTEX)
{
shaderObjects.push_back(glCreateShader(GL_VERTEX_S HADER));
glShaderSource(shaderObjects.back(), 1, programPtr, NULL);
}
else
{
shaderObjects.push_back(glCreateShader(GL_FRAGMENT _SHADER));
glShaderSource(shaderObjects.back(), 1, programPtr, NULL);
}
}


The content of the char-array containing the shader-sourcecode seems fine within the debugging-session.

My vertex shader:


uniform float timeIndex;
varying vec3 Position;
varying vec3 Normal;

void main()
{
Position = vec3(gl_ModelViewMatrix * gl_Vertex);
Normal = gl_NormalMatrix * gl_Normal;

gl_TexCoord[0] = gl_MultiTexCoord0 - vec4(0.01,0.0,0.0,0.0) * timeIndex;
gl_TexCoord[1] = gl_MultiTexCoord0 - vec4(0.012,0.0,0.0,0.0) * timeIndex;

gl_Position = ftransform();
}


My fragment shader:


uniform sampler2D earth_clouds;
uniform sampler2D earth_day;
uniform sampler2D earth_night;
uniform sampler2D earth_specular;

uniform vec3 LightPosition;

varying vec3 Normal;
varying vec3 Position;

void main()
{
vec4 TexLayer = texture2D(earth_day, vec2(gl_TexCoord[0]));
vec4 CloudLayer = texture2D(earth_clouds, vec2(gl_TexCoord[1]));

vec3 nNormal = normalize(Normal);
vec3 nLight = normalize(LightPosition - Position);
float Diffuse = max(dot(nNormal, nLight), 0.0);

TexLayer = mix(texture2D(earth_night, vec2(gl_TexCoord[0])), texture2D(earth_day, vec2(gl_TexCoord[0])), Diffuse);

vec4 SpecularLayer = vec4(.0, 0.0, 1.0, 0.0) * mix(0.0, 1.0, texture2D(earth_specular, vec2(gl_TexCoord[0])).r);
gl_FragColor = mix(TexLayer + SpecularLayer, CloudLayer, CloudLayer * (Diffuse * 0.95 + 0.05));

}


Any ideas?

Thank you!

ma_luh
08-04-2010, 04:33 AM
- gentle push -