0

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

Wolfhrat
  • 11
  • 5
  • Assuming that `scalesize` is a global variable, update and verify its value in your `glutMouseFunc`. For example, do `scalesize -= .1` when the left button is pressed (similar operation for when the right button is pressed), and before exiting your `glutMouseFunc`, just do a `std::clamp` (or a couple of `if` statements) making sure `scalesize` isn't too big or small (e.g., `if (scalesize < 0.15) scalesize = 0.15`. What you don't want to do is call `glScalef` in your mouse function; just let that happen in `scene`. – radical7 Jan 24 '21 at 08:00

1 Answers1

0

Ok, thanks to @radical7 I've figured it out. Already did everything what he said, but the real solution was to let scene function do its job, I didnt have to call glScalef in my mouse function.

Thanks again.

Wolfhrat
  • 11
  • 5