I was following this tutorial (http://www.lighthouse3d.com/tutorials/glsl-12-tutorial/point-light-per-pixel/) but when the camera is at a certain angle, if I had alpha test and blend enabled the cube i have in the scene wouldn't draw, otherwise they would be black(if alpha and blend was disabled) Any thoughts on what's going on?
here is some relevant code:
glClearColor(0.6, 0.6, 0.6, 1);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(80, (float)window.getSize().x / (float)window.getSize().y, 0.01f, 1000.0);
glMatrixMode(GL_MODELVIEW);
glEnable(GL_TEXTURE_2D);
glEnable(GL_DEPTH_TEST);
glEnable(GL_CULL_FACE);
glCullFace(GL_BACK);
//glEnable(GL_BLEND);
//glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
//glEnable(GL_ALPHA_TEST);
//glAlphaFunc(GL_GREATER, 0.1f);
glEnable(GL_COLOR_MATERIAL);
glShadeModel(GL_SMOOTH);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_AUTO_NORMAL);
glEnable(GL_NORMALIZE);
.....
void Lighting(Camera cam, sf::Vector3f Pos) {
GLfloat amb[] = {0.2, 0.2, 0.2, 1};
glLightModelfv(GL_LIGHT_MODEL_AMBIENT, amb);
GLfloat diff[] = { 1, 1, 1, 1 };
GLfloat pos[] = { Pos.x, Pos.y, Pos.z, 1 };
glLightfv(GL_LIGHT0, GL_DIFFUSE, diff);
glLightfv(GL_LIGHT0, GL_POSITION, pos);
}
....
glLoadIdentity();
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
cam.up(delta, window);
Lighting(cam, Pos);
sf::Shader::bind(&shader);
cube.draw();
cube1.draw();
window.display();
sf::Shader::bind(NULL);
draw function for cubes:
glPushMatrix();
glTranslatef(pos.x, pos.y, pos.z);
glBegin(GL_QUADS);
glColor3f(color.r / 255, color.g / 255, color.b / 255);
glVertex3f(0, 0, 0);
glVertex3f(width, 0, 0);
glVertex3f(width, height, 0);
glVertex3f(0, height, 0);
glVertex3f(width, 0, 0);
glVertex3f(width, 0, -length);
glVertex3f(width, height, -length);
glVertex3f(width, height, 0);
glVertex3f(0, 0, -length);
glVertex3f(0, 0, 0);
glVertex3f(0, height, 0);
glVertex3f(0, height, -length);
glVertex3f(width, 0, -length);
glVertex3f(0, 0, -length);
glVertex3f(0, height, -length);
glVertex3f(width, height, -length);
glVertex3f(width, 0, 0);
glVertex3f(0, 0, 0);
glVertex3f(0, 0, -length);
glVertex3f(width, 0, -length);
glVertex3f(0, height, 0);
glVertex3f(width, height, 0);
glVertex3f(width, height, -length);
glVertex3f(0, height, -length);
glEnd();
glPopMatrix();