调整过剩窗口的大小
我正在一个过多的窗口中进行 2D 绘图,并且无法正确调整窗口大小。
我的 glutDisplayFunc 和 glutReshapeFunc 如下。实际上,当调整窗口大小时,绘图就会消失。如果我从 displayFunc() 中删除 glClear(),新像素不会“初始化”并且存在剪切问题。我该如何解决这个问题?
glutDisplayFunc:
void displayFunc() {
glDisable( GL_DEPTH_TEST );
glClear( GL_COLOR_BUFFER_BIT );
glPointSize ( 3.0 );
glFlush();
}
glutReshapeFunc:
void windowReshapeFunc( GLint newWidth, GLint newHeight ) {
glViewport( 0, 0, newWidth, newHeight );
glMatrixMode( GL_PROJECTION );
glLoadIdentity();
gluOrtho2D( 0, GLdouble (newWidth), 0, GLdouble (newHeight) );
windowWidth = newWidth;
windowHeight = newHeight;
}
I'm doing 2D drawing in a glut window, and I'm having trouble making the window resize properly.
My glutDisplayFunc and glutReshapeFunc are below. As it is, the drawing disappears when the window is resized. If I delete the glClear() from displayFunc(), new pixels don't "initialize" and there are clipping problems. How do I fix this?
glutDisplayFunc:
void displayFunc() {
glDisable( GL_DEPTH_TEST );
glClear( GL_COLOR_BUFFER_BIT );
glPointSize ( 3.0 );
glFlush();
}
glutReshapeFunc:
void windowReshapeFunc( GLint newWidth, GLint newHeight ) {
glViewport( 0, 0, newWidth, newHeight );
glMatrixMode( GL_PROJECTION );
glLoadIdentity();
gluOrtho2D( 0, GLdouble (newWidth), 0, GLdouble (newHeight) );
windowWidth = newWidth;
windowHeight = newHeight;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我会尝试在重塑函数末尾添加对 glutPostRedisplay() 的调用。
I'd try adding a call to
glutPostRedisplay()
around the end of your reshape function.这是我使用的基本模板...
This is basic template that I use...
您不能使用同一窗口调用 gluOrtho2D 两次,它会破坏图形,因此不会显示任何内容。您必须初始化窗口大小并将 Ortho 设置为屏幕大小(当前显示分辨率),然后相对于窗口大小进行绘制。
You can not call gluOrtho2D twice with the same window, it will break the graphics and so nothing shows up. You would have to init window size and set Ortho to the size of the screen (current display resolution), then draw relative to the size of the window.
我猜你的代码不会在显示函数中绘制场景上的所有内容,你看,如果没有发生任何事件,你必须调用一次显示,并且第一次它有你的绘图。但是,当有一个事件表明窗口大小已调整时,您的问题就会出现!尝试将您的绘图部分放入显示功能中。像这样,
如果这没有帮助,请发布完整的代码。
I guess your code does not draw everything on scene in display func, you see, if no events occcur ever you have to call display one time and in the first time it has your drawing. But your problem rises when there is an event which says the window is resized! try putting your drawing part in display function. Like so,
Please post the full code if this was not helpful.
您没有在重塑函数结束时将矩阵模式设置回 GL_MODELVIEW。
如果没有看到更多代码,很难说您的显示函数中是否还有其他内容。我希望这有帮助。
You're not setting the matrix mode back to GL_MODELVIEW at the end of your reshape function.
It's hard to say if there's something else in your display function without seeing more code. I hope that helps.