Page 1 of 3
Draw Single Pixel?
Posted: Sun Nov 24, 2013 7:55 pm
by nutcase84
I can't find out how to draw a single pixel, and change it's color. Is it love.graphics.point? Thanks!
Re: Draw Single Pixel?
Posted: Sun Nov 24, 2013 8:04 pm
by Boolsheet
Yes, [wiki]love.graphics.point[/wiki] is one way to do it. Another would be drawing 1x1 rectangles with [wiki]love.graphics.rectangle[/wiki]. You can select the color for if you call [wiki]love.graphics.setColor[/wiki] beforehand.
Code: Select all
love.graphics.setColor(255, 0, 0) -- Red point.
love.graphics.point(10.5, 10.5)
love.graphics.setColor(255, 255, 0) -- Yellow rectangle.
love.graphics.rectangle("fill", 15, 10, 1, 1)
love.graphics.setColor(255, 255, 255) -- Don't forget to set the color back to white or you'll ask yourself why your images look weird.
Re: Draw Single Pixel?
Posted: Mon Nov 25, 2013 2:04 pm
by nutcase84
Thanks a lot!
Re: Draw Single Pixel?
Posted: Mon Nov 25, 2013 2:57 pm
by nutcase84
I'm using the rectangle method, and it's really really slow. It gets about 1 frame per 10 - 15 seconds! Is there any way to speed this up?
Re: Draw Single Pixel?
Posted: Mon Nov 25, 2013 3:21 pm
by Robin
Yeah, not draw things pixel per pixel. What is it you want to achieve? There is probably a better way to go about it.
Re: Draw Single Pixel?
Posted: Mon Nov 25, 2013 3:43 pm
by nutcase84
Here's the latest working build.
https://dl.dropboxusercontent.com/u/157 ... ild-2.love
It's a ComputerCraft emulator, with a high resolution. I want to keep the simpleness of CC, but be able to use full graphics.
Re: Draw Single Pixel?
Posted: Mon Nov 25, 2013 10:12 pm
by Robin
In that case, it might be a good idea to look into
Shaders (or PixelEffects, as they are called in 0.8.0). There are some threads on these forums that can help you get started (especially
Share a Shader).
Re: Draw Single Pixel?
Posted: Mon Nov 25, 2013 10:34 pm
by T-Bone
Drawing stuff pixel by pixel tends to be terribly slow. Shaders are a very flexible and fast way. Another possibility is to logically separate your drawing into pieces that don't change often, and draw them to some kind of buffer instead of directly drawing them to the screen. The buffer can then be quickly drawn on screen. LÖVE has two kinds of buffers: canvas and spritebatch. They work a little differently and I think canvases would probably fit your needs best.
I personally find working with canvases much easier than working with shaders, but it doesn't fit every situation.
Another possibility that I don't think is likely to fit your needs is to make a multithreaded program, with a second thread building images with ImageData:setPixel and then sending Images to the main thread to be drawn. This fits if you really want real pixel-by-pixel control but it's messy to work with and ineffient.
Re: Draw Single Pixel?
Posted: Mon Nov 25, 2013 10:44 pm
by nutcase84
Thanks, but I can't seem to find a pixel thing. What am I doing wrong?
[]
Posted: Tue Nov 26, 2013 4:00 am
by bekey
-snip-