Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Direct filling the texture buffer  (Read 1103 times)

0 Members and 1 Guest are viewing this topic.

thorr

  • Newbie
  • *
  • Posts: 2
    • View Profile
    • Email
Direct filling the texture buffer
« 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
« Last Edit: January 16, 2018, 04:58:55 pm by thorr »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
Re: Direct filling the texture buffer
« Reply #1 on: January 16, 2018, 04:33:51 pm »
You first need to create the texture and tell what size it should be.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

thorr

  • Newbie
  • *
  • Posts: 2
    • View Profile
    • Email
Re: Direct filling the texture buffer
« Reply #2 on: January 16, 2018, 04:58:22 pm »
Thanx a lot!

bg.create(SCR_WIDTH,SCR_HEIGHT);

Now it's work.