I have a simple OpenGL object which has defined certain glScalef size. It needs glutMouseFunc to make it work as I imagined. So, this is what I've imagined:
On GLUT_LEFT_BUTTON
object needs to go bigger for 0.1, so:
glScalef(scalesize+0.1,scalesize+0.1,0.0.);
polygon();
On GLUT_RIGHT_BUTTON
object needs to go smaller for 0.1, so:
glScalef(scalesize-0.1,scalesize-0.1,0.0);
polygon();
This is my polygon function:
void polygon(void){
glBegin(GL_POLYGON);
glColor3f(1.0,0.0,0.0);
glVertex2f(-0.15, -0.15);
glColor3f(0.0,0.0,0.0);
glVertex2f(-0.15, 0.15);
glColor3f(0.0,0.0,1.0);
glVertex2f(0.15, 0.15);
glColor3f(0.0,1.0,0.0);
glVertex2f(0.15, -0.15);
glEnd();
glEnable (GL_LINE_STIPPLE);
glLineWidth(3.0);
glLineStipple (6, 0x1C47);
glBegin(GL_LINES);
glColor3f(0.0,0.0,0.0);
glVertex2f(-0.25, -0.25);
glVertex2f(-0.25, 0.25);
glVertex2f(0.25, 0.25);
glVertex2f(0.25, -0.25);
glVertex2f(-0.25, 0.25);
glVertex2f(0.25, 0.25);
glVertex2f(-0.25, -0.25);
glVertex2f(0.25, -0.25);
glEnd();
}
This is my scene function:
void scene(void){
glClear(GL_COLOR_BUFFER_BIT);
glPushMatrix();
glScalef(scalesize,scalesize,0.0);
polygon();
glPopMatrix();
glFlush();
}
float scalesize = 1.0;
Now I'm not sure how to prevent scaling lower than 0.15, regarding to my object size. I've tried with if statement to check if scalesize is bigger than 1.0, but didn't worked. Any solutions?
Thanks
question from:
https://stackoverflow.com/questions/65864519/how-to-prevent-scaling-lower-than-defined-opengl