我正在编写一个程序来显示 500 万个矩形,使用 OpenGL 渲染。 大约需要大约。 3 秒在屏幕上显示这些矩形。 但是,当我尝试放大/缩小或向左/向右平移屏幕时,它也会花费相同的时间。
我想知道是否有一种方法可以将所有内容保存到内存/缓冲区中,因此不必一次又一次地重绘屏幕。
我也对其他解决方案持开放态度。
以下是我的reshape函数:
static void reshape_cb() {
glViewport(0, 0, (GLint) screen_width, (GLint) screen_height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D (0.0, DESIGN_SIZE, 0.0, DESIGN_SIZE);
}
最佳答案
I am writing a program to display 5 millions rectangles, rendering with OpenGL. It takes about approx. 3 seconds to display these rectangles on the screen.
这听起来像是您在以非常低效的方式发送绘图命令。现代 GPU 每秒能够渲染数亿个三角形。我的猜测是,您正在使用即时模式。
I am wondering if there is a way to save everything into memory/buffer, therefore the screen doesn't have to be redraw all over again and again.
缩放通常意味着视角或渲染分辨率的改变,因此需要完全重绘。
I am also open with other solutions. Thank you.
您应该优化绘图代码。关键字是:
- 顶点数组
- 顶点缓冲对象
- 大批量绘图
关于c++ - 如何在不再次渲染整个屏幕的情况下放大/缩小到 OpenGL 屏幕,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22675014/