I have created following objects…each belongs to a class
I have two rendering objects box and buckets initialized using shaders as shown…
vb=Vertex_Buffer(POS,4*3*sizeof(float),0,3,1);
ib=Index_buffer(index,3*2*sizeof(unsigned int),1);
sh=shader_processor(std::string("shader.glsl"));
box=Object_2D(vb,ib,sh,GL_TRIANGLES);
bucket=Object_2D(vb,ib,sh,GL_TRIANGLES);
VertexBuffer constructor
Vertex_Buffer(float *aData,int aSize,int aindex,int vertex_comp,int buffCount,int use_as=GL_STATIC_DRAW,int bind_as=GL_ARRAY_BUFFER)
{
as_used=use_as;
as_binded=bind_as;
bCount=buffCount;
bsize=aSize;
glGenBuffers(buffCount,&ID);
//glGenBuffers(1,&ID);
glBindBuffer(bind_as,ID);
glBufferData(bind_as,aSize,aData,use_as);
glVertexAttribPointer(0,2,GL_FLOAT,GL_FALSE,vertex_comp*sizeof(float),NULL);
//glVertexAttribPointer(0,3,GL_FLOAT,GL_FALSE,3*sizeof(float),NULL);
glEnableVertexAttribArray(0);
glBindBuffer(bind_as,0);
ready=true;
}
and Index buffer
Index_buffer(unsigned int *aIndex,int aSize,int bCount,int bind_as=GL_ELEMENT_ARRAY_BUFFER,int use_as=GL_STATIC_DRAW )
{
as_used=use_as;
as_binded=bind_as;
buffer_count=bCount;
buffer_size=aSize;
indices=aIndex;
glGenBuffers(bCount,&ID);
glBindBuffer(bind_as,ID);
glBufferData(bind_as,aSize,aIndex,use_as);
glBindBuffer(bind_as,0);
ready=true;
}
this is how I am rendering them…
translation[X_]=-5.0;
box.shader.setUniformat4x4("translation_matrix",translation);
box.shader.setUniformat4x4("rotation_matrix",rotation_arr);
box.shader.setUniformat4x4("projection_matrix",glm::value_ptr(proj));
box.render();
//translation is a float array having vertex coordinates//
translation[X_]=-20*sin(0.3*t.getTicks());
bucket.shader.setUniformat4x4("translation_matrix",translation);
bucket.shader.setUniformat4x4("rotation_matrix",rotation_arr);
bucket.shader.setUniformat4x4("projection_matrix",glm::value_ptr(proj));
bucket.render();
The Shader…I have combined and pharsed both shaders in one file…all fine here nothing wrong with parsing…
#shader vertex
#version 330 core
layout(location=0) in vec2 texCoords;
layout(location = 0) in vec4 pts;
uniform mat4 translation_matrix; //active
uniform mat4 rotation_matrix;
mat4 model_matrix; //
uniform mat4 projection_matrix;
out vec4 pos;
out vec2 frag_TexCoord;
void main()
{
vec4 v=pts;
projection_matrix*(rotation_matrix*translation_matrix);
gl_Position=projection_matrix*(rotation_matrix*translation_matrix)*(v); //translation matrix operated with POS vector..
pos=gl_Position;
frag_TexCoord=texCoords;
}
#shader fragment
#version 330 core
layout(location=0) out vec4 color;
in vec4 pos;
in vec2 frag_TexCoord;
vec4 frag_pos;
void main()
{
//color=texture(a_texture,frag_TexCoord);
color=vec4(0.4,0.4,0.2,1.0);
}
Here two objects are expected to be rendered simultaneously one will move sine function ,other will stay at z=-5
But either one is rendered Like this
Why I cant see both objects rendered even after shader,vb and Ib are binded created and implemented sperately