Hi Im trying to understadn shaders and my thist experiant has not good result. So here some variants code of vertex shader:
#version 120
void main(void) {
gl_Position = ftransform();
}
#version 120
void main(void) {
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
}
#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:
#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:
/* 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.