Hi all,
i am trying to wrie a program where in i am updating the data using idle function.
but instead of smooth transition , it is giving me some flickering problem.
but when the same code is run in Linux it’s doing fine.
below is my code pasted. try to run it on ur m/c and pls do help me out.
code :
#include<stdlib.h>
#include<stdio.h>
#include"GL/glut.h"
#include<math.h>
#include<windows.h>
#include<string.h>
float z;
int n,i,j,k,sw,pw,cw, curx,cury;
float position [7][2] = { -0.75,0.85,-0.40,0.85,-0.05,0.85,
0.30,0.85,0.65,0.85,-0.85,0.55,0.80,0.55};
char label[10][10] = {“ADI”,“HSI”,“NAV”, “”,“ELE”, “ENG”,“FUL”};
char airspeed[11][10]={“330”,“331”,“332”,“333”,“334”,“335”,“336”,“337”,“338”,
“339”,“340”};
char machcounter[11][10]={“0.20”,“0.21”,“0.22”,“0.23”,“0.24”,“0.25”,“0.26”,
“0.27”,“0.28”,“0.29”,“0.30”};
char baltitude[11][10]={“04.990”,“05.110”,“05.225”,“05.555”,“05.785”,“06.050”,
“06.185”,“06.678”,“08.849”,“09.985”,“09.987”};
char raltitude[11][10]={“4907”,“4909”,“4911”,“4913”,“4915”,“4917”,“4919”,“4921”,
“4923”,“4925”,“4950”};
char navigdtk[11][10]={“020”,“021”,“022”,“023”,“024”,“025”,“026”,
“027”,“028”,“029”,“030”};
char navigttg[11][10]={“003:41”,“003:42”,“003:45”,“003:50”,“003:55”,“003:60”,“003:65”,“003:70”,
“003:75”,“003:80”,“003:85”};
char navigeta[11][10]={“00:08:10”,“00:08:11”,“00:08:12”,“00:08:13”,“00:08:14”,“00:08:15”,
“00:08:16”,“00:08:17”,“00:08:18”,“00:08:20”,“00:08:22”};
char superscript[2]=“R”;
int aspeed=0, state=0;
int pitch[11]={0,10,20,30,40,50,-10,-20,-30,-40,70};
//int hsiyaw[31]={50,50,50,50,50,50,50,50,50,50,160,160,160,160,160,160,160,160,160,160,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100};
int
hsiyaw[31]={-10,-20,-30,-40,-50,-60,-70,-80,-90,100,110,120,130,140,150,160,170,180,190,200,210,220,230,240,250,260,270,280,290};
float rotate[10]={0,10,20,30,40,25,0,-30,-45,60};
float lposition[722],Xpos,Ypos, radius;
static char stringlabel[100];
void init(void)
{
glLoadIdentity();
glClearColor(1.0,1.0,1.0,1.0);
glShadeModel(GL_SMOOTH);
}
void idle(void)
{
if(aspeed==9)
aspeed=0;
aspeed++;
if(state==30)
state=0;
state++;
//sleep(4.0);
glutSetWindow(pw);
glutPostRedisplay();
}
void drawstring(char *s)
{
unsigned int i;
for(i=0;i<strlen(s);i++)
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18,s[i]);
}
void drawSmall(char *s)
{
unsigned int i;
for(i=0;i<strlen(s);i++)
glutBitmapCharacter(GLUT_BITMAP_9_BY_15,s[i]);
}
void DrawCircle(float Xpos, float Ypos , float radius)
{
int i=0;
float vectorX, vectorX1=Xpos+radius,vectorY,vectorY1=Ypos;
float angle;
glPointSize(2.0);
glEnable(GL_LINE_SMOOTH);
glLineWidth(2.0);
glColor3f(0.0,1.0,0.0);
glBegin(GL_LINE_STRIP);
k=0;
for(angle=0.0;angle<=(2.03.14159265358979323846)+(20.0175);angle+=0.0175)
{
vectorX=Xpos+(radius*(float)cos((double)angle));
vectorY=Ypos+(radius*(float)sin((double)angle));
glVertex2f(vectorX1,vectorY1);
lposition[k]=vectorX1;k++;
lposition[k]=vectorY1;k++;
glBegin(GL_LINES);
vectorX1=vectorX;
vectorY1=vectorY;
}
glEnd();
}
void Line (void)
{
int m,n,k;
k=0;
for(m=0;m<=180;m+=2)
{ glColor3f(0.0,1.0,1.0);
glEnable(GL_LINE_SMOOTH);
glLineWidth(4.0);
glBegin(GL_LINES);
glVertex2f(lposition[m],lposition[m+1]);
glVertex2f(-(lposition[m]),lposition[m+1]);
glEnd();
k++;
}
printf("
these many lines %d",k);
for(n=360;n<=540;n+=2)
{
glColor3f(0.5,0.3,0.1);
glLineWidth(4.0);
glBegin(GL_LINES);
glVertex2f(lposition[n],lposition[n+1]);
glVertex2f(-(lposition[n]),lposition[n+1]);
glEnd();
}
m=pitch[aspeed];
m*=2;
if(m>0)
{
for(n=360;n<=360+m;n+=2)
{ glColor3f(0.0,1.0,1.0);
glEnable(GL_LINE_SMOOTH);
glLineWidth(4.0);
glBegin(GL_LINES);
glVertex2f(lposition[n],lposition[n+1]);
glVertex2f(-(lposition[n]),lposition[n+1]);
glEnd();
}
}
if(m<0)
{
for(n=360;n>=360+m;n-=2)
{
glColor3f(0.5,0.3,0.1);
glLineWidth(4.0);
glBegin(GL_LINES);
glVertex2f(lposition[n],lposition[n+1]);
glVertex2f(-(lposition[n]),lposition[n+1]);
glEnd();
}
}
glLoadIdentity();
}
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0,1.0,1.0);
glRasterPos2f(-0.2,-0.82);
sprintf(stringlabel,“Attitude Direction Indicator”);
drawstring(stringlabel);
DrawCircle(0.0,0.0,0.4);
glRotatef(rotate[aspeed],0.0,0.0,1.0);
Line();
glLoadIdentity();
glLineWidth(2.0);
glBegin(GL_LINE_STRIP);
glVertex2f(0.0,0.5);
glVertex2f(0.0,0.6);
glVertex2f(-0.05,0.55);
glVertex2f(0.0,0.6);
glVertex2f(0.05,0.55);
glEnd();
glFlush();
glutIdleFunc(idle);
glutSwapBuffers();
}
void keyboard(unsigned char key , int x , int y)
{
switch(key)
{
case 's' : exit(0);
break;
case 'f' : exit(0);
break;
case 27: exit(0);
break;
default : break;
}
glutPostRedisplay();
}
void reshape( int w, int h)
{
glViewport(0,0,(GLsizei)w,(GLsizei)h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(-1.0,1.0,-1.0,1.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
int main(int argc, char **argv)
{
glutInit(&argc,argv);
glutInitWindowSize(800,625);
glutInitWindowPosition(0,0);
pw=glutCreateWindow(“Multi Function Display”);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH );
init();
glutDisplayFunc(display);
glutKeyboardFunc(keyboard);
glutReshapeFunc(reshape);
glutMainLoop();
return 0;
}
i am using VC++ to run this program.
thanks in advance
bye bye
prashant