我想在 OpenGL 窗口中显示当前屏幕/dev/fb0
,我需要获得更快的像素映射,我已经编写了一些代码,但不幸的是它没有达到我的预期?这是因为使用 /dev/fb0 还是代码本身的问题?任何有关如何在 C++ 中比 /dev/fb0 更快地获取屏幕地图的建议都值得赞赏。
#used below Perl code just to check whether image formation is correct manually
#But it didn't work (png didn't form as a screen)
#!/usr/bin/perl -w
$w = shift || 240;
$h = shift || 320;
$pixels = $w * $h;
open OUT, "|pnmtopng" or die "Can't pipe pnmtopng: $!\n";
printf OUT "P6%d %d\n255\n", $w, $h;
while ((read STDIN, $raw, 2) and $pixels--) {
$short = unpack('S', $raw);
print OUT pack("C4444",
($short & 0xf800) >> 8,
($short & 0x7e0) >> 3,
($short & 0x1f) << 3);
}
close OUT;
也使用了 glDrawpixels 但没有打印:
//内部渲染函数(使用这个我得到白色|在黑屏上)
glClear(GL_COLOR_BUFFER_BIT);
int fbfd = 0;
struct fb_var_screeninfo vinfo;
struct fb_fix_screeninfo finfo;
int wrap = 1;
long int screensize = 0;
fbfd = open("/dev/fb0", O_RDWR);
if (fbfd == -1) {
.....
}
printf("The framebuffer device was opened successfully.\n");
if (ioctl(fbfd, FBIOGET_FSCREENINFO, &finfo) == -1) {
....
}
if (ioctl(fbfd, FBIOGET_VSCREENINFO, &vinfo) == -1) {
.....
}
screensize = vinfo.xres * vinfo.yres * vinfo.bits_per_pixel / 8;
GLubyte * fbp = nullptr;
fbp = (GLubyte * ) mmap(NULL, screensize, PROT_READ | PROT_WRITE, MAP_SHARED, fbfd, 0);
if(fbp != MAP_FAILED){
printf("mmap seems worked\n");
};
if ((int)*fbp == -1) {
......
exit(4);
}
printf("The framebuffer device was mapped to memory successfully.\n");
//display
glBitmap(1366,768,0,0,0,0,fbp);
glFlush();
…………