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 1 of 1

Thread: Shader problems: How to use custom vetex shader attributes

  1. #1
    Intern Contributor
    Join Date
    Sep 2013
    Posts
    81

    [Solved] Shader problems: How to use custom vetex shader attributes

    Solved
    I feel dumb now. 2 minutes after opening the thread I managed to fix the problem after working on this for a whole day.
    For anyone who is just as clueless as I was: I had to bind the attribute location. Or at least this solved my problem.

    I was toying around with shaders recently but I got into a problem I just can not fix myself.

    I have one very simple shader program:
    Vertex-Shader
    Code :
    	varying vec4 v_color;
     
    	void main()
    	{
    		v_color = gl_Color;
    		gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
    	}\n
    Fragment-Shader
    Code :
    	varying vec4 v_color;
     
    	void main()
    	{
    		gl_FragColor = v_color;
    	}\n

    And I have a VBO with an Array-Buffer like this:
    Code :
    [ 53.0, 353.0, 1.0, 1.0, 
      1.0, 0.5, 0.0, 1.0, 
      654.0, 31.0, 1.0, 1.0, 
      1.0, 0.5, 0.0, 1.0 ]
    and an Element-Array-Buffer like this: [0, 1]

    I draw with glDrawElements(GL_LINES, 2, GL_INT, 0);

    And I have this code to set the attribute pointers:
    Code :
    	glEnableClientState(GL_VERTEX_ARRAY);
    	glVertexPointer(4, GL_FLOAT, 32, 0);
    	glEnableClientState(GL_COLOR_ARRAY);
    	glColorPointer(4, GL_FLOAT, 32, 16);

    And everything works. I see a line being drawn on the screen.
    But now I wanted to toy around and change the shader slightly:
    Vertex-Shader
    Code :
    	attribute vec4 test;
    	varying vec4 v_color;
     
    	void main()
    	{
    		v_color = gl_Color;
    		gl_Position = gl_ModelViewProjectionMatrix * test;
    	}\n
    Fragment-Shader
    Code :
    	varying vec4 v_color;
     
    	void main()
    	{
    		gl_FragColor = v_color;
    	}\n

    The VBO and the buffers still look the same but I changed the pointers to this:
    Code :
    	int id = glGetAttribLocation(pId, "test");
    	glEnableVertexAttribArray(id);
    	glVertexAttribPointer(id, 4, GL_FLOAT, GL_FALSE, 32, 0);
    	glEnableClientState(GL_COLOR_ARRAY);
    	glColorPointer(4, GL_FLOAT, 32, 16);
    But nothing is drawn anymore.
    I know I did something wrong, but I dont know what. I am probably using the custom vertex attribute incorrectly I guess.

    Thank you very much for your help.
    Last edited by Cornix; 11-01-2013 at 06:43 AM.

Posting Permissions

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