Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/144.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/58.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 我似乎无法修改帧缓冲区_C++_C_Linux_Framebuffer - Fatal编程技术网

C++ 我似乎无法修改帧缓冲区

C++ 我似乎无法修改帧缓冲区,c++,c,linux,framebuffer,C++,C,Linux,Framebuffer,我正在尝试修改Linux上的帧缓冲区。我正在通过虚拟终端(tty)运行该程序。我似乎无法修改我想要的像素。这是我的密码: #include <stdio.h> unsigned char buffer[4 * 1366 * 768]; const int framewidth = 1366; void placepixel(int x, int y, int r, int g, int b, int a){ buffer[(framewidth * y) +

我正在尝试修改Linux上的帧缓冲区。我正在通过虚拟终端(tty)运行该程序。我似乎无法修改我想要的像素。这是我的密码:

#include <stdio.h>

    unsigned char buffer[4 * 1366 * 768];
    const int framewidth = 1366;
void placepixel(int x, int y, int r, int g, int b, int a){
    buffer[(framewidth * y) + x] = b;
    buffer[(framewidth * y) + x+1] = g;
    buffer[(framewidth * y) + x+2] = r;
    buffer[(framewidth * y) + x+3] = a;
}

void placepixelbynum(int i, int r, int g, int b, int a){
    buffer[i] = b;
    buffer[i+1] = g;
    buffer[i+2] = r;
    buffer[i+3] = a;
}
int main(){
    for(int i = 0; i < 4 * 1366 * 768; i+=4){
        placepixelbynum(i, 50,50,50,0);
    }
    FILE *write_ptr;

    write_ptr = fopen("/dev/fb0","wb");

    int x, y, z, xr, yr, zr;

    while(true){

    for(int i = 0; i < 128; i++){

    placepixel(128+i,128,255,0,0,0);
    }
    fwrite(buffer,sizeof(buffer),1,write_ptr);

    }
    return 0;

}



#包括
无符号字符缓冲区[4*1366*768];
const int framewidth=1366;
空像素(整数x,整数y,整数r,整数g,整数b,整数a){
缓冲区[(帧宽*y)+x]=b;
缓冲区[(帧宽*y)+x+1]=g;
缓冲区[(帧宽*y)+x+2]=r;
缓冲区[(帧宽*y)+x+3]=a;
}
void placepixelbynum(inti,intr,intg,intb,inta){
缓冲区[i]=b;
缓冲区[i+1]=g;
缓冲区[i+2]=r;
缓冲器[i+3]=a;
}
int main(){
对于(int i=0;i<4*1366*768;i+=4){
placepixelbynum(i,50,50,50,0);
}
文件*write_ptr;
write_ptr=fopen(“/dev/fb0”,“wb”);
整数x,y,z,xr,yr,zr;
while(true){
对于(int i=0;i<128;i++){
placepixel(128+i,128255,0,0,0);
}
fwrite(buffer,sizeof(buffer),1,write_ptr);
}
返回0;
}

当我运行此命令时,屏幕会变为灰色(如预期的那样),但会将行放置在我预期的位置之外。(我希望它从128x128开始,到256x128结束),但它靠近屏幕的右端。

问题似乎是,没有为每个像素计算4字节的缓冲空间。考虑下面的书桌检查< /P>
像素(0,0)
(帧宽*y)+x+0->0
(帧宽*y)+x+1->1
(帧宽*y)+x+2->2
(帧宽*y)+x+3->3
像素(1,0)
(帧宽*y)+x+0->1
(帧宽*y)+x+1->2
(帧宽*y)+x+2->3
(帧宽*y)+x+3->4
我想你会在这样的事情上取得更大的成功:

void placePixel(int x, int y, int r, int g, int b, int a)
{
    int index = 4 * ((frameWidth*y) + x)
    buffer[index+0] = r;
    buffer[index+1] = g;
    buffer[index+2] = b;
    buffer[index+3] = a;
}

问题似乎是,没有为每个像素分配4字节的缓冲空间。考虑下面的书桌检查< /P>
像素(0,0)
(帧宽*y)+x+0->0
(帧宽*y)+x+1->1
(帧宽*y)+x+2->2
(帧宽*y)+x+3->3
像素(1,0)
(帧宽*y)+x+0->1
(帧宽*y)+x+1->2
(帧宽*y)+x+2->3
(帧宽*y)+x+3->4
我想你会在这样的事情上取得更大的成功:

void placePixel(int x, int y, int r, int g, int b, int a)
{
    int index = 4 * ((frameWidth*y) + x)
    buffer[index+0] = r;
    buffer[index+1] = g;
    buffer[index+2] = b;
    buffer[index+3] = a;
}