Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 2 of 2

Thread: Problems debugging a GLSL-Shader-containing app

  1. #1
    Junior Member Newbie
    Join Date
    Aug 2010
    Posts
    2

    Problems debugging a GLSL-Shader-containing app

    Hi,

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

    Code :
    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:

    Code :
    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:

    Code :
    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_SHADER));
    	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:
    Code :
    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:
    Code :
    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!

  2. #2
    Junior Member Newbie
    Join Date
    Aug 2010
    Posts
    2

    Re: Problems debugging a GLSL-Shader-containing app

    - gentle push -

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •