SFML community forums

Help => General => Topic started by: thorr on January 16, 2018, 03:21:39 pm

Title: Direct filling the texture buffer
Post by: thorr on January 16, 2018, 03:21:39 pm
I'm trying to fill texture buffer with numeric RGBA-values, but that doesn't work, window remains black.

   RenderWindow window(VideoMode(SCR_WIDTH,SCR_HEIGHT),"test");
   
   Texture bg;

   Uint8* pixels = new Uint8[SCR_WIDTH * SCR_HEIGHT * 4];
   
   for(int j=0;j<SCR_HEIGHT;j++)
      for(int i=0;i<SCR_WIDTH;i++)
      {
         pixels[j*SCR_WIDTH*4+i*4]=50;   //red
         pixels[j*SCR_WIDTH*4+i*4+1]=j%255;   // green
         pixels[j*SCR_WIDTH*4+i*4+2]=j%255;   // blue
         pixels[j*SCR_WIDTH*4+i*4+3]=255;// alpha
      }

   bg.update(pixels);
     
   Sprite sprite_bg;
   sprite_bg.setTexture(bg);

   while(window.isOpen()){
      Event e;
      while (window.pollEvent(e))
         if (e.type==Event::Closed)    window.close();
   
      window.draw(sprite_bg);
      window.display();
     
   }

Win7x64, SFML 2.4.2, MinGW 7.2.0
Title: Re: Direct filling the texture buffer
Post by: eXpl0it3r on January 16, 2018, 04:33:51 pm
You first need to create the texture and tell what size it should be.
Title: Re: Direct filling the texture buffer
Post by: thorr on January 16, 2018, 04:58:22 pm
Thanx a lot!

bg.create(SCR_WIDTH,SCR_HEIGHT);

Now it's work.