Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Sprite Rendering, bit blitting, and other questions  (Read 8069 times)

0 Members and 1 Guest are viewing this topic.

Cyrano

  • Newbie
  • *
  • Posts: 19
    • View Profile
Sprite Rendering, bit blitting, and other questions
« on: April 22, 2010, 07:54:46 am »
SFML is a fine library, but once again, I have some questions regarding one of its core areas: Sprite manipulation.

My Questions:

What is the fastest way to render a sprite? (I'm not entirely sure what people on this site mean by "render"; from what I understand, it's fairly similar to bit blitting.)

What's the deal with "arrays of pixels?" I keep seeing this term, but do not fully grasp what it means. Is it perhaps referring to all the pixels in an individual image?

Why do some people say bit blitting is slow?
Is there some faster method I was not aware of?

What is the screen tear effect?
Is this the phenomenon that occurs when update cycles are faster than the monitor's refresh rate? (Dumb question, but I just want to make sure I get it). Is there a way around it?

Can a screen (game screen) be updated in part? (Ex: A character sprite is updated, but not the whole background with it.)


These are some questions I've wanted answers to for a while, but did not know whom to ask. I put all these questions together so that I don't have to spam other people's topics or create a bunch of topics of my own.

Thanks in advance. Happy programming!

-Cyrano
– A cape? Forsooth! 'Tis a peninsula!

Ashenwraith

  • Sr. Member
  • ****
  • Posts: 270
    • View Profile
Sprite Rendering, bit blitting, and other questions
« Reply #1 on: April 22, 2010, 08:15:00 am »
Modern graphics hardware is mainly about geometry, pixel data, and buffers.

Blitting the entire screen is slow because you are copying all of the screen pixels and sometimes even editing them depending on what you are doing.

Modern blitting can still be achieved with pixel array transformations, but you want to blit the least amount for performance so you would only 'blit' part of a sprite instead of the whole screen. In most cases you do not need to blit unless you are doing something fancy like a pixel shader.

The fastest hardware techniques for rapid drawing are volatile, meaning they destroy or flush your screen and then quickly rebuild it again at a constant rate. This is the opposite to software blitting which is like going in like a surgeon and cutting pixels out and moving them around on a static image.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Sprite Rendering, bit blitting, and other questions
« Reply #2 on: April 22, 2010, 09:53:29 am »
Quote
What is the fastest way to render a sprite? (I'm not entirely sure what people on this site mean by "render"; from what I understand, it's fairly similar to bit blitting.)

"Render" just means "draw".
There's only one way to render a sprite in SFML, so there nothing much to discuss about it.

Quote
What's the deal with "arrays of pixels?" I keep seeing this term, but do not fully grasp what it means. Is it perhaps referring to all the pixels in an individual image?

It refers to a bidimensional array of pixels (32-bits RGBA colors), usually the pixels that define an image or a portion of it.

Quote
Why do some people say bit blitting is slow? Is there some faster method I was not aware of?

Bit blitting is completely deprecated with today's hardware. The most efficient way of drawing things, even 2D geometry, is to create geometry made of triangles, map some texture on it and send it to the graphics card.

Quote
What is the screen tear effect? Is this the phenomenon that occurs when update cycles are faster than the monitor's refresh rate? (Dumb question, but I just want to make sure I get it). Is there a way around it?

You can enable vertical synchronization to solve this problem (see sf::Window::UseVerticalSync).

Quote
Can a screen (game screen) be updated in part? (Ex: A character sprite is updated, but not the whole background with it.)

This is not a good strategy, you should always clear and redraw the entire scene.
Laurent Gomila - SFML developer

Cyrano

  • Newbie
  • *
  • Posts: 19
    • View Profile
Sprite Rendering, bit blitting, and other questions
« Reply #3 on: April 22, 2010, 03:49:03 pm »
Quote from: "Laurent"
Quote
What is the fastest way to render a sprite? (I'm not entirely sure what people on this site mean by "render"; from what I understand, it's fairly similar to bit blitting.)

"Render" just means "draw".
There's only one way to render a sprite in SFML, so there nothing much to discuss about it.

Quote
What's the deal with "arrays of pixels?" I keep seeing this term, but do not fully grasp what it means. Is it perhaps referring to all the pixels in an individual image?

It refers to a bidimensional array of pixels (32-bits RGBA colors), usually the pixels that define an image or a portion of it.

Quote
Why do some people say bit blitting is slow? Is there some faster method I was not aware of?

Bit blitting is completely deprecated with today's hardware. The most efficient way of drawing things, even 2D geometry, is to create geometry made of triangles, map some texture on it and send it to the graphics card.

Quote
What is the screen tear effect? Is this the phenomenon that occurs when update cycles are faster than the monitor's refresh rate? (Dumb question, but I just want to make sure I get it). Is there a way around it?

You can enable vertical synchronization to solve this problem (see sf::Window::UseVerticalSync).

Quote
Can a screen (game screen) be updated in part? (Ex: A character sprite is updated, but not the whole background with it.)

This is not a good strategy, you should always clear and redraw the entire scene.


Thanks! I was wondering about those things.

I have another question though:

How do I use that "geometry of triangles" you mention? (I'm assuming you are referring to something like a gourad shader?) I'm only using 2D art, and have no use for 3D figures. If it helps, I'm designing and programming a 2D side-scroller game (think mario). I want to use high quality graphics, but I also want high performance too. That's why I was asking if there was a faster way to accomplish bit blitting.

Thanks again!

-Cyrano
– A cape? Forsooth! 'Tis a peninsula!

Breakman79

  • Jr. Member
  • **
  • Posts: 58
    • View Profile
Sprite Rendering, bit blitting, and other questions
« Reply #4 on: April 22, 2010, 04:07:39 pm »
Quote
How do I use that "geometry of triangles" you mention?


You don't need to.  All of the complicated opengl calls for binding the textures to quads for 2D rendering are nicely wrapped up in easy to use objects and methods.  

I suggest taking a look at Drawing Sprites tutorial and the source code example it provides.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Sprite Rendering, bit blitting, and other questions
« Reply #5 on: April 22, 2010, 06:33:42 pm »
If you use SFML you don't need to ask this kind of questions, just use the API and it will take care of all the low-level details for you.
Laurent Gomila - SFML developer

Cyrano

  • Newbie
  • *
  • Posts: 19
    • View Profile
Sprite Rendering, bit blitting, and other questions
« Reply #6 on: April 22, 2010, 06:35:35 pm »
Quote
You don't need to.  All of the complicated opengl calls for binding the textures to quads for 2D rendering are nicely wrapped up in easy to use objects and methods.  

I suggest taking a look at Drawing Sprites tutorial and the source code example it provides.


Thanks for the link, it looks good from what I saw.

So if you bind a texture (which seems to be akin to an image ".gif, .png, .jpg, etc.") to quads (some form of coordinates? like x and y perhaps?), that simply  means that you have attached coordinates that can be manipulated to an image?

Answers appreciated!

-Cyrano
– A cape? Forsooth! 'Tis a peninsula!

Ashenwraith

  • Sr. Member
  • ****
  • Posts: 270
    • View Profile
Sprite Rendering, bit blitting, and other questions
« Reply #7 on: April 23, 2010, 04:39:26 am »
Read and do the NeHe opengl tutorials.

Then come back and do the sfml tutorials.

You can talk about basics all day long and not understand anything because it's meaningless since you have no where to start from.

Cyrano

  • Newbie
  • *
  • Posts: 19
    • View Profile
Sprite Rendering, bit blitting, and other questions
« Reply #8 on: April 23, 2010, 05:15:40 am »
Quote from: "Ashenwraith"
Read and do the NeHe opengl tutorials.

Then come back and do the sfml tutorials.

You can talk about basics all day long and not understand anything because it's meaningless since you have no where to start from.


Sorry, I don't do OpenGL at this time.

I don't need to render 40 gazillion polygonal, gourad-shaded, light and bump-mapped sprites. All I need are the tools to quickly take 2D images from image sheets and put them on a screen. That's why I haven't really looked into OpenGL. I expect it probably has most of the functionality I'm looking for, but I have been under the impression that it is not the easiest API to learn. I've got other things to do with my life than program, so I don't want to spend half of my programming time sifting through loads of documentation just for the few graphics functions I need.

Still, it could save me a lot of trouble...

I'll consider it.

-Cyrano
– A cape? Forsooth! 'Tis a peninsula!

Breakman79

  • Jr. Member
  • **
  • Posts: 58
    • View Profile
Sprite Rendering, bit blitting, and other questions
« Reply #9 on: April 23, 2010, 06:49:56 am »
Actually, you don't need to know any OpenGL to use this library to make a 2D game.  

It's just that this library is built on top of OpenGL though so it creates a 2D scene by mapping your images to a texture that is applied to a flat polygon which is then drawn by your 3D video card.  This allows all of your sprites to be hardware-accelerated and thus freeing up your CPU for other tasks.

Works wonderfully for things like alpha-blending and lighting which were extremely slow and CPU intensive with the old blitting way.

Cyrano

  • Newbie
  • *
  • Posts: 19
    • View Profile
Sprite Rendering, bit blitting, and other questions
« Reply #10 on: April 23, 2010, 03:28:56 pm »
Quote from: "Breakman79"
Actually, you don't need to know any OpenGL to use this library to make a 2D game.  

It's just that this library is built on top of OpenGL though so it creates a 2D scene by mapping your images to a texture that is applied to a flat polygon which is then drawn by your 3D video card.  This allows all of your sprites to be hardware-accelerated and thus freeing up your CPU for other tasks.

Works wonderfully for things like alpha-blending and lighting which were extremely slow and CPU intensive with the old blitting way.


Thank you! :)
– A cape? Forsooth! 'Tis a peninsula!

Ashenwraith

  • Sr. Member
  • ****
  • Posts: 270
    • View Profile
Sprite Rendering, bit blitting, and other questions
« Reply #11 on: April 23, 2010, 03:57:33 pm »
You do realize you have to write an entire engine with animation, timing, and collision at the minimum? That is unless you are writing a complete turn based/non-animating game.

Doing an OpenGL tutorial is like a breeze in comparison.

Cyrano

  • Newbie
  • *
  • Posts: 19
    • View Profile
Sprite Rendering, bit blitting, and other questions
« Reply #12 on: April 24, 2010, 04:50:09 am »
Quote from: "Ashenwraith"
You do realize you have to write an entire engine with animation, timing, and collision at the minimum? That is unless you are writing a complete turn based/non-animating game.


Writing an engine will be the fun part for me (I already am laying the groundwork for one). Animation, timing, and collisions are areas I'm much more familiar with. Figuring out rendering calls, however, will not be pleasant, as I have virtually no experience with rendering code. I feel fairly confident about the other areas, though.:)

Quote
Doing an OpenGL tutorial is like a breeze in comparison.


Well, I'll take that into consideration, seeing as Ashenwraith appears to favor it highly.

I've got some great ideas, but I'll just have to see how OpenGL will work with them before I go full bore on this.

-Cyrano
– A cape? Forsooth! 'Tis a peninsula!

 

anything