hi,
so i started to build a program from scratch and try to do basic lighting. all i want to do is to have a spotlight inside my plane(top of the cube), so basically there will be part that is lighted and part that is not lighted, and i can see the border. this is the entire code hope so you can see my problem straight away:
/*
* untitled.cpp
* LightTest
*
* Created by Jos Timanta Tarigan on 11/28/09.
* Copyright 2009 Linkoping University. All rights reserved.
*
*/
#include <GLUT/glut.h>
float light0Direction[] = {0, -90, 0};
float light0SpotCutOff = 40.0;
GLuint objectList = 0;
void init(void)
{
GLfloat mat_specular[] = { 1.0, 1.0, 1.0, 1.0};
GLfloat mat_shininess[] = {50.0};
GLfloat light_position[] = {3.0, 3.0, 3.0, 1.0};
GLfloat light_ambient[] = {1.0, .0, .0, 1.0};
GLfloat light_specular[] = {.0, .5, .5, 1.0};
GLfloat light_diffuse[] = {.0, .1, 1, 1.0};
glClearColor(.0, .0, .0, .0);
glShadeModel(GL_SMOOTH);
glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);
glLightfv(GL_LIGHT0, GL_POSITION, light_position);
glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);
glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular);
glLightfv(GL_LIGHT0, GL_SPECULAR, light_diffuse);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_DEPTH_TEST);
}
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glLightfv(GL_LIGHT0, GL_SPOT_DIRECTION, light0Direction);
glLightf(GL_LIGHT0, GL_SPOT_CUTOFF, light0SpotCutOff);
objectList = glGenLists(1);
glNewList(objectList, GL_COMPILE);
glScalef(20.0, 0.1, 10.0f);
glutSolidCube(1.0);
glEndList();
glCallList(objectList);
//glutSolidCube(1.0);
glutSwapBuffers();
}
void reshape(int w, int h)
{
glViewport(.0, .0, (GLsizei) w, (GLsizei) h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(65.0, (GLfloat) w/(GLfloat) h, 1.0, 20.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(.0, .0, -5);
gluLookAt(.0, 5.0, 7.0,
.0, .0, .0,
.0, 3.0, .0);
}
int main(int argc, char ** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize(1000, 500);
glutInitWindowPosition(100, 100);
glutCreateWindow("ARGV");
init();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutMainLoop();
return 0;
}
its osx based, so you might wanna change the header.
i’ve been playing with the direction and and spotcutoff but the result is either half of them is lighted (splitted in the diagonal) or not lighted at all. any idea?
thanks in advance