-
Notifications
You must be signed in to change notification settings - Fork 33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
When debugging, Surface.pixels is not set #29
Comments
Please add some details or better, reproducible code. I gave no idea what you're doing and expecting... |
Yes, sorry, I totally forgot to include any actual source code.. What I'm trying to do (surely in a unsafe, inefficient way, but I don't mind at the moment..) is to get the RGB values of a pixel at def get_pix_at(surf, x, y)
# debugger
LibSDL.lock_surface(surf)
ll_surface = surf.surface
bpp = ll_surface.format.value.bytesPerPixel
pix = (ll_surface.pixels + y * ll_surface.pitch * bpp).as(UInt32*).value
r = 0_u8
g = 0_u8
b = 0_u8
pr : UInt8* = pointerof(r)
pg : UInt8* = pointerof(g)
pb : UInt8* = pointerof(b)
LibSDL.get_rgb(pix, ll_surface.format, pr, pg, pb)
res = [pr.value, pg.value, pb.value]
LibSDL.unlock_surface(surf)
return res
end This compiles with no warning whatsoever, does not crash when used, but the RGB array is constantly lib LibSDL
# ...
struct Surface
flags : UInt32
format : PixelFormat*
w : Int
h : Int
pitch : Int
pixels : Void*
userdata : Void*
locked : Int
lock_data : Void*
clip_rect : Rect
map : Void* # BlitMap*
refcount : Int
end
# and so forth... |
Have a look to http://lazyfoo.net/SDL_tutorials/lesson31/index.php All samples are ports of Lazy Foo' tutorials, but I never went as far as reading a pixel color (lesson 31) and |
Oh, I see... Are there any plans/timelines to make |
You can reopen class SDL::Surface
def pixels
surface.pixels
end
end Then you have a direct access to the underlying def get_pixel(surface, x, y)
buffer = surface.pixels.as(UInt32*) # <= assumes 32-bit depth!
pixel = buffer + x + y * surface.width
LibSDL.get_rgb(pixel.value, out r, out g, out b)
{r, g, b}
end
window = SDL::Window.new(640, 480)
window.surface.fill(255, 0, 0)
p get_pixel(window.surface, 120, 240) |
Hi, sorry to reply so lately, but I got stuck with other things.. I tried this piece of code, it has the problem that you're not passing a |
No problem for me on Linux. Is the surface really 32-bit? |
When debugging,
Surface
struct returned fromwindow.surface.to_unsafe
does not containpixels
, but property is clearly defined (atsdl/src/lib_sdl/surface.cr
), therefore pixel read access is impossibleThe text was updated successfully, but these errors were encountered: