opengl flickering image in labtop

Hii friends,
I am just frustrated with the flickering type or moving ting in my opengl image… When i use in my system it is working perfectly But when i use in my labtop My opengl image contains a moving type black flcikering image… I tried changing the display size to glut_DOUBLE.Then the flickering image stops but my mouse func is not working. the passive mousefunc is not working. when i am moving my mouse value should be displayed in text box but it is not displayed when i am using glut_Double…
Please help me out
If i use glut_SINGLE then mouse func works but a flicker image appears…Whats is the solution for it…Please help me out
:confused: :sorrow:

  • be sure to never write explicitely to GL_FRONT or GL_BACK buffers.
  • be sure to swapbuffers whenever you want the display to update

Can you show the code and some code context around your text box update ?

Thanks its workin…
I put glutswapBufers only in one place…Now that u mentioned to put wr i must update i did it… got it

no its not working again…its just working on system not labtop…i dnt no y…i changed everywr glutSwapBuffers then too…
i am pasting few code please help me out

void display(void)
{
GLfloat xsize, ysize; /* Size of image /
GLfloat xscale, yscale; /
Scaling of image */
glutSetWindow(win);
glutShowWindow();

   a1=0;
   no_of_pts1=0;
   cheak=0;
   glutSetCursor(GLUT_CURSOR_LEFT_ARROW);
  // glClearColor(0.0, 0.0, 0.0, 1.0);
 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  if (BitmapInfo)
    {
    xsize = Width;
    ysize = BitmapInfo->bmiHeader.biHeight * xsize /
            BitmapInfo->bmiHeader.biWidth;
    if (ysize > Height)
        {
        ysize = Height;
        xsize = BitmapInfo->bmiHeader.biWidth * ysize /
                BitmapInfo->bmiHeader.biHeight;
        }
    xscale  = xsize / BitmapInfo->bmiHeader.biWidth;
    yscale  = ysize / BitmapInfo->bmiHeader.biHeight;
    glRasterPos2f(0,0);
    glPixelZoom(xscale, yscale);
   glDrawPixels(BitmapInfo->bmiHeader.biWidth,  BitmapInfo->bmiHeader.biHeight,
                 GL_RGB, GL_UNSIGNED_BYTE, BitmapBits);

textbox(797,670,919,620,1,1,0); //exit
textbox(790,590,926,530,1,1,0);//magn
textbox(790,500,926,440,1,1,0);//year
textbox(790,410,926,350,1,1,0);
textbox(790,320,926,200,0,0,1);//lat,lon box
textbox(790,170,926,30,0,0,1); //mesg

    glColor3f(1.0,0.0,1.0);
    output2(830,635,"EXIT")  ;
    glColor3f(0.0,0.0,0.0);
    output1(815,572,"Magnitude")  ;
    output1(837,482,"Year") ;
    output1(810,395,"Focal Mech.") ;
    output1(840,380,"(0/1)");
    glColor3f(1.0,0.0,1.0);
//    output1(865,405,ww5) ; 
//  output1(925,405,"ww5") ;
    glColor3f(0,1,1);
    output1(810,300,"Latitude") ;
    output1(810,255,"Longitude") ;
    output3(810,155,"Required Map:") ;
    output3(797,140,"Enter Magn & Yr") ;
    output3(797,125,"ranges, 0 for ") ;
    output3(797,110,"map with only") ;
    output3(797,95,"Epicentres or 1") ;
    output3(797,80,"with Focal Mech.") ;
    output3(797,65,"Then Click on ") ;

output3(797,50,“points on map”) ;
output3(797,35,“to display it.”) ;

glBegin(GL_POLYGON);
glColor3f(1.0, 1.0, 1.0);
glVertex2f(800,535);
glVertex2f(800,560);
glVertex2f(850,560);
glVertex2f(850,535);
glEnd();
glColor3f(0.0, 0.0, 0.0);
output4(824,541,ww1);
glLoadIdentity();

glBegin(GL_POLYGON);
 glColor3f(1.0, 1.0, 1.0);

// glColor3f(0.8, 0.8, 0.8);
glVertex2f(865,535);
glVertex2f(865,560);
glVertex2f(915,560);
glVertex2f(915,535);
glEnd();
glColor3f(0.0, 0.0, 0.0);
output4(888,541,ww2);
glLoadIdentity();

glBegin(GL_POLYGON);

// glColor3f(0.8, 0.8, 0.8);
glColor3f(1.0, 1.0, 1.0);
glVertex2f(795,445);
glVertex2f(795,470);
glVertex2f(850,470);
glVertex2f(850,445);
glEnd();
glColor3f(0.0, 0.0, 0.0);
output4(805,451,ww3);
glLoadIdentity();

glBegin(GL_POLYGON);
//glColor3f(0.8, 0.8, 0.8);
glColor3f(1.0, 1.0, 1.0);
glVertex2f(865,445);
glVertex2f(865,470);
glVertex2f(920,470);
glVertex2f(920,445);
glEnd();
glColor3f(0.0, 0.0, 0.0);
output4(875,451,ww4);
glLoadIdentity();
glBegin(GL_POLYGON);
glColor3f(1.0, 1.0, 1.0);

// glColor3f(0.8, 0.8, 0.8);
glVertex2f(840,353);
glVertex2f(840,373);
glVertex2f(880,373);
glVertex2f(880,353);
glEnd();
glColor3f(0.0, 0.0, 0.0);
output4(858,360,ww5);
glLoadIdentity();

    glFinish();

// glFlush();
glutSwapBuffers();

}	

}

void Resize(int width, int height)
{
Width = width;
Height = height;
glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0.0, (GLfloat)width, 0.0, (GLfloat)height, -1.0, 1.0);
glMatrixMode(GL_MODELVIEW);
glutReshapeWindow(950,700);
glutSwapBuffers();
// glLoadIdentity();
}
/*
void cmouse(int but,int state,int x , int y)
{
int y1=700-y;
if(state== GLUT_DOWN){
printf("coordinates are x=%d, y=%d
",x,y);
printf("coordinates are x=%d, y=%d
",x,y1);
}
}
*/

int stx=0,sty=0;//for taking initial values
int ptx=0,pty=0;
int focus=0;
float latitude[50],longitude[50];
float lat=0.0,lon=0.0;
extern void cr_gmt(float *lt,float * ln,int n,int w1,int w2);
extern void cr_gmt2(float *lt,float * ln,int n,int w1,int w2);

void cmouse(int but,int state,int x , int y)
{
char st2[4];
int y1;
//y1=700-y;
//char ww1[3], ww2[3];
if(cheak==2)
cheak=0;
if(cheak==0)
{
//x1=x;
y1=700-y;
if(but==GLUT_LEFT_BUTTON)
{
if(x>617 && x<949)
{
if(y>630 && y<670)
{
a1=0;
no_of_pts1=0;
glutSetWindow(win);
glutShowWindow();
}
else
if(y>45 && y<70 && x>830 && x<890)
exit(0);
else

if(x>800 && x<850 && y>140 && y<165)
{
clear_text(ww1);
glBegin(GL_LINES);
glColor3f(0,0,0);
glVertex2f(820,538);
glVertex2f(835,538);
glEnd();
get_text(ww1,convert_int);
glutSwapBuffers();
}

if(x>865 && x<915 && y>140 && y<165)
{
clear_text(ww2);
glBegin(GL_LINES);
glColor3f(0,0,0);
glVertex2f(885,538);
glVertex2f(900,538);
glEnd();
get_text(ww2,convert_int2);
glutSwapBuffers();
}

if(x>795 && x<850 && y>230 && y<255)
{
clear_text(ww3);
glBegin(GL_LINES);
glColor3f(0,0,0);
glVertex2f(805,448);
glVertex2f(842,448);
glEnd();
get_text(ww3,convert_int3);
glutSwapBuffers();
}
if(x>865 && x<920 && y>230 && y<255)
{
clear_text(ww4);
glBegin(GL_LINES);
glColor3f(0,0,0);
glVertex2f(875,448);
glVertex2f(912,448);
glEnd();
get_text(ww4,convert_int4);
glutSwapBuffers();
}
if(x>840 && x<880 && y>327 && y<347)
{
clear_text(ww5);
glBegin(GL_LINES);
glColor3f(0,0,0);
glVertex2f(855,356);
glVertex2f(870,356);
glEnd();
get_text(ww5,convert_int5);
glutSwapBuffers();
}

}
else
if( x>42 && x<615 && y>38 && y<662)
{
latitude[no_of_pts1]=lat;
longitude[no_of_pts1]=lon;
no_of_pts1++;
if(abs(x-stx)<6 && abs(y1-sty)<6 && no_of_pts1>2)
{
glutSetCursor(GLUT_CURSOR_WAIT);
glutSetCursor(GLUT_CURSOR_LEFT_ARROW);
int w1,w2,w3,w4,n;
w1 = atoi(ww1);
w2 = atoi(ww2);
w3 = atoi(ww3);
w4 = atoi(ww4);
n = atoi(ww5);
printf("w1=%d
",w1);
printf("w2=%d
",w2);
printf("w3=%d
",w3);
printf("w4=%d
",w4);
printf("n=%d
",n);
//glutSetCursor(GLUT_CURSOR_WAIT);
//glutSetCursor(GLUT_CURSOR_LEFT_ARROW);
if( w1==0 && w2 ==0 && w3==0 && w4==0)
{
main1(latitude, longitude,no_of_pts1-1,0,2010,0,9);
system(“gedit al_mg.dat &”);
cr_gmt(latitude,longitude,no_of_pts1-1,0,9);
}
else {
main1(latitude, longitude,no_of_pts1-1,w3,w4,w1,w2);

//main2(latitude, longitude,no_of_pts1-1,w3,w4);
system(“gedit al_mg.dat &”);
switch (n) {
case 0:cr_gmt(latitude,longitude,no_of_pts1-1,w1,w2);
break;
case 1: main2(latitude, longitude,no_of_pts1-1,w3,w4);
cr_gmt2(latitude,longitude,no_of_pts1-1,w1,w2);
break;
default:break;
} }
//cr_gmt(latitude,longitude,no_of_pts1-1,w1,w2);
//else if(x>885 && x<924 && y>431 && y<448)
}
//if(state== GLUT_DOWN){
//printf("coordinates are x=%d, y=%d
",x,y);
//printf("coordinates are x=%d, y=%d
",x,y1);
//}

if(a1==0)
{
ptx=x;
pty=y1;
stx=x;
sty=y1;
a1=1;

}

glColor3f(1.0,0, 0);
glPointSize(5);
glBegin(GL_POINTS);
glVertex2i(x, y1);
glEnd();
glBegin(GL_LINES);
glVertex2i(ptx,pty);
glVertex2i(x,y1);
glEnd();
ptx=x;
pty=y1;
// glFlush();
glutSwapBuffers();
}
}

}
cheak++;
}

void pmotion(int x, int y)
{

char st1[6],st2[10];
switch(focus)
{
case 1:
focus=0;
textbox(797,670,919,620,1,1,0);
glColor3f(1.0,0,1);
output2(830,635,“EXIT”);
break;

case 2:
focus=0;
textbox(790,590,926,530,0,0,0);
glColor3f(1.0,0,1);
output1(815,572,“Magnitude”) ;
break;
case 3:
focus=0;
textbox(790,500,926,440,0,0,0);
glColor3f(1.0,0,1);
output1(837,482,“Year”) ;
break;

}
//printf("motion: x=%3d y=%3d
",x,y);

if(x>42 && x<=614 && y>38 && y<=661)
{
if(y>=39 && y<=128)
{
lat=40-(float)(5*(y-39))/(89);
}
else if(y<=213)
{
lat=35-(float)(5*(y-128))/(85);
}
else if(y<=293)
{
lat=30-(float)(5*(y-213))/(80);
}
else if(y<=371)
{
lat=25-(float)(5*(y-293))/(78);
}
else if(y<=444)
{
lat=20-(float)(5*(y-371))/(73);
}
else if(y<=518)
{
lat=15-(float)(5*(y-444))/(74);
}
else if(y<=588)
{
lat=10-(float)(5*(y-518))/(70);
}
else if(y<=661)
{
lat=5-(float)((5*(y-588)))/(73);
}
if(x>=43 && x<=116)
{
lon=60+(float)(5*(x-43))/73;
}
else if(x<=185)
{
lon=65+(float)(5*(x-116))/69;
}
else if(x<=258)
{
lon=70+(float)(5*(x-185))/73;
}
else if(x<=328)
{
lon=75+(float)(5*(x-258))/70;
}
else if(x<=401)
{
lon=80+(float)(5*(x-328))/73;
}
else if(x<=472)
{
lon=85+(float)(5*(x-401))/71;
}
else if(x<=544)
{
lon=90+(float)(5*(x-472))/72;
}
else if(x<=614)
{
lon=95+(float)(5*(x-544))/70;
}

//textbox(862,306,999,470,0,0,1);
textbox(790,270,926,296,0,0,1);
textbox(790,200,926,247,0,0,1);
glColor3f(1,1,0);
sprintf(st2,“%f”,lat);
output1(815,275,st2);
sprintf(st2,“%f”,lon);
output1(815,230,st2);
glutSwapBuffers();
}
else
{
textbox(790,320,926,200,0,0,1);
glColor3f(0,1,0);
output1(810,300,“Latitude”) ;
output1(810,255,“Longitude”) ;
output1(810,209,“Out of map”);
glutSwapBuffers();
if(x>830 && x<890)
{
if(y>45 && y<70)
{
focus=1;
textbox(797,670,919,620,1,1,0);
glColor3f(0.0,0,1);
output2(830,635,“EXIT”);
glutSwapBuffers();
}

}
}
}
static int add_text(unsigned char key)
{
char msg = “x”;
int len;
if(!getting_text) return 0;
if(key==8) /* backspace */
{
len = strlen(the_text);
the_text[len-1] = ‘\0’;
}
else if(key==13 || key==9)
{
getting_text = 0;
text_entered(the_text);
}
else
{
msg[0] = key;
strcat(the_text, msg);
}
glutPostRedisplay();
return 1;
}

void keyboard(unsigned char key, int x, int y)
{
//int y1=850-y;
//printf("x=%d,y=%d
",x,y1);
//printf("x=%d,y=%d
",x,y);
if(add_text(key)) return;

switch (key)
{
case ‘a’:
break;
default :
break;
}
glutPostRedisplay();
}

int main(int argc, char* argv)
{
glutInit(&argc,argv);
glutInitDisplayMode (GLUT_RGBA | GLUT_DOUBLE);
glutInitWindowSize(767,700);
glutInitWindowPosition(0,0);
win=glutCreateWindow(“simple”);
glutReshapeFunc(Resize);
glutDisplayFunc(display);
glutMouseFunc(cmouse);
glutPassiveMotionFunc(pmotion);
glutKeyboardFunc(keyboard);
glutCreateMenu(selectColor);
glutAddMenuEntry(" REFRESH “, 1);
glutAddMenuEntry(” EXIT ", 2);
glutAttachMenu(GLUT_RIGHT_BUTTON);

    if (argc &gt; 1)
    BitmapBits = LoadDIBitmap(argv[1], &BitmapInfo);
    else
    BitmapBits = LoadDIBitmap(filepath, &BitmapInfo);  /*loading image here*/
    glutMainLoop();
    if (BitmapInfo)
    {
      free(BitmapInfo);
      free(BitmapBits);
    }
return (0);

}

Do not forget that after a swapbuffers, the framebuffer content is undefined, you will have to clear and redraw everything.

I didnt get you… So how should i correct it in my code…Can you please explain me in detail…I am just beginner not sure.

What you did not get in “clear and redraw everything” ?