简体   繁体   中英

OpenGL Smooth Zooming

My goal is to implement a zooming function on scroll of the mouse. So far I implemented the zooming effect using glViewport, which works quite fine. But of course the image is not really smooth, it shows edgy pixels.

I want to try now to make the image more smooth after zooming. I already tried using the glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); (and MIN_FILTER), but it does not show any difference compared to the GL_NEAREST.

Do you guys have any good ideas on how to make the zoomed image look smoother? Is it maybe a good idea to take the pixel matrix and calculate the pixels manually by using a scalar algorithm like 2xSal for example?

so far, my code is

void zoom(double scale) {
    GLint m_viewport[4];

    glGetIntegerv(GL_VIEWPORT, m_viewport);

    if (scale > 0) {

        glViewport(m_viewport[0] - (m_viewport[2] / 2), m_viewport[1] - (m_viewport[3] / 2), m_viewport[2] * 2, m_viewport[3] * 2);
    }
    else {
        glViewport(m_viewport[0] + (m_viewport[2] / 4), m_viewport[1] + (m_viewport[3] / 4), m_viewport[2] / 2, m_viewport[3] / 2);
    }

    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); 

These functions modify whatever texture is currently bound to the OpenGL context at the time they are called. Before calling them, you must first bind the texture who's parameters you want to change.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM