Here I am writing this question regarding a problem that I am trying to solve but don’t find any better method to debug.
The problem is I am rendering a rectangle using my own abstracted class for buffer objects and rendering. which are totally fine no need to worry about that.
I see that when I try to render something in immediate mode (glBegin()) it works fine…even if I multiply it with perspective and view matrix during immediate mode…
But when the same thing is done with buffer object …God knows where is the primitive;
here is the rendering part:
void render()
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glClearColor(0.1,0.4,0.2,1.0);
glm::mat4 proj=glm::perspective<float>(45.0f,1024.0f/786.0f,-0.1f,100.0f);
glm::mat4 view=glm::lookAt(glm::vec3(-0.3,0.0,5.0),glm::vec3(0.0,0.0,0.0),glm::vec3(0.0,1.0,0.0));
box.shader.setUniformat4x4("projection_matrix",glm::value_ptr(proj));
box.shader.setUniformat4x4("view_matrix",glm::value_ptr(view));
glm::vec4 test(200.0,0.2,-1.1,0.0),
o(-0.2,0.2, -1.1,0.0),
l(-0.2,-0.2,-1.1,0.0);
/*
test=test*proj;
o=o*proj;
l=l*proj;
*/
glPolygonMode(GL_FRONT_AND_BACK,GL_LINE);
box.render();
glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);
glBegin(GL_LINES);
glColor3f(0.0,0.0,1.0);
glVertex2f(-1.0,0.0);
glVertex2f(1.0,0.0);
glColor3f(1.0,0.0,0.0);
glVertex2f(0.0,-1.0);
glVertex2f(0.0,1.0);
glEnd();
glFlush();
}
box.render() is the abstracted instance of modern opengl concepts…
this will basically call glDrawelements() followed by binding shader,vertex buffer and texture…
My question here is if I do same thing in immediate mode what ever box.render is doing…it works fine…but why does this method is failing?
coordinates of vertex buffer is :-
float data_vertex[]={
0.2,0.2, 0.0,
-0.2,0.2, 0.0,
-0.2,-0.2,0.0,
0.2,-0.2,0.0,
};
and this is the test shader I am using
#shader vertex
#version 330 core
layout(location=0) in vec4 pos;
uniform mat4 translate;
uniform mat4 projection_matrix;
uniform mat4 view_matrix;
out vec4 vertex;
void main()
{
projection_matrix;
view_matrix;
//if(pos.x<0)
//vertex=projection_matrix*pos;
//else
vertex=pos;
gl_Position=view_matrix*projection_matrix*vertex;
}
#shader fragment
#version 330 core
in vec4 vertex;
out vec4 color;
void main()
{
color=vec4(0.5,1.0,1.0,1.0);
//color=vec4(1.0,01.0,1.0,1.0);
}
What shall I minimally do to at least make my box appear on screen
Thank You…