I have this code and I dont know why it is not working and can somebody explain me this line please
glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_TRUE);
?
Here is code
#include <GL/glu.h>
#include "Primitives.hpp"
#include <SFML/System.hpp>
#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>
float angle=0;
void InitGL(void) // All Setup For OpenGL Goes Here
{
glClearColor(0.0, 0.0, 0.0, 0.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glViewport(0,0,400,400);
glOrtho(-1, 1, -1, 1, -1, 1);
// Lighting set up
glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_TRUE);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
// Set lighting intensity and color
GLfloat qaAmbientLight[] = {0.2, 0.2, 0.2, 1.0};
GLfloat qaDiffuseLight[] = {0.8, 0.8, 0.8, 1.0};
GLfloat qaSpecularLight[] = {1.0, 1.0, 1.0, 1.0};
glLightfv(GL_LIGHT0, GL_AMBIENT, qaAmbientLight);
glLightfv(GL_LIGHT0, GL_DIFFUSE, qaDiffuseLight);
glLightfv(GL_LIGHT0, GL_SPECULAR, qaSpecularLight);
// Set the light position
GLfloat qaLightPosition[] = {0.5, 0.5, 0.0, 1.0};
glLightfv(GL_LIGHT0, GL_POSITION, qaLightPosition);
}
void DrawGLScene(void) // Here's Where We Do All The Drawing
{
glClear(GL_COLOR_BUFFER_BIT);
// Set material properties
GLfloat qaBlack[] = {0.0, 0.0, 0.0, 1.0};
GLfloat qaGreen[] = {0.0, 1.0, 0.0, 1.0};
GLfloat qaWhite[] = {1.0, 1.0, 1.0, 1.0};
glMaterialfv(GL_FRONT, GL_AMBIENT, qaGreen);
glMaterialfv(GL_FRONT, GL_DIFFUSE, qaGreen);
glMaterialfv(GL_FRONT, GL_SPECULAR, qaWhite);
glMaterialf(GL_FRONT, GL_SHININESS, 60.0);
glBegin(GL_QUADS);
glNormal3f(0.0, 0.0, 1.0);
glVertex3f(-0.9,0.9, -.2);
glVertex3f(0.9,0.9, -.2);
glVertex3f(0.9,-0.9, -.2);
glVertex3f(-0.9,-0.9, -.2);
glEnd();
glFlush();
}
int main()
{
// Create the main window
sf::Window App(sf::VideoMode(400, 400, 32), "SFML OpenGL", sf::Style::Close);
InitGL();
// Start game loop
App.SetFramerateLimit(60);
while (App.IsOpened())
{
// Process events
sf::Event Event;
while (App.PollEvent(Event))
{
// Close window : exit
if (Event.Type == sf::Event::Closed)
App.Close();
// Resize event : adjust viewport
if (Event.Type == sf::Event::Resized)
glViewport(0, 0, Event.Size.Width, Event.Size.Height);
}
DrawGLScene();
App.Display();
}
return 0;
}
it looks like