Reputation: 55
Trying to draw wavefront obj files using OpenGL but it seems there is a depth-buffer problem.
Source:
// Default constructor
Engine::Engine()
{
initialize();
loadModel();
start();
}
// Initialize OpenGL
void Engine::initialize()
{
// Enable depth test
glEnable(GL_DEPTH_TEST);
// Enable depth write
glDepthMask(GL_TRUE);
}
void Engine::start()
{
// Main loop
while(isOpen())
{
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// Draw 3D model to screen
draw();
}
}
Upvotes: 2
Views: 593
Reputation: 4443
Are you using vertex shaders? This thing would happen if at the exit of vertex shader gl_Position.z is accidentally set to 0. Or to any value between -1 and 1 I believe.
It would also happen if all vertices had equal z value before the input stage, albeit there must be something wrong with your transformation matrices in this case. Or simply you may be doing something very exotic with your transformation matrices, and the model is fine. Have you set up both MODELVIEW and PROJECTION, and multiplied them accordingly? Either in the vertex shader or in the FFP?
Upvotes: 0
Reputation: 52093
Request a GL context with a depth buffer and glEnable(GL_DEPTH_TEST)
.
Try this:
mainWindow.create
(
sf::VideoMode
(
settings.getWidth(),
settings.getHeight()
),
"",
sf::Style::Resize,
sf::ContextSettings( 16, 0, 0, 2, 0 )
);
Upvotes: 1
Reputation: 35943
Things to check:
glEnable(GL_DEPTH_TEST)
glDepthMask(true)
Assert(glGetIntegerv(GL_DEPTH_BITS) != 0))
Upvotes: 2