Hello,
after glutDisplayFunc() done I start to work with glutMouseFunc() - here I draw some objects but if I make reshaping of the window by mouse then all the objects, which were drawn with glutMouseFunc(),
disappear. Wich were created before glutMouseFunc() call - they present on the window. What is wrong?
I made very simple version of my program which show the same mistake(second object disappear disappear after reshaping):
Regards/Oleg
#include <iostream.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <GL/gl.h>
#include <GL/glut.h>
int screenWidth = 800;
int screenHeight = 800;
const float winWidth = 130.;
const float winHeight = 130.;
void myMouse(int button, int state, int x, int y) {
if(button == GLUT_RIGHT_BUTTON && state == GLUT_DOWN) exit(-1);
if(button == GLUT_LEFT_BUTTON && state == GLUT_DOWN)
{
glColor3f(0.,0.,1.);
glBegin(GL_LINE_LOOP);
glVertex2f(50.,50.);
glVertex2f(50.,90.);
glVertex2f(90.,90.);
glVertex2f(90.,50.);
glEnd();
glFlush();
}
}
void reshape (int w, int h)
{
screenWidth = w;
screenHeight = h;
glViewport(0, 0, (GLsizei)screenWidth, (GLsizei)screenHeight);
}
void myInit(void)
{
glClearColor(1.0,1.0,1.0,0.0);
glColor3f(0.0f, 0.0f, 0.0f);
glPointSize(2.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0, 130., 0.0, 130.);
glViewport(0, 0, (GLsizei)screenWidth, (GLsizei)screenHeight);
glDrawBuffer(GL_FRONT);
}
void myDisplay(void)
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(0.,0.,1.);
glBegin(GL_LINE_LOOP);
glVertex2f(70.,70.);
glVertex2f(70.,110.);
glVertex2f(110.,110.);
glVertex2f(110.,70.);
glEnd();
glFlush();
}
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(screenWidth, screenHeight);
glutInitWindowPosition(100, 100);
glutCreateWindow(“Dot Plot of a Function”);
glutMouseFunc(myMouse);
glutDisplayFunc(myDisplay);
glutReshapeFunc(reshape);
myInit();
glutMainLoop();
return 0;
}