Hi people,
I've got a strange problem with the depth buffer (?).
It's similar to:
https://en.sfml-dev.org/forums/index.php?topic=20693.msg148603;topicseen#msg148603I've made a "room" (without ceiling and ground), but the walls are transparent and I don't know why.
I have tried the solution from the link from above, but it didn't work and changing the drawing order didn't either. What I am doing wrong? Many thanks in advance for any help. Sorry that the indentation is wrong, but I don't know how to fix it, because in my compiler it looks ok.
#include <SFML/Graphics.hpp>
#include <iostream>
#define _USE_MATH_DEFINES
#include <math.h>
#include <SFML/OpenGL.hpp>
void myGluPerspective(double fovy, double aspect, double zNear, double zFar)
{
double f = 1.0 / tan(fovy * M_PI / 360); // convert degrees to radians and divide by 2
double xform[16] =
{
f / aspect, 0, 0, 0,
0, f, 0, 0,
0, 0, (zFar + zNear)/(zFar - zNear), -1,
0, 0, 2*zFar*zNear/(zFar - zNear), 0
};
glMultMatrixd(xform);
}
int main()
{
sf::ContextSettings Settings;
Settings.depthBits = 24;
Settings.stencilBits = 8;
Settings.antialiasingLevel = 2;
sf::Window window(sf::VideoMode(800, 600, 32), "SFML OpenGL", sf::Style::Close, Settings);
window.setFramerateLimit(40);
glClearDepth(1.f);
glClearColor(0.8f, 0.8f, 0.8f, 0);
glEnable(GL_DEPTH_TEST);
glDepthMask(GL_TRUE);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
myGluPerspective(60,800/600,0,180);
glTranslatef(0,0,-3);
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
switch (event.type)
{
case sf::Event::Closed:
window.close();
break;
}
}
window.setActive();
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glRotatef(1,0,0.5f,0);
glBegin(GL_QUADS);
glColor3f(1.0f,1.0f,1.0f); // white
glVertex3f(-1,-1,-1);
glVertex3f(1,-1,-1);
glVertex3f(1,1,-1);
glVertex3f(-1,1,-1);
glColor3f(0.0f,1.0f,0.0f); // green
glVertex3f(-1,1,1);
glVertex3f(-1,-1,1);
glVertex3f(-1,-1,-1);
glVertex3f(-1,1,-1);
glColor3f(0.0f,0.0f,1.0f); // blue
glVertex3f(1,1,1);
glVertex3f(1,-1,1);
glVertex3f(1,-1,-1);
glVertex3f(1,1,-1);
glColor3f(0.0f,1.0f,1.0f); // cyan
glVertex3f(-1,-1,1);
glVertex3f(1,-1,1);
glVertex3f(1,1,1);
glVertex3f(-1,1,1);
glEnd();
window.display();
}
return 0;
}