我搜索了一些轻量级GUI,并找到了一些(例如FLTK),但我真正想要的是Linux/Ubuntu上的一个快速库。它不需要跨平台。一定要快一点。
我的申请很简单。我有一个画布,比如800x800,在上面我是:--在一个网格中画200x200个正方形--几串文字--一些热点,一个人可以在那里按下鼠标。
我正试着尽可能快地推进帧速。我已经找到了示例X11 C++代码。
有比X更快的库吗?
提亚
更新:这是过剩中的示例代码。看起来我可以在我的笔记本电脑(索尼Vaioi7-3632QM2.2GHz运行Ubuntu12.04)上获得20 my的一帧。顺便说一句,它看起来就像电视上的“雪”.
我无法获得使用Xlib运行的等效示例。它一直以类似于"XIO:致命IO错误11 (资源暂时不可用)在X服务器上“:0的错误结束,在86次请求(86次已知已处理)之后,还有10个事件。
#include <GL/glut.h>
#include <cstdlib>
#include <pthread.h>
#include <unistd.h>
int win_w = 0.0;
int win_h = 0.0;
#include <pthread.h>
#include <iostream>
void drawGrid(int size)
{
const int cellsize = 3;
const int gridsize = size * cellsize;
for (int y = 0; y < gridsize; y += cellsize)
{
for (int x = 0; x < gridsize; x += cellsize)
{
int c = rand() % 100;
if (c < 33)
glColor3f(1.0, 0.0, 0.0);
else if (c < 66)
glColor3f(0.0, 1.0, 0.0);
else
glColor3f(0.0, 0.0, 1.0);
glRecti(x, y, x + cellsize, y + cellsize);
}
}
}
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, win_w, 0, win_h, -1, 1);
glColor3f(0.0, 0.0, 1.0);
glTranslatef(30, 30, 0);
drawGrid(200);
glFlush();
glutSwapBuffers();
}
void reshape(int w, int h)
{
win_w = w;
win_h = h;
glViewport(0, 0, w, h);
}
static int lasttime = 0L;
void idle()
{
const int timePerFrame = 19; //ms
int t = glutGet(GLUT_ELAPSED_TIME);
int delay = timePerFrame - (t - lasttime);
if (delay < 0)
{
std::cout << t << " " << lasttime << " " << delay << "\n";
}
else
{
::usleep(delay * 1000);
}
glutPostRedisplay();
lasttime = glutGet(GLUT_ELAPSED_TIME);
}
int main(int argc, char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGBA | GLUT_DEPTH | GLUT_DOUBLE);
glutInitWindowSize(800, 800);
glutCreateWindow("test Glut");
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutIdleFunc(idle);
glutMainLoop();
return 0;
}发布于 2014-01-30 18:04:41
有两个"X库“。好的,旧的Xlib和XCB。XCB应该“更快”,因为它有现代的架构。如果您对这两者的性能不满意,可以直接使用Linux框架缓冲区或使用DirectFB (http://www.directfb.org)来避免它们。
但是,框架缓冲区不会在X窗口中运行。因此,您确实需要最简单的Xlib或XCB代码来为您的应用程序创建一个窗口,并使用GLX在该窗口的表面上呈现。
最后,我相信对你来说最好的选择是SDL。网址:http://www.libsdl.org。
https://stackoverflow.com/questions/16338477
复制相似问题