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: Thirst in shaders

Hybrid View

  1. #1
    Junior Member Newbie
    Join Date
    Nov 2012
    Posts
    13

    Thirst in shaders

    Hi Im trying to understadn shaders and my thist experiant has not good result. So here some variants code of vertex shader:

    Code :
    #version 120
    void main(void) {
    	gl_Position = ftransform();
    }

    Code :
    #version 120
    void main(void) {
    	gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
    }

    Code :
    #version 120
    attribute vec3 coord3d;
    void main(void) {
    	gl_Position = gl_ModelViewProjectionMatrix * vec4(coord3d,1.0);
    }

    In last version in coord3d I pass gl_Vertex manualy by glVertexAttribPointer. None of this versions does't show me objects, I want.

    If shader has code:
    Code :
    #version 120
    attribute vec3 coord3d;
    void main(void) {
    	gl_Position = gl_Vertex;
    }
    I saw a not transformed object.

    On every step of my program I trasform ModelView matrix by using glRotated and glTranslated. On init I transform Projection matrix by using gluPerspective.
    Every objects, drawing without shaders, shows as they must. What wrong can by with mya shaders?

    Here full code of drawing my object:

    Code :
    /* Here I have two swappable VBO, thirst (m_idVertecesVBO_0) drwaing in this thread
     * second calculated in second thread, then they swaps. So here I use mutex.
     * All wark fine without shaders.
     */
     
            glEnable(GL_BLEND);
    	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
     
    	glMateriali ( GL_SHININESS, GL_FRONT_AND_BACK, 127);
    	GLfloat vSpecular[4] = {0.3,0.3,1,1};
    	glMaterialfv ( GL_SPECULAR, GL_FRONT_AND_BACK, vSpecular);
    	GLfloat vEmission[4] = {1,1,1,1};
    	glMaterialfv ( GL_EMISSION, GL_FRONT_AND_BACK, vEmission);
     
    	tDrawingMutex.lock();
     
    	GLint attribute_coord3d = glGetAttribLocation(m_ShaderProgram, "coord3d"); //zero in using of first two versions of shader
    	if (attribute_coord3d == -1) {
    		throw runtime_error ( _ExceptionString "Could not bind attribute coord3d");
    	}
     
    	glUseProgram(m_ShaderProgram);
     
    	glEnableVertexAttribArray(attribute_coord3d);
     
    	glEnableClientState(GL_VERTEX_ARRAY);
    	glEnableClientState(GL_NORMAL_ARRAY);
     
    	tBindingMutex.lock();
    	glBindBufferARB(GL_ARRAY_BUFFER_ARB, m_idVertecesVBO_0);
    	glVertexAttribPointer(
    		attribute_coord3d,	// attribute
    		3,			// number of elements per vertex, here (x,y,z)
    		GL_FLOAT,		// the type of each element
    		GL_FALSE,		// take our values as-is
    		0,			// no extra data between each position
    		0			// pointer to the C array
    	);
    	tBindingMutex.unlock();
     
    	tBindingMutex.lock();
    	glBindBufferARB(GL_ARRAY_BUFFER_ARB, m_idNormalsVBO_0);
    	glVertexAttribPointer(
    		0,			// attribute
    		3,			// number of elements per vertex, here (x,y,z)
    		GL_FLOAT,		// the type of each element
    		GL_FALSE,		// take our values as-is
    		0,			// no extra data between each position
    		0			// pointer to the C array
    	);
    	tBindingMutex.unlock();
     
    	glDrawArrays(GL_TRIANGLE_STRIP, 0,(m_Dimension + 1)*(m_Dimension - 1)*2);
     
    	glDisableVertexAttribArray(attribute_coord3d);
    	glDisableClientState(GL_VERTEX_ARRAY);
    	glDisableClientState(GL_NORMAL_ARRAY);
     
    	glUseProgram(0);
    	tDrawingMutex.unlock();

    P.S. Sorry for my english.

  2. #2
    Junior Member Newbie
    Join Date
    Nov 2012
    Posts
    13
    Oh Im so sorry, I has an mistake in my C++ code. I forget to put back glNormalPointer instead glVertexAttribPointer, in binding normal vbo after some experiments. Forget me, please))

Posting Permissions

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