Search Results

Search found 53 results on 3 pages for 'ambiance'.

Page 3/3 | < Previous Page | 1 2 3 

  • The program is executing properly on dev C++ but is giving problem in Linux.The movement is becoming

    - by srinija
    #include<stdio.h> #include<GL/glut.h> GLfloat v[3][24]={{100.0,300.0,350.0,50.0,100.0,120.0,120.0,100.0,260.0,280.0, 280.0,260.0,140.0,160.0,160.0,140.0,180.0,200.0,200.0,180.0, 220.0,240.0,240.0,220.0},{100.0,100.0,200.0,200.0,160.0, 160.0,180.0,180.0,160.0,160.0,180.0,180.0,160.0,160.0,180.0, 180.0,160.0,160.0,180.0,180.0,160.0,160.0,180.0,180.0}, {1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0, 1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0}}; GLfloat v1[3][16]={{50.0,350.0,350.0,50.0,100.0,300.0,300.0,100.0,125.0,175.0, 175.0,125.0,225.0,275.0,275.0,225.0},{200.0,200.0,210.0, 210.0,210.0,210.0,240.0,240.0,240.0,240.0,310.0,310.0,240.0, 240.0,310.0,310.0},{1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0, 1.0,1.0,1.0,1.0,1.0,1.0}}; GLfloat colors[4][3]={{0.0,0.0,1.0},{0.9961,0.9961,0.65625},{1.0,0.0,1.0}, {1.0,.0,1.0}}; static float q,w,e; static float fq,fw,fe; static GLfloat wa=0,wb=0,wc=0,ba,bb,bc; int flag; void myinit(void) { glClearColor(0.506,.7,1,0.0); glPointSize(2.0); glLoadIdentity(); glOrtho(0.0,499.0,0.0,499.0,-300.0,300.0); } void draw_top_boxes(GLint i,GLint j) { glColor3f(1.0,0.0,0.0); glBegin(GL_POLYGON); glColor3fv(colors[j]); // to draw the boat glVertex2f(v1[0][i+0],v1[1][i+0]); glColor3fv(colors[j+1]); glVertex2f(v1[0][i+1],v1[1][i+1]); glColor3fv(colors[j+2]); glVertex2f(v1[0][i+2],v1[1][i+2]); glColor3fv(colors[j+3]); glVertex2f(v1[0][i+3],v1[1][i+3]); glEnd(); } void draw_polygon(GLint i) { glBegin(GL_POLYGON); // to draw the boat glColor3f(0.0,0.0,0.0); glColor3fv(colors[0]); glVertex2f(v[0][i+0],v[1][i+0]); glColor3fv(colors[1]); glVertex2f(v[0][i+1],v[1][i+1]); glColor3fv(colors[2]); glVertex2f(v[0][i+2],v[1][i+2]); glColor3fv(colors[3]); glVertex2f(v[0][i+3],v[1][i+3]); glEnd(); } void draw_boat() { draw_polygon(0); draw_polygon(4); draw_polygon(8); draw_polygon(12); draw_polygon(16); draw_polygon(20); draw_top_boxes(0,0); draw_top_boxes(4,0); draw_top_boxes(8,0); draw_top_boxes(12,0); glFlush(); glPopMatrix(); glPopMatrix(); } void draw_water() { GLfloat i; GLfloat x=0,y=103,j=0; GLfloat k; glPushMatrix(); glTranslatef(wa,wb,wc); glPushMatrix(); glColor3f(0,0,1); for(k=y;k>0;k-=6) { for(i=1;i<30;i++) { glBegin(GL_LINES); glVertex2f(j,k); glVertex2f(j+10,k); glEnd(); j=j+20; } j=0; } glPopMatrix(); glPopMatrix(); } void draw_fishes() { glPushMatrix(); glTranslatef(fq,12.0,fe); glPushMatrix(); glColor3f(.99609375,0.2578125,0.2578125); glBegin(GL_TRIANGLES); glVertex2f(100,80); glVertex2f(100,60); glVertex2f(85,70); glEnd(); glColor3f(.99609375,0.2578125,0.2578125); glBegin(GL_TRIANGLES); glVertex2f(100,70); glVertex2f(110,75); glVertex2f(110,65); glEnd(); glColor3f(0,0,0); glBegin(GL_POINTS); glVertex2f(90,71); glEnd(); glColor3f(.99609375,0.2578125,0.2578125); glBegin(GL_TRIANGLES); glVertex2f(200,80); glVertex2f(200,60); glVertex2f(185,70); glEnd(); glColor3f(.99609375,0.2578125,0.2578125); glBegin(GL_TRIANGLES); glVertex2f(200,70); glVertex2f(210,75); glVertex2f(210,65); glEnd(); glColor3f(0,0,0); glBegin(GL_POINTS); glVertex2f(190,71); glEnd(); glPopMatrix(); glPopMatrix(); glFlush(); } void draw_cloud() { GLfloat m=100,n=400,o=10; for(int i=0;i<7;i++) { glPushMatrix(); glColor3f(1.0,1.0,1.0); if(i==1) glTranslated(125,415,10); else if(i==3||i==5) glTranslated(m,n+5,o); else glTranslated(m,n,o); glutSolidSphere(20.0,5000,150); glPopMatrix(); m+=10; } } void draw_square() { glColor3f(0,0.5,0.996); glBegin(GL_POLYGON); glVertex2f(0,0); glVertex2f(1000,0); glVertex2f(0,300); glVertex2f(1000,300); glEnd(); glFlush(); } void draw_brotate() { glPushMatrix(); glColor3f(0.96,0.5,0.25); //to draw body of the bird glTranslated(300,400,10); glScalef(3,1,1); glutSolidSphere(6,50000,15); glPopMatrix(); glPushMatrix(); glTranslated(323,400,10); glutSolidSphere(5,50000,15); glPopMatrix(); glColor3f(0,0,0); glBegin(GL_POINTS); glVertex2f(325,401); glEnd(); glColor3f(0.96,0.5,0.25); //to draw wings glBegin(GL_LINES); glVertex2f(294,394); glVertex2f(286,389); glEnd(); glBegin(GL_LINES); glVertex2f(286,389); glVertex2f(295,391); glEnd(); glBegin(GL_LINES); glVertex2f(295,391); glVertex2f(285,385); glEnd(); glBegin(GL_LINES); glVertex2f(285,385); glVertex2f(309,395); glEnd(); glBegin(GL_LINES); glVertex2f(294,406); glVertex2f(286,411); glEnd(); glBegin(GL_LINES); glVertex2f(286,411); glVertex2f(295,409); glEnd(); glBegin(GL_LINES); glVertex2f(295,409); glVertex2f(285,415); glEnd(); glBegin(GL_LINES); glVertex2f(285,415); glVertex2f(309,406); glEnd(); glColor3f(0.96,0.5,0.25); } void draw_bird() { GLfloat x=200,y=400,z=10; draw_brotate(); glBegin(GL_LINES); //draw legs of the bird glVertex2f(285,402); glVertex2f(275,402); glEnd(); glBegin(GL_LINES); glVertex2f(285,398); glVertex2f(275,398); glEnd(); glBegin(GL_LINES); glVertex2f(275,402); glVertex2f(270,405); glEnd(); glBegin(GL_LINES); glVertex2f(275,402); glVertex2f(270,398); glEnd(); glBegin(GL_LINES); glVertex2f(275,398); glVertex2f(273,400); glEnd(); glBegin(GL_LINES); glVertex2f(275,398); glVertex2f(270,395); glEnd(); glBegin(GL_LINES); glVertex2f(323,405); glVertex2f(323,407); glEnd(); glPushMatrix(); glTranslatef(323,409,10); glutSolidSphere(2,200,20); glPopMatrix(); glBegin(GL_TRIANGLES); glVertex2f(328,400); glVertex2f(331,397); glVertex2f(327,398.5); glEnd(); glFlush(); } void drawstars() { glColor3f(1.0,1.0,1.0); glBegin(GL_POINTS); glVertex3f(300.0,400.0,10.0); glVertex3f(200,400.0,10.0); glVertex3f(150,450.0,10.0); glVertex3f(100,470.0,10.0); glVertex3f(50,450.0,10.0); glVertex3f(50,350.0,10.0); glVertex3f(90,365.0,10.0); glVertex3f(350,450.0,10.0); glVertex3f(275,470.0,10.0); glVertex3f(280,430.0,10.0); glVertex3f(250,400.0,10.0); glVertex3f(450,450.0,10.0); glVertex3f(430,430.0,10.0); glVertex3f(430,470.0,10.0); glVertex3f(300,450.0,10.0); glVertex3f(265,380.0,10.0); glVertex3f(235,450.0,10.0); glEnd(); } void draw_all() { glClear(GL_COLOR_BUFFER_BIT); if(flag==0) { glDisable(GL_LIGHTING); //immp one draw_square(); draw_cloud(); glClearColor(0.506,.7,1,0.0); glTranslatef(q,w,e); glPushMatrix(); glColor3f(1.0,0.0,0.0); draw_boat(); draw_fishes(); glPushMatrix(); glColor3f(1.0,1.0,0.0); glTranslated(400,400,10); glutSolidSphere(20.0,5000,150); glPopMatrix(); } if(flag==1) { glDisable(GL_LIGHTING); //imp one draw_square(); draw_cloud(); glClearColor(0.9960,0.7070,0.3164,0.0); glTranslatef(q,w,e); glPushMatrix(); glColor3f(1.0,0.0,0.0); draw_boat(); draw_fishes(); glPushMatrix(); glColor3f(1.0,1.0,0.0); glTranslated(400,400,10); glutSolidSphere(20.0,500,100); glPopMatrix(); } if(flag==2) { // just try and change values in these arrays, specially the position array drawstars(); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); // GLfloat emission[]={0.1,0.1,0.1,0.0}; GLfloat diffuse[] = { 0.40, 0.40,0.40, 1.0 }; GLfloat ambiance[] = { 0.5, 0.5,0.5, 1.0 }; GLfloat specular[] = { 1.3, 1.3,.3, 1.0 }; GLfloat intensity[]={500.0}; GLfloat position[] = { 10,30,-30,1.0 }; glLightfv (GL_LIGHT0, GL_POSITION, position); glLightfv (GL_LIGHT0, GL_DIFFUSE,diffuse); glLightfv (GL_LIGHT0, GL_AMBIENT,ambiance); glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER,GL_TRUE); glLightfv (GL_LIGHT0, GL_SPECULAR,specular); glLightfv (GL_LIGHT0, GL_INTENSITY,intensity); glColor3f(0,0.5,0.996); glBegin(GL_POLYGON); glVertex2f(0,0); glVertex2f(1000,0); glVertex2f(0,150); glVertex2f(1000,150); glEnd(); glTranslatef(q,w,e); glPushMatrix(); glColor3f(1.0,0.0,0.0); draw_boat(); draw_fishes(); glDisable(GL_LIGHTING); glDisable(GL_LIGHT0); draw_cloud(); glClearColor(0.0,0.0,0.0,0.0); glPushMatrix(); glColor3f(1.0,1.0,1.0); glTranslated(400,400,10); glutSolidSphere(20.0,500,100); glPopMatrix(); glColor3f(1.0,1.0,1.0); glBegin(GL_POINTS); glVertex3f(300.0,400.0,10.0); glEnd(); } glPushMatrix(); glTranslatef(ba,bb,bc); glPushMatrix(); draw_bird(); glPopMatrix(); glPopMatrix(); GLfloat i; glPushMatrix(); GLfloat x=0,y=100,j=0; int k; //draw_water(); Sleep(60); q+=5; fq-=3.5; if(q>=440.0) //470 q=-390.0; //400 if(fq<=-300) //500 fq=400.0; //400 wa-=1; if(wa<=(-20)) wa=-0.5; ba+=6; if(ba>=500) ba=-400; glFlush(); glutSwapBuffers(); } void display(void) { draw_all(); } void color_menu(int id) { switch(id) { case 1: flag=0;break; case 2: flag=1;break; case 3: flag=2;break; case 4: exit(0); break; } glutPostRedisplay(); } void main_menu(int id) { switch(id) { case 1: break; case 2:exit(0);break; glutPostRedisplay(); } } int main(int argc,char **argv) { int sub_menu; glutInit(&argc,argv); glutInitDisplayMode(GLUT_RGB|GLUT_DOUBLE); glutInitWindowSize(1000,1000); glutInitWindowPosition(0,0); glutCreateWindow("Ship"); sub_menu=glutCreateMenu(color_menu); glutAddMenuEntry("Morning",1); glutAddMenuEntry("Evening",2); glutAddMenuEntry("Night",3); glutAddMenuEntry("Quit",4); glutCreateMenu(main_menu); glutAddSubMenu("View",sub_menu); glutAddMenuEntry("Quit",2); glutAttachMenu(GLUT_RIGHT_BUTTON); glutDisplayFunc(display); glutIdleFunc(display); myinit(); glutMainLoop(); glFlush(); }

    Read the article

  • This code is working properly in Dev C++ .But on Linux platform it is giving problem with the moveme

    - by srinija
    #include<stdio.h> #include<GL/glut.h> #include<stdlib.h> GLfloat v[3][24]={{100.0,300.0,350.0,50.0,100.0,120.0,120.0,100.0,260.0,280.0, 280.0,260.0,140.0,160.0,160.0,140.0,180.0,200.0,200.0,180.0, 220.0,240.0,240.0,220.0},{100.0,100.0,200.0,200.0,160.0, 160.0,180.0,180.0,160.0,160.0,180.0,180.0,160.0,160.0,180.0, 180.0,160.0,160.0,180.0,180.0,160.0,160.0,180.0,180.0}, {1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0, 1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0}}; GLfloat v1[3][16]={{50.0,350.0,350.0,50.0,100.0,300.0,300.0,100.0,125.0,175.0, 175.0,125.0,225.0,275.0,275.0,225.0},{200.0,200.0,210.0, 210.0,210.0,210.0,240.0,240.0,240.0,240.0,310.0,310.0,240.0, 240.0,310.0,310.0},{1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0, 1.0,1.0,1.0,1.0,1.0,1.0}}; GLfloat colors[4][3]={{0.0,0.0,1.0},{0.9961,0.9961,0.65625},{1.0,0.0,1.0}, {1.0,.0,1.0}}; static float q,w,e; static float fq,fw,fe; static GLfloat wa=0,wb=0,wc=0,ba,bb,bc; int flag; void myinit(void) { glClearColor(0.506,.7,1,0.0); glPointSize(2.0); glLoadIdentity(); glOrtho(0.0,499.0,0.0,499.0,-300.0,300.0); } void draw_top_boxes(GLint i,GLint j) { glColor3f(1.0,0.0,0.0); glBegin(GL_POLYGON); glColor3fv(colors[j]); // to draw the boat glVertex2f(v1[0][i+0],v1[1][i+0]); glColor3fv(colors[j+1]); glVertex2f(v1[0][i+1],v1[1][i+1]); glColor3fv(colors[j+2]); glVertex2f(v1[0][i+2],v1[1][i+2]); glColor3fv(colors[j+3]); glVertex2f(v1[0][i+3],v1[1][i+3]); glEnd(); } void draw_polygon(GLint i) { glBegin(GL_POLYGON); // to draw the boat glColor3f(0.0,0.0,0.0); glColor3fv(colors[0]); glVertex2f(v[0][i+0],v[1][i+0]); glColor3fv(colors[1]); glVertex2f(v[0][i+1],v[1][i+1]); glColor3fv(colors[2]); glVertex2f(v[0][i+2],v[1][i+2]); glColor3fv(colors[3]); glVertex2f(v[0][i+3],v[1][i+3]); glEnd(); } void draw_boat() { draw_polygon(0); draw_polygon(4); draw_polygon(8); draw_polygon(12); draw_polygon(16); draw_polygon(20); draw_top_boxes(0,0); draw_top_boxes(4,0); draw_top_boxes(8,0); draw_top_boxes(12,0); glFlush(); glPopMatrix(); glPopMatrix(); } void draw_water() { GLfloat i; GLfloat x=0,y=103,j=0; GLfloat k; glPushMatrix(); glTranslatef(wa,wb,wc); glPushMatrix(); glColor3f(0,0,1); for(k=y;k>0;k-=6) { for(i=1;i<30;i++) { glBegin(GL_LINES); glVertex2f(j,k); glVertex2f(j+10,k); glEnd(); j=j+20; } j=0; } glPopMatrix(); glPopMatrix(); } void draw_fishes() { glPushMatrix(); glTranslatef(fq,12.0,fe); glPushMatrix(); glColor3f(.99609375,0.2578125,0.2578125); glBegin(GL_TRIANGLES); glVertex2f(100,80); glVertex2f(100,60); glVertex2f(85,70); glEnd(); glColor3f(.99609375,0.2578125,0.2578125); glBegin(GL_TRIANGLES); glVertex2f(100,70); glVertex2f(110,75); glVertex2f(110,65); glEnd(); glColor3f(0,0,0); glBegin(GL_POINTS); glVertex2f(90,71); glEnd(); glColor3f(.99609375,0.2578125,0.2578125); glBegin(GL_TRIANGLES); glVertex2f(200,80); glVertex2f(200,60); glVertex2f(185,70); glEnd(); glColor3f(.99609375,0.2578125,0.2578125); glBegin(GL_TRIANGLES); glVertex2f(200,70); glVertex2f(210,75); glVertex2f(210,65); glEnd(); glColor3f(0,0,0); glBegin(GL_POINTS); glVertex2f(190,71); glEnd(); glPopMatrix(); glPopMatrix(); glFlush(); } void draw_cloud() { GLfloat m=100,n=400,o=10; for(int i=0;i<7;i++) { glPushMatrix(); glColor3f(1.0,1.0,1.0); if(i==1) glTranslated(125,415,10); else if(i==3||i==5) glTranslated(m,n+5,o); else glTranslated(m,n,o); glutSolidSphere(20.0,5000,150); glPopMatrix(); m+=10; } } void draw_square() { glColor3f(0,0.5,0.996); glBegin(GL_POLYGON); glVertex2f(0,0); glVertex2f(1000,0); glVertex2f(0,300); glVertex2f(1000,300); glEnd(); glFlush(); } void draw_brotate() { glPushMatrix(); glColor3f(0.96,0.5,0.25); //to draw body of the bird glTranslated(300,400,10); glScalef(3,1,1); glutSolidSphere(6,50000,15); glPopMatrix(); glPushMatrix(); glTranslated(323,400,10); glutSolidSphere(5,50000,15); glPopMatrix(); glColor3f(0,0,0); glBegin(GL_POINTS); glVertex2f(325,401); glEnd(); glColor3f(0.96,0.5,0.25); //to draw wings glBegin(GL_LINES); glVertex2f(294,394); glVertex2f(286,389); glEnd(); glBegin(GL_LINES); glVertex2f(286,389); glVertex2f(295,391); glEnd(); glBegin(GL_LINES); glVertex2f(295,391); glVertex2f(285,385); glEnd(); glBegin(GL_LINES); glVertex2f(285,385); glVertex2f(309,395); glEnd(); glBegin(GL_LINES); glVertex2f(294,406); glVertex2f(286,411); glEnd(); glBegin(GL_LINES); glVertex2f(286,411); glVertex2f(295,409); glEnd(); glBegin(GL_LINES); glVertex2f(295,409); glVertex2f(285,415); glEnd(); glBegin(GL_LINES); glVertex2f(285,415); glVertex2f(309,406); glEnd(); glColor3f(0.96,0.5,0.25); } void draw_bird() { GLfloat x=200,y=400,z=10; draw_brotate(); glBegin(GL_LINES); //draw legs of the bird glVertex2f(285,402); glVertex2f(275,402); glEnd(); glBegin(GL_LINES); glVertex2f(285,398); glVertex2f(275,398); glEnd(); glBegin(GL_LINES); glVertex2f(275,402); glVertex2f(270,405); glEnd(); glBegin(GL_LINES); glVertex2f(275,402); glVertex2f(270,398); glEnd(); glBegin(GL_LINES); glVertex2f(275,398); glVertex2f(273,400); glEnd(); glBegin(GL_LINES); glVertex2f(275,398); glVertex2f(270,395); glEnd(); glBegin(GL_LINES); glVertex2f(323,405); glVertex2f(323,407); glEnd(); glPushMatrix(); glTranslatef(323,409,10); glutSolidSphere(2,200,20); glPopMatrix(); glBegin(GL_TRIANGLES); glVertex2f(328,400); glVertex2f(331,397); glVertex2f(327,398.5); glEnd(); glFlush(); } void drawstars() { glColor3f(1.0,1.0,1.0); glBegin(GL_POINTS); glVertex3f(300.0,400.0,10.0); glVertex3f(200,400.0,10.0); glVertex3f(150,450.0,10.0); glVertex3f(100,470.0,10.0); glVertex3f(50,450.0,10.0); glVertex3f(50,350.0,10.0); glVertex3f(90,365.0,10.0); glVertex3f(350,450.0,10.0); glVertex3f(275,470.0,10.0); glVertex3f(280,430.0,10.0); glVertex3f(250,400.0,10.0); glVertex3f(450,450.0,10.0); glVertex3f(430,430.0,10.0); glVertex3f(430,470.0,10.0); glVertex3f(300,450.0,10.0); glVertex3f(265,380.0,10.0); glVertex3f(235,450.0,10.0); glEnd(); } void draw_all() { glClear(GL_COLOR_BUFFER_BIT); if(flag==0) { glDisable(GL_LIGHTING); //immp one draw_square(); draw_cloud(); glClearColor(0.506,.7,1,0.0); glTranslatef(q,w,e); glPushMatrix(); glColor3f(1.0,0.0,0.0); draw_boat(); draw_fishes(); glPushMatrix(); glColor3f(1.0,1.0,0.0); glTranslated(400,400,10); glutSolidSphere(20.0,5000,150); glPopMatrix(); } if(flag==1) { glDisable(GL_LIGHTING); //imp one draw_square(); draw_cloud(); glClearColor(0.9960,0.7070,0.3164,0.0); glTranslatef(q,w,e); glPushMatrix(); glColor3f(1.0,0.0,0.0); draw_boat(); draw_fishes(); glPushMatrix(); glColor3f(1.0,1.0,0.0); glTranslated(400,400,10); glutSolidSphere(20.0,500,100); glPopMatrix(); } if(flag==2) { // just try and change values in these arrays, specially the position array drawstars(); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); // GLfloat emission[]={0.1,0.1,0.1,0.0}; GLfloat diffuse[] = { 0.40, 0.40,0.40, 1.0 }; GLfloat ambiance[] = { 0.5, 0.5,0.5, 1.0 }; GLfloat specular[] = { 1.3, 1.3,.3, 1.0 }; GLfloat intensity[]={500.0}; GLfloat position[] = { 10,30,-30,1.0 }; glLightfv (GL_LIGHT0, GL_POSITION, position); glLightfv (GL_LIGHT0, GL_DIFFUSE,diffuse); glLightfv (GL_LIGHT0, GL_AMBIENT,ambiance); glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER,GL_TRUE); glLightfv (GL_LIGHT0, GL_SPECULAR,specular); glLightfv (GL_LIGHT0, GL_INTENSITY,intensity); glColor3f(0,0.5,0.996); glBegin(GL_POLYGON); glVertex2f(0,0); glVertex2f(1000,0); glVertex2f(0,150); glVertex2f(1000,150); glEnd(); glTranslatef(q,w,e); glPushMatrix(); glColor3f(1.0,0.0,0.0); draw_boat(); draw_fishes(); glDisable(GL_LIGHTING); glDisable(GL_LIGHT0); draw_cloud(); glClearColor(0.0,0.0,0.0,0.0); glPushMatrix(); glColor3f(1.0,1.0,1.0); glTranslated(400,400,10); glutSolidSphere(20.0,500,100); glPopMatrix(); glColor3f(1.0,1.0,1.0); glBegin(GL_POINTS); glVertex3f(300.0,400.0,10.0); glEnd(); } glPushMatrix(); glTranslatef(ba,bb,bc); glPushMatrix(); draw_bird(); glPopMatrix(); glPopMatrix(); GLfloat i; glPushMatrix(); GLfloat x=0,y=100,j=0; int k; //draw_water(); q+=25; fq-=3.5; if(q>=440.0) //470 q=-390.0; //400 if(fq<=-300) //500 fq=400.0; //400 wa-=1; if(wa<=(-20)) wa=-0.5; ba+=6; if(ba>=500) ba=-400; glFlush(); glutSwapBuffers(); } void display(void) { draw_all(); } void color_menu(int id) { switch(id) { case 1: flag=0;break; case 2: flag=1;break; case 3: flag=2;break; case 4: exit(0); break; } glutPostRedisplay(); } void main_menu(int id) { switch(id) { case 1: break; case 2:exit(0);break; glutPostRedisplay(); } } int main(int argc,char **argv) { int sub_menu; glutInit(&argc,argv); glutInitDisplayMode(GLUT_RGB|GLUT_DOUBLE); glutInitWindowSize(1000,1000); glutInitWindowPosition(0,0); glutCreateWindow("Ship"); sub_menu=glutCreateMenu(color_menu); glutAddMenuEntry("Morning",1); glutAddMenuEntry("Evening",2); glutAddMenuEntry("Night",3); glutAddMenuEntry("Quit",4); glutCreateMenu(main_menu); glutAddSubMenu("View",sub_menu); glutAddMenuEntry("Quit",2); glutAttachMenu(GLUT_RIGHT_BUTTON); glutDisplayFunc(display); glutIdleFunc(display); myinit(); glutMainLoop(); glFlush(); }

    Read the article

  • OpenGL render vs. own Phong Illumination Implementation

    - by Myx
    Hello: I have implemented a Phong Illumination Scheme using a camera that's centered at (0,0,0) and looking directly at the sphere primitive. The following are the relevant contents of the scene file that is used to view the scene using OpenGL as well as to render the scene using my own implementation: ambient 0 1 0 dir_light 1 1 1 -3 -4 -5 # A red sphere with 0.5 green ambiance, centered at (0,0,0) with radius 1 material 0 0.5 0 1 0 0 1 0 0 0 0 0 0 0 0 10 1 0 sphere 0 0 0 0 1 The resulting image produced by OpenGL. The image that my rendering application produces. As you can see, there are various differences between the two: The specular highlight on my image is smaller than the one in OpenGL. The diffuse surface seems to not diffuse in the correct way, resulting in the yellow region to be unneccessarily large in my image, whereas in OpenGL there's a nice dark green region closer to the bottom of the sphere The color produced by OpenGL is much darker than the one in my image. Those are the most prominent three differences that I see. The following is my implementation of the Phong illumination: R3Rgb Phong(R3Scene *scene, R3Ray *ray, R3Intersection *intersection) { R3Rgb radiance; if(intersection->hit == 0) { radiance = scene->background; return radiance; } R3Vector normal = intersection->normal; R3Rgb Kd = intersection->node->material->kd; R3Rgb Ks = intersection->node->material->ks; // obtain ambient term R3Rgb intensity_ambient = intersection->node->material->ka*scene->ambient; // obtain emissive term R3Rgb intensity_emission = intersection->node->material->emission; // for each light in the scene, obtain calculate the diffuse and specular terms R3Rgb intensity_diffuse(0,0,0,1); R3Rgb intensity_specular(0,0,0,1); for(unsigned int i = 0; i < scene->lights.size(); i++) { R3Light *light = scene->Light(i); R3Rgb light_color = LightIntensity(scene->Light(i), intersection->position); R3Vector light_vector = -LightDirection(scene->Light(i), intersection->position); // calculate diffuse reflection intensity_diffuse += Kd*normal.Dot(light_vector)*light_color; // calculate specular reflection R3Vector reflection_vector = 2.*normal.Dot(light_vector)*normal-light_vector; reflection_vector.Normalize(); R3Vector viewing_vector = ray->Start() - intersection->position; viewing_vector.Normalize(); double n = intersection->node->material->shininess; intensity_specular += Ks*pow(max(0.,viewing_vector.Dot(reflection_vector)),n)*light_color; } radiance = intensity_emission+intensity_ambient+intensity_diffuse+intensity_specular; return radiance; } Here are the related LightIntensity(...) and LightDirection(...) functions: R3Vector LightDirection(R3Light *light, R3Point position) { R3Vector light_direction; switch(light->type) { case R3_DIRECTIONAL_LIGHT: light_direction = light->direction; break; case R3_POINT_LIGHT: light_direction = position-light->position; break; case R3_SPOT_LIGHT: light_direction = position-light->position; break; } light_direction.Normalize(); return light_direction; } R3Rgb LightIntensity(R3Light *light, R3Point position) { R3Rgb light_intensity; double distance; double denominator; if(light->type != R3_DIRECTIONAL_LIGHT) { distance = (position-light->position).Length(); denominator = light->constant_attenuation + light->linear_attenuation*distance + light->quadratic_attenuation*distance*distance; } switch(light->type) { case R3_DIRECTIONAL_LIGHT: light_intensity = light->color; break; case R3_POINT_LIGHT: light_intensity = light->color/denominator; break; case R3_SPOT_LIGHT: R3Vector from_light_to_point = position - light->position; light_intensity = light->color*( pow(light->direction.Dot(from_light_to_point), light->angle_attenuation)); break; } return light_intensity; } I would greatly appreciate any suggestions as to any implementation errors that are apparent. I am wondering if the differences could be occurring simply because of the gamma values used for display by OpenGL and the default gamma value for my display. I also know that OpenGL (or at least tha parts that I was provided) can't cast shadows on objects. Not that this is relevant for the point in question, but it just leads me to wonder if it's simply display and capability differences between OpenGL and what I am trying to do. Thank you for your help.

    Read the article

< Previous Page | 1 2 3