Results 1 to 7 of 7

Thread: glEnableVertexAttribArray?

  1. #1
    Senior Member Regular Contributor
    Join Date
    Mar 2006
    Posts
    160

    glEnableVertexAttribArray?

    Hi all!

    can I use those:
    glEnableClientState(GL_NORMAL_ARRAY);
    glEnableClientState(GL_TEXTURE_COORD_ARRAY);
    glEnableClientState(GL_VERTEX_ARRAY);
    with:
    glEnableVertexAttribArray(6); < -- Tangents

    or do I need to convert them all to VertexAttribArray?

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

    Re: glEnableVertexAttribArray?

    no you don't need to convert them all. Just upload your tangent vector with the glEnableVertexAttribArray() along with the rest of the setup code you need with that function and all should be fine.

  3. #3
    Senior Member Regular Contributor
    Join Date
    Mar 2006
    Posts
    160

    Re: glEnableVertexAttribArray?

    Hi Marss! would you mind ginving me a feedback on this?!

    here is my VOB code:
    Code :
     
    #define TANGENT_ARRAY 6
     
    void OpenGL::SetClientBuffer(Primitive *in_primitive)
    {
    	m_CurrentColor		= in_primitive->GetColor();
    	m_CurrentFogCoord	= in_primitive->GetFogCoord();
    	m_CurrentNormal		= in_primitive->GetNormal();
    	m_CurrentTangent	= in_primitive->GetTangent();
    	m_CurrentUV		= in_primitive->GetUV(0);
    	m_CurrentVertex		= in_primitive->GetVertex();
     
    	GLuint &amp;l_buffer = in_primitive->GetBufferArray();
    	if (l_buffer == 0)
    		glGenBuffers((GLsizei) 1, &amp;l_buffer);
     
    	glBindBuffer(GL_ARRAY_BUFFER, l_buffer);
     
    	if (in_primitive->IsState(STATE_RESET_BUFFER))
    	{
    		GLuint &amp;l_offsUVs = in_primitive->GetUVId();
    		GLuint &amp;l_offsCol = in_primitive->GetColorId();
    		GLuint &amp;l_offsFog = in_primitive->GetFogCoordId();
    		GLuint &amp;l_offsNor = in_primitive->GetNormalId();
    		GLuint &amp;l_offsTan = in_primitive->GetTangentId();
    		GLuint &amp;l_offsVer = in_primitive->GetVertexId();
     
    		GLuint l_sizeCol = in_primitive->GetColorCount()	* sizeof(Color);
    		GLuint l_sizeFog = in_primitive->GetFogCoordCount()	* sizeof(GLfloat);
    		GLuint l_sizeNor = in_primitive->GetNormalCount()	* sizeof(Vector3);
    		GLuint l_sizeTan = in_primitive->GetNormalCount()	* sizeof(Vector3);
    		GLuint l_sizeUV0 = in_primitive->GetUVCount()		* sizeof(Vector2);
    		GLuint l_sizeVer = in_primitive->GetVertexCount()	* sizeof(Vector3);
     
    		GLuint l_sizeUVs = 0;
    		for (GLint i = 0; i < GetMaxTextures(); ++i)
    			if (in_primitive->GetUV(i) != NULL)
    				l_sizeUVs += l_sizeUV0;
     
    		l_offsUVs = 0;
    		l_offsCol = l_offsUVs + l_sizeUVs;
    		l_offsFog = l_offsCol + l_sizeCol;
    		l_offsNor = l_offsFog + l_sizeFog;
    		l_offsTan = l_offsNor + l_sizeNor;
    		l_offsVer = l_offsTan + l_sizeTan;
     
    		GLuint l_sizeVOB = l_offsVer + l_sizeVer;
    		glBufferData(GL_ARRAY_BUFFER, l_sizeVOB, NULL, in_primitive->GetBufferType());
     
    		Vector2 *l_uv = NULL;
    		for (GLint i = 0; i < GetMaxTextures(); ++i)
    		{
    			l_uv = in_primitive->GetUV(i);
    			if (l_uv != NULL)
    				glBufferSubData(GL_ARRAY_BUFFER, (i * l_sizeUVs), l_sizeUVs, l_uv);
    		}
     
    		glBufferSubData(GL_ARRAY_BUFFER, l_offsCol, l_sizeCol, m_CurrentColor);
    		glBufferSubData(GL_ARRAY_BUFFER, l_offsFog, l_sizeFog, m_CurrentFogCoord);
    		glBufferSubData(GL_ARRAY_BUFFER, l_offsNor, l_sizeNor, m_CurrentNormal);
    		glBufferSubData(GL_ARRAY_BUFFER, l_offsTan, l_sizeTan, m_CurrentTangent);
    		glBufferSubData(GL_ARRAY_BUFFER, l_offsVer, l_sizeVer, m_CurrentVertex);
    	}
     
    ...SNIP
     
    		if (m_CurrentTangent)
    		{
    			glEnableVertexAttribArray(TANGENT_ARRAY);
    			glVertexAttribPointer(TANGENT_ARRAY, 3, GL_FLOAT, GL_FALSE, sizeof(Vector3), BUFFER_OFFSET(in_primitive->GetTangentId()));
    		}
    		else
    			glDisableVertexAttribArray(TANGENT_ARRAY);
     
    ...SNIP

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

    Re: glEnableVertexAttribArray?

    Not sure what you want me to look at but after a quick glance, your call to glVertexAttribPointer() the BUFFER_OFFSET() needs a byte offset and not a memory address like VA do. So with your GetTangentID() is this returning something like this

    Code :
    sizeof(float) * 6;
    I am assuming 6, due to you probably like me, have vertices, normals, tangents, texcoords... I also am assuming Vector3 is a struct that holds all your vertex data?

  5. #5
    Senior Member Regular Contributor
    Join Date
    Mar 2006
    Posts
    160

    Re: glEnableVertexAttribArray?

    thx Marss!
    GetTangentID() = in_primitive->GetTangentCount() * sizeof(Vector3);

    which is the buffer offset... in fact I should rename to: GetTangentBufferOffset()

    I am assuming 6
    I use 6 because i read that 1 to 5 are used for standard gl_* arrays... 6 and 7 are free... 8 and up are for matrices... correct?

    I also am assuming Vector3 is a struct that holds all your vertex data?
    for tangents yes... but not for all data see l_size* variables.

    Im trying to retrieve tangents in glsl... it is not working yet, so im still digging... to know that this piece of code is correct will definitely help!

    thx again

  6. #6
    Guest

    Re: glEnableVertexAttribArray?

    to know that this piece of code is correct will definitely help!
    don't post code and then ask people if it's correct!

    rtfm... try it for yourself... debug it yourself...

    only post a question if you really can't figure it out or make it work on your own. don't waste people's time...

  7. #7
    Senior Member Regular Contributor
    Join Date
    Mar 2006
    Posts
    160

    Re: glEnableVertexAttribArray?

    ... excuse me???... please, feel free not to waist your time writing 2d comment like this one... unregistered...

    I ve got it working, this thread is closed.

    thx again for your inputs!

Similar Threads

  1. glEnableVertexAttribArray
    By holyll in forum OpenGL: Basic Coding
    Replies: 7
    Last Post: 01-17-2013, 01:58 AM
  2. glEnableVertexAttribArray - when to call?
    By PeTeAR in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 12-08-2011, 02:26 PM
  3. When to call glEnableVertexAttribArray()
    By ManuelP in forum OpenGL ES
    Replies: 2
    Last Post: 08-22-2011, 08:07 AM
  4. Crash at glEnableVertexAttribArray
    By strattonbrazil in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 05-04-2011, 10:11 PM
  5. glEnableVertexAttribArray but not using the array
    By Schnulla in forum OpenGL: Basic Coding
    Replies: 14
    Last Post: 08-23-2010, 03:02 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