PDA

View Full Version : Depth testing is not working



CowNecromancer
01-21-2018, 01:24 AM
I have stumbled upon a problem which I don't even understand why it is a problem. I've done a few OpenGL applications and depth testing has never bothered me. This error I am having has taking me a while to pin point the problem - the depth testing not working. The cubes, on the screen, have the faces drawn over each other. While it may seem like a simple problem, I used to think it was a problem with blitting the depth buffer among other things.


Depth buffer is working - in shader gl_FragCoord.z works correctly


So to be clear, I want the depth testing to work.
Also I have been through tons of google pages and nothing is helping. This issue has been bothering me on and off for days (for a period I just ignored it).

The code I present is not all the code, but just what I think is relevant - if everything should be working I will release more code.
Functions that are ran:
Init()

void Program::Init()
{
SetPriorityClass(GetCurrentProcess(), HIGH_PRIORITY_CLASS);

std::cout << "Initialising" << std::endl;
glViewport(0, 0, Options::width, Options::height);

glewExperimental = true; // Needed in core profile
if (glewInit() != GLEW_OK) {
fprintf(stderr, "Failed to initialize GLEW\n");
return;
}

// window.setVerticalSyncEnabled(true);
window.setKeyRepeatEnabled(false);

sf::Mouse::setPosition(sf::Vector2i(Options::width / 2, Options::height / 2), window);

network = new Network();
std::cout << "dwoidjwaoidwaodj \n";
LoadGameState(GameState::INGAME, false);
Run();
}
GLInit()

void Program::GLInit() {

lampShader = Shader("StandardVertex.shader", "LightingFragmentShader.shader");
ourShader = Shader("VertexShader.shader", "SimpleFragmentShader.shader");
screenShader = Shader("FrameVertexShader.shader", "FrameFragmentShader.shader");
skyboxShader = Shader("SkyboxVertex.shader", "SkyboxFragment.shader");
cubeDepthShader = Shader("CubeDepthVertex.shader", "CubeDepthFragment.shader", &std::string("CubeDepthGeometry.shader"));
debugDepthQuad = Shader("SimpleVertex.shader", "DepthFragment.shader");
blurShader = Shader("SimpleVertex.shader", "BloomFragment.shader");
bloomShader = Shader("SimpleVertex.shader", "FinalBloom.shader");

depthShader = Shader("VertexDepth.shader", "EmptyFragment.shader");

geometryPass = Shader("GeometryVertex.shader", "GeometryFragment.shader");
lightingPass = Shader("SimpleVertex.shader", "LightingFragment.shader");
shaderSSAO = Shader("SimpleVertex.shader", "SSAOFragment.shader");
shaderSSAOblur = Shader("SimpleVertex.shader", "SSAOBlurFragment.shader");

colliders = Shader("VertexShader.shader", "GreenFragment.shader");


glEnable(GL_DEPTH_TEST);
//glEnable(GL_PROGRAM_POINT_SIZE);
//glEnable(GL_POINT_SPRITE);
//glEnable(GL_CULL_FACE);

//depthmapshadows



//GenBuffers();
}
RunGame()

void Program::RunGame()
{


scene->mainCamera.Input(Options::deltaTime, window);

if(timeSinceGameStart.getElapsedTime().asSeconds()<2)
DoLights();

if(timeSinceGameStart.getElapsedTime().asSeconds() > 5.0f)
scene->DoPhysics();

scene->CheckCollisions();


glClearColor(0.32f, 0.5f, 0.58f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

//scene->DrawSkybox();



projection = glm::mat4();
view = glm::mat4();
// view/projection transformations
projection = glm::perspective(glm::radians(Options::fov), (float)Options::width / (float)Options::height, 0.1f, 100.0f);
view = scene->mainCamera.GetViewMatrix();

lampShader.use();
lampShader.setMat4("projection", projection);
lampShader.setMat4("view", view);
lampShader.setInt("setting", Options::settings);
glm::mat4 model;
for (unsigned int i = 0; i < lights.size(); i++)
{
model = glm::mat4();
model = glm::translate(model, lights[i].position);
model = glm::scale(model, glm::vec3(0.125f));
lampShader.setMat4("model", model);
lampShader.setVec3("lightColor", lights[i].colour);
Scene::renderCube();
}


if (Options::showColliders) {
colliders.use();
colliders.setMat4("projection", projection);
colliders.setMat4("view", view);
scene->RenderColliders(colliders);
}


//bloom
}


I hope this is enough to understand. All of the functions I have tested and are not the problem. The main area is where I the lights in the main loop.

OceanJeff40
01-24-2018, 06:28 AM
I was just noticing the standardization of your shader filenames, except the depth shaders, the debugDepthQuad and depthShader fragment shaders have names that are not expected. Could this be the source of aggravation?

Jeff