Page 1 of 2 12 LastLast
Results 1 to 10 of 18

Thread: flickering problem

  1. #1
    Member Contributor
    Join Date
    Oct 2002
    Location
    bangalore
    Posts
    56

    flickering problem

    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","00 3: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,16 0,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.0*3.14159265358979323846)+ (2*0.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("\n 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
    thanks & regards
    Prashant G.P

  2. #2
    Senior Member Frequent Contributor
    Join Date
    Nov 2002
    Location
    Latvia
    Posts
    626

    Re: flickering problem

    Originally posted by prashantgp:
    void display(void)
    {

    glClear(GL_COLOR_BUFFER_BIT);
    glColor3f(1.0,1.0,1.0);
    ...
    ...
    glVertex2f(0.05,0.55);
    glEnd();
    glFlush();
    glutIdleFunc(idle);
    glutSwapBuffers();

    }
    What the h.ll glFlush & glutidleFunc is doing there glFlush is for single buffer progs & idle func should be under init or some sort of keyb funcs. You could use simple idle f like {glutPostRedisplay();} and do all the comparisions in display, maybe under some f name.
    And PLZ use code tags next time


    [This message has been edited by M/\dm/\n (edited 12-15-2002).]

  3. #3
    Member Contributor
    Join Date
    Oct 2002
    Location
    bangalore
    Posts
    56

    Re: flickering problem

    hey man,
    but the same code is running very much fine on Linux.
    if i remove glLflush() also it does not make any difference.
    thanks & regards
    Prashant G.P

  4. #4
    Senior Member Frequent Contributor
    Join Date
    Nov 2002
    Location
    Latvia
    Posts
    626

    Re: flickering problem

    The fact it runs on Linux means nothing, I had a program that was runing nice on TNT2 &GeForce2GTS, but in the same time was showing wonders on Intel graphic chipsets
    I have no time to look at your code right now, but I'll try to check it out after 3 hours.

  5. #5
    Senior Member OpenGL Guru
    Join Date
    Jun 2000
    Location
    Gastonia, NC, USA
    Posts
    2,068

    Re: flickering problem

    Try putting the glutIdleFunc in the init routine.

    I don't know why there is a linux run's diffrent the windows.

    But glutIdleFunc should only be called once to enable, not over and over as you have.

    Only glutTimerFunc has to be called again after being called.

    Could be adding to overhead in the windows version of GLUT...


    [This message has been edited by nexusone (edited 12-16-2002).]

  6. #6
    Senior Member Frequent Contributor
    Join Date
    Nov 2002
    Location
    Latvia
    Posts
    626

    Re: flickering problem

    Here comes little improved version. Problem arises at glutPostRedisplay. I'll try to look through that once more tomorrow. Maybe to much calculations? Something could be moved to lists! Actually it looks like Z fighting, but there's no depth! Maybe I just missed something
    Code :
    #include <stdlib.h>
    #include <stdio.h>
    #include <GL/glut.h>
    #include <math.h>
    #include <windows.h>
    #include <string.h>
     
    //float z; Unused.
    int n,i,j,k,sw,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 idle()//you can skip voids
    {
    	aspeed==9?aspeed=0:aspeed++;// ?: operator "A+" you can use - comp?NULL(if true):do if false
    	state==30?state=0:state++;
    	//Sleep(500);//Msecs !!!
    	glutPostRedisplay();
    }
     
    void init()//you can skip voids
    {
    	glLoadIdentity();
    	glClearColor(1.0,1.0,1.0,1.0);
    	glEnable(GL_LINE_SMOOTH);
    	glShadeModel(GL_SMOOTH);
    }
     
    void drawstring(char *s)
    {
    	//unsigned int i;
    	for(unsigned int i=0;i<strlen(s);i++)//Easier
    		glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18,s[i]);
    }
     
    void drawSmall(char *s)
    {
    	//unsigned int i;
    	for(unsigned int i=0;i<strlen(s);i++)//Same as above
    		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); I was looooooking for few hours, but didn't found any points anywayZ
    	//glEnable(GL_LINE_SMOOTH); Already at init  [img]http://www.opengl.org/discussion_boards/ubb/smile.gif[/img])
    	glLineWidth(2.0);
    	glColor3f(0.0,1.0,0.0);//This is where it happens (killing)
    	glBegin(GL_LINE_STRIP);
    	k=0;
    	float speedup=2.0*3.14159265358979323846+2*0.0175;//You think that float can be THAT long? And especialy prcision on the display  [img]http://www.opengl.org/discussion_boards/ubb/smile.gif[/img]))))
    	for(angle=0.0;angle<=speedup;angle+=0.0175)//You should multiply all this stuff to var doblepi etc. for performance reasons
    	{
    		vectorX=Xpos+(radius* (float)cos(/*(double)*/angle));//why double? Wellllll OK I understood "It's military stuff"
    		vectorY=Ypos+(radius* (float)sin(/*(double)*/angle));
    		glVertex2f(vectorX1,vectorY1);
    		lposition[k]=vectorX1;
    		k++;
    		lposition[k]=vectorY1;
    		k++;
    		//glBegin(GL_LINES); Initeration without end??? & under LineStrip
    		vectorX1=vectorX;
    		vectorY1=vectorY;
    	}
    	glEnd();
    }
     
    void Line ()//you can skip voids
    {
    	int m,n,k=0;//Drop to null at init [img]http://www.opengl.org/discussion_boards/ubb/smile.gif[/img]
    	//k=0;
    	glColor3f(0.0,1.0,1.0);//Lets call that only once  [img]http://www.opengl.org/discussion_boards/ubb/smile.gif[/img]
    	glLineWidth(4.0);
    	glBegin(GL_LINES);
    	//glColor3f(0.0,1.0,1.0);
    	//glEnable(GL_LINE_SMOOTH);
    	for(m=0;m<=180;m+=2)//You can use for(int m=0;m<=180;m+=2) if you dont want to call 1st line in this func [img]http://www.opengl.org/discussion_boards/ubb/smile.gif[/img]
    	{
    		glVertex2f(lposition[m],lposition[m+1]);
    		glVertex2f(-(lposition[m]),lposition[m+1]);
    		k++;
    	}
    	glEnd();
    	printf("\n these many lines %d",k);//Try to use cout for simpler output cout<<"Hi!"<<x<<"/t"<<endl; And maybe So many lines or cout<<x<<" Lines [img]http://www.opengl.org/discussion_boards/ubb/smile.gif[/img]))"; use #include <iostream.h>
    	glColor3f(0.5,0.3,0.1);//Lets call that only once  [img]http://www.opengl.org/discussion_boards/ubb/smile.gif[/img]
    	//glColor3f(0.5,0.3,0.1);
    	glLineWidth(4.0);
    	glBegin(GL_LINES);
    	for(n=360;n<=540;n+=2)
    	{
    		glVertex2f(lposition[n],lposition[n+1]);
    		glVertex2f(-(lposition[n]),lposition[n+1]);
    	}
    	glEnd();
    	m=pitch[aspeed];
    	m*=2;
    	if(m>0)
    	{
    		glColor3f(0.0,1.0,1.0);//Lets call that only once  [img]http://www.opengl.org/discussion_boards/ubb/smile.gif[/img]
    		//glColor3f(0.0,1.0,1.0);
    		//glEnable(GL_LINE_SMOOTH);
    		glLineWidth(4.0);
    		glBegin(GL_LINES);
    		for(n=360;n<=360+m;n+=2)
    		{
    			glVertex2f(lposition[n],lposition[n+1]);
    			glVertex2f(-(lposition[n]),lposition[n+1]);
    		}
    		glEnd();
    	}
    	if(m<0)
    	{
    		glColor3f(0.5,0.3,0.1);//Lets call that only once  [img]http://www.opengl.org/discussion_boards/ubb/smile.gif[/img]
    		//glColor3f(0.5,0.3,0.1);
    		glLineWidth(4.0);
    		glBegin(GL_LINES);
    		for(n=360;n>=360+m;n-=2)
    		{
    			glVertex2f(lposition[n],lposition[n+1]);
    			glVertex2f(-(lposition[n]),lposition[n+1]);
    		}
    		glEnd();
    	}
    	//glLoadIdentity(); No reason to call
    }
     
    void display()//you can skip voids
    {
    	glClear(GL_COLOR_BUFFER_BIT);
    	//glColor3f(1.0,1.0,1.0); Evry call to DrawCircle kills this line anywayZ
    	glRasterPos2f(-0.2,-0.82);
    	sprintf(stringlabel,"Attitude Direction Indicator");
    	drawstring(stringlabel);
    	DrawCircle(0.0,0.0,0.4);
     
    	glPushMatrix();//You pushed matrix away for later use  [img]http://www.opengl.org/discussion_boards/ubb/smile.gif[/img]
    	glRotatef(rotate[aspeed],0.0,0.0,1.0);
    	Line();
    	glPopMatrix();//You took it back (less costly than glLoadIdentity)
     
    	//glLoadIdentity(); No need anymore  [img]http://www.opengl.org/discussion_boards/ubb/smile.gif[/img])
    	//glLineWidth(2.0); you are calling that before each object anyway  [img]http://www.opengl.org/discussion_boards/ubb/smile.gif[/img] It was 2 at line call.
    	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();
     
    	glutSwapBuffers();
    }
     
    void keyboard(unsigned char key , int x , int y)
    {
    	switch(key)
    	{
    	case 27: exit(0);
    		break;
    	default :
    		break;
    	}
    //	glutPostRedisplay(); No need while there's no movment
    }
     
    void reshape( int w, int h)
    {
    	glViewport(0,0,(GLsizei)w,(GLsizei)h);
    	glMatrixMode(GL_PROJECTION);
    	glLoadIdentity();
    	glMatrixMode(GL_MODELVIEW);
    	glLoadIdentity();
    } 
     
    int main(int argc, char **argv)
    {
    	glutInit(&amp;argc,argv);
    	glutInitWindowSize(800,625);
    	glutInitWindowPosition(0,0);
    	glutCreateWindow("Multi Function Display");//Why you need pw??
    	glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB/* | GLUT_DEPTH*/ );//You don't use depth anywayZ
    	init();
     
    	glutDisplayFunc(display);
    	glutIdleFunc(idle);
    	glutKeyboardFunc(keyboard);
    	glutReshapeFunc(reshape);
     
    	glutMainLoop();
    	return 0;
    }

  7. #7
    Member Contributor
    Join Date
    Oct 2002
    Location
    bangalore
    Posts
    56

    Re: flickering problem

    Hey,
    thanks for putting so much of time on this.
    u've suggested me to use cout and all , why i am sticking to C is, because i want to run the same program both on Linux and Windows.

    did u try running it on ur m/c??
    hey nexusone,
    i included idle call in init,but it didn;t work.
    looking forward for the help.
    thanks
    bye bye
    thanks & regards
    Prashant G.P

  8. #8
    Senior Member Frequent Contributor
    Join Date
    Nov 2002
    Location
    Latvia
    Posts
    626

    Re: flickering problem

    Whooow, that's one cool prog. I havn't seen anything like that so far! And, honestly, I don't know whats wrong
    Code :
    #include <GL/glut.h>//OK
    #include <windows.h>//OK
     
    void idle()
    {
    	glutPostRedisplay();//?Maybe that's the problem, although it should work.
    }
     
    void display()
    {
    	glClear(GL_COLOR_BUFFER_BIT);//OK
    	glColor3f(1.0,0.0,0.0);//OK
    	glBegin(GL_LINES);//OK
    		glVertex2f(-1,-1);//OK
    		glVertex2f(1,1);//OK
    	glEnd();//OK
    	glutSwapBuffers();//? Flickering could arise because bufers aren't swaped as they should
    }
     
    void reshape( int w, int h)
    {
    	glViewport(0,0,(GLsizei)w,(GLsizei)h);//OK
    	glMatrixMode(GL_PROJECTION);//OK
    	glLoadIdentity();//OK
    	gluOrtho2D(1.0,1.0,-1.0,1.0);//OK
    	glMatrixMode(GL_MODELVIEW);//OK
    	glLoadIdentity();//OK
    } 
     
    int main(int argc, char **argv)
    {
    	glutInit(&amp;argc,argv);//OK
    	glutInitWindowSize(800,625);//OK
    	glutCreateWindow("Multi Function Display");//OK
    	glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);//? Works like GLUT_SINGLE with glFlush();, Maybe there's some sort of dept problem.
     
    	glutDisplayFunc(display);//OK
    	glutIdleFunc(idle);//? Redisplay causes mess. 
    	glutReshapeFunc(reshape);//OK
     
    	glutMainLoop();//OK
    	return 0;//OK
    }
    That's the absolute minimum for the program to run & draw somthing, but it still catches gliches. Maybe there is specific inits for Ortho, can't tell you as I havn't worked with it lot

  9. #9
    Senior Member Frequent Contributor
    Join Date
    Aug 2000
    Location
    Cardiff University
    Posts
    653

    Re: flickering problem

    gluOrtho2D(1.0,1.0,-1.0,1.0);//OK

    HUH!
    left, right, bottom, top

  10. #10
    Senior Member Frequent Contributor
    Join Date
    Nov 2002
    Location
    Latvia
    Posts
    626

    Re: flickering problem

    I checked with other values, so ther's no problem

    Yes, checked once more - no problem

    [This message has been edited by M/\dm/\n (edited 12-17-2002).]

Page 1 of 2 12 LastLast

Similar Threads

  1. Flickering Problem with Display Lists
    By jcoplan in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 05-06-2008, 09:51 AM
  2. FLICKERING PROBLEM.....Please Help
    By zadeh79 in forum OpenGL: Basic Coding
    Replies: 6
    Last Post: 08-03-2006, 05:42 PM
  3. problem with flickering
    By presoftdev in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 11-28-2005, 09:11 PM
  4. Texture flickering problem.
    By zenon in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 02-24-2003, 12:21 AM
  5. flickering problem
    By monka in forum OpenGL: Advanced Coding
    Replies: 4
    Last Post: 09-17-2002, 06:41 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean