私はopenglチュートリアルに従っていますが、何らかの理由でreshape関数を追加しました(ウィンドウのサイズを変更して比率を修正するため)。openglウィンドウには、オブジェクト(形状)はまったく表示されず、黒い画面だけが表示されます。スペルミスか何かをしたかどうかわかりません。
リシェイプ機能は物事を台無しにしていますか?
#include <GL/gl.h>
#include <GL/glut.h>
void renderScene(void);
void changeSize(int w, int h);
int main(int argc, char **argv){
// init GLUT and create window
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
glutInitWindowPosition(100,100);
glutInitWindowSize(320,320);
glutCreateWindow("Testing");
// register callbacks
glutDisplayFunc(renderScene);
// animation in reshaping
glutReshapeFunc(changeSize);
// enter GLUT event processing cycle
glutMainLoop();
return 1;
}
void renderScene(void){
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glBegin(GL_TRIANGLES);
glVertex3f(-0.5,-0.5,0.0);
glVertex3f(0.5,0.0,0.0);
glVertex3f(0.0,0.5,0.0);
glEnd();
glutSwapBuffers();
}
void changeSize(int w, int h){
if (h==0)
h = 1;
float ratio = 1.0*w/h;
// use the projection matrix
glMatrixMode(GL_PROJECTION);
//reset matrix
glLoadIdentity();
// set the viewpoint to be the entire window
glViewport(0,0,w,h);
// set the correct perspective
gluPerspective(45, ratio, 1, 1000);
// get back to the modelview
glMatrixMode(GL_MODELVIEW);
}
助けてくれてありがとう!これは、Lighthouse3dチュートリアルからのものです。
PS:リシェイプ機能を外すと、三角形が表示されます(正常に動作します)。