我想让它成为双缓冲,但它仍然在闪烁。它基本上是 OpenNI UserTracker 示例的修改版本,它在我的计算机上运行良好,但我认为我没有删除或显着更改任何重要的 OpenGL 命令,使其运行方式不同。我在我的电脑上运行 Ubuntu 10.04。
#include <GL/glut.h>
#include <GL/glx.h>
void DrawRectangle(float topLeftX, float topLeftY, float bottomRightX, float bottomRightY){
GLfloat verts[8] = { topLeftX, topLeftY,
topLeftX, bottomRightY,
bottomRightX, bottomRightY,
bottomRightX, topLeftY };
glVertexPointer(2, GL_FLOAT, 0, verts);
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
}
void DrawTexture(float topLeftX, float topLeftY, float bottomRightX, float bottomRightY){
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glTexCoordPointer(2, GL_FLOAT, 0, texcoords);
DrawRectangle(topLeftX, topLeftY, bottomRightX, bottomRightY);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
}
void DrawLimb(KinectUserData player, int a, int b){
glBegin(GL_LINES);
glVertex3d((player.joints[a].x/500), (player.joints[a].y/400), 0);
glVertex3d((player.joints[b].x/500), (player.joints[b].y/400), 0);
glEnd();
}
void Draw(KinectData kdata){
glColor4f(0.75,0.75,0.75,1);
glEnable(GL_TEXTURE_2D);
DrawTexture(320,240,0,0);
glDisable(GL_TEXTURE_2D);
for (uint i = 0; i < kdata.size(); i++){
glColor4f(1-Colors[kdata[i].getID()%nColors][0], 1-Colors[kdata[i].getID()%nColors][1], 1-Colors[kdata[i].getID()%nColors][2], 1);
DrawLimb(kdata[i], 0, 1);
DrawLimb(kdata[i], 1, 3);
DrawLimb(kdata[i], 3, 4);
DrawLimb(kdata[i], 4, 5);
DrawLimb(kdata[i], 1, 6);
DrawLimb(kdata[i], 6, 7);
DrawLimb(kdata[i], 7, 8);
DrawLimb(kdata[i], 3, 2);
DrawLimb(kdata[i], 6, 2);
DrawLimb(kdata[i], 2, 9);
DrawLimb(kdata[i], 9, 10);
DrawLimb(kdata[i], 10, 11);
DrawLimb(kdata[i], 2, 12);
DrawLimb(kdata[i], 12, 13);
DrawLimb(kdata[i], 13, 14);
DrawLimb(kdata[i], 9, 12);
}
}
void glutDisplay(void){
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
glDisable(GL_TEXTURE_2D);
Draw(data); //data is correctly intialized in other functions
glPopMatrix();
glutSwapBuffers();
glutPostRedisplay();
}
void glInit(int * pargc, char ** argv){
glutInit(pargc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
glutInitWindowSize(GL_WIN_SIZE_X, GL_WIN_SIZE_Y);
glutCreateWindow("Tracker");
glutSetCursor(GLUT_CURSOR_NONE);
glutDisplayFunc(glutDisplay);
glDisable(GL_DEPTH_TEST);
glEnable(GL_TEXTURE_2D);
glEnableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_COLOR_ARRAY);
}
int main(int argc, char** argv){
glInit(&argc, argv);
glutMainLoop();
}