void drawScene() { glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glEnable(GL_LIGHT1); glEnable(GL_NORMALIZE); /* GLuint texture = LoadGLTexture("water.bmp", 396, 734); glEnable(GL_TEXTURE_2D); glBindTexture( GL_TEXTURE_2D, texture );*/ //Add ambient light /* GLfloat ambientColor[] = {0.2f, 0.2f, 0.2f, 1.0f}; //Color(0.2, 0.2, 0.2) glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambientColor); //Add positioned light GLfloat lightColor0[] = {0.5f, 0.5f, 0.5f, 1.0f}; //Color (0.5, 0.5, 0.5) GLfloat lightPos0[] = {4.0f, 0.0f, 8.0f, 1.0f}; //Positioned at (4, 0, 8) glLightfv(GL_LIGHT0, GL_DIFFUSE, lightColor0); glLightfv(GL_LIGHT0, GL_POSITION, lightPos0); //Add directed light GLfloat lightColor1[] = {0.5f, 0.2f, 0.2f, 1.0f}; //Color (0.5, 0.2, 0.2) //Coming from the direction (-1, 0.5, 0.5) GLfloat lightPos1[] = {-1.0f, 0.5f, 0.5f, 0.0f}; glLightfv(GL_LIGHT1, GL_DIFFUSE, lightColor1); glLightfv(GL_LIGHT1, GL_POSITION, lightPos1);*/ glRotatef(-0.0, 0.0f, 1.0f, 0.0f); glTranslatef(-4*1.5, 0.0, 4*1.5); //int gifts_x1 = -1, gifts_x2 = -1, gifts_z1 = -1, gifts_z2 = -1; int g=0,h=0,gg=-1,hh=-2,fl1=0,fl2=0,kk=0; int tile_x1=-1,tile_z1=-1; int tile_x2=-1,tile_z2=-1,c*k = 0; int obs_x1=-1,obs_z1=-1,obs_x2=-1,obs_z2=-1; //int gifts_x1=-1,gifts_z1=-1,gifts_x2=-1,gifts_z2=-1; p1.drawtree(-40.0,0.0,-40.0); p1.drawtree(-30.0,0.0,-40.0); p1.drawtree(-20.0,0.0,-40.0); p1.drawtree(-10.0,0.0,-40.0); p1.drawtree(0.0,0.0,-40.0); p1.drawtree(10.0,0.0,-40.0); p1.drawtree(20.0,0.0,-40.0); p1.drawtree(30.0,0.0,-40.0); p1.drawtree(40.0,0.0,-40.0); p1.drawtree(0.0,0.0,0.0); p1.drawtree(12.0,0.0,0.0); glPushMatrix(); glTranslatef(-50*1.5, 0.0, 50*1.5); //change = 10.0f; for(float j=0.0;j>(-100*1.5);j-=1.5) { k++; for(i=0.0;i<(50*3.0);i+=3.0) { glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, x); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,GL_NEAREST); if(k%2==0) { glPushMatrix(); glTranslatef(i,-1.0,j); p1.draw_BlackArea(); //Add commands for drawing a black area to the display list // glCallList(_displayListId_blackArea); glPopMatrix(); } else { glPushMatrix(); glTranslatef(i+1.5,-1.0,j); p1.draw_BlackArea(); //Add commands for drawing a black area to the display list // glCallList(_displayListId_blackArea); glPopMatrix(); } glDisable(GL_TEXTURE_2D); } } for(float j=0.0;j>(-100*1.5);j-=1.5) { k++; for(i=0.0;i<(50*3.0);i+=3.0) { glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, x); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,GL_NEAREST); if(k%2!=0) { glPushMatrix(); glTranslatef(i,-1.0,j); p1.draw_whiteArea(); //Add commands for drawing a black to the display list // glCallList(_displayListId_whiteArea); glPopMatrix(); } else { glPushMatrix(); glTranslatef(i+1.5,-1.0,j); p1.draw_whiteArea(); //Add commands for drawing a black to the display list // glCallList(_displayListId_whiteArea); glPopMatrix(); } glDisable(GL_TEXTURE_2D); } } glPopMatrix(); k=0; change = 1.0; if(mode == 2) { for(float j=0.0;j>(-8*1.5);j-=1.5) { k++;kk++; if(kk%2==0) { fl1 = 1; } if(kk%2==1 && kk>1) c*k =1; for(i=0.0;i<(4*3.0);i+=3.0) { g++; if(fl1 == 1) { fl1=0; gg = gg + 1; } else if(c*k == 1) { c*k = 0; gg = gg +3; } else gg = gg + 2; //if(call_randb == g) //{ tile_x1 = gg%8; tile_z1 = gg/8; //} //else{ if((tile_x1 == sx && tile_z1 == sz && gir == 1) || (sx < 0) || (sx > 7) || (sz < 0) || (sz > 7)) { flag_exit = 1; } else{ glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, grassTextureId); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); if(k%2==0) { if(obs_b == g) { obs_x1=gg%8; obs_z1=gg/8; p1.obstacle(i,j); } glPushMatrix(); glTranslatef(i,0.0,j); glCallList(_displayListId_blackArea); glPopMatrix(); } else { if(obs_b == g) { obs_x1=gg%8; obs_z1=gg/8; p1.obstacle(i+1.5,j); } glPushMatrix(); glTranslatef(i+1.5,0.0,j); glCallList(_displayListId_blackArea); glPopMatrix(); } } //} } } kk=0;int dnt = 0; for(float j=0.0;j>(-8*1.5);j-=1.5) { k++;kk++; if(kk%2==1 && kk>1) { fl2 = 1; } if(kk%2==0) dnt =1; for(i=0.0;i<(4*3.0);i+=3.0) { h++; if(fl2 == 1) { fl2=0; hh = hh + 1; } else if(dnt ==1) { dnt =0; hh = hh +3; } else hh = hh +2; //if(call_randw == h) //{ tile_x2 = hh%8; tile_z2 = hh/8; //} //else{ if( (tile_x2 == sx && tile_z2 == sz && gir == 1) || (sx < 0) || (sx > 7) || (sz < 0) || (sz > 7)) { flag_exit = 1; } else{ glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, grassTextureId); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); if(k%2!=0) { if(obs_w == h) { obs_x2=hh%8; obs_z2=hh/8; p1.obstacle(i,j); } glPushMatrix(); glTranslatef(i,0.0,j); glCallList(_displayListId_whiteArea); glPopMatrix(); } else { if(obs_w == h) { obs_x2=hh%8; obs_z2=hh/8; p1.obstacle(i+1.5,j); } glPushMatrix(); glTranslatef(i+1.5,0.0,j); glCallList(_displayListId_whiteArea); glPopMatrix(); } } //} } } } if(mode == 1) { for(float j=0.0;j>(-8*1.5);j-=1.5) { k++;kk++; if(kk%2==0) { fl1 = 1; // printf("-------------in----------\n"); } if(kk%2==1 && kk>1) c*k =1; for(i=0.0;i<(4*3.0);i+=3.0) { g++; if(fl1 == 1) { fl1=0; gg = gg + 1; } else if(c*k == 1) { c*k = 0; gg = gg +3; } else gg = gg + 2; // printf("gg: %d\n", gg); if(call_randb == g) { // printf("------------------GG is %d\n",gg); tile_x1 = gg%8; tile_z1 = gg/8; } else{ glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, grassTextureId); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); // tile_x1 = gg%8; // tile_z1 = gg/8; if(k%2==0) { if(obs_b == g) { obs_x1=gg%8; obs_z1=gg/8; p1.obstacle(i,j); } /* if(gift_b == g) { gifts_x1=gg%8; gifts_z1=gg/8; p1.gifts(i,j); }*/ glPushMatrix(); glTranslatef(i,0.0,j); glCallList(_displayListId_blackArea); glPopMatrix(); } else { if(obs_b == g) { obs_x1=gg%8; obs_z1=gg/8; p1.obstacle(i+1.5,j); } /*if(gift_b == g) { gifts_x1=gg%8; gifts_z1=gg/8; p1.gifts(i+1.5,j); }*/ glPushMatrix(); glTranslatef(i+1.5,0.0,j); glCallList(_displayListId_blackArea); glPopMatrix(); } } } } kk=0;int dnt = 0; for(float j=0.0;j>(-8*1.5);j-=1.5) { k++;kk++; if(kk%2==1 && kk>1) { fl2 = 1; // printf("---------------in----------------\n"); } if(kk%2==0) dnt =1; for(i=0.0;i<(4*3.0);i+=3.0) { h++; if(fl2 == 1) { fl2=0; hh = hh + 1; } else if(dnt ==1) { dnt =0; hh = hh +3; } else hh = hh +2; // printf("hh:%d\n",hh); if(call_randw == h) { // printf("------------------HH is %d\n",hh); tile_x2 = hh%8; tile_z2 = hh/8; } else{ glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, grassTextureId); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); // tile_x2 = hh%8; // tile_z2 = hh/8; if(k%2!=0) { if(obs_w == h) { obs_x2=hh%8; obs_z2=hh/8; p1.obstacle(i,j); } /*if(gift_w == h) { gifts_x2=hh%8; gifts_z2=hh/8; p1.gifts(i,j); }*/ glPushMatrix(); glTranslatef(i,0.0,j); glCallList(_displayListId_whiteArea); glPopMatrix(); } else { if(obs_w == h) { obs_x2=hh%8; obs_z2=hh/8; p1.obstacle(i+1.5,j); } /*if(gift_w == h) { gifts_x2=hh%8; gifts_z2=hh/8; p1.gifts(i+1.5,j); }*/ glPushMatrix(); glTranslatef(i+1.5,0.0,j); glCallList(_displayListId_whiteArea); glPopMatrix(); } } } } } else if(mode == 0) { for(float j=0.0;j>(-8*1.5);j-=1.5) { k++; for(i=0.0;i<(4*3.0);i+=3.0) { glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, grassTextureId); //Bottom glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); if(k%2==0) { glPushMatrix(); glTranslatef(i,0.0,j); glCallList(_displayListId_blackArea); glPopMatrix(); } else { glPushMatrix(); glTranslatef(i+1.5,0.0,j); glCallList(_displayListId_blackArea); glPopMatrix(); } } } for(float j=0.0;j>(-8*1.5);j-=1.5) { k++; for(i=0.0;i<(4*3.0);i+=3.0) { glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, grassTextureId); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); if(k%2!=0) { glPushMatrix(); glTranslatef(i,0.0,j); glCallList(_displayListId_whiteArea); glPopMatrix(); } else { glPushMatrix(); glTranslatef(i+1.5,0.0,j); glCallList(_displayListId_whiteArea); glPopMatrix(); } } } } if(mode == 0 || mode ==1) { if((tile_x1 == sx && tile_z1 == sz) ||( tile_x2 == sx && tile_z2 == sz) || (sx < 0) || (sx > 7) || (sz < 0) || (sz > 7)) { flag_exit = 1; } if((sx == obs_x1 && sz == obs_z1) || (sx == obs_x2 && sz == obs_z2)) { printf("You are DEAD !!!\nLOL!!!!!\n"); exit(0); } } glPushMatrix(); glTranslatef(0.0f, 0.0f, -5.0f); // Push eveything 5 units back into the scene, otherwise we won't see the primitive gluLookAt (0.0, 0.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0); p1.drawPerson(); //p1.obstacle(); //p1.gifts(1,1); glPopMatrix(); glutSwapBuffers(); angle++; }
void initRendering() { /* glDisable(GL_LIGHTING); glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, x); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glDisable(GL_NORMALIZE); glEnable(GL_BLEND); glColor4f(1, 1, 1, WATER_ALPHA); glNormal3f(0, 1, 0); glBegin(GL_QUADS); glTexCoord2f(200 / WATER_TEXTURE_SIZE, -waterTextureOffset / WATER_TEXTURE_SIZE); glVertex3f(-100, 0, -100); glTexCoord2f(200 / WATER_TEXTURE_SIZE, (200 - waterTextureOffset) / WATER_TEXTURE_SIZE); glVertex3f(-100, 0, 100); glTexCoord2f(0, (200 - waterTextureOffset) / WATER_TEXTURE_SIZE); glVertex3f(100, 0, 100); glTexCoord2f(0, -waterTextureOffset / WATER_TEXTURE_SIZE); glVertex3f(100, 0, -100); glEnd(); glDisable(GL_BLEND); glEnable(GL_LIGHTING); */ glEnable(GL_DEPTH_TEST); glEnable(GL_COLOR_MATERIAL); glClearColor(0.0f,0.0f,0.2f,1.0f); Image* image = loadBMP("images.bmp"); grassTextureId = loadTexture(image); Image* image1 = loadBMP("fire2.bmp"); x = loadTexture(image1); //Set up a display list for drawing a cube _displayListId_blackArea = glGenLists(1); // Make room for the display list glNewList(_displayListId_blackArea, GL_COMPILE); // Begin the display list change = 1.0f; p1.draw_BlackArea(); //Add commands for drawing a black area to the display list glEndList(); //End the display list //Set up a display list for drawing a cube _displayListId_whiteArea = glGenLists(2); //Make room for the display list glNewList(_displayListId_whiteArea, GL_COMPILE); //Begin the display list p1.draw_whiteArea(); //Add commands for drawing a black to the display list glEndList(); //End the display list // To uncomment later GLfloat sun_direction[] = { 0.0, 2.0, -1.0, 1.0 }; GLfloat sun_intensity[] = { 0.7, 0.7, 0.7, 1.0 }; GLfloat ambient_intensity[] = { 0.3, 0.3, 0.3, 1.0 }; glEnable(GL_DEPTH_TEST); // Enable objects to be drawn ahead/behind one another glEnable(GL_COLOR_MATERIAL); // Enable coloring glClearColor(0.0f, 0.0f, 1.0f, 1.0f); // Setting a background color glEnable(GL_LIGHTING); // Set up ambient light. glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambient_intensity); glEnable(GL_LIGHT0); // Set up sunlight. glLightfv(GL_LIGHT0, GL_POSITION, sun_direction); glLightfv(GL_LIGHT0, GL_DIFFUSE, sun_intensity); glEnable(GL_COLOR_MATERIAL); // Configure glColor(). glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE); delete image; delete image1; }