Avatar of mattososky
mattososky
 asked on

How to remove antialiasing for sprites?

My sprites are being drawing antialiased. I don't what this, I what the sprite to be a pixel for pixel match of the texture. What do I need to do?

Thanks,
Matthew
Game ProgrammingC++

Avatar of undefined
Last Comment
Jose Parrot

8/22/2022 - Mon
Jose Parrot

When we create an antialized sprite, we actually mix the sprite color with the background color at sprite boundaries. Say, if the sprite is red and background is white, there are some pixels with colors between red and white in the sprite boundaries.

If we apply another backgrond color, say, by painting it blue, the painting process stops at non-white pixels, thus resulting in bad contour and bad integration of the sprite to the background, and pre-antialized pixels works inverse...

The better solution is to create the sprites with transparent background so that you program knows how to treat transparency values (alpha channel).

If it is not possible, then make your sprites not anti-alized, only with horizontal, verrtical and 45 degrees inclined lines, to minimize the non-antialized sprite.

As an option, if anti-aliazing is mandatory, repeat your original sprites and create a number of different versions of it, each one with a different background color, such that you chose, at a given situation, the most appropriate version. Say, for a almost green scenario you use the sprite that was mixed with a green background, and so on.

This trick is easy to implement and as sprites are typicaly small, there is no problem if your program spend a liitle bit more memory.

Jose
mattososky

ASKER
It's not just that the sprite is being antialiases, against the backgroud, it's perforing some kinda of smoothing or blending itself when it is drawn. I created a texture with some pretty high contrast textels next to eachother, and it's the like entire sprite is antialiasing all textels/pixels.

I was getting very frustrated with this, not so much as it was a roadblock, but on pricipal. I should be able to use directx to transfer a bitmap file onto the screen as it is, not being antialiased.

Currently I am trying textured quads. I actually got an interesting result. I notice that the texture was still being antialiases on the quad, but then I went full screen instead of windowed mode. The texture appeared seemingly corrent with no antialias!

Any comment on that? why should windowed / fullscreen mode effect texture antialiasing? One of my thoughts was that even though i specified a device of 800/600, and put it on a window of same size, the actual rendering size was smaller giving the windows border in windowed mode. I ran into that phenonmenon in C# alot. I'm thinking thing images are being rasterize, not antialiased, into a screen dimension that is perhaps a few pixels short of the 800x600, because of the windows border. That's just a guess cause I still need to check.
SOLUTION
Jose Parrot

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
ASKER CERTIFIED SOLUTION
Jose Parrot

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
mattososky

ASKER
I don't agree with your comments concerning using GDI. I've been using GDI for some years and it is not an acceptable replacement for what directX is providing. First oft, utilizing directX gives you direct access to hardward, allowing hardward accellerated functions. Have you every tried to alphablend, or rapidly switch between big images (any over 640x480) using GDI? I have also come accross bugs in the GDI API, when pushing things to extreams. (Try scaling an image, a small one, 6-5 times). DirectX is a totally appropriate API for developing 2D applications. Yes, even Direct3D.

Now, back to the question at hand, I have implemented the textured quads and gotten excellent results. The bitmaps are coming through 100% accurate. I'm not sure what the deal is with sprites, I saw one post which seemingly had the same problem, but their solution was not working for me.

Anyway, appriciate the input.
Thanks,
Matt
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
mattososky

ASKER
Some good points, but I disagree with some of the statements
Jose Parrot

I agree entirely with your points about GDI. DX is by far superior to that API, merely an API to the graphics windows interface, in contrast to rich DX, a true graphics engine.
But making pixel by pixel translation from a bitmap to the screen is very easy with GDI and constrained in DX, forcing the programmer to limit DX richness.
I hope the comments were useful anyway.
Regards,
Jose