Hey guys !
I'm new to löve there but trying to make things work.
I'm creating a game for android (a maze in fake 3D). It was going well until I tried to draw the ground. Turns out trying to draw thousands of individual points one by one is not the way to go.
I had the idea to precompute all the ground configurations (30 or so) and store those in images at the launch of the game.
I suppose it won't be that hard to create ImageData objects storing my data, but how do you create images from ImageData objects ?
Thanks
EDIT : I changed the title due to the change of direction and the new problem
[SOLVED] How to draw the floor in raycasters - scaling problem
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
[SOLVED] How to draw the floor in raycasters - scaling problem
Last edited by Koxinga on Thu Oct 13, 2022 10:17 am, edited 4 times in total.
- zorg
- Party member
- Posts: 3468
- Joined: Thu Dec 13, 2012 2:55 pm
- Location: Absurdistan, Hungary
- Contact:
Re: precompute images at the launch of the game
Hi and welcome to the forums!
Not sure why you're trying to draw anything out with points though...
Code: Select all
yourImageData = love.image.newImageData()
-- Fill up imagedata with pretty visuals
yourImage = love.graphics.newImage(yourImageData)
function love.draw()
-- draw out your image
love.graphics.draw(yourImage, 0, 0)
end
Me and my stuff True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
Re: precompute images at the launch of the game
Use the Canvas https://love2d.org/wiki/Canvas
If you want, you can save it as files and you don't need to precompute it before the game.
If you want, you can save it as files and you don't need to precompute it before the game.
Re: precompute images at the launch of the game
Thanks guys.
I suppose I can combine both methods : draw on canvases then store them as images. I'll look into this
As you see on the screenshot, the fps count was a bit problematic
EDIT : Apparently, there is a more efficient way to draw the floor... I'm learning every minute https://lodev.org/cgtutor/raycasting2.html
I suppose I can combine both methods : draw on canvases then store them as images. I'll look into this
I am implementing fake 3D as it was in doom or more specifically in Lands of Lore (cause you move on a grid).When the player is turning the texture of the floor is rotated so I can't draw it as strips as I did for the walls. The only way I found was to draw each point separately.zorg wrote:Not sure why you're trying to draw anything out with points though...
As you see on the screenshot, the fps count was a bit problematic
EDIT : Apparently, there is a more efficient way to draw the floor... I'm learning every minute https://lodev.org/cgtutor/raycasting2.html
Re: [SOLVED] precompute images at the launch of the game
Thanks, I guess I'll look at shaders later. That's already a lot to process for me.
Re: [SOLVED] precompute images at the launch of the game
Raycasting and real 3D are fundamentally different. Real 3D is hardware accelerated and cheap for the CPU; true raycasting is CPU-expensive. It's possible to simulate raycasting with real 3D.
Re: [SOLVED] precompute images at the launch of the game
I finally got it by writing a shader.
It seems to be working perfectly on my computer, at 60 fps. But when I try to run it on the android emulator or on my phone, the floor texture is stretched.
Any idea why this is happening ? Is there maybe something to do with love-android that I'm using ?
EDIT : Should I rename the thread ?
Code: Select all
extern Image ground;
extern number playerX;
extern number playerY;
extern number playerA;
extern number D;
vec4 effect( vec4 color, Image texture, vec2 texture_coords, vec2 screen_coords ){
number angle = mod((playerA - atan((love_ScreenSize.x/2.0 - ((love_ScreenSize.x-screen_coords.x)-1.0))/D)) , (2.0*3.14159));
number d = D / cos(angle - playerA);
number cosA = cos(angle);
number sinA = sin(angle);
number distGround = 0.5 * d / (screen_coords.y - love_ScreenSize.y/2.0);
vec4 pixel = Texel(ground, vec2( (mod((playerX + distGround*cosA),1.0)),(mod((playerY - distGround*sinA),1.0)) ));
return pixel;
}
Any idea why this is happening ? Is there maybe something to do with love-android that I'm using ?
EDIT : Should I rename the thread ?
Re: [SOLVED] precompute images at the launch of the game
I can see the other floor: Maybe it comes from low display resolution with high dpi.
Re: How to draw the floor in raycasters - scaling problem
I removed the texture of the floor and put a gradient instead to see what was going on, and I printed the dpiscale. But unfortunately, I don't have any idea if the problem is because of a change in the DPI scale (1 on my computer and almost 3 on the phone) or because some function in the shader doesn't return the same value on both platforms.
Here are the screenshots if you want to have a look at it (the computer ones are the expected behavior, it is cut at the wrong places on the phone) :
Here are the screenshots if you want to have a look at it (the computer ones are the expected behavior, it is cut at the wrong places on the phone) :
Who is online
Users browsing this forum: Ahrefs [Bot], Bing [Bot], Google [Bot] and 4 guests