Skip to content
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

Problem with love.graphics.newQuad #52

Closed
Przemekkkth opened this issue May 16, 2024 · 0 comments
Closed

Problem with love.graphics.newQuad #52

Przemekkkth opened this issue May 16, 2024 · 0 comments

Comments

@Przemekkkth
Copy link

Hello,
I created a program:

push = require 'push'

-- close resolution to NES but 16:9
virtualWidth = 33 * 16
virtualHeight = 28 * 16

-- actual window resolution
windowWidth = 33 * 16
windowHeight = 28 * 16

mode = 0

function generateQuads(atlas, tilewidth, tileheight)
    local sheetWidth = atlas:getWidth() / tilewidth
    local sheetHeight = atlas:getHeight() / tileheight

    local sheetCounter = 1
    local quads = {}

    for y = 0, sheetHeight - 1 do
        for x = 0, sheetWidth - 1 do
            -- this quad represents a square cutout of our atlas that we can
            -- individually draw instead of the whole atlas
            quads[sheetCounter] =
                love.graphics.newQuad(x * tilewidth, y * tileheight, tilewidth,
                tileheight, atlas:getDimensions())
            sheetCounter = sheetCounter + 1
        end
    end

    return quads
end

function love.load()
    spriteSheets = love.graphics.newImage("tiles.png")
    tilesSprite = generateQuads(spriteSheets, 16, 16)
    love.window.setMode(33*16, 28*16)
    love.window.setTitle("Without push")

    love.graphics.setDefaultFilter('nearest', 'nearest')
    -- sets up virtual screen resolution for an authentic retro feel
    if mode == 1 then 
        push:setupScreen(virtualWidth, virtualHeight, windowWidth, windowHeight, {
            fullscreen = false,
            resizable = false
        })
    end
end

-- called whenever window is resized
function love.resize(w, h)
    if mode == 1 then
        push:resize(w, h)
    end
end

function love.update(dt) 

end

function love.draw()
    if mode == 0 then
        love.graphics.clear(255, 255, 255)
        local index = 1
        for x = 1, 33 do
            for y = 1, 28 do 
                love.graphics.draw(spriteSheets, tilesSprite[index], (y - 1) * 16, (x - 1) * 16)
                index = index + 1
            end
        end
    end
    if mode == 1 then
        -- begin virtual resolution drawing
        push:apply('start')

        -- clear screen using Mario background blue
        love.graphics.clear(108, 140, 255, 255)
        local index = 1
        for x = 1, 33 do
            for y = 1, 28 do 
                love.graphics.draw(spriteSheets, tilesSprite[index], (y - 1) * 16, (x - 1) * 16)
                index = index + 1
            end
        end
        
        push:apply('end')
    end
end

You can use mode variable to control app. With mode equals 1 app runs with push otherwise without it. Result:

example

As you can see, there is a 1-pixel border at the edge of the tile and I don't know how to get rid of it. This is actually the most important part of this thread. You know how to get rid of this border. You can see it better when you scale it up, but to compare it with the version without push, I used such a low resolution.

I also create thread in love2d forum about that: https://www.love2d.org/forums/viewtopic.php?t=95753

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant