Matrix multiplication in vertex shader is malfunctioning. Resulting to blank screen

I have been trying to tackle the blank screen problem in OpenGL.I decided to debug with render doc.

here is source.cpp section…

 {
    glm::mat4 proj=glm::perspective<float>(45.0f,1024.0f/786.0f,0.0f,10.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));

	
	glm::mat4 translate=glm::make_mat4x4(translation);

	glm::translate(translate, glm::vec3(glm::sin(glfwGetTime()), 0.0, glm::abs(glm::sin(glfwGetTime()))));
	box.shader.setUniformat4x4("projection_matrix",glm::value_ptr(proj));
	box.shader.setUniformat4x4("view_matrix",glm::value_ptr(view));
	box.shader.setUniformat4x4("translate",glm::value_ptr(translate));
	static Timer t;
	t.startTimer();
	box.shader.setUniform1f("time",t.getTicks());

	box.render();
	
	glm::vec4 p1(0.2, 0.2, -2.0, 1.0),p2(-0.2, 0.2, 0.0,1.0),p3(0.00,-0.2,0.0,1.0);

	p1 = proj * p1;
	p2 = proj * p2;
	p3 = proj * p3;

 	/*
	glBegin(GL_TRIANGLES);
	glColor3f(1.0, 1.0, 1.0);
	glVertex3f(p1.x,p1.y,p1.z);
	glVertex3f(p2.x, p2.y, p2.z);
	glVertex3f(p3.x, p3.y, p3.z);
	glEnd();

	*/
	
	//glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);




	glFlush();
}

And the vertex shader…

#version 330 core
layout(location=0) in vec3 pos1;

uniform mat4 translate;
uniform mat4 projection_matrix;
uniform mat4 view_matrix;

 uniform float time;
out float t;
 out vec4 vertex;
 void main()
 {
 	
 	projection_matrix;
 	view_matrix;
 	translate;
 	//if(pos1.x<0)
 	//vertex=projection_matrix*pos1;
 	//else
 	
vec4 p=vec4(pos1.x,pos1.y,pos1.z,1.0);

 gl_Position=projection_matrix*p;
 t=time;
 }

Here when I don’t apply projection multiplication with p;everything works fine.
But with above mentioned shader RenderDoc shows this

empty VS output gl_position.Why!
what is wrong here.

here is projection matrix

mat4x4((1.853097, 0.000000, 0.000000, 0.000000), (0.000000, 2.414213, 0.000000, 0.000000), (0.000000, 0.000000, -1.000000, -1.000000), (0.000000, 0.000000, -0.000000, 0.000000))

Your vertex shader looks somewhat fancy. Read at least this.

This implies the projection matrix was constructed with zNear=0. This will result in ZNDC=1 which will may cause the polygon to be clipped away by the far plane. The near distance should be greater than zero, and in practice should be as large as possible without nearby objects intersecting the near plane. Too small a value for the near distance results in poor depth resolution.

I can’t get the word fancy.I am only applying projection …not view and model transfom.Will this affect?

I’m not sure what “the word fancy” has to do with anything. As explained by GClements, your problem is that you provided an improper value to glm::perspective. You cannot use a zNear of 0, ever.

@coderboyisongithub
The way you set up your shader suggests that you’r blank on a complex subject. Yes, you have to multiply matrices in the shader. The problem here is the view-matrix. Spend time on figuring that out before you attempt to construct your projection from scratch. GLM has them ready-made … construct it there.

This looked fancy from my opinion:

Oh!, these make uniforms active in shaders.so that while uplaoding uniform via set uniform …to avoid error that uniforms are not found…

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.