Что мне делать? Я решил написать вращающийся куб на SFML и OpenGL (с SFML работаю давно, а OpenGL только начал изучать). Сделал все, как было показано в видеоуроке, но почему-то это не работает. Мой куб вращается, и это хорошо, но тест глубины не работает или работает неправильно. Почему? Где ошибка? Что не так? Его грани рисуются в соответствии с тем, как я указал, то есть те грани, которые я рисовал последними рисуются перед другими, а мне надо чтоб грани рисовались правильно, и куб не был полупрозрачным.
![5dd114a807f23570745727.png](https://habrastorage.org/webt/5d/d1/14/5dd114a807f23570745727.png)
Вот сам код:
#include <SFML/Window.hpp>
#include <SFML/OpenGL.hpp>
#include <SFML/Graphics.hpp>
#include <GL/glut.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include <windows.h>
using namespace sf;
GLuint LoadTexture(const char *name)
{
Image image;
image.loadFromFile(name);
GLuint texture = 0;
glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_2D, texture);
gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGBA, image.getSize().x, image.getSize().y, GL_RGBA, GL_UNSIGNED_BYTE, image.getPixelsPtr());
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
return texture;
}
int main(int argc, char **argv)
{
RenderWindow window(VideoMode(400, 400), "");
Event event;
/*GLuint texture = 0;
{
Image image;
image.loadFromFile("D:/C++/GlutExample/resources/img.png");
glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_2D, texture);
gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGBA, image.getSize().x, image.getSize().y, GL_RGBA, GL_UNSIGNED_BYTE, image.getPixelsPtr());
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
}*/
GLuint box[6];
box[0] = LoadTexture("D:/C++/GlutExample/resources/back.png");
box[1] = LoadTexture("D:/C++/GlutExample/resources/front.png");
box[2] = LoadTexture("D:/C++/GlutExample/resources/left.png");
box[3] = LoadTexture("D:/C++/GlutExample/resources/right.png");
box[4] = LoadTexture("D:/C++/GlutExample/resources/bottom.png");
box[5] = LoadTexture("D:/C++/GlutExample/resources/top.png");
glEnable(GL_DEPTH_TEST);
glDepthMask(GL_FALSE);
glClearDepth(1.f);
glDepthFunc(GL_LESS);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(90.0f, 1.f, 0.0f, 500.f);
glEnable(GL_TEXTURE_2D);
Clock clock;
while(window.isOpen()) {
while(window.pollEvent(event)) {
if(event.type == Event::Closed)
window.close();
}
float time = clock.getElapsedTime().asSeconds() * 180;
float size = 25;
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
//glClearColor(0.5f, 0.0f, 0.0f, 0.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0, 0, -100);
glRotatef(time / 4, 50, 50, 0);
glBindTexture(GL_TEXTURE_2D, box[0]);
glBegin(GL_QUADS);
//back
glTexCoord2f(0, 0); glVertex3f(-size, -size, -size);
glTexCoord2f(1, 0); glVertex3f( size, -size, -size);
glTexCoord2f(1, 1); glVertex3f( size, size, -size);
glTexCoord2f(0, 1); glVertex3f(-size, size, -size);
glEnd();
glBindTexture(GL_TEXTURE_2D, box[1]);
glBegin(GL_QUADS);
//front
glTexCoord2f(0, 0); glVertex3f( size, -size, size);
glTexCoord2f(1, 0); glVertex3f(-size, -size, size);
glTexCoord2f(1, 1); glVertex3f(-size, size, size);
glTexCoord2f(0, 1); glVertex3f( size, size, size);
glEnd();
glBindTexture(GL_TEXTURE_2D, box[2]);
glBegin(GL_QUADS);
//left
glTexCoord2f(0, 0); glVertex3f(-size, -size, size);
glTexCoord2f(1, 0); glVertex3f(-size, -size, -size);
glTexCoord2f(1, 1); glVertex3f(-size, size, -size);
glTexCoord2f(0, 1); glVertex3f(-size, size, size);
glEnd();
glBindTexture(GL_TEXTURE_2D, box[3]);
glBegin(GL_QUADS);
//right
glTexCoord2f(0, 0); glVertex3f( size, -size, -size);
glTexCoord2f(1, 0); glVertex3f( size, -size, size);
glTexCoord2f(1, 1); glVertex3f( size, size, size);
glTexCoord2f(0, 1); glVertex3f( size, size, -size);
glEnd();
glBindTexture(GL_TEXTURE_2D, box[4]);
glBegin(GL_QUADS);
//bottom
glTexCoord2f(0, 0); glVertex3f(-size, -size, size);
glTexCoord2f(1, 0); glVertex3f( size, -size, size);
glTexCoord2f(1, 1); glVertex3f( size, -size, -size);
glTexCoord2f(0, 1); glVertex3f(-size, -size, -size);
glEnd();
glBindTexture(GL_TEXTURE_2D, box[5]);
glBegin(GL_QUADS);
//bottom
glTexCoord2f(0, 0); glVertex3f(-size, size, -size);
glTexCoord2f(1, 0); glVertex3f( size, size, -size);
glTexCoord2f(1, 1); glVertex3f( size, size, size);
glTexCoord2f(0, 1); glVertex3f(-size, size, size);
glEnd();
window.display();
}
}
P.S. я уже перерыл огромное количество информации, перепробовал все, что можно, но проблему решить так и не удалось. ПОМОГИТЕ!!!