PDA

View Full Version : Problem with light



Srcee
06-01-2011, 10:27 AM
I have really trouble understanding the light in OpenGl.
A code that works in one program, doesn't work in other.
For example:

This code works pretty well:

#include <GL/glut.h>
#include <math.h>
#include <stdio.h> // Header file for standard file i/o.
#include <stdlib.h> // Header file for malloc/free.
#include "utils.c"

const int chekor=9;
float agolX=0;
float agolY=0;
float agolZ=0;
float transZ=80;
float rotateA=0;
float rotateAspeed=0.0f;
int polygonMode=GL_FILL;

float svX=0, svY=0, svZ=10;

#define checkImageWidth 64
#define checkImageHeight 64
static GLubyte checkImage[checkImageHeight][checkImageWidth][4];
static GLuint texName1;
static GLuint texName2;
static GLuint texName3;

void kocka1 (float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4) // ova e objektot koj go pretstavuva svetloto
{
int i, j;
glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE);
glFrontFace(GL_CW);

glColor3f(1,1,1);

glBindTexture(GL_TEXTURE_2D, texName3);
glBegin(GL_QUADS);
glNormal3f(0,0,1);

glTexCoord2f(x1, y1);
glVertex3f(-10,-10,13);

glTexCoord2f(x2, y2);
glVertex3f(-10,10,13);

glTexCoord2f(x3, y3);
glVertex3f(10,10,13);

glTexCoord2f(x4, y4);
glVertex3f(10,-10,13);

glEnd();
glBindTexture(GL_TEXTURE_2D, 0);

glBindTexture(GL_TEXTURE_2D, texName3);
glBegin(GL_QUADS);
glNormal3f(0,0,-1);

glTexCoord2f(x1, y1);
glVertex3f(-10,-10,0);

glTexCoord2f(x4, y4);
glVertex3f(10,-10,0);

glTexCoord2f(x3, y3);
glVertex3f(10,10,0);

glTexCoord2f(x2, y2);
glVertex3f(-10,10,0);
glEnd();
glBindTexture(GL_TEXTURE_2D, 0);

glBegin(GL_QUADS);

glNormal3f(0,1,0);
glVertex3f(-10,-10,0);
glVertex3f(-10,-10,13);
glVertex3f(10,-10,13);
glVertex3f(10,-10,0);

glNormal3f(-1,0,0);
glVertex3f(10,10,0);
glVertex3f(10,-10,0);
glVertex3f(10,-10,13);
glVertex3f(10,10,13);

glNormal3f(0,-1,0);
glVertex3f(10,10,0);
glVertex3f(10,10,13);
glVertex3f(-10,10,13);
glVertex3f(-10,10,0);

glNormal3f(1,0,0);
glVertex3f(-10,10,0);
glVertex3f(-10,10,13);
glVertex3f(-10,-10,13);
glVertex3f(-10,-10,0);
glEnd();
}
void kocka () // ova e objektot koj go pretstavuva svetloto
{
int i, j;
glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE);
glFrontFace(GL_CW);

glColor3f(1,1,1);

glBegin(GL_QUADS);
glNormal3f(0,0,-1);
glVertex3f(-10,-10,0);
glVertex3f(10,-10,0);
glVertex3f(10,10,0);
glVertex3f(-10,10,0);

glNormal3f(0,0,1);
glVertex3f(-10,-10,13);
glVertex3f(-10,10,13);
glVertex3f(10,10,13);
glVertex3f(10,-10,13);

glNormal3f(0,1,0);
glVertex3f(-10,-10,0);
glVertex3f(-10,-10,13);
glVertex3f(10,-10,13);
glVertex3f(10,-10,0);

glNormal3f(-1,0,0);
glVertex3f(10,10,0);
glVertex3f(10,-10,0);
glVertex3f(10,-10,13);
glVertex3f(10,10,13);

glNormal3f(0,-1,0);
glVertex3f(10,10,0);
glVertex3f(10,10,13);
glVertex3f(-10,10,13);
glVertex3f(-10,10,0);

glNormal3f(1,0,0);
glVertex3f(-10,10,0);
glVertex3f(-10,10,13);
glVertex3f(-10,-10,13);
glVertex3f(-10,-10,0);
glEnd();
}

void mrezha10x10 (void) {
glBegin(GL_QUADS);
glNormal3f(0,0,1); // edna zaednichka normala za site chetiriagolnici od mrezhata
int i=0;
int j=0;
for ( i=0; i<10; i++)
{
for ( j=0; j<10; j++)
{
glVertex3f(i, 0,j);
glVertex3f(i+1,0,j);
glVertex3f(i+1,0,j+1);
glVertex3f(i, 0,j+1);
}
}
kocka();
glEnd();
}
void mrezha10x101 (float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4) {
glBegin(GL_QUADS);
glNormal3f(0,0,1); // edna zaednichka normala za site chetiriagolnici od mrezhata
int i=0;
int j=0;
for ( i=0; i<10; i++)
{
for ( j=0; j<10; j++)
{
glVertex3f(i, 0,j);
glVertex3f(i+1,0,j);
glVertex3f(i+1,0,j+1);
glVertex3f(i, 0,j+1);
}
}
kocka1(x1,y1,x2,y2,x3,y3,x4,y4);
glEnd();
}

void podloga (void) {

float mat_ambient []={0.0f, 0.0f, 0.0f, 0};
float mat_diffuse []={1.0f, 1.0f, 1.0f, 0};
float mat_specular[]={1.0f, 1.0f, 1.0f, 0};
float mat_shininess = 100.0f;
glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, mat_ambient);
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, mat_diffuse);
glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, mat_specular);
glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, mat_shininess);
glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE);
glFrontFace(GL_CW);

glBindTexture(GL_TEXTURE_2D, texName2);
glBegin(GL_QUADS);
glNormal3f(0,1,0); // edna zaednichka normala za site chetiriagolnici od mrezhata

int i=0;
int j=0;
for ( i=0; i<100; i++)
{
for ( j=0; j<100; j++)
{
glTexCoord2f(i/100.0, j/100.0); glNormal3f(0,1,0); glVertex3f(i,0,j);
glTexCoord2f((i+1)/100.0, j/100.0); glNormal3f(0,1,0); glVertex3f(i+1,0,j);
glTexCoord2f((i+1)/100.0, (j+1)/100.0); glNormal3f(0,1,0); glVertex3f(i+1,0,j+1);
glTexCoord2f(i/100.0, (j+1)/100.0); glNormal3f(0,1,0); glVertex3f(i,0,j+1);
}
}
glEnd();
glBindTexture(GL_TEXTURE_2D, 0);

}
void test (void) {

float mat_ambient []={0.0f, 0.0f, 0.0f, 0};
float mat_diffuse []={0.0f, 0.0f, 0.0f, 0};
float mat_specular[]={0.0f, 0.0f, 0.0f, 0};
float mat_shininess = 0.9;
glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, mat_ambient);
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, mat_diffuse);
glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, mat_specular);
glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, mat_shininess);
glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE);
glFrontFace(GL_CW);

glBindTexture(GL_TEXTURE_2D, texName3);
glBegin(GL_QUADS);
glNormal3f(0,1,0); // edna zaednichka normala za site chetiriagolnici od mrezhata

int i=0;
int j=0;
for ( i=0; i<100; i++)
{
for ( j=0; j<100; j++)
{
glTexCoord2f(i/100.0, j/100.0); glVertex3f(i,j,0);
glTexCoord2f((i+1)/100.0, j/100.0); glVertex3f(i+1,j,0);
glTexCoord2f((i+1)/100.0, (j+1)/100.0); glVertex3f(i+1,j+1,0);
glTexCoord2f(i/100.0, (j+1)/100.0); glVertex3f(i,j+1,0);
}
}
glEnd();
glBindTexture(GL_TEXTURE_2D, 0);

}
void bukvaK()
{
glPushMatrix();
glTranslatef(-60,0,0);
glScalef(0.12,1.5,0.12);
kocka1(0.0,0.0,0.0,1.0,0.053,1.0,0.053,0.0);
glPopMatrix();

glPushMatrix();
glTranslatef(-54,7,0);
glRotatef(-35,0,0,1);
glScalef(0.12,0.95,0.12);
kocka1(0.052,0.538,0.122,1.0,0.16,0.962,0.054,0.5) ;
glPopMatrix();

glPushMatrix();
glTranslatef(-54,-9,0);
glRotatef(-145,0,0,1);
glScalef(0.12,0.95,0.12);
kocka1(0.054,0.5,0.16,0.038,0.122,0.0,0.052,0.462) ;
glPopMatrix();
}
void bukvaP()
{
glPushMatrix();
glTranslatef(-40,0,0);
glScalef(0.12,1.5,0.12);
kocka1(0.17,0.0,0.17,1.0,0.223,1.0,0.223,0.0);
//mrezha10x10();
glPopMatrix();

glPushMatrix();
glTranslatef(-33,14,0);
glRotatef(90,0,0,1);
glScalef(0.12,0.6,0.12);
kocka1(0.33,0.947,0.223,0.947,0.223,1.0,0.33,1.0);
//mrezha10x10();
glPopMatrix();

glPushMatrix();
glTranslatef(-28,6,0);
glScalef(0.12,0.75,0.12);
kocka1(0.277,0.5,0.277,0.947,0.33,0.947,0.33,0.5);
//mrezha10x10();
glPopMatrix();

glPushMatrix();
glTranslatef(-33,-1,0);
glRotatef(90,0,0,1);
glScalef(0.12,0.6,0.12);
kocka1(0.33,0.447,0.223,0.447,0.223,0.5,0.33,0.5);
//mrezha10x10();
glPopMatrix();
}
void bukvaI()
{
glPushMatrix();
glTranslatef(-20,0,0);
glScalef(0.12,1.5,0.12);
kocka1(0.34,0.0,0.34,1.0,0.393,1.0,0.393,0.0);
//mrezha10x10();
glPopMatrix();

glPushMatrix();
glTranslatef(-8,0,0);
glScalef(0.12,1.5,0.12);
kocka1(0.447,0.0,0.447,1.0,0.5,1.0,0.5,0.0);
//mrezha10x10();
glPopMatrix();

glPushMatrix();
glTranslatef(-14,0,0);
glRotatef(-20,0,0,1);
glScalef(0.12,1.6,0.12);
kocka1(0.355,0.038,0.447,1.0,0.485,0.962,0.393,0.0 );
//mrezha10x10();
glPopMatrix();

}
void bukvaS()
{
glPushMatrix();
glTranslatef(0,0,0);
glScalef(0.12,1.5,0.12);
kocka1(0.51,0.0,0.51,1.0,0.563,1.0,0.563,0.0);
//mrezha10x10();
glPopMatrix();

glPushMatrix();
glTranslatef(8,14,0);
glRotatef(90,0,0,1);
glScalef(0.12,0.7,0.12);
kocka1(0.67,0.947,0.563,0.947,0.563,1.0,0.67,1.0);
//mrezha10x10();
glPopMatrix();

glPushMatrix();
glTranslatef(8,-14,0);
glRotatef(90,0,0,1);
glScalef(0.12,0.7,0.12);
kocka1(0.67,0.0,0.563,0.0,0.563,0.053,0.67,0.053);
//mrezha10x10();
glPopMatrix();
}
void bukvaT()
{
glPushMatrix();
glTranslatef(30,-0.5,0);
glScalef(0.12,1.35,0.12);
kocka1(0.7335,0.0,0.7335,0.947,0.7865,0.947,0.7865 ,0.0);
//mrezha10x10();
glPopMatrix();

glPushMatrix();
glTranslatef(30,14,0);
glRotatef(90,0,0,1);
glScalef(0.12,1.2,0.12);
kocka1(0.84,0.947,0.68,0.947,0.68,1.0,0.84,1.0);
//mrezha10x10();
glPopMatrix();
}
void bukvaI2()
{
glPushMatrix();
glTranslatef(50,0,0);
glScalef(0.12,1.5,0.12);
kocka1(0.84,0.0,0.84,1.0,0.893,1.0,0.893,0.0);
//mrezha10x10();
glPopMatrix();

glPushMatrix();
glTranslatef(62,0,0);
glScalef(0.12,1.5,0.12);
kocka1(0.947,0.0,0.947,1.0,1.0,1.0,1.0,0.0);
//mrezha10x10();
glPopMatrix();

glPushMatrix();
glTranslatef(56,0,0);
glRotatef(-20,0,0,1);
glScalef(0.12,1.6,0.12);
kocka1(0.855,0.038,0.947,1.0,0.985,0.985,0.893,0.0 );
//mrezha10x10();
glPopMatrix();
}
void bukvi()
{
glPushMatrix();
glTranslatef(-300,-15,-300);
glScalef(6,1,6);

podloga();

glPopMatrix();

float mat_ambient []={0.0f, 0.0f, 0.0f, 0};
float mat_diffuse []={0.0f, 0.0f, 0.0f, 0};
float mat_specular[]={0.0f, 0.0f, 0.0f, 0};
float mat_shininess = 0.9;
glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, mat_ambient);
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, mat_diffuse);
glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, mat_specular);
glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, mat_shininess);
glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE);
glFrontFace(GL_CW);

bukvaK();
bukvaP();
bukvaI();
bukvaS();
bukvaT();
bukvaI2();

}

void display(void)
{
glPolygonMode(GL_FRONT_AND_BACK,polygonMode);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

glEnable(GL_TEXTURE_2D);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);

//Mestenje pogled
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(0,70,transZ,0,0,0,0,1,0);
glRotatef(rotateA,0,1,0);

// repozicioniranje na svetloto
GLfloat svetlo0_position[]= {-2,60,22,1};
//GLfloat svetlo0_position[]= {svX,svY,svZ,1};
glLightfv(GL_LIGHT0,GL_POSITION,svetlo0_position);

//GLfloat svetlo1_position[]= {2,63,-40,1};
//GLfloat svetlo1_position[]= {svX,svY,svZ,1};
//glLightfv(GL_LIGHT1,GL_POSITION,svetlo1_position);

// crtanje na scenata
//glPushMatrix();
// glTranslatef(svX,svY,svZ);
// glScalef(0.2,0.2,0.2);
// kocka();
// glPopMatrix();

bukvi();

glFlush();

// smeni buffer
glutSwapBuffers();
}

void init (void)
{
glClearColor(0.1f, 0.1f, 0.1f, 0.0f);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glFrustum(-50, 50, -50, 50, 40, 1000);

glShadeModel(GL_SMOOTH);
glEnable(GL_DEPTH_TEST);
glEnable(GL_LIGHTING);
glEnable(GL_COLOR_MATERIAL);

//treta tekstura - od datoteka
Image *image2;

image2 = (Image *) malloc(sizeof(Image));
if (image2 == NULL) {
printf("Error allocating space for image");
exit(0);
}

if (!ImageLoad("mkd.bmp", image2)) {
exit(1);
}

glGenTextures(1, &amp;texName3);
glBindTexture(GL_TEXTURE_2D, texName3);

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTE R,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTE R,GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, 3, image2->sizeX, image2->sizeY,
0, GL_RGB, GL_UNSIGNED_BYTE, image2->data);


//vtora tekstura - od datoteka
Image *image1;

image1 = (Image *) malloc(sizeof(Image));
if (image1 == NULL) {
printf("Error allocating space for image");
exit(0);
}

if (!ImageLoad("p5.bmp", image1)) {
exit(1);
}

glGenTextures(1, &amp;texName2);
glBindTexture(GL_TEXTURE_2D, texName2);

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTE R,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTE R,GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, 3, image1->sizeX, image1->sizeY,
0, GL_RGB, GL_UNSIGNED_BYTE, image1->data);


// globalno svetlo

GLfloat specular[] = { 1.0f, 1.0f, 1.0f, 1.0f};
GLfloat ambientLight[] = { 0.0f, 0.0f, 0.0f, 1.0f};
GLfloat spotDir1[] = { 0.0f, -1.0f, -1.0f };
GLfloat spotDir[] = { 0.0f, -1.0f, -1.0f };
GLfloat global_ambient[]= {0.2,0.2,0.2,1};

/*glLightModelfv(GL_LIGHT_MODEL_AMBIENT, global_ambient);
glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_TRUE);
glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE);*/

glLightfv(GL_LIGHT0,GL_DIFFUSE,specular);
glLightfv(GL_LIGHT0,GL_SPECULAR,specular);
glLightfv(GL_LIGHT0,GL_SPOT_DIRECTION, spotDir);
glLightf(GL_LIGHT0,GL_SPOT_CUTOFF,60.0f);
glLightf(GL_LIGHT0,GL_SPOT_EXPONENT,5.0f);
glEnable(GL_LIGHT0);

/*
glLightfv(GL_LIGHT1,GL_DIFFUSE,specular);
glLightfv(GL_LIGHT1,GL_SPECULAR,specular);
glLightfv(GL_LIGHT1,GL_SPOT_DIRECTION, spotDir1);
glLightf(GL_LIGHT1,GL_SPOT_CUTOFF,60.0f);
glLightf(GL_LIGHT1,GL_SPOT_EXPONENT,5.0f);
glEnable(GL_LIGHT1);*/

}

void keyboard(unsigned char key, int x, int y)
{
printf("%d %f %f %f %f \n", key, svX, svY, svZ, transZ);
switch (key) {
case 27:
exit(0);
break;
case 'W':
transZ+=0.5f;
glutPostRedisplay(); // obnovi go prikazot
break;
case 'S':
transZ-=0.5f;
if (transZ<0) transZ=0;
glutPostRedisplay(); // obnovi go prikazot
break;
case 'w':
transZ+=0.1f;
glutPostRedisplay(); // obnovi go prikazot
break;
case 's':
transZ-=0.1f;
if (transZ<0) transZ=0;
glutPostRedisplay(); // obnovi go prikazot
break;
case 'A':
rotateAspeed+=1.0f;
glutPostRedisplay(); // obnovi go prikazot
break;
case 'a':
rotateAspeed+=0.1f;
glutPostRedisplay(); // obnovi go prikazot
break;
case 'D':
rotateAspeed-=1.0f;
glutPostRedisplay(); // obnovi go prikazot
break;
case 'd':
rotateAspeed-=0.1f;
glutPostRedisplay(); // obnovi go prikazot
break;
case '1':
polygonMode=GL_LINE;
glutPostRedisplay(); // obnovi go prikazot
break;
case '2':
polygonMode=GL_FILL;
glutPostRedisplay(); // obnovi go prikazot
break;
case 'i':
svY+=1.0f;
glutPostRedisplay(); // obnovi go prikazot
break;
case 'k':
svY-=1.0f;
glutPostRedisplay(); // obnovi go prikazot
break;
case 'j':
svX-=1.0f;
glutPostRedisplay(); // obnovi go prikazot
break;
case 'l':
svX+=1.0f;
glutPostRedisplay(); // obnovi go prikazot
break;
case 'y':
svZ+=1.0f;
glutPostRedisplay(); // obnovi go prikazot
break;
case 'h':
svZ-=1.0f;
glutPostRedisplay(); // obnovi go prikazot
break;
}
}

void idle(void)
{
rotateA+=rotateAspeed;
glutPostRedisplay();
}

int main(int argc, char** argv)
{
glutInit(&amp;argc, argv);
glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB);
glutInitWindowSize (450, 350);
glutInitWindowPosition (100, 100);
glutCreateWindow ("Име во 3Д со користење на текстури");
init ();
glutDisplayFunc(display);
glutIdleFunc(idle); // ovaa funkcija treba da se povika koga programot ne pravi nishto
glutKeyboardFunc(keyboard); // Pri pritisok na tastaturata se povikuva keboard
glutMainLoop();
return 0;
}




But, when I copy the code concerning the light in other program, it doesn't work like in the previous one:
#include <GL/glut.h> //moe
#include <math.h>
#include <stdio.h> // Header file for standard file i/o.
#include <stdlib.h> // Header file for malloc/free.
#include "utils.c"

const int chekor=9;
float agolX=0;
float agolY=0;
float agolZ=0;
float transZ=70;
float rotateA=0;
float rotateAspeed=0.0f;
int polygonMode=GL_FILL;

float svX=0, svY=0, svZ=10;
#define checkImageWidth 64
#define checkImageHeight 64
static GLubyte checkImage[checkImageHeight][checkImageWidth][4];
static GLuint texName3;
static GLuint texName2;
static GLuint texName1;

void D(float z){
//o ili 4
if(z==4){
glBindTexture(GL_TEXTURE_2D, texName2);
glBegin(GL_QUADS);
glTexCoord2f(0.05, 0.0); glVertex3f(0,0.75,z);
glTexCoord2f(0.05, 1.0); glVertex3f(0,0.25,z);
glTexCoord2f(0.15, 1.0); glVertex3f(0.10,0.25,z);
glTexCoord2f(0.15, 0.0); glVertex3f(0.10,0.75,z);
glEnd();
glBindTexture(GL_TEXTURE_2D, 0);

glBindTexture(GL_TEXTURE_2D, texName2);
glBegin(GL_QUADS);
glTexCoord2f(0.15, 1.00); glVertex3f(0.10,0.75,z);
glTexCoord2f(0.15, 0.80); glVertex3f(0.10,0.65,z);/////
glTexCoord2f(0.22, 0.80); glVertex3f(0.20,0.65,z);
glTexCoord2f(0.22, 1.00); glVertex3f(0.20,0.75,z);
glEnd();
glBindTexture(GL_TEXTURE_2D, 0);

glBindTexture(GL_TEXTURE_2D, texName2);
glBegin(GL_QUADS);
glTexCoord2f(0.22, 0.0); glVertex3f(0.17,0.75,z);
glTexCoord2f(0.22, 1.0); glVertex3f(0.17,0.25,z);
glTexCoord2f(0.25, 1.0); glVertex3f(0.20,0.25,z);
glTexCoord2f(0.25, 0.0); glVertex3f(0.20,0.75,z);
glEnd();
glBindTexture(GL_TEXTURE_2D, 0);

glBindTexture(GL_TEXTURE_2D, texName2);
glBegin(GL_QUADS);
glTexCoord2f(0.15, 0); glVertex3f(0.10,0.25,z);
glTexCoord2f(0.22, 0); glVertex3f(0.17,0.25,z);
glTexCoord2f(0.22, 0.10); glVertex3f(0.17,0.30,z);
glTexCoord2f(0.15, 0.10); glVertex3f(0.10,0.30,z);
glEnd();
glBindTexture(GL_TEXTURE_2D, 0);
}
if(z==0){
glBindTexture(GL_TEXTURE_2D, texName1);
glBegin(GL_QUADS);
glTexCoord2f(0.05, 0.0); glVertex3f(0,0.75,z);
glTexCoord2f(0.05, 1.0); glVertex3f(0,0.25,z);
glTexCoord2f(0.15, 1.0); glVertex3f(0.10,0.25,z);
glTexCoord2f(0.15, 0.0); glVertex3f(0.10,0.75,z);
glEnd();
glBindTexture(GL_TEXTURE_2D, 0);

glBindTexture(GL_TEXTURE_2D, texName1);
glBegin(GL_QUADS);
glTexCoord2f(0.15, 1.00); glVertex3f(0.10,0.75,z);
glTexCoord2f(0.15, 0.80); glVertex3f(0.10,0.65,z);/////
glTexCoord2f(0.22, 0.80); glVertex3f(0.20,0.65,z);
glTexCoord2f(0.22, 1.00); glVertex3f(0.20,0.75,z);
glEnd();
glBindTexture(GL_TEXTURE_2D, 0);

glBindTexture(GL_TEXTURE_2D, texName1);
glBegin(GL_QUADS);
glTexCoord2f(0.22, 0.0); glVertex3f(0.17,0.75,z);
glTexCoord2f(0.22, 1.0); glVertex3f(0.17,0.25,z);
glTexCoord2f(0.25, 1.0); glVertex3f(0.20,0.25,z);
glTexCoord2f(0.25, 0.0); glVertex3f(0.20,0.75,z);
glEnd();
glBindTexture(GL_TEXTURE_2D, 0);

glBindTexture(GL_TEXTURE_2D, texName1);
glBegin(GL_QUADS);
glTexCoord2f(0.15, 0); glVertex3f(0.10,0.25,z);
glTexCoord2f(0.22, 0); glVertex3f(0.17,0.25,z);
glTexCoord2f(0.22, 0.10); glVertex3f(0.17,0.30,z);
glTexCoord2f(0.15, 0.10); glVertex3f(0.10,0.30,z);
glEnd();
glBindTexture(GL_TEXTURE_2D, 0);
}
glBegin(GL_QUADS);
glVertex3f(0,0.75,0);
glVertex3f(0,0.25,0);
glVertex3f(0,0.25,4);
glVertex3f(0,0.75,4);
glEnd();
glBegin(GL_QUADS);
glVertex3f(0.20,0.75,0);
glVertex3f(0.20,0.25,0);
glVertex3f(0.20,0.25,4);
glVertex3f(0.20,0.75,4);
glEnd();
glBegin(GL_QUADS);
glVertex3f(0.10,0.25,0);
glVertex3f(0.10,0.75,0);
glVertex3f(0.10,0.75,4);
glVertex3f(0.10,0.25,4);
glEnd();
glBegin(GL_QUADS);
glVertex3f(0.17,0.25,0);
glVertex3f(0.17,0.75,0);
glVertex3f(0.17,0.75,4);
glVertex3f(0.17,0.25,4);
glEnd();
glBegin(GL_QUADS);
glVertex3f(0,0.25,0);/////////
glVertex3f(0,0.25,4);
glVertex3f(0.20,0.25,4);
glVertex3f(0.20,0.25,0);
glEnd();
glBegin(GL_QUADS);
glVertex3f(0.10,0.30,0);
glVertex3f(0.10,0.30,4);
glVertex3f(0.17,0.30,4);
glVertex3f(0.17,0.30,0);
glEnd();
glBegin(GL_QUADS);
glVertex3f(0.10,0.65,0);
glVertex3f(0.10,0.65,4);
glVertex3f(0.17,0.65,4);
glVertex3f(0.17,0.65,0);
glEnd();
glBegin(GL_QUADS);
glVertex3f(0.10,0.75,0);
glVertex3f(0.10,0.75,4);
glVertex3f(0.17,0.75,4);
glVertex3f(0.17,0.75,0);
glEnd();
}

void A(float z){

glBindTexture(GL_TEXTURE_2D, texName2);
glBegin(GL_QUADS);
glTexCoord2f(0.28, 0.0); glVertex3f(0.23,0.25,z);
glTexCoord2f(0.30, 0.0); glVertex3f(0.25,0.25,z);
glTexCoord2f(0.38, 1.0); glVertex3f(0.33,0.75,z);
glTexCoord2f(0.35, 1.0); glVertex3f(0.30,0.75,z);
glEnd();
glBindTexture(GL_TEXTURE_2D, 0);

glBindTexture(GL_TEXTURE_2D, texName2);
glBegin(GL_QUADS);
glTexCoord2f(0.42, 0.0); glVertex3f(0.38,0.25,z);
glTexCoord2f(0.45, 0.0); glVertex3f(0.40,0.25,z);
glTexCoord2f(0.38, 1.0); glVertex3f(0.33,0.75,z);
glTexCoord2f(0.35, 1.0); glVertex3f(0.30,0.75,z);
glEnd();
glBindTexture(GL_TEXTURE_2D, 0);

glBindTexture(GL_TEXTURE_2D, texName2);
glBegin(GL_QUADS);
glTexCoord2f(0.30, 0.1); glVertex3f(0.25,0.29,z);
glTexCoord2f(0.43, 0.1); glVertex3f(0.38,0.29,z);
glTexCoord2f(0.43, 0.2); glVertex3f(0.38,0.34,z);
glTexCoord2f(0.30, 0.2); glVertex3f(0.25,0.34,z);
glEnd();
glBindTexture(GL_TEXTURE_2D, 0);

glBegin(GL_QUADS);
glVertex3f(0.23,0.25,0);
glVertex3f(0.30,0.75,0);
glVertex3f(0.30,0.75,4);
glVertex3f(0.23,0.25,4);
glEnd();

glBegin(GL_QUADS);
glVertex3f(0.40,0.25,0);
glVertex3f(0.33,0.75,0);
glVertex3f(0.33,0.75,4);
glVertex3f(0.40,0.25,4);
glEnd();
glBegin(GL_QUADS);
glVertex3f(0.25,0.25,0);
glVertex3f(0.33,0.75,0);
glVertex3f(0.33,0.75,4);
glVertex3f(0.25,0.25,4);
glEnd();

glBegin(GL_QUADS);
glVertex3f(0.40,0.25,0);
glVertex3f(0.33,0.75,0);
glVertex3f(0.33,0.75,4);
glVertex3f(0.40,0.25,4);
glEnd();

////////
glBegin(GL_QUADS);
glVertex3f(0.23,0.25,0);
glVertex3f(0.23,0.25,4);
glVertex3f(0.25,0.25,4);
glVertex3f(0.25,0.25,0);
glEnd();

glBegin(GL_QUADS);
glVertex3f(0.38,0.25,0);
glVertex3f(0.38,0.25,4);
glVertex3f(0.40,0.25,4);
glVertex3f(0.40,0.25,0);
glEnd();

glBegin(GL_QUADS);
glVertex3f(0.30,0.75,0);
glVertex3f(0.33,0.75,0);
glVertex3f(0.33,0.75,4);
glVertex3f(0.30,0.75,4);
glEnd();

glBegin(GL_QUADS);
glVertex3f(0.25,0.29,0);
glVertex3f(0.38,0.29,0);
glVertex3f(0.38,0.29,4);
glVertex3f(0.25,0.29,4);
glEnd();

glBegin(GL_QUADS);
glVertex3f(0.25,0.34,0);
glVertex3f(0.38,0.34,0);
glVertex3f(0.38,0.34,4);
glVertex3f(0.25,0.34,4);
glEnd();

}


void N(float z){
glBindTexture(GL_TEXTURE_2D, texName2);
glBegin(GL_QUADS);
glTexCoord2f(0.50, 0.0); glVertex3f(0.45,0.25,z);
glTexCoord2f(0.50, 0.0); glVertex3f(0.45,0.75,z);
glTexCoord2f(0.48, 0.0); glVertex3f(0.43,0.75,z);
glTexCoord2f(0.8, 0.0); glVertex3f(0.43,0.25,z);
glEnd();
glBindTexture(GL_TEXTURE_2D, 0);

glBindTexture(GL_TEXTURE_2D, texName2);
glBegin(GL_QUADS);
glTexCoord2f(0.61, 0.0); glVertex3f(0.56,0.25,z);
glTexCoord2f(0.64, 0.0); glVertex3f(0.59,0.25,z);
glTexCoord2f(0.64, 0.0); glVertex3f(0.59,0.75,z);
glTexCoord2f(0.61, 0.0); glVertex3f(0.56,0.75,z);
glEnd();
glBindTexture(GL_TEXTURE_2D, 0);

glBindTexture(GL_TEXTURE_2D, texName2);
glBegin(GL_QUADS);
glTexCoord2f(0.61, 0.0); glVertex3f(0.56,0.25,z);
glTexCoord2f(0.61, 0.0); glVertex3f(0.56,0.28,z);
glTexCoord2f(0.50, 0.0); glVertex3f(0.45,0.75,z);
glTexCoord2f(0.50, 0.0); glVertex3f(0.45,0.72,z);
glEnd();
glBindTexture(GL_TEXTURE_2D, 0);

glBegin(GL_QUADS);
glVertex3f(0.43,0.25,0);
glVertex3f(0.43,0.25,4);
glVertex3f(0.43,0.75,4);
glVertex3f(0.43,0.75,0);
glEnd();

glBegin(GL_QUADS);
glVertex3f(0.59,0.25,4);
glVertex3f(0.59,0.25,0);
glVertex3f(0.59,0.75,0);
glVertex3f(0.59,0.75,4);
glEnd();

glBegin(GL_QUADS);
glVertex3f(0.45,0.25,0);
glVertex3f(0.45,0.25,4);
glVertex3f(0.45,0.75,4);
glVertex3f(0.45,0.75,0);
glEnd();
glBegin(GL_QUADS);
glVertex3f(0.56,0.25,0);
glVertex3f(0.56,0.25,4);
glVertex3f(0.56,0.75,4);
glVertex3f(0.56,0.75,0);
glEnd();
glBegin(GL_QUADS);
glVertex3f(0.56,0.28,0);
glVertex3f(0.56,0.28,4);
glVertex3f(0.45,0.75,4);
glVertex3f(0.45,0.75,0);
glEnd();
glBegin(GL_QUADS);
glVertex3f(0.56,0.25,0);
glVertex3f(0.56,0.25,4);
glVertex3f(0.45,0.72,4);
glVertex3f(0.45,0.72,0);
glEnd();
//////
glBegin(GL_QUADS);
glVertex3f(0.43,0.25,0);
glVertex3f(0.43,0.25,4);
glVertex3f(0.45,0.25,4);
glVertex3f(0.45,0.25,0);
glEnd();
glBegin(GL_QUADS);
glVertex3f(0.56,0.25,0);
glVertex3f(0.56,0.25,4);
glVertex3f(0.59,0.25,4);
glVertex3f(0.59,0.25,0);
glEnd();
glBegin(GL_QUADS);
glVertex3f(0.43,0.75,0);
glVertex3f(0.43,0.75,4);
glVertex3f(0.45,0.75,4);
glVertex3f(0.45,0.75,0);
glEnd();
glBegin(GL_QUADS);
glVertex3f(0.56,0.75,0);
glVertex3f(0.56,0.75,4);
glVertex3f(0.59,0.75,4);
glVertex3f(0.59,0.75,0);
glEnd();
}


void I(float z){
glBindTexture(GL_TEXTURE_2D, texName2);
glBegin(GL_QUADS);
glTexCoord2f(0.66, 0.0); glVertex3f(0.62,0.25,z);
glTexCoord2f(0.71, 0.0); glVertex3f(0.66,0.25,z);
glTexCoord2f(0.71, 0.0); glVertex3f(0.66,0.75,z);
glTexCoord2f(0.66, 0.0); glVertex3f(0.62,0.75,z);
glEnd();
glBindTexture(GL_TEXTURE_2D, 0);

glBegin(GL_QUADS);
glVertex3f(0.62,0.25,0);
glVertex3f(0.62,0.25,4);
glVertex3f(0.62,0.75,4);
glVertex3f(0.62,0.75,0);
glEnd();

glBegin(GL_QUADS);
glVertex3f(0.66,0.25,0);
glVertex3f(0.66,0.25,4);
glVertex3f(0.66,0.75,4);
glVertex3f(0.66,0.75,0);
glEnd();

glBegin(GL_QUADS);////
glVertex3f(0.62,0.25,0);
glVertex3f(0.66,0.25,0);
glVertex3f(0.66,0.25,4);
glVertex3f(0.62,0.25,4);
glEnd();

glBegin(GL_QUADS);
glVertex3f(0.62,0.75,0);
glVertex3f(0.66,0.75,0);
glVertex3f(0.66,0.75,4);
glVertex3f(0.62,0.75,4);
glEnd();

}


void E(float z){
glBindTexture(GL_TEXTURE_2D, texName2);
glBegin(GL_QUADS);
glTexCoord2f(0.77, 0.0); glVertex3f(0.72,0.25,z);
glTexCoord2f(0.77, 0.0); glVertex3f(0.72,0.75,z);
glTexCoord2f(0.74, 0.0); glVertex3f(0.69,0.75,z);
glTexCoord2f(0.74, 0.0); glVertex3f(0.69,0.25,z);
glEnd();
glBindTexture(GL_TEXTURE_2D, 0);

glBindTexture(GL_TEXTURE_2D, texName2);
glBegin(GL_QUADS);
glTexCoord2f(0.77, 0.0); glVertex3f(0.72,0.72,z);
glTexCoord2f(0.83, 0.0); glVertex3f(0.78,0.75,z);
glTexCoord2f(0.83, 0.0); glVertex3f(0.78,0.72,z);
glTexCoord2f(0.77, 0.0); glVertex3f(0.72,0.75,z);
glEnd();
glBindTexture(GL_TEXTURE_2D, 0);

glBindTexture(GL_TEXTURE_2D, texName2);
glBegin(GL_QUADS);
glTexCoord2f(0.83, 0.0); glVertex3f(0.78,0.25,z);
glTexCoord2f(0.83, 0.0); glVertex3f(0.78,0.28,z);
glTexCoord2f(0.77, 0.0); glVertex3f(0.72,0.28,z);
glTexCoord2f(0.77, 0.0); glVertex3f(0.72,0.25,z);
glEnd();
glBindTexture(GL_TEXTURE_2D, 0);

glBindTexture(GL_TEXTURE_2D, texName2);
glBegin(GL_QUADS);
glTexCoord2f(0.83, 0.0); glVertex3f(0.78,0.48,z);
glTexCoord2f(0.83, 0.0); glVertex3f(0.78,0.51,z);
glTexCoord2f(0.77, 0.0); glVertex3f(0.72,0.51,z);
glTexCoord2f(0.77, 0.0); glVertex3f(0.72,0.48,z);
glEnd();
glBindTexture(GL_TEXTURE_2D, 0);

glBegin(GL_QUADS);
glVertex3f(0.69,0.25,0);
glVertex3f(0.69,0.25,4);
glVertex3f(0.69,0.75,4);
glVertex3f(0.69,0.75,0);
glEnd();

glBegin(GL_QUADS);
glVertex3f(0.78,0.75,0);
glVertex3f(0.78,0.72,0);
glVertex3f(0.78,0.72,4);
glVertex3f(0.78,0.75,4);
glEnd();

glBegin(GL_QUADS);
glVertex3f(0.78,0.25,0);
glVertex3f(0.78,0.28,0);
glVertex3f(0.78,0.28,4);
glVertex3f(0.78,0.25,4);
glEnd();

glBegin(GL_QUADS);
glVertex3f(0.78,0.48,0);
glVertex3f(0.78,0.51,0);
glVertex3f(0.78,0.51,4);
glVertex3f(0.78,0.48,4);
glEnd();

glBegin(GL_QUADS);
glVertex3f(0.72,0.25,0);
glVertex3f(0.72,0.25,4);
glVertex3f(0.72,0.75,4);
glVertex3f(0.72,0.75,0);
glEnd();
//////
glBegin(GL_QUADS);
glVertex3f(0.69,0.25,0);
glVertex3f(0.78,0.25,0);
glVertex3f(0.78,0.25,4);
glVertex3f(0.69,0.25,4);
glEnd();

glBegin(GL_QUADS);
glVertex3f(0.69,0.75,0);
glVertex3f(0.78,0.75,0);
glVertex3f(0.78,0.75,4);
glVertex3f(0.69,0.75,4);
glEnd();

glBegin(GL_QUADS);
glVertex3f(0.69,0.48,0);
glVertex3f(0.78,0.48,0);
glVertex3f(0.78,0.48,4);
glVertex3f(0.69,0.48,4);
glEnd();


glBegin(GL_QUADS);
glVertex3f(0.69,0.51,0);
glVertex3f(0.78,0.51,0);
glVertex3f(0.78,0.51,4);
glVertex3f(0.69,0.51,4);
glEnd();

glBegin(GL_QUADS);
glVertex3f(0.69,0.72,0);
glVertex3f(0.78,0.72,0);
glVertex3f(0.78,0.72,4);
glVertex3f(0.69,0.72,4);
glEnd();

glBegin(GL_QUADS);
glVertex3f(0.69,0.28,0);
glVertex3f(0.78,0.28,0);
glVertex3f(0.78,0.28,4);
glVertex3f(0.69,0.28,4);
glEnd();

}


void L(float z){
glBindTexture(GL_TEXTURE_2D, texName2);
glBegin(GL_QUADS);
glTexCoord2f(0.89, 0.0); glVertex3f(0.84,0.25,z);
glTexCoord2f(0.89, 0.0); glVertex3f(0.84,0.75,z);
glTexCoord2f(0.86, 0.0); glVertex3f(0.81,0.75,z);
glTexCoord2f(0.86, 0.0); glVertex3f(0.81,0.25,z);
glEnd();
glBindTexture(GL_TEXTURE_2D, 0);

glBindTexture(GL_TEXTURE_2D, texName2);
glBegin(GL_QUADS); glNormal3f(0,0,1);
glTexCoord2f(0.94, 0.0); glVertex3f(0.89,0.25,z);
glTexCoord2f(0.94, 0.0); glVertex3f(0.89,0.28,z);
glTexCoord2f(0.86, 0.0); glVertex3f(0.81,0.28,z);
glTexCoord2f(0.86, 0.0); glVertex3f(0.81,0.25,z);
glEnd();
glBindTexture(GL_TEXTURE_2D, 0);

glBegin(GL_QUADS);
glVertex3f(0.81,0.25,0);
glVertex3f(0.81,0.75,0);
glVertex3f(0.81,0.75,4);
glVertex3f(0.81,0.25,4);
glEnd();

glBegin(GL_QUADS);
glVertex3f(0.89,0.25,0);
glVertex3f(0.89,0.28,0);
glVertex3f(0.89,0.28,4);
glVertex3f(0.89,0.25,4);
glEnd();

glBegin(GL_QUADS);
glVertex3f(0.84,0.25,0);
glVertex3f(0.84,0.75,0);
glVertex3f(0.84,0.75,4);
glVertex3f(0.84,0.25,4);
glEnd();
/////

glBegin(GL_QUADS);
glVertex3f(0.81,0.75,0);
glVertex3f(0.84,0.75,0);
glVertex3f(0.84,0.75,4);
glVertex3f(0.81,0.75,4);
glEnd();

glBegin(GL_QUADS);
glVertex3f(0.81,0.28,0);
glVertex3f(0.89,0.28,0);
glVertex3f(0.89,0.28,4);
glVertex3f(0.81,0.28,4);
glEnd();
glBegin(GL_QUADS);
glVertex3f(0.81,0.25,0);
glVertex3f(0.81,0.25,4);
glVertex3f(0.89,0.25,4);
glVertex3f(0.89,0.25,0);
glEnd();

}


void kocka (void) // ova e objektot koj go pretstavuva svetloto
{
int i, j;

glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE);
glFrontFace(GL_CW);

glColor3f(1,1,1);
glBegin(GL_QUADS);
glNormal3f(0,0,1); // za sekoj poedinechen poligon mora da se navede vektor
// koj e normalen na ramninata na poligonot, za da se znae
// vo koj pravec se odbiva svetloto
glVertex3f(-10,-10,0);
glVertex3f(10,-10,0);
glVertex3f(10,10,0);
glVertex3f(-10,10,0);

glNormal3f(0,0,-1);
glVertex3f(-10,-10,13);
glVertex3f(-10,10,13);
glVertex3f(10,10,13);
glVertex3f(10,-10,13);

glNormal3f(0,1,0);
glVertex3f(-10,-10,0);
glVertex3f(-10,-10,13);
glVertex3f(10,-10,13);
glVertex3f(10,-10,0);

glNormal3f(-1,0,0);
glVertex3f(10,10,0);
glVertex3f(10,-10,0);
glVertex3f(10,-10,13);
glVertex3f(10,10,13);

glNormal3f(0,-1,0);
glVertex3f(10,10,0);
glVertex3f(10,10,13);
glVertex3f(-10,10,13);
glVertex3f(-10,10,0);

glNormal3f(1,0,0);
glVertex3f(-10,10,0);
glVertex3f(-10,10,13);
glVertex3f(-10,-10,13);
glVertex3f(-10,-10,0);
glEnd();
}

void mrezha10x10 (void) {
glBegin(GL_QUADS);
glNormal3f(0,1,0); // edna zaednichka normala za site chetiriagolnici od mrezhata
int i=0;
int j=0;
for ( i=0; i<10; i++)
{
for ( j=0; j<10; j++)
{
glVertex3f(i, 0,j);
glVertex3f(i+1,0,j);
glVertex3f(i+1,0,j+1);
glVertex3f(i, 0,j+1);
}
}
glEnd();
}

void soba (void)
{
float mat_ambient []={0.1f, 0.1f, 0.1f, 0};
float mat_diffuse []={0.5f, 0.5f, 0.5f, 0};
float mat_specular[]={0.9f, 0.9f, 0.9f, 0};
float mat_shininess = 0.8;
glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, mat_ambient);
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, mat_diffuse);
glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, mat_specular);
glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, mat_shininess);
glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE);
glFrontFace(GL_CW);

// eden po eden zidovite od sobata
glColor3f(0.2,0.2,1);
glPushMatrix();
glTranslatef(-50,-50,-50);
glScalef(10,10,10);
mrezha10x10();
glPopMatrix();

glColor3f(1,0.2,1);
glPushMatrix();
glTranslatef(-50,-50,-50);
glScalef(10,10,10);
glRotatef(-90,1,0,0);
mrezha10x10();
glPopMatrix();

glColor3f(1,0.2,0);
glPushMatrix();
glTranslatef(-50,50,50);
glScalef(10,10,10);
glRotatef(90,1,0,0);
mrezha10x10();
glPopMatrix();

glColor3f(1,0.2,0);
glPushMatrix();
glTranslatef(50,-50,-50);
glScalef(10,10,10);
glRotatef(90,0,0,1);
mrezha10x10();
glPopMatrix();

glColor3f(1,0.2,0);
glPushMatrix();
glTranslatef(-50,50,-50);
glScalef(10,10,10);
glRotatef(-90,0,0,1);
mrezha10x10();
glPopMatrix();

glColor3f(1,0.2,0);
glPushMatrix();
glTranslatef(-50,50,50);
glScalef(10,10,10);
glRotatef(180,1,0,0);
mrezha10x10();
glPopMatrix();
}

void display(void)
{
glPolygonMode(GL_FRONT_AND_BACK,polygonMode);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

glEnable(GL_TEXTURE_2D);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);

//Mestenje pogled
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(0,100,transZ,0,0,0,0,1,0);
glRotatef(rotateA,0,1,0);

// repozicioniranje na svetloto
GLfloat svetlo0_position[]= {-2,60,22,1};
//GLfloat svetlo0_position[]= {svX,svY,svZ,1};
glLightfv(GL_LIGHT0,GL_POSITION,svetlo0_position);

//GLfloat svetlo1_position[]= {2,63,-40,1};
//GLfloat svetlo1_position[]= {svX,svY,svZ,1};
//glLightfv(GL_LIGHT1,GL_POSITION,svetlo1_position);
//crtanje na scenata
glPushMatrix();
glTranslatef(svX,svY,svZ);
glScalef(0.2,0.2,0.2);
kocka();
glPopMatrix();

double amb=0.19225;
double dif=0.50754;
double spec=0.508273;


double pom=amb;
float niza[]={0.19225f,0.19225f,0.19225f,0.0f};

//podloga
glPushMatrix();
glTranslatef(200,0,-20);
glScalef(500,500,500);
glBindTexture(GL_TEXTURE_2D, texName3);
glRotatef(90,0,2,0);//glTranslatef(0,0,0);
glBegin(GL_POLYGON);
glTexCoord2f(0, 0.0); glVertex3f (1, 0,-1);
glTexCoord2f(0, 1.0); glVertex3f (1, 0,1);
glTexCoord2f(1, 1.0); glVertex3f (-1, 0,1);
glTexCoord2f(1, 0.0); glVertex3f (-1, 0,-1);
glEnd();
glBindTexture(GL_TEXTURE_2D, 0);
glPopMatrix();


//zlaten materijal
/*float mat_ambient []={0.24725f, 0.2245f, 0.0645f, 1.0};
float mat_diffuse []={0.34615f, 0.3143f, 0.0903f, 1.0};
float mat_specular[]={0.797357f, 0.723991f, 0.208006f, 1.0};
float mat_shininess = 83.2;
glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, mat_ambient);
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, mat_diffuse);
glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, mat_specular);
glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, mat_shininess);
glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE);
glFrontFace(GL_CW);*/
/* svetlo();
glPushMatrix();
glTranslatef(8,22,0);
glScalef(18,1,1);
glRotatef(-90,0,0,1);
strana1();
glPopMatrix();*/
glScalef(50,50,1);
glTranslatef(-0.5,0,0);
glNormal3f(0,0,-1);
D(0);
glNormal3f(0,0,1);
D(4);
glNormal3f(0,0,-1);
A(0);
glNormal3f(0,0,1);
A(4);
glNormal3f(0,0,-1);
N(0);
glNormal3f(0,0,1);
N(4);
glNormal3f(0,0,-1);
I(0);
glNormal3f(0,0,1);
I(4);
glNormal3f(0,0,-1);
E(0);
glNormal3f(0,0,1);
E(4);
glNormal3f(0,0,-1);
L(0);
glNormal3f(0,0,1);
L(4);
glTranslatef(0.7,0,0);
glNormal3f(0,0,-1);
A(0);
glNormal3f(0,0,1);
A(4);

glFlush();

// smeni buffer
glutSwapBuffers();
}

void init (void)
{
glClearColor(0.1f, 0.1f, 0.1f, 0.0f);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glFrustum(-50, 50, -50, 50, 40, 800);

glShadeModel(GL_SMOOTH);
glEnable(GL_DEPTH_TEST);
glEnable(GL_LIGHTING);
glEnable(GL_COLOR_MATERIAL);
glEnable(GL_NORMALIZE);



// globalno svetlo
/*GLfloat global_ambient[]= {0,0,0,0};
glLightModelfv(GL_LIGHT_MODEL_AMBIENT, global_ambient);
glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_TRUE);
glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE);*/

// Svetlo 1
/*GLfloat svetlo0_ambient[]= {0.3,0.3,0.3,0};
GLfloat svetlo0_diffuse[]= {1.9,1.9,1.9,0};
GLfloat svetlo0_specular[]= {3,3,3,1};
glLightfv(GL_LIGHT0,GL_AMBIENT,svetlo0_ambient);
glLightfv(GL_LIGHT0,GL_DIFFUSE,svetlo0_diffuse);
glLightfv(GL_LIGHT0,GL_SPECULAR,svetlo0_specular);
glEnable(GL_LIGHT0);

GLfloat light1_ambient[] = { 1.0, 0.0, 0.0, 0 };
GLfloat light1_diffuse[] = { 1.9, 0, 0, 0 };
GLfloat light1_specular[] = {3,3,3, 1};
//GLfloat light1_position[] = {17.0,24.0,2.5,1.0};
GLfloat spot_direction[] = { 0.0, -1.0, 0.0 };
glLightfv(GL_LIGHT1, GL_AMBIENT, light1_ambient);
glLightfv(GL_LIGHT1, GL_DIFFUSE, light1_diffuse);
glLightfv(GL_LIGHT1, GL_SPECULAR, light1_specular);
//glLightfv(GL_LIGHT1, GL_POSITION, light1_position);
//glLightf(GL_LIGHT1, GL_CONSTANT_ATTENUATION, 1.5);
//glLightf(GL_LIGHT1, GL_LINEAR_ATTENUATION, 0.5);
//glLightf(GL_LIGHT1, GL_QUADRATIC_ATTENUATION, 0.2);
glLightf(GL_LIGHT1, GL_SPOT_CUTOFF, 30.0);
glLightfv(GL_LIGHT1, GL_SPOT_DIRECTION, spot_direction);
//glLightf(GL_LIGHT1, GL_SPOT_EXPONENT, 2.0);
glEnable(GL_LIGHT1);*/


/*GLfloat svetlo1_ambient[]= {0.1,0.1,0.1,0};
GLfloat svetlo1_diffuse[]= {0.1,0.1,0.1,0};//////////////////////////////
GLfloat svetlo1_specular[]= {0.6,0.6,0.6,1};
glLightfv(GL_LIGHT1,GL_AMBIENT,svetlo1_ambient);
glLightfv(GL_LIGHT1,GL_DIFFUSE,svetlo1_diffuse);
glLightfv(GL_LIGHT1,GL_SPECULAR,svetlo1_specular);
glLightf(GL_LIGHT1, GL_SPOT_CUTOFF, 55.0);
GLfloat spot_direction[] = { 0.0, 5.0, -6.85 };
glLightfv(GL_LIGHT1, GL_SPOT_DIRECTION, spot_direction);
glEnable(GL_LIGHT1);*/


/*GLfloat specular[] = { 1.0f, 1.0f, 1.0f, 1.0f};
GLfloat ambientLight[] = { 0.0f, 0.0f, 0.0f, 1.0f};
GLfloat spotDir[] = { 0.0f, -1.0f, -1.0f };
glLightfv(GL_LIGHT0,GL_DIFFUSE,specular);
glLightfv(GL_LIGHT0,GL_SPECULAR,specular);
glLightfv(GL_LIGHT0,GL_SPOT_DIRECTION, spotDir);
glLightf(GL_LIGHT0,GL_SPOT_CUTOFF,60.0f);
glLightf(GL_LIGHT0,GL_SPOT_EXPONENT,5.0f);
glEnable(GL_LIGHT0);

GLfloat spotDir1[] = { 0.0f, -1.0f, -1.0f };
glLightfv(GL_LIGHT1,GL_DIFFUSE,specular);
glLightfv(GL_LIGHT1,GL_SPECULAR,specular);
glLightfv(GL_LIGHT1,GL_SPOT_DIRECTION, spotDir1);
glLightf(GL_LIGHT1,GL_SPOT_CUTOFF,60.0f);
glLightf(GL_LIGHT1,GL_SPOT_EXPONENT,5.0f);
glEnable(GL_LIGHT1);*/

GLfloat specular[] = { 1.0f, 1.0f, 1.0f, 1.0f};
GLfloat ambientLight[] = { 0.0f, 0.0f, 0.0f, 1.0f};
GLfloat spotDir1[] = { 0.0f, -1.0f, -1.0f };
GLfloat spotDir[] = { 0.0f, -1.0f, -1.0f };
GLfloat global_ambient[]= {0.2,0.2,0.2,1};
glLightfv(GL_LIGHT0,GL_DIFFUSE,specular);
glLightfv(GL_LIGHT0,GL_SPECULAR,specular);
glLightfv(GL_LIGHT0,GL_SPOT_DIRECTION, spotDir);
glLightf(GL_LIGHT0,GL_SPOT_CUTOFF,60.0f);
glLightf(GL_LIGHT0,GL_SPOT_EXPONENT,5.0f);
glEnable(GL_LIGHT0);



//podloga
Image *image1;

image1 = (Image *) malloc(sizeof(Image));
if (image1 == NULL) {
printf("Error allocating space for image");
exit(0);
}

if (!ImageLoad("parket.bmp", image1)) {
exit(1);
}

glGenTextures(1, &amp;texName3);
glBindTexture(GL_TEXTURE_2D, texName3);

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTE R,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTE R,GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, 3, image1->sizeX, image1->sizeY,
0, GL_RGB, GL_UNSIGNED_BYTE, image1->data);



//textura
Image *image2;

image2 = (Image *) malloc(sizeof(Image));
if (image2 == NULL) {
printf("Error allocating space for image");
exit(0);
}

if (!ImageLoad("front.bmp", image2)) {
exit(1);
}

glGenTextures(1, &amp;texName2);
glBindTexture(GL_TEXTURE_2D, texName2);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTE R,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTE R,GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, 3, image2->sizeX, image2->sizeY,
0, GL_RGB, GL_UNSIGNED_BYTE, image2->data);

//textura 3
Image *image3;

image3 = (Image *) malloc(sizeof(Image));
if (image3 == NULL) {
printf("Error allocating space for image");
exit(0);
}

if (!ImageLoad("back.bmp", image3)) {
exit(1);
}

glGenTextures(1, &amp;texName1);
glBindTexture(GL_TEXTURE_2D, texName1);

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTE R,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTE R,GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, 3, image3->sizeX, image3->sizeY,
0, GL_RGB, GL_UNSIGNED_BYTE, image3->data);



}


void keyboard(unsigned char key, int x, int y)
{
printf("%d %f %f %f %f \n", key, svX, svY, svZ, transZ);
switch (key) {
case 27:
exit(0);
break;
case 'W':
transZ+=0.5f;
glutPostRedisplay(); // obnovi go prikazot
break;
case 'S':
transZ-=0.5f;
if (transZ<0) transZ=0;
glutPostRedisplay(); // obnovi go prikazot
break;
case 'w':
transZ+=0.1f;
glutPostRedisplay(); // obnovi go prikazot
break;
case 's':
transZ-=0.1f;
if (transZ<0) transZ=0;
glutPostRedisplay(); // obnovi go prikazot
break;
case 'A':
rotateAspeed+=1.0f;
glutPostRedisplay(); // obnovi go prikazot
break;
case 'a':
rotateAspeed+=0.1f;
glutPostRedisplay(); // obnovi go prikazot
break;
case 'D':
rotateAspeed-=1.0f;
glutPostRedisplay(); // obnovi go prikazot
break;
case 'd':
rotateAspeed-=0.1f;
glutPostRedisplay(); // obnovi go prikazot
break;
case '1':
polygonMode=GL_LINE;
glutPostRedisplay(); // obnovi go prikazot
break;
case '2':
polygonMode=GL_FILL;
glutPostRedisplay(); // obnovi go prikazot
break;
case 'i':
svY+=1.0f;
glutPostRedisplay(); // obnovi go prikazot
break;
case 'k':
svY-=1.0f;
glutPostRedisplay(); // obnovi go prikazot
break;
case 'j':
svX-=1.0f;
glutPostRedisplay(); // obnovi go prikazot
break;
case 'l':
svX+=1.0f;
glutPostRedisplay(); // obnovi go prikazot
break;
case 'y':
svZ+=1.0f;
glutPostRedisplay(); // obnovi go prikazot
break;
case 'h':
svZ-=1.0f;
glutPostRedisplay(); // obnovi go prikazot
break;
}
}

void idle(void)
{
rotateA+=rotateAspeed;
glutPostRedisplay();
}

int main(int argc, char** argv)
{
glutInit(&amp;argc, argv);
glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB);
glutInitWindowSize (450, 350);
glutInitWindowPosition (100, 100);
glutCreateWindow ("Соба со скалила");
init ();
glutDisplayFunc(display);
glutIdleFunc(idle); // ovaa funkcija treba da se povika koga programot ne pravi nishto
glutKeyboardFunc(keyboard); // Pri pritisok na tastaturata se povikuva keboard
glutMainLoop();
return 0;
}


Maybe the problem in the second program is the coordinate system, the x-axis, y-axis and z-axis, maybe they are somehow mixed.
Can someone help me, I'm getting headaches all day with the stupid light.

BionicBytes
06-02-2011, 01:43 AM
I lost the will to live with this post.
The problem is that your code is so unstructured I can't follow what's going on. Secondly, why did you post so much code - most of it is not relevant to the issue you describe - so why post it?

Srcee
06-02-2011, 05:09 AM
Okay, I'll reduce the code but I'm afraid that the error is in the code that i'll delete. However, here it is:

This code works pretty well:
#include <GL/glut.h>
#include <math.h>
const int chekor=9;
float agolX=0;
float agolY=0;
float agolZ=0;
float transZ=80;
float rotateA=0;
float rotateAspeed=0.0f;
int polygonMode=GL_FILL;
float svX=0, svY=0, svZ=10;


void kocka1 (float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4) // ova e objektot koj go pretstavuva svetloto
{
int i, j;
glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE);
glFrontFace(GL_CW);

glColor3f(1,1,1);

glBindTexture(GL_TEXTURE_2D, texName3);
glBegin(GL_QUADS);
glNormal3f(0,0,1);

glTexCoord2f(x1, y1);
glVertex3f(-10,-10,13);

glTexCoord2f(x2, y2);
glVertex3f(-10,10,13);

glTexCoord2f(x3, y3);
glVertex3f(10,10,13);

glTexCoord2f(x4, y4);
glVertex3f(10,-10,13);

glEnd();
glBindTexture(GL_TEXTURE_2D, 0);

glBindTexture(GL_TEXTURE_2D, texName3);
glBegin(GL_QUADS);
glNormal3f(0,0,-1);

glTexCoord2f(x1, y1);
glVertex3f(-10,-10,0);

glTexCoord2f(x4, y4);
glVertex3f(10,-10,0);

glTexCoord2f(x3, y3);
glVertex3f(10,10,0);

glTexCoord2f(x2, y2);
glVertex3f(-10,10,0);
glEnd();
glBindTexture(GL_TEXTURE_2D, 0);

glBegin(GL_QUADS);

glNormal3f(0,1,0);
glVertex3f(-10,-10,0);
glVertex3f(-10,-10,13);
glVertex3f(10,-10,13);
glVertex3f(10,-10,0);

glNormal3f(-1,0,0);
glVertex3f(10,10,0);
glVertex3f(10,-10,0);
glVertex3f(10,-10,13);
glVertex3f(10,10,13);

glNormal3f(0,-1,0);
glVertex3f(10,10,0);
glVertex3f(10,10,13);
glVertex3f(-10,10,13);
glVertex3f(-10,10,0);

glNormal3f(1,0,0);
glVertex3f(-10,10,0);
glVertex3f(-10,10,13);
glVertex3f(-10,-10,13);
glVertex3f(-10,-10,0);
glEnd();
}
void kocka () // ova e objektot koj go pretstavuva svetloto
{
int i, j;
glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE);
glFrontFace(GL_CW);

glColor3f(1,1,1);

glBegin(GL_QUADS);
glNormal3f(0,0,-1);
glVertex3f(-10,-10,0);
glVertex3f(10,-10,0);
glVertex3f(10,10,0);
glVertex3f(-10,10,0);

glNormal3f(0,0,1);
glVertex3f(-10,-10,13);
glVertex3f(-10,10,13);
glVertex3f(10,10,13);
glVertex3f(10,-10,13);

glNormal3f(0,1,0);
glVertex3f(-10,-10,0);
glVertex3f(-10,-10,13);
glVertex3f(10,-10,13);
glVertex3f(10,-10,0);

glNormal3f(-1,0,0);
glVertex3f(10,10,0);
glVertex3f(10,-10,0);
glVertex3f(10,-10,13);
glVertex3f(10,10,13);

glNormal3f(0,-1,0);
glVertex3f(10,10,0);
glVertex3f(10,10,13);
glVertex3f(-10,10,13);
glVertex3f(-10,10,0);

glNormal3f(1,0,0);
glVertex3f(-10,10,0);
glVertex3f(-10,10,13);
glVertex3f(-10,-10,13);
glVertex3f(-10,-10,0);
glEnd();
}

void mrezha10x10 (void) {
glBegin(GL_QUADS);
glNormal3f(0,0,1); // edna zaednichka normala za site chetiriagolnici od mrezhata
int i=0;
int j=0;
for ( i=0; i<10; i++)
{
for ( j=0; j<10; j++)
{
glVertex3f(i, 0,j);
glVertex3f(i+1,0,j);
glVertex3f(i+1,0,j+1);
glVertex3f(i, 0,j+1);
}
}
kocka();
glEnd();
}
void mrezha10x101 (float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4) {
glBegin(GL_QUADS);
glNormal3f(0,0,1); // edna zaednichka normala za site chetiriagolnici od mrezhata
int i=0;
int j=0;
for ( i=0; i<10; i++)
{
for ( j=0; j<10; j++)
{
glVertex3f(i, 0,j);
glVertex3f(i+1,0,j);
glVertex3f(i+1,0,j+1);
glVertex3f(i, 0,j+1);
}
}
kocka1(x1,y1,x2,y2,x3,y3,x4,y4);
glEnd();
}
void bukvi()
{
glPushMatrix();
glTranslatef(-300,-15,-300);
glScalef(6,1,6);

podloga();

glPopMatrix();

float mat_ambient []={0.0f, 0.0f, 0.0f, 0};
float mat_diffuse []={0.0f, 0.0f, 0.0f, 0};
float mat_specular[]={0.0f, 0.0f, 0.0f, 0};
float mat_shininess = 0.9;
glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, mat_ambient);
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, mat_diffuse);
glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, mat_specular);
glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, mat_shininess);
glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE);
glFrontFace(GL_CW);
void display(void)
{
glPolygonMode(GL_FRONT_AND_BACK,polygonMode);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

glEnable(GL_TEXTURE_2D);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);

//Mestenje pogled
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(0,70,transZ,0,0,0,0,1,0);
glRotatef(rotateA,0,1,0);

// repozicioniranje na svetloto
GLfloat svetlo0_position[]= {-2,60,22,1};
//GLfloat svetlo0_position[]= {svX,svY,svZ,1};
glLightfv(GL_LIGHT0,GL_POSITION,svetlo0_position);

bukvi();

glFlush();

// smeni buffer
glutSwapBuffers();
}

void init (void)
{
glClearColor(0.1f, 0.1f, 0.1f, 0.0f);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glFrustum(-50, 50, -50, 50, 40, 1000);

glShadeModel(GL_SMOOTH);
glEnable(GL_DEPTH_TEST);
glEnable(GL_LIGHTING);
glEnable(GL_COLOR_MATERIAL);

// globalno svetlo

GLfloat specular[] = { 1.0f, 1.0f, 1.0f, 1.0f};
GLfloat ambientLight[] = { 0.0f, 0.0f, 0.0f, 1.0f};
GLfloat spotDir1[] = { 0.0f, -1.0f, -1.0f };
GLfloat spotDir[] = { 0.0f, -1.0f, -1.0f };
GLfloat global_ambient[]= {0.2,0.2,0.2,1};
glLightfv(GL_LIGHT0,GL_DIFFUSE,specular);
glLightfv(GL_LIGHT0,GL_SPECULAR,specular);
glLightfv(GL_LIGHT0,GL_SPOT_DIRECTION, spotDir);
glLightf(GL_LIGHT0,GL_SPOT_CUTOFF,60.0f);
glLightf(GL_LIGHT0,GL_SPOT_EXPONENT,5.0f);
glEnable(GL_LIGHT0);

void idle(void)
{
rotateA+=rotateAspeed;
glutPostRedisplay();
}

int main(int argc, char** argv)
{
glutInit(&amp;argc, argv);
glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB);
glutInitWindowSize (450, 350);
glutInitWindowPosition (100, 100);
glutCreateWindow ("Име во 3Д со користење на текстури");
init ();
glutDisplayFunc(display);
glutIdleFunc(idle); // ovaa funkcija treba da se povika koga programot ne pravi nishto
glutKeyboardFunc(keyboard); // Pri pritisok na tastaturata se povikuva keboard
glutMainLoop();
return 0;
}



When I copy the code concerning the light in this code, it doesn't work the same, or at all:

#include <GL/glut.h> //moe
#include <math.h>
const int chekor=9;
float agolX=0;
float agolY=0;
float agolZ=0;
float transZ=70;
float rotateA=0;
float rotateAspeed=0.0f;
int polygonMode=GL_FILL;
float svX=0, svY=0, svZ=10;

void kocka (void) // ova e objektot koj go pretstavuva svetloto
{
int i, j;

glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE);
glFrontFace(GL_CW);

glColor3f(1,1,1);
glBegin(GL_QUADS);
glNormal3f(0,0,1); // za sekoj poedinechen poligon mora da se navede vektor
// koj e normalen na ramninata na poligonot, za da se znae
// vo koj pravec se odbiva svetloto
glVertex3f(-10,-10,0);
glVertex3f(10,-10,0);
glVertex3f(10,10,0);
glVertex3f(-10,10,0);

glNormal3f(0,0,-1);
glVertex3f(-10,-10,13);
glVertex3f(-10,10,13);
glVertex3f(10,10,13);
glVertex3f(10,-10,13);

glNormal3f(0,1,0);
glVertex3f(-10,-10,0);
glVertex3f(-10,-10,13);
glVertex3f(10,-10,13);
glVertex3f(10,-10,0);

glNormal3f(-1,0,0);
glVertex3f(10,10,0);
glVertex3f(10,-10,0);
glVertex3f(10,-10,13);
glVertex3f(10,10,13);

glNormal3f(0,-1,0);
glVertex3f(10,10,0);
glVertex3f(10,10,13);
glVertex3f(-10,10,13);
glVertex3f(-10,10,0);

glNormal3f(1,0,0);
glVertex3f(-10,10,0);
glVertex3f(-10,10,13);
glVertex3f(-10,-10,13);
glVertex3f(-10,-10,0);
glEnd();
}

void mrezha10x10 (void) {
glBegin(GL_QUADS);
glNormal3f(0,1,0); // edna zaednichka normala za site chetiriagolnici od mrezhata
int i=0;
int j=0;
for ( i=0; i<10; i++)
{
for ( j=0; j<10; j++)
{
glVertex3f(i, 0,j);
glVertex3f(i+1,0,j);
glVertex3f(i+1,0,j+1);
glVertex3f(i, 0,j+1);
}
}
glEnd();
}

void display(void)
{
glPolygonMode(GL_FRONT_AND_BACK,polygonMode);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

glEnable(GL_TEXTURE_2D);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);

//Mestenje pogled
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(0,100,transZ,0,0,0,0,1,0);
glRotatef(rotateA,0,1,0);

// repozicioniranje na svetloto
GLfloat svetlo0_position[]= {-2,60,22,1};
//GLfloat svetlo0_position[]= {svX,svY,svZ,1};
glLightfv(GL_LIGHT0,GL_POSITION,svetlo0_position);

//GLfloat svetlo1_position[]= {2,63,-40,1};
//GLfloat svetlo1_position[]= {svX,svY,svZ,1};
//glLightfv(GL_LIGHT1,GL_POSITION,svetlo1_position);
//crtanje na scenata
glPushMatrix();
glTranslatef(svX,svY,svZ);
glScalef(0.2,0.2,0.2);
kocka();
glPopMatrix();

glFlush();

// smeni buffer
glutSwapBuffers();
}



void init (void)
{
glClearColor(0.1f, 0.1f, 0.1f, 0.0f);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glFrustum(-50, 50, -50, 50, 40, 800);

glShadeModel(GL_SMOOTH);
glEnable(GL_DEPTH_TEST);
glEnable(GL_LIGHTING);
glEnable(GL_COLOR_MATERIAL);
glEnable(GL_NORMALIZE);

GLfloat specular[] = { 1.0f, 1.0f, 1.0f, 1.0f};
GLfloat ambientLight[] = { 0.0f, 0.0f, 0.0f, 1.0f};
GLfloat spotDir1[] = { 0.0f, -1.0f, -1.0f };
GLfloat spotDir[] = { 0.0f, -1.0f, -1.0f };
GLfloat global_ambient[]= {0.2,0.2,0.2,1};
glLightfv(GL_LIGHT0,GL_DIFFUSE,specular);
glLightfv(GL_LIGHT0,GL_SPECULAR,specular);
glLightfv(GL_LIGHT0,GL_SPOT_DIRECTION, spotDir);
glLightf(GL_LIGHT0,GL_SPOT_CUTOFF,60.0f);
glLightf(GL_LIGHT0,GL_SPOT_EXPONENT,5.0f);
glEnable(GL_LIGHT0);

}//end of init


void idle(void)
{
rotateA+=rotateAspeed;
glutPostRedisplay();
}

int main(int argc, char** argv)
{
glutInit(&amp;argc, argv);
glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB);
glutInitWindowSize (450, 350);
glutInitWindowPosition (100, 100);
glutCreateWindow ("Соба со скалила");
init ();
glutDisplayFunc(display);
glutIdleFunc(idle); // ovaa funkcija treba da se povika koga programot ne pravi nishto
glutKeyboardFunc(keyboard); // Pri pritisok na tastaturata se povikuva keboard
glutMainLoop();
return 0;
}