Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <windows.h>
- #ifdef __APPLE__
- #include <GLUT/glut.h>
- #else
- #include <GL/glut.h>
- #endif
- #include <math.h>
- #include <stdlib.h>
- #include <iostream>
- #include <time.h>
- using namespace std;
- enum{
- LUSTRO,
- MGLA,
- CIEN,
- };
- static int slices = 16;
- static int stacks = 16;
- double t1 =0.0;
- double t2 =0.0;
- double t3 =0.0;
- GLdouble PI = 3.14;
- GLdouble beta = -PI / 2;
- GLdouble skok_point = 10.0;
- GLdouble skok_eye = 1.0;
- GLdouble eyex=0.0;
- GLdouble eyey=0.0;
- GLdouble eyez=1.0;
- GLdouble pointx = skok_point * cos (beta);
- GLdouble pointy = 0.0;
- GLdouble pointz = skok_point * sin (beta);
- GLdouble fovy =45;
- //GLfloat* fPozycja_swiatla_pod = { 2.0f, 5.0f, 5.0f, 0.0f };
- GLfloat* fPozycja_swiatla;
- GLdouble alfa=1.0;
- int lustro =-1;
- int mgla = -1;
- int cien = -1;
- float g_mgly = 0.2f;
- /* GLUT callback Handlers */
- const GLfloat light_ambient[] = { 0.0f, 0.0f, 0.0f, 1.0f };
- const GLfloat light_diffuse[] = { 1.0f, 1.0f, 1.0f, 1.0f };
- const GLfloat light_specular[] = { 1.0f, 1.0f, 1.0f, 1.0f };
- const GLfloat light_position[] = { 2.0f, 5.0f, 5.0f, 0.0f };
- const GLfloat light_position_under[] = { -2.0f, -5.0f, -5.0f, 0.0f };
- const GLfloat mat_ambient[] = { 0.7f, 0.7f, 0.7f, 1.0f };
- const GLfloat mat_diffuse[] = { 0.8f, 0.8f, 0.8f, 1.0f };
- const GLfloat mat_specular[] = { 1.0f, 1.0f, 1.0f, 1.0f };
- const GLfloat high_shininess[] = { 100.0f };
- static void resize(int width, int height)
- {
- const float ar = (float) width / (float) height;
- glViewport(0, 0, width, height);
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- glFrustum(-ar, ar, -1.0, 1.0, 2.0, 200.0);
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity() ;
- }
- void Podloze()
- {
- glPushMatrix();
- //glColor3d(1,0,0);
- //glTranslated(0,-3,-5);
- //glutSolidCube(5);
- if(lustro==LUSTRO || cien == CIEN){
- glColor4d(1,0,0,0.9);
- }
- else{
- glColor4d(1,0,0,1);
- }
- glTranslated(0,-3,-5);
- glDisable (GL_LIGHTING);
- glEnable (GL_BLEND);
- glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- glutSolidCube(5);
- glDisable (GL_BLEND);
- glEnable (GL_LIGHTING);
- glPopMatrix();
- }
- /*
- void Rys_aktorow(int a)
- {
- glPushMatrix();
- //glColor4d(0,1,0,beta);
- glColor4d(0,1,0,1);
- glTranslated(0,0,-3);
- // glScalef(1.0f, -1.0f, 1.0f).
- // glDisable (GL_LIGHTING);
- // glEnable (GL_BLEND);
- // glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- glutSolidTorus(0.1,0.3,20,20);
- // glDisable (GL_BLEND);
- // glEnable (GL_LIGHTING);
- glPopMatrix();
- }
- */
- /*
- void Rys_aktorow(int a)
- {
- glColor4f (1.0f, 0.0f, 0.0f, 0.4f);
- glDisable (GL_LIGHTING);
- glEnable (GL_BLEND);
- glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- glTranslated(0,0,-3);
- glutSolidCube (0.7f);
- glDisable (GL_BLEND);
- glEnable (GL_LIGHTING);
- }
- */
- void Rys_aktorow(int a)
- {
- if(a == 0)
- {
- glPushMatrix();
- glColor4d(0,1,0,alfa);
- glTranslated(0,0,-3);
- glutSolidTorus(0.1,0.3,20,20);
- glPopMatrix();
- }
- if(a == -1)
- {
- glPushMatrix();
- glColor4d(0,1,0,alfa);
- glTranslated(0,-1,-3);
- glutSolidTorus(0.1,0.3,20,20);
- glPopMatrix();
- }
- if(a == -2)
- {
- glPushMatrix();
- glColor4d(0,0,0,alfa);
- glTranslated(-0.2,-0.6,-3);
- glScaled(0.7,0.1,0.5);
- glutSolidTorus(0.1,0.3,20,20);
- glPopMatrix();
- }
- }
- static void display(void)
- {
- const double t = glutGet(GLUT_ELAPSED_TIME) / 1000.0;
- const double a = t*90.0;
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- glColor3d(1,0,0);
- /*
- if (lustro == LUSTRO)
- {
- glLightfv (GL_LIGHT0, GL_POSITION, light_position_under); // ustawienie światła pod podłogą
- glPushMatrix ();
- glFrontFace (GL_CW); // zmiana domyślnego nawinięcia
- glScalef (1.0f, -1.0f, 1.0f); // przeskalowanie położenia wszystkich aktorów
- Rys_aktorow (0); // narysowanie aktorów pod podłogą
- glFrontFace (GL_CCW); // przywrócenie domyślnego nawinięcia
- glPopMatrix ();
- glDisable (GL_LIGHTING); // wyłączenie oświetlenia
- glEnable (GL_BLEND); // włączenie mieszania kolorów
- glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // równanie mieszania kolorów
- Podloze (); // narysowanie podłogi
- glDisable (GL_BLEND); // wyłączenie mieszania
- glEnable (GL_LIGHTING); // włączenie oświetlenia
- glLightfv (GL_LIGHT0, GL_POSITION, light_position); // ustawienie światła nad podłogą
- Rys_aktorow (0); // narysowanie aktorów nad podłogą
- }
- glPushMatrix();
- glColor4d(0,0,1,1);
- glTranslated(0,-1,-3);
- glutSolidTorus(0.1,0.3,20,20);
- glPopMatrix();
- */
- if(cien == CIEN){
- Rys_aktorow(0);
- Rys_aktorow(-2);
- Podloze();
- }
- if(lustro == LUSTRO)
- {
- Rys_aktorow(0);
- Rys_aktorow(-1);
- Podloze();
- }
- if(lustro != LUSTRO)
- {
- Rys_aktorow (0);
- Podloze ();
- }
- if (mgla == MGLA){
- // ustalenie koloru mgły
- GLfloat Kolor_mgly[] = {0.5, 0.5, 0.5, 1.0};
- // ustawienia parametrów mgły
- glFogfv(GL_FOG_COLOR, Kolor_mgly); // ustawienie koloru mgły
- glFogf(GL_FOG_START, 10.0f); // początek mgły
- glFogf(GL_FOG_END, 100.0f); // koniec mgły
- glFogf(GL_FOG_DENSITY, 0.2f); // gęstość mgły
- glFogf(GL_FOG_MODE, GL_EXP); // rozkład mgły
- glEnable(GL_FOG); // włączeni emgły
- }
- glutSwapBuffers();
- }
- static void key(unsigned char key, int x, int y)
- {
- switch (key)
- {
- case 27 :
- case 'q':
- exit(0);
- break;
- case '+':
- if(alfa<1)
- {
- alfa+=0.1;
- }
- cout<<"ALFA : "<<alfa<<endl;
- break;
- case '-':
- if(alfa>0.1)
- {
- alfa-=0.1;;
- }
- cout<<"ALFA : "<<alfa<<endl;
- break;
- }
- glutPostRedisplay();
- }
- static void idle(void)
- {
- glutPostRedisplay();
- }
- /* Program entry point */
- void Menu(int val)
- {
- switch(val)
- {
- case LUSTRO:
- if(lustro == LUSTRO)
- {
- lustro = -1.0;
- }
- else{
- lustro = LUSTRO;
- }
- break;
- case MGLA:
- if(mgla == MGLA)
- {
- mgla = -1.0;
- glDisable(GL_FOG);
- }
- else{
- mgla = MGLA;
- }
- case CIEN:
- if(cien == CIEN)
- {
- cien = -1.0;
- }
- else{
- cien = CIEN;
- }
- }
- }
- int main(int argc, char *argv[])
- {
- glutInit(&argc, argv);
- glutInitWindowSize(640,480);
- glutInitWindowPosition(10,10);
- glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
- glutCreateWindow("GLUT Shapes");
- glutReshapeFunc(resize);
- glutDisplayFunc(display);
- glutKeyboardFunc(key);
- glutIdleFunc(idle);
- glutCreateMenu (Menu);
- glutAddMenuEntry("ODBICIE LUSTRZANE : ", LUSTRO);
- glutAddMenuEntry("MGŁA: ", MGLA);
- glutAddMenuEntry("CIEN: ", CIEN);
- glutAttachMenu (GLUT_RIGHT_BUTTON);
- glClearColor(1,1,1,1);
- glEnable(GL_CULL_FACE);
- glCullFace(GL_BACK);
- glEnable(GL_DEPTH_TEST);
- //glEnable(GL_BLEND);
- glDepthFunc(GL_LESS);
- //glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- glEnable(GL_LIGHT0);
- glEnable(GL_NORMALIZE);
- glEnable(GL_COLOR_MATERIAL);
- glEnable(GL_LIGHTING);
- glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);
- glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
- glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular);
- glLightfv(GL_LIGHT0, GL_POSITION, light_position);
- glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);
- glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
- glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
- glMaterialfv(GL_FRONT, GL_SHININESS, high_shininess);
- glutMainLoop();
- return EXIT_SUCCESS;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement