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

Author Topic: sfml 2.0 texture  (Read 3932 times)

0 Members and 1 Guest are viewing this topic.

max_vodoo

  • Newbie
  • *
  • Posts: 4
    • View Profile
    • Email
sfml 2.0 texture
« on: April 01, 2012, 11:56:16 am »
dose sfml 2.0 support to load raw data from the memory,cuz every time i try to load data from memory
i get this error "Failed to load image from memory"

ToRGBA(v.getPixels(1,true,true),ar,320,240);// get frame from webcam videoinput.lib and convert it to rgba
t.loadFromMemory(&ar,320*240*4); //t is sf::Texture;
t.bind();
s.setTexture(t);//s is sf::Sprite
App->draw(s);

but in sfml 1.6 sf::Image load the raw data from the memory and display it .

my second question which is not important can i load the data from the memory in the rgb format directly ?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: sfml 2.0 texture
« Reply #1 on: April 01, 2012, 12:46:47 pm »
loadFromMemory loads an image file from memory. What you need is something that loads an array of pixels. If you stream webcam data, you need to call Texture::update (and Texture::create at init time).
Laurent Gomila - SFML developer

neolord12

  • Newbie
  • *
  • Posts: 5
    • ICQ Messenger - 98543691
    • View Profile
Re: sfml 2.0 texture
« Reply #2 on: June 14, 2012, 11:54:48 am »
Hey , I am also trying the same.
I use videoInput for capture.
All works fine except i can't figure out how to map the captured Image to a sprite or rectangle.
Any idea's how i could tell a texture to use my Buffer for its pixels?(buffer is a pointer to array of pixels)
LoadFromMemory doesn't work.
How exactly does the texture::update work?It wants sf::Uint8 *pointer but my buffer is unsigned char arrayPointer.
Think i have to convert my pixelarray first to RGBA, but actually i should be able to at least see something but when i use texture.Update(captureBuffer) application crashes right after start.

thanks for any suggestions!
« Last Edit: June 14, 2012, 12:21:19 pm by neolord12 »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11033
    • View Profile
    • development blog
    • Email
Re: sfml 2.0 texture
« Reply #3 on: June 14, 2012, 01:32:24 pm »
sf::Uint8* is not the same as unsigned char[] and the crash is kind of obvious and also described in the documentation.
Quote
The pixel array is assumed to have the same size as the area rectangle, and to contain 32-bits RGBA pixels.
No additional check is performed on the size of the pixel array, passing invalid arguments will lead to an undefined behaviour.

So you need to convert your uchar array to a 32bit RGBA array, how you would do that, I've no idea. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

neolord12

  • Newbie
  • *
  • Posts: 5
    • ICQ Messenger - 98543691
    • View Profile
Re: sfml 2.0 texture
« Reply #4 on: June 14, 2012, 01:36:19 pm »
oh well...i guess you knew what i mean, thanks for reply :)

neolord12

  • Newbie
  • *
  • Posts: 5
    • ICQ Messenger - 98543691
    • View Profile
Re: sfml 2.0 texture
« Reply #5 on: June 14, 2012, 02:03:12 pm »
okay, i got it ...videoInput lib returns RGB so array for SFML Texture needs to be RGBA.

Thanks alot for your help!!


SFML is AWESOME!!

 

anything