So, let's suppose I have a 100X100 pixels image. It counts 10000 of pixels with x, y coordinates, r, g, b, a color, compression rate, etc...
That's a lot of values, and still, I can draw it without problems. the same goes for a 600X600 image, or even higher, and if I increment/decrement it's position, It will work almost always in real time. So, How it works? If i just make a table of pixels it will take a lot of time to render or decrement/increment positions. How that bunch of interactions are otimizted? I'm really curious.
How drawing a Image works?
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
- Calandriel
- Prole
- Posts: 39
- Joined: Wed Apr 22, 2015 9:00 am
How drawing a Image works?
If violence is not solving all your problems, You're simply not using enough of it.
Twitter: https://twitter.com/Calandriell Some news about wtf I'm doing.
Tumblr:https://www.tumblr.com/blog/calandriell I use to draw some random stuff.
Twitter: https://twitter.com/Calandriell Some news about wtf I'm doing.
Tumblr:https://www.tumblr.com/blog/calandriell I use to draw some random stuff.
- radgeRayden
- Prole
- Posts: 29
- Joined: Sun Jul 27, 2014 6:49 pm
- Location: Brasil
- Contact:
Re: How drawing a Image works?
You seem to be under the assumption this is made in Lua. It isn't. OpenGL (not SDL) handles this and although it seems that filling pixels and 'moving' them around is a lot of work, it turns out computers are really fast, specially when dealt at a lower level (with less abstraction layers, which Lua is a big one). And some neat tricks are involved as well, besides the fact that most of it is taken care of by the graphics card.
PS: sorry if my answer is too dumbed down or something, I have no idea about how much do you know. I don't know very much about the underlying processes behind this, but reading technical writing about OpenGL would most likely enlighten you.
Edited because of misleading information.
PS: sorry if my answer is too dumbed down or something, I have no idea about how much do you know. I don't know very much about the underlying processes behind this, but reading technical writing about OpenGL would most likely enlighten you.
Edited because of misleading information.
Last edited by radgeRayden on Sun Dec 27, 2015 7:48 am, edited 2 times in total.
- slime
- Solid Snayke
- Posts: 3163
- Joined: Mon Aug 23, 2010 6:45 am
- Location: Nova Scotia, Canada
- Contact:
Re: How drawing a Image works?
LÖVE doesn't actually use SDL for rendering, it uses OpenGL directly.
OpenGL is an API designed to provide access to the capabilities of a video card / GPU – so when you draw things, LÖVE basically sends commands to the GPU to render them, like this: http://data.simonschreibt.de/gat049/com ... cation.mp4
And then the GPU renders them kind of like this: http://data.simonschreibt.de/gat049/pip ... erview.mp4
GPU hardware is specifically designed to maximize the number of pixels (and vertex data and other graphics-related things) that it can process at once – modern video cards are capable of processing hundreds of millions or even billions or tens of billions of pixels per second.
So GPUs actually render things like this (but on a much larger scale): http://data.simonschreibt.de/gat049/pip ... ticore.mp4
The videos are from a pretty cool overview of what GPUs and rendering systems do and what they're good at (created by a non-programmer): http://simonschreibt.de/gat/renderhell/
One thing to note with image positions (when you draw images) is that there are really only 4 points per image that need to change (its 4 corners, a.k.a. its vertices), rather than every pixel – and even those vertex positions are calculated on your GPU based on a single input transformation matrix.
Once it calculates those positions, each screen pixel that's inside the rectangle formed by the 4 positions has a pixel from the texture mapped to it (again using the GPU, so it's super parallel and super fast).
OpenGL is an API designed to provide access to the capabilities of a video card / GPU – so when you draw things, LÖVE basically sends commands to the GPU to render them, like this: http://data.simonschreibt.de/gat049/com ... cation.mp4
And then the GPU renders them kind of like this: http://data.simonschreibt.de/gat049/pip ... erview.mp4
GPU hardware is specifically designed to maximize the number of pixels (and vertex data and other graphics-related things) that it can process at once – modern video cards are capable of processing hundreds of millions or even billions or tens of billions of pixels per second.
So GPUs actually render things like this (but on a much larger scale): http://data.simonschreibt.de/gat049/pip ... ticore.mp4
The videos are from a pretty cool overview of what GPUs and rendering systems do and what they're good at (created by a non-programmer): http://simonschreibt.de/gat/renderhell/
One thing to note with image positions (when you draw images) is that there are really only 4 points per image that need to change (its 4 corners, a.k.a. its vertices), rather than every pixel – and even those vertex positions are calculated on your GPU based on a single input transformation matrix.
Once it calculates those positions, each screen pixel that's inside the rectangle formed by the 4 positions has a pixel from the texture mapped to it (again using the GPU, so it's super parallel and super fast).
- Calandriel
- Prole
- Posts: 39
- Joined: Wed Apr 22, 2015 9:00 am
Re: How drawing a Image works?
Thanks, It was really enlightening. So, OpenGL is the answer. Nice.
I tried to decompose a picture into a matrix of points, so I could edit every pixel separetely, do that old 3d trick(x_screen=real_x/real_z, where real_x equals x position of pixel, and z equals depth). My depth would be the amount of black, you know, 0,0,0 equals 100% and 255,255,255 equals 0%, to give an effect to image, but, all I got was a lag of 10 fakhen minutes.
So, to get this effect, I'll have to write a code in OpenGL and run it with my LÖVE game, right?
I tried to decompose a picture into a matrix of points, so I could edit every pixel separetely, do that old 3d trick(x_screen=real_x/real_z, where real_x equals x position of pixel, and z equals depth). My depth would be the amount of black, you know, 0,0,0 equals 100% and 255,255,255 equals 0%, to give an effect to image, but, all I got was a lag of 10 fakhen minutes.
So, to get this effect, I'll have to write a code in OpenGL and run it with my LÖVE game, right?
If violence is not solving all your problems, You're simply not using enough of it.
Twitter: https://twitter.com/Calandriell Some news about wtf I'm doing.
Tumblr:https://www.tumblr.com/blog/calandriell I use to draw some random stuff.
Twitter: https://twitter.com/Calandriell Some news about wtf I'm doing.
Tumblr:https://www.tumblr.com/blog/calandriell I use to draw some random stuff.
- radgeRayden
- Prole
- Posts: 29
- Joined: Sun Jul 27, 2014 6:49 pm
- Location: Brasil
- Contact:
Re: How drawing a Image works?
@slime oops, should have fact checked my answer :#. But löve does use SDL for something, right? Now I'm a bit confused because I've seen it mentioned someplace and just assumed by memory it was rendering.
@Calandriel, you should take a look at shaders. You can use pixel shaders in löve, there's a neat summary here: http://blogs.love2d.org/content/beginners-guide-shaders
@Calandriel, you should take a look at shaders. You can use pixel shaders in löve, there's a neat summary here: http://blogs.love2d.org/content/beginners-guide-shaders
- Calandriel
- Prole
- Posts: 39
- Joined: Wed Apr 22, 2015 9:00 am
Re: How drawing a Image works?
Yeah, maybe all I need is a shader,(and some coffe though )
There is a port of LÖVE, I guess it's labeled "nLove" that uses SDL. It's for older machines imo.oops, should have fact checked my answer :#. But löve does use SDL for something, right? Now I'm a bit confused because I've seen it mentioned someplace and just assumed by memory it was rendering.
If violence is not solving all your problems, You're simply not using enough of it.
Twitter: https://twitter.com/Calandriell Some news about wtf I'm doing.
Tumblr:https://www.tumblr.com/blog/calandriell I use to draw some random stuff.
Twitter: https://twitter.com/Calandriell Some news about wtf I'm doing.
Tumblr:https://www.tumblr.com/blog/calandriell I use to draw some random stuff.
-
- Party member
- Posts: 730
- Joined: Sat Apr 26, 2014 7:46 pm
Re: How drawing a Image works?
radgeRayden love uses sdl for a variety of things. It is used to create the window and context. To get keyboard/mouse/gamepad input. And to do a couple other things.
Who is online
Users browsing this forum: Bing [Bot] and 5 guests