我试图显示一个只有两个面的简单三角形,但当我执行它,试图旋转三角形时,没有刷新:(仅当我全屏显示,或最小化和重新最大化时才刷新)
我的代码是:
#include <GL/freeglut.h>
#include <GL/gl.h>
#include <stdio.h>
#include <math.h>//useless but I will need it soon.
float rotx, roty = 0.0f;
char srotx[40];
int win;
void display()
{
glViewport(0,0,1000,800);
glBegin(GL_QUADS);
glColor3f(0.5,0,0);
glVertex3f(0.5,0.5,0);
glColor3f(0,0.5,0);
glVertex3f(-0.5,0.5,0.5);
glColor3f(0,0,0.5);
glVertex3f(0,-0.5,0.5);
glColor3f(0.5,0.5,0);
glVertex3f(-0.5,0.5,-0.5);
glEnd();
glRotatef(rotx,1.0f,0.0f,0.0f);
glRotatef(roty,0.0f,1.0f,0.0f);
glutSetWindowTitle(srotx);//not working
glutSwapBuffers();
}
void BindInput(unsigned char key, int Mx, int My)
{
switch(key)
{
case 'z' :
rotx += 0.2f;
break;
case 's' :
rotx -= 0.2f;
break;
case 'd' :
roty += 0.2f;
break;
case 'q' :
roty -= 0.2f;
break;
}
if(key == 27)
{
glFinish();
exit(0);
}
if(rotx >= 360.0f || key == 'a' || roty >= 360.0f)
{
glutPostWindowRedisplay(win);//testing...
rotx = 0.0f;
roty = 0.0f;
}
glutPostRedisplay();
}
int main(int argc, char* argv[])
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize(1000,800);
sprintf(srotx, "DEBUG Mayo Test, rotx : %f", rotx);
win = glutCreateWindow(srotx);
glutSetCursor(GLUT_CURSOR_DESTROY);
glEnable(GL_DEPTH_TEST);
glMatrixMode(GL_PROJECTION);
glutDisplayFunc(display);
glutIdleFunc(display);
glutKeyboardFunc(BindInput);
glutMainLoop();
return 0;
}
截图: Starting个 spining it, no refresh
还有tasks.json:
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: gcc générer le fichier actif",
"command": "/usr/bin/gcc",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}",
"-lglut",
"-lGLU",
"-lGL"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Tâche générée par le débogueur."
},
],
"version": "2.0.0"
}
我试着在网上搜索,但我找到的所有东西都不起作用.
在Visual Studio代码上使用xubuntu 22.04(X11). 事先感谢您的回复.