Author Topic: SDL2 getting pixel data from a texture  (Read 13569 times)

reaver

  • Rogueliker
  • ***
  • Posts: 207
  • Karma: +0/-0
    • View Profile
SDL2 getting pixel data from a texture
« on: July 22, 2014, 08:08:49 AM »
Not sure if I'm missing something obvious, but I can't find any API whatsoever to help me with getting the pixels from a static texture, so that I can save them to file.
I can create a render target and copy the texture to the rendertarget, but then again I can't find any way to get the pitch which is needed to read the texture pixels. That's ludicrous! Never mind the fact that people have said that SDL_RenderReadPixels() has been buggy and only gets pixels from the window, even if you set the rendertarget to be a texture..

Cfyz

  • Rogueliker
  • ***
  • Posts: 194
  • Karma: +0/-0
    • View Profile
    • Email
Re: SDL2 getting pixel data from a texture
« Reply #1 on: July 22, 2014, 11:57:48 AM »

reaver

  • Rogueliker
  • ***
  • Posts: 207
  • Karma: +0/-0
    • View Profile
Re: SDL2 getting pixel data from a texture
« Reply #2 on: July 22, 2014, 12:02:51 PM »
Thanks, but nope :)
This solution requires the texture to be created as streaming and I do not want that.

Cfyz

  • Rogueliker
  • ***
  • Posts: 194
  • Karma: +0/-0
    • View Profile
    • Email
Re: SDL2 getting pixel data from a texture
« Reply #3 on: July 22, 2014, 12:27:27 PM »
Quote from: reaver
I can't find any way to get the pitch which is needed to read the texture pixels.
A brief peek into SDL2 sources revealed that this pitch parameter tells SDL the width of a single line in your buffer, in bytes. SDL copies the data to your buffer line-by-line, incrementing the pointer by that value.

reaver

  • Rogueliker
  • ***
  • Posts: 207
  • Karma: +0/-0
    • View Profile
Re: SDL2 getting pixel data from a texture
« Reply #4 on: July 22, 2014, 02:45:02 PM »
Ok, yeah, apparently the only sure way is copy to rendertarget and readpixels(), but readpixels() is broken and tries to use the backbuffer instead of the rendertarget. Awesome. Perhaps I need to ditch SDL2, if it can't do correctly something as basic as this.

UPDATE: ok, actually readpixels() works using the OpenGL driver instead of the default D3D9 one.
« Last Edit: July 22, 2014, 03:10:31 PM by reaver »

Krice

  • (Banned)
  • Rogueliker
  • ***
  • Posts: 2316
  • Karma: +0/-2
    • View Profile
    • Email
Re: SDL2 getting pixel data from a texture
« Reply #5 on: April 19, 2016, 11:01:01 AM »
ok, actually readpixels() works using the OpenGL driver instead of the default D3D9 one.

Is this still true? I'm trying to save a piece of screen with SDL_RenderReadPixels, but it's crashing for some reason. In some cases saving the background is just a feature you need (if you have a window or menu pop on previous graphics).

abraksil

  • Rogueliker
  • ***
  • Posts: 134
  • Karma: +0/-0
    • View Profile
    • Email
Re: SDL2 getting pixel data from a texture
« Reply #6 on: April 23, 2016, 09:39:59 PM »
Woow haven't used SDL for quite some  time now. Didn't new there was 2.0.

Krice

  • (Banned)
  • Rogueliker
  • ***
  • Posts: 2316
  • Karma: +0/-2
    • View Profile
    • Email
Re: SDL2 getting pixel data from a texture
« Reply #7 on: April 24, 2016, 07:39:31 AM »
Didn't new there was 2.0.

No, it's 2.0.4.