SOLUTION
The problem was in my z interval I was considering negative values on z like (-0.1f < z < 100f), instead I used a positive interval for near/far plane ex : (0.0f < z < 100.0f), I arranged other stuffs with deprecated void's in OpenGL, and I arranged my bad position on my glm :: lookAt.
Note : Dont mix the old render way with the new render way (is a good practice but could be a problem), Btw :You must understand your position in the space.
Thanks for everyone guys :)
I'm a beginner graphic programmer and I was trying to draw a very simple triangle using a basic vertex/fragment shaders. But I've one error with my projection matrix and I can't find it. Also, Im trying to do a reshape void and I want that reshape callback works well with the triangle drawn by the shader. When I write these products in my render void happens this:
MVP = ProjectionMatrix * ModelViewMatrix;
Result -> I dont Like
And if I only assign to MVP the ModelView Matrix I got this:
These are my Reshape Voids
void OpenGL_Initialization(int w, int h){
ProjectionMatrix = glm :: ortho(0.0f,(GLfloat)w,(GLfloat)h,0.0f,0.1f, 100.0f);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glLoadMatrixf(glm :: value_ptr(ProjectionMatrix));
glMatrixMode(GL_MODELVIEW);
}
void Reshape(int w, int h){
width = w;
height = h;
glViewport(0,0,w,h);
OpenGL_Initialization(w,h);
}
And this is my render callback :
void Render(){
glClearColor(0.75,0.75,0.75,1.0);
glClear(GL_COLOR_BUFFER_BIT);
glGetFloatv(GL_MODELVIEW_MATRIX,glm :: value_ptr(ModelViewMatrix));
MVP = ProjectionMatrix * ModelViewMatrix;
glUniformMatrix4fv(glGetUniformLocation(ProgramHandler,"MVP"),1,GL_FALSE,glm :: value_ptr(MVP));
glBindVertexArray(vaoHandle);
glDrawArrays(GL_TRIANGLES, 0, 3);
glBindVertexArray(0);
glutSwapBuffers();
}
Also these are my vertex and fragment shader
#version 400
layout (location = 0) in vec3 VertexPosition;
layout (location = 1) in vec3 VertexColor;
uniform mat4 MVP;
out vec3 Color;
void main(){
Color = VertexColor;
gl_Position = MVP*vec4(VertexPosition,1.0);
}
#version 400
in vec3 Color;
out vec4 FragColor;
void main(){
FragColor = vec4(Color,1.0);
}
The VBOs and VAO initialization:
void InitVBO(GLuint programHandler){
glBindAttribLocation(programHandler,0,"VertexPosition");
glBindAttribLocation(programHandler,1,"VertexColor");
GLfloat positionData[] = {-0.5f,0.5f,0.0f,0.0f,-.5f,0.0f,0,0,0};
GLfloat colorData[] = {1.0f,0.0f,0.0f,0.0f,1.0f,0.0f,0.0f,0.0f,1.0f};
GLuint vboHandles[2];
glGenBuffers(2,vboHandles);
glBindBuffer(GL_ARRAY_BUFFER,vboHandles[0]);
glBufferData(GL_ARRAY_BUFFER,9*sizeof(GLfloat),positionData,GL_STATIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER,vboHandles[1]);
glBufferData(GL_ARRAY_BUFFER,9*sizeof(GLfloat),colorData,GL_STATIC_DRAW);
glGenVertexArrays(1, &vaoHandle);
glBindVertexArray(vaoHandle);
glEnableVertexAttribArray(0);
glEnableVertexAttribArray(1);
glBindBuffer(GL_ARRAY_BUFFER, vboHandles[0]);
glVertexAttribPointer( 0, 3, GL_FLOAT, GL_FALSE, 0,(GLubyte *)NULL );
glBindBuffer(GL_ARRAY_BUFFER, vboHandles[1]);
glVertexAttribPointer( 1, 3, GL_FLOAT, GL_FALSE, 0,(GLubyte *)NULL );
}