Canvas color problem

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.
Post Reply
User avatar
BadLuckBurt
Prole
Posts: 6
Joined: Mon Oct 07, 2013 2:05 pm
Location: Netherlands

Canvas color problem

Post by BadLuckBurt »

Hello everyone,

I'm having some trouble rendering a canvas in the correct colors. It works fine the first time (when the canvas is generated in love.load()), that version is rendered in a random alternating green and blue as expected. Pressing 'R' once will regenerate the canvas using the same code that's called in love.load(), pressing 'R' again will swap the old canvas with the one generated in the previous step. When the new canvas is rendered it's either green on black or blue on black.

The larger square that's rendered after somehow becomes blue too. I'm sure I'm doing something dumb, it's been a while since I messed around with Love and probably missing something very obvious.

- edit
Added the ZIP file, didn't realise the attachment upload is separate from the post submit :)

Love version: 0.9.2

The functions involved:

modules/tilemapGenerator.lua
tilemapGenerator:generateWater(bFillAll)
Generates a new random map

modules/tilemapRenderer.lua
tilemapRenderer:drawMap(map)
Renders the map table to a canvas

main.lua
love.load()
Generates the map for the first time (this one renders OK)

love.update(dt)
The first time 'R' is pressed, a new map is generated, the second time 'R' is pressed, the canvas for the new map is rendered

load.draw()
Draws the canvas and the 'player tile'

love.keypressed()
Increments 'iMapRefresh' which is used in love.update() to refresh the map.
Attachments
dunia.zip
Project files
(6.74 KiB) Downloaded 167 times
User avatar
s-ol
Party member
Posts: 1077
Joined: Mon Sep 15, 2014 7:41 pm
Location: Cologne, Germany
Contact:

Re: Canvas color problem

Post by s-ol »

Are you setting the color back to white before drawing the canvas onto the main screen (love.graphics.setColor(255,255,255))?

s-ol.nu /blog  -  p.s-ol.be /st8.lua  -  g.s-ol.be /gtglg /curcur

Code: Select all

print( type(love) )
if false then
  baby:hurt(me)
end
User avatar
BadLuckBurt
Prole
Posts: 6
Joined: Mon Oct 07, 2013 2:05 pm
Location: Netherlands

Re: Canvas color problem

Post by BadLuckBurt »

S0lll0s wrote:Are you setting the color back to white before drawing the canvas onto the main screen (love.graphics.setColor(255,255,255))?
No, I was not but just added that line and it works fine now :)

Thank you very much!
User avatar
s-ol
Party member
Posts: 1077
Joined: Mon Sep 15, 2014 7:41 pm
Location: Cologne, Germany
Contact:

Re: Canvas color problem

Post by s-ol »

BadLuckBurt wrote:
S0lll0s wrote:Are you setting the color back to white before drawing the canvas onto the main screen (love.graphics.setColor(255,255,255))?
No, I was not but just added that line and it works fine now :)

Thank you very much!
As an explanation: when drawing Canvas or Images, the color and image texel get mixed (see the default shader in love.graphics.newImage's documentation) by multiplying the colors component-wise.

s-ol.nu /blog  -  p.s-ol.be /st8.lua  -  g.s-ol.be /gtglg /curcur

Code: Select all

print( type(love) )
if false then
  baby:hurt(me)
end
User avatar
BadLuckBurt
Prole
Posts: 6
Joined: Mon Oct 07, 2013 2:05 pm
Location: Netherlands

Re: Canvas color problem

Post by BadLuckBurt »

Thanks for explaining. When I ran into the problem I did recall posts on this forum from people having the same issue (yes, I lurked :P) so I figured I'd ask.

I changed the code a bit last night and now it can generate an image with random colors and an adjustable tile size :cool:
Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests