小编no8*_*1no的帖子

OpenGL - 如何在调整大小时适应窗口

我有一个以窗口屏幕为中心的形状。目前,窗口大小调整保持不变(相同的宽度和高度)。在调整大小时使其适合窗口并保持其纵横比的最佳方法是什么?

const int WIDTH = 490;
const int HEIGHT = 600;

/**
* render scene
*/
void renderScene(void)
{
    //clear all data on scene
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    //set white bg color
    glClearColor(1, 1, 1, 1);

    glColor3ub(153, 153, 255);
    glBegin(GL_POLYGON);
        glVertex2f(60, 310);
        glVertex2f(245, 50);
        glVertex2f(430, 310);
        glVertex2f(245, 530);
    glEnd();

    glutSwapBuffers();
}

/**
* reshape scene
*/
void reshapeScene(GLint width, GLint height)
{
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();

    glViewport(0, 0, width, height);
    gluOrtho2D(0, width, height, 0);
    glMatrixMode(GL_MODELVIEW);

    glutPostRedisplay();
}

/**
* entry point
*/
int …
Run Code Online (Sandbox Code Playgroud)

c++ opengl resize

0
推荐指数
1
解决办法
1万
查看次数

标签 统计

c++ ×1

opengl ×1

resize ×1