OpenGL空白屏幕
OpenGL blank screen?
我正在从书中学习OpenGL,我完全按照书中的内容做了,但是当我运行它(Eclipse c++ IDE)时,我得到的只是空白屏幕。这本书是"OpenGL程序员指南"。我认为错误是在重塑(),但代码是从书。
#include <iostream>
#include <GL/glew.h>
#include <GL/glut.h>
typedef const char* String;
String TITLE = "OpenGL";
int HEIGHT = 480;
int WIDTH = HEIGHT / 9 * 12;
void Update(int time){
glutPostRedisplay();
glutTimerFunc( 10, Update, 1);
}
void Init(){
glClearColor(1.0, 1.0, 1.0, 0.0);
glShadeModel(GL_FLAT);
}
void Render(){
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0, 1.0, 0.0);
glLoadIdentity();
gluLookAt(0.0, 0.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
glScalef(1.0, 2.0, 1.0); // Modeling transformation
glutWireCube(1.0);
glutSwapBuffers();
}
void Reshape(int w, int h){
glViewport(0, 0, (GLsizei) w, (GLsizei) h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glMatrixMode(GL_MODELVIEW);
}
int main(int argc, char** argv){
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA);
glutInitWindowSize(WIDTH, HEIGHT);
glutCreateWindow(TITLE);
glewExperimental = true;
GLenum err = glewInit();
if(err!=GLEW_OK){
exit(1);
}
Init();
Update(1);
glutDisplayFunc(Render);
glutReshapeFunc(Reshape);
glutMainLoop();
return 0;
}
是,重塑函数肯定是错误的
使用void Reshape(GLsizei w,GLsizei h)
{
glViewport(0,0,w,h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
if (h == 0)
h = 1;
GLfloat aspectRatio;
aspectRatio = static_cast<GLfloat>(w) / static_cast<GLfloat>(h);
gluPerspective(45.0,aspectRatio,1.0,4000.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
相反,相关文章:
- OpenGL - 添加第二个着色器属性会导致空白屏幕
- WXWIDGETS应用于WXStaticBitMap时,屏幕截图将大部分图像留为空白
- OpenGL多个带有独特着色器的呼叫可提供空白屏幕
- 绘制三角形时只有空白屏幕
- OpenGL 3 Qt 渲染空白屏幕
- OpenGL显示空白屏幕.可能是因为着色器
- Qml 中的 PyQt5 ApplicationWindow 出现空白屏幕
- SDL3dOpenGL:立方体上的纹理产生空白屏幕
- visualstudio-提供空白屏幕作为输出
- 如何排除vulkan空白屏幕故障
- TMXTiledMap显示空白屏幕
- C++生成随机数而不重复.输出屏幕只是一片空白,光标在闪烁
- GLUT只是呈现一个空白的白色屏幕
- 在OpenGL中启用深度测试后,我的整个屏幕是空白的(恢复为清晰的颜色)-为什么
- 在c++中调试程序时,我得到一个空白屏幕
- OpenGL空白屏幕
- 记录屏幕时不出现的奇怪的 MFC/GDI 行为(空白图像)
- gluLookAt()使屏幕空白
- QT OpenGL, glDrawElements和glDrawArray只显示空白屏幕
- 使用帧缓冲和Oculus Rift的空白屏幕