G
G
Gokilla2018-02-09 22:55:44
C++ / C#
Gokilla, 2018-02-09 22:55:44

RGBA not displaying correctly?

There is a source image bmp size 960 * 495
5a7dfbfe12911717707076.png
Here is the program
5a7dfc547bc90727604293.png
Here is the code:

void FileReader::FileReader__(const char__ *filename,const char__ *state)
{
  std::string ext="";
  int__ l=strlen(filename);
  while(--l>0&&filename[l]!='.')
    ext+=filename[l];
  if(strstr(ext.c_str(),"fnoc") || strstr(ext.c_str(),"lmx"))
  {
    ext_=true;
    file=fopen(filename,state);
    open_=true;
    char__ ch;
    while((ch=fgetc(file))!=-1)
    {
          if(ch==10)
        strokoffile++;
      countbyte++;
    }
    fclose(file);
    file=fopen(filename,state);
  }
  else
  {
    life=open(filename,_A_ARCH);
    ext_=false;
    org=0;
  }
}
void__ FileReader::ReadFile(int__ size_,void__ *buf)
{
  lseek(life,0,org);
    read(life,buf,size_);
  org=1;
}
void__ Scene::EnableTexture(float__*texcoor, float__*vercoor)
{
    glBegin(GL_QUADS);
    glTexCoord2f(texcoor[0],texcoor[2]);
    glVertex2f(vercoor[0],vercoor[2]);
    glTexCoord2f(texcoor[1],texcoor[2]);
    glVertex2f(vercoor[1],vercoor[2]);
    glTexCoord2f(texcoor[1],texcoor[3]);
    glVertex2f(vercoor[1],vercoor[3]);
    glTexCoord2f(texcoor[0],texcoor[3]);
    glVertex2f(vercoor[0],vercoor[3]);
    glEnd();
}
    NewData=new uchar__[4*960*495];
    NewTexture=new uint__[1];
void__ Scene::ShowBackGround()
{
  filereader->FileReader__("J:\\фукрпкявамчс\\content\\Загрузки\\table.bmp","r");
  filereader->ReadFile(960*495*4,NewData);
  for(float__ i=0;i<960*495;i++)
    {
        int__ index=i*4;
        uchar__ R,G,B,A;
        B=NewData[index];
        G=NewData[index+1];//Green(B)
        A=NewData[index+2];//Red(G)
        R=NewData[index+3];//blue(R)
        NewData[index]=R;
        NewData[index+1]=G;//(G)
        NewData[index+2]=B;//(B)
        NewData[index+3]=A;//(R)
        //GBR
        //BGsR
    }
    glBindTexture(GL_TEXTURE_2D,NewTexture[0]);
    gluBuild2DMipmaps(GL_TEXTURE_2D,GL_RGBA,960,495,GL_RGBA,GL_UNSIGNED_BYTE,NewData);
    EnableTexture(GetTextureCoordinats(10),GetVertexCoordinats(0));
  return;
}

Where is the mistake?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
G
Gokilla, 2018-02-10
@Gokilla

for(float__ i=54;i<960*495;i++)
    {
        int__ index=i*4;
        uchar__ R,G,B,A;
        
    R=NewData[index];				//R
        A=NewData[index+1];//Green(B)	//G
        B=NewData[index+2];//Red(G)		//A
        G=NewData[index+3];//blue(R)	//B
        NewData[index]=R;
        NewData[index+1]=G;//(G)
        NewData[index+2]=B;//(B)
        NewData[index+3]=A;//(R)
    
        //GBR
        //BGsR
    }

Here is the answer

V
VoidVolker, 2018-02-09
@VoidVolker

filereader->FileReader__("J:\\фукрпкявамчс\\content\\Загрузки\\table.bmp","r");
  filereader->ReadFile(960*495*4,NewData);

The BMP format is fully documented and described - there are a lot of ready-made libraries. So either use ready-made code to read the file or implement it yourself. This format supports palettes, and the color of a pixel can be from one to 64 bits (i.e. up to eight bytes). In this case, there is clearly an incorrect interpretation of the color data. In addition, it also contains a header, which fully describes all the information about the image and the pixel format, and which is completely ignored in this code. And there the lines are aligned by the power of four - so in any case, all the pixels are read in two cycles (the second one is nested).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question