問題は
私はちょうどGLUTを使用してOpenGLで作業を始めました。以下のコードは、2つのワイヤフレームの立方体と球をコンパイルして表示します。問題は、ウィンドウをドラッグまたはサイズ変更しようとすると、マウスをたどる前に目に見える遅延が発生することです。OpenGL GLUTウィンドウが非常に遅いのはなぜですか?
この問題は、同僚のコンピュータでは発生しません。同じコードです。
私は、Visual Studio 2012 C++ expressをWindows 7コンピュータで使用しています。 私は経験豊富なプログラマーではありません。
コード
// OpenGLHandin1.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <GL/glut.h>
void initView(int argc, char * argv[]){
//init here
glutInit(&argc, argv);
//Simple buffer
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGBA);
glutInitWindowPosition(100,100);
glutInitWindowSize(800,400);
glutCreateWindow("Handin 2");
}
void draw(){
glClearColor(0,0,0,1);
glClear(GL_COLOR_BUFFER_BIT);
//Background color
glPushMatrix();
glLoadIdentity();
glTranslatef(0.6, 0, 0);
glColor3f(0.8,0,0);
glutWireCube(1.1); //Draw the cube
glPopMatrix();
glPushMatrix();
glLoadIdentity();
glTranslatef(-0.5, 0, -0.2);
glColor3f(0,0.8,0);
glutWireCube(1.1); //Draw the cube
glPopMatrix();
glPushMatrix();
glLoadIdentity();
glTranslatef(0, 1.2, 0);
glRotatef(90, 1, 0, 0);
glColor3f(1,1,1);
glutWireSphere(0.6, 20, 20); //Draw the sphere
glPopMatrix();
//draw here
//glutSwapBuffers();
glutPostRedisplay();
glFlush();
}
void reshape (int w, int h){
glViewport(0,0,w ,h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45, (float)w/(float)h, 1.5, 10);
gluLookAt(1.5, 2.5, 4,
0, 0.6, 0,
0, 1, 0); //Orient the camera
glRotatef(5, 0, 0, 1);
glMatrixMode(GL_MODELVIEW);
}
int main(int argc, char * argv[])
{
initView(argc,argv);
glutDisplayFunc(draw);
glutReshapeFunc(reshape);
glutMainLoop();
}
あなたの 'draw'関数で' Sleep(1) 'を追加しようとしたかもしれません。 –
実際にはうまくいきました!あなたはこの仕事の技術的理由を知っていますか、私の仲間の生徒は必要としないのですか? – aPerfectMisterMan