reshape func problem =(

Hello,
Help me to understand reshape function plz
for example in this code
<div class=“ubbcode-block”><div class=“ubbcode-header”>Click to reveal… <input type=“button” class=“form-button” value=“Show me!” onclick=“toggle_spoiler(this, ‘Yikes, my eyes!’, ‘Show me!’)” />]<div style=“display: none;”>
#include <GL/glut.h>
#include <stdio.h>
#define drawLine(x1,y1,x2,y2) glBegin(GL_LINES); glVertex2f((x1),(y1)); glVertex2f((x2),(y2)); glEnd();

void init(void){
glClearColor(1.0,1.0,1.0,0.0);
glShadeModel(GL_FLAT);
//glMatrixMode(GL_PROJECTION);
// glLoadIdentity;
// gluOrtho2D(0.0, 400.0, 0.0, 150.0);
printf("init
");
}

void display(void){
glClear(GL_COLOR_BUFFER_BIT);
//белый цвет всех линий
glColor3f(0.0,0.0,0.0);
//3 линии разного вида
glEnable(GL_LINE_STIPPLE);
glLineStipple(1,0x3F07);
drawLine(0.0,0.0,400.0,150.0);
glDisable(GL_LINE_STIPPLE);
glFlush();
printf("display
");
}

void reshape(int w, int h){
glViewport(0,0,(GLsizei)w,(GLsizei)h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity;
gluOrtho2D(0.0, (GLdouble) w, 0.0, (GLdouble) h);
printf("reshape
");
}

int main(int argc,char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
glutInitWindowSize(400,150);
glutInitWindowPosition(100,100);
glutCreateWindow(argv[0]);
init();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutMainLoop();

return 0;

}
[/QUOTE]</div>
I used printf(); to learn what func works first, what second …
at first i saw comment Init, then reshape, then display
after displaying and drawing line i try to change window size and
i see a lot of reshape comments
but suddenly, line, that was drawn disappears(at momment when i started changing windowsize). I cant understand why.
reshape func had worked before display at first, and then line was drown.After i had changed size of window line wasnt drown again and i saw white window.

Sorry for my terrible English=(

I don’t see a glutSwapBuffers() at the end of your display function which would be a problem unless you are drawing to a single-buffered window.

i cant understand…There is a problem if there is function glutSwapBuffers() when i draw in single-buffer mode?
But I havent this func, so there cant be problem with this func,cant it?
I dont understand why after first reshape func line was drawn(when reshape func works before display func) and then, after reshape func i had the same situation and line wasn’t drown.
May be these situations arent similar?
display func works again after reshape, why it doesnt draw my line again?=(

or its only possible in double-buffer mode? i Think no. Help me to understand plz)

  1. never use single buffer mode. Use only double buffered mode. Otherwise you expose yourself to a lot of problems, as it is less and less supported.
  2. in double buffered mode, you must call glutSwapBuffers() when you want something to appear.

Thank u very much, ill consider this advice

Don’t just consider it. :wink:

There are no technical or other reasons to not use double-buffering. It’s not more difficult than single-buffering (just one changed flag at startup and an extra function call at the end of each frame), it’s a lot more stable, gives a better image, and avoids a lot of headaches in the future.

Ok, thanks=) i meant that i will use it.
Im bad in Engl sorry=)

I tried double-buff mode, but line wasnt redrawn =)
where is a problem?
<div class=“ubbcode-block”><div class=“ubbcode-header”>Click to reveal… <input type=“button” class=“form-button” value=“Show me!” onclick=“toggle_spoiler(this, ‘Yikes, my eyes!’, ‘Show me!’)” />]<div style=“display: none;”>
#include <GL/glut.h>
#include <stdio.h>
#define drawLine(x1,y1,x2,y2) glBegin(GL_LINES); glVertex2f((x1),(y1)); glVertex2f((x2),(y2)); glEnd();

void init(void){
glClearColor(1.0,1.0,1.0,0.0);
glShadeModel(GL_FLAT);
//glMatrixMode(GL_PROJECTION);
// glLoadIdentity;
// gluOrtho2D(0.0, 400.0, 0.0, 150.0);
printf("init
");
}

void display(void){
glClear(GL_COLOR_BUFFER_BIT);
//белый цвет всех линий
glColor3f(0.0,0.0,0.0);
//3 линии разного вида
glEnable(GL_LINE_STIPPLE);
glLineStipple(1,0x3F07);
drawLine(0.0,0.0,400.0,150.0);
glDisable(GL_LINE_STIPPLE);
glFlush();
glutSwapBuffers();

printf("display 

");
}

void reshape(int w, int h){
glViewport(0,0,(GLsizei)w,(GLsizei)h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity;
gluOrtho2D(0.0, (GLdouble) w, 0.0, (GLdouble) h);
printf("reshape
");
}

int main(int argc,char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB);
glutInitWindowSize(400,150);
glutInitWindowPosition(100,100);
glutCreateWindow(argv[0]);
init();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutMainLoop();

return 0;

}
[/QUOTE]</div>

I think i should find out smth about double-buf mode xD, but if u say me where is problem it will not be bad