Draw Single Pixel?

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
nutcase84
Prole
Posts: 11
Joined: Sun Nov 24, 2013 7:48 pm

Draw Single Pixel?

Post by nutcase84 »

I can't find out how to draw a single pixel, and change it's color. Is it love.graphics.point? Thanks!
User avatar
Boolsheet
Inner party member
Posts: 780
Joined: Wed Dec 29, 2010 4:57 am
Location: Switzerland

Re: Draw Single Pixel?

Post 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.
Shallow indentations.
nutcase84
Prole
Posts: 11
Joined: Sun Nov 24, 2013 7:48 pm

Re: Draw Single Pixel?

Post by nutcase84 »

Thanks a lot!
nutcase84
Prole
Posts: 11
Joined: Sun Nov 24, 2013 7:48 pm

Re: Draw Single Pixel?

Post 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?
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Draw Single Pixel?

Post 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.
Help us help you: attach a .love.
nutcase84
Prole
Posts: 11
Joined: Sun Nov 24, 2013 7:48 pm

Re: Draw Single Pixel?

Post 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.
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Draw Single Pixel?

Post 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).
Help us help you: attach a .love.
User avatar
T-Bone
Inner party member
Posts: 1492
Joined: Thu Jun 09, 2011 9:03 am

Re: Draw Single Pixel?

Post 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.
nutcase84
Prole
Posts: 11
Joined: Sun Nov 24, 2013 7:48 pm

Re: Draw Single Pixel?

Post by nutcase84 »

Thanks, but I can't seem to find a pixel thing. What am I doing wrong?
bekey
Party member
Posts: 255
Joined: Tue Sep 03, 2013 6:27 pm

[]

Post by bekey »

-snip-
Last edited by bekey on Fri Jan 24, 2014 2:01 am, edited 1 time in total.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot] and 8 guests