Results 1 to 8 of 8

Thread: glGetAttribLocation and a -1 return value?

  1. #1
    Senior Member Frequent Contributor Mars_999's Avatar
    Join Date
    Mar 2001
    Location
    Sioux Falls, SD, USA
    Posts
    519

    glGetAttribLocation and a -1 return value?

    I am at my minds end, I have no errors when checking my code with GL's built in calls, and I am using the vertex attribute in my VS... What else would cause me to get a -1? I am using GLUT to do some test runs on my new shader lib, and the same code works in my engine. The shader runs and shows a textured surface, but the values are wrong, and gDebugger throws the error saying that glEnableVertexAttribArray() has a wrong value...

    Thanks

  2. #2
    Senior Member Frequent Contributor _NK47's Avatar
    Join Date
    Mar 2008
    Posts
    574

    Re: glGetAttribLocation and a -1 return value?

    might be that your attrib variable isn't properly used in your shader thus might be skipped because of no use. happend to me because of exactly that but with uniform variables.

  3. #3
    Senior Member Frequent Contributor Mars_999's Avatar
    Join Date
    Mar 2001
    Location
    Sioux Falls, SD, USA
    Posts
    519

    Re: glGetAttribLocation and a -1 return value?

    I doubt it as render monkey says its compiles with success. The code in the shader is the same as my engines code and that returns a value other than -1...

  4. #4
    Senior Member OpenGL Pro dletozeun's Avatar
    Join Date
    Jan 2006
    Location
    FRANCE
    Posts
    1,367

    Re: glGetAttribLocation and a -1 return value?

    Did you test your code on the same hardware for your engine and your new shader lib?
    If you did, it seems that your problem comes from your opengl program. I advise you to use the GetActiveAttrib function to get the list of all active attributes and see if everything is fine.

    Are you sure that Opengl did not threw any error? Shader program is succesfully linked?

    I am not sure to understand you about "GL's built in calls", can you elaborate a bit more?

  5. #5
    Senior Member Frequent Contributor Mars_999's Avatar
    Join Date
    Mar 2001
    Location
    Sioux Falls, SD, USA
    Posts
    519

    Re: glGetAttribLocation and a -1 return value?

    glGetActiveAttrib()

    I checked and I only have two active, and those are gl_Vertex and gl_MultiTexCoord0... I should have 5

    tangent, bitangent, gl_Normal doesn't even show up ....

    Code :
    #version 120
     
    attribute vec3 Tangent, BiTangent;
     
    void main()
    {    
    	vec3 t = gl_NormalMatrix * Tangent;
    	vec3 b = gl_NormalMatrix * BiTangent;
    	vec3 n = gl_NormalMatrix * gl_Normal;
    	gl_TexCoord[0] = gl_MultiTexCoord0;
    	gl_Position = ftransform();   
    }

  6. #6
    Senior Member Frequent Contributor scratt's Avatar
    Join Date
    May 2008
    Location
    Thailand
    Posts
    555

    Re: glGetAttribLocation and a -1 return value?

    The only place I have seen this happen before is when I got the order of GLSL compiling, linking, binding and so on messed up. Is that any help?

  7. #7
    Senior Member Frequent Contributor Mars_999's Avatar
    Join Date
    Mar 2001
    Location
    Sioux Falls, SD, USA
    Posts
    519

    Re: glGetAttribLocation and a -1 return value?

    Hi scratt, nah, I have kept the code in order from my other code base, which works.

  8. #8
    Senior Member Regular Contributor
    Join Date
    Mar 2007
    Location
    Latvia
    Posts
    225

    Re: glGetAttribLocation and a -1 return value?

    _NK47 already explained your problem.
    In your vertex shader code you posted I do not see how t, b and n variables are used - therefore they are optimized out. That is why Tangent, BiTangent and gl_Normal also is not needed in shader - so they are also optimized out. This is normal for GLSL. Same thing happens also with uniforms - if you do not use them or some other variables (which are calculated from these uniforms) then uniforms are optimized out.

Similar Threads

  1. Transform-feedback / glGetAttribLocation
    By art-ganseforth in forum OpenGL: Basic Coding
    Replies: 14
    Last Post: 10-03-2018, 04:54 PM
  2. Use of discard and return
    By Kopelrativ in forum OpenGL: GLSL
    Replies: 5
    Last Post: 08-29-2012, 07:34 AM
  3. return value about glAttachShader
    By neol in forum OpenGL ES
    Replies: 0
    Last Post: 08-17-2012, 02:45 AM
  4. glGetAttribLocation on separate shader objects
    By imported_Anteru in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 01-24-2012, 11:22 AM
  5. glGetAttribLocation returning -1
    By Guillaume G. in forum OpenGL: Basic Coding
    Replies: 6
    Last Post: 10-11-2009, 03:54 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean