Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
602 views
in Technique[技术] by (71.8m points)

codeblocks - How to prevent scaling lower than defined (OpenGL)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...