PDA

View Full Version : reshape func problem =(



Meatz0r
04-21-2011, 03:33 PM
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 \n");
}


void display(void){
glClear(GL_COLOR_BUFFER_BIT);
//&amp;#1073;&amp;#1077;&amp;#1083;&amp;#1099;&amp;#1081; &amp;#1094;&amp;#1074;&amp;#1077;&amp;#1090; &amp;#1074;&amp;#1089;&amp;#1077;&amp;#1093; &amp;#1083;&amp;#1080;&amp;#1085;&amp;#1080;&amp;#1081;
glColor3f(0.0,0.0,0.0);
//3 &amp;#1083;&amp;#1080;&amp;#1085;&amp;#1080;&amp;#1080; &amp;#1088;&amp;#1072;&amp;#1079;&amp;#1085;&amp;#1086;&amp;#1075;&amp;#108 6; &amp;#1074;&amp;#1080;&amp;#1076;&amp;#1072;
glEnable(GL_LINE_STIPPLE);
glLineStipple(1,0x3F07);
drawLine(0.0,0.0,400.0,150.0);
glDisable(GL_LINE_STIPPLE);
glFlush();
printf("display \n");
}

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 \n");
}



int main(int argc,char** argv)
{
glutInit(&amp;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=(

Kelvin
04-21-2011, 08:56 PM
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.

Meatz0r
04-22-2011, 09:00 AM
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?=(

Meatz0r
04-23-2011, 03:50 AM
or its only possible in double-buffer mode? i Think no. Help me to understand plz)

ZbuffeR
04-23-2011, 04:07 AM
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.

Meatz0r
04-23-2011, 07:41 AM
Thank u very much, ill consider this advice

mhagain
04-23-2011, 08:18 AM
Don't just consider it. ;)

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.

Meatz0r
04-23-2011, 11:47 AM
Ok, thanks=) i meant that i will use it.
Im bad in Engl sorry=)

Meatz0r
04-23-2011, 03:20 PM
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 \n");
}


void display(void){
glClear(GL_COLOR_BUFFER_BIT);
//&amp;#1073;&amp;#1077;&amp;#1083;&amp;#1099;&amp;#1081; &amp;#1094;&amp;#1074;&amp;#1077;&amp;#1090; &amp;#1074;&amp;#1089;&amp;#1077;&amp;#1093; &amp;#1083;&amp;#1080;&amp;#1085;&amp;#1080;&amp;#1081;
glColor3f(0.0,0.0,0.0);
//3 &amp;#1083;&amp;#1080;&amp;#1085;&amp;#1080;&amp;#1080; &amp;#1088;&amp;#1072;&amp;#1079;&amp;#1085;&amp;#1086;&amp;#1075;&amp;#108 6; &amp;#1074;&amp;#1080;&amp;#1076;&amp;#1072;
glEnable(GL_LINE_STIPPLE);
glLineStipple(1,0x3F07);
drawLine(0.0,0.0,400.0,150.0);
glDisable(GL_LINE_STIPPLE);
glFlush();
glutSwapBuffers();

printf("display \n");
}

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 \n");
}



int main(int argc,char** argv)
{
glutInit(&amp;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