Say you have a function like this (from SDL_Surface.h in hg):
int SDL_BlendPoint(SDL_Surface * dst, int x, int y, int blendMode,
Uint8 r, Uint8 g, Uint8 b, Uint8 a);
… and you want to plot a point at a floating point position on a
surface, that is, you have a “double x” and “double y” which can have
values like x = 324.6, y = 287.3.
To plot such a point, plot the four pixels surrounding it and adjust
the alpha value according to the distance from the point to each
pixel. That is, for (324.6, 287.3), you would plot the following:
(324, 287) with alpha = 255 / (0.62 + 0.32),
(325, 287) with alpha = 255 / ((1 - 0.6)2 + 0.32),
(324, 288) with alpha = 255 / (0.6**2 + (1 - 0.3)**2), and
(325, 288) with alpha = 255 / ((1 - 0.6)**2 + (1 - 0.3)**2).
So you need a function like this:
#include <math.h>
void PlotPoint(SDL_Surface* dst, double x, double y, Uint8 r, Uint8 g,
Uint8 b, Uint8 a) {
double ix, rx, iy, ry;
rx = modf(x, &ix);
ry = modf(y, &iy);
SDL_BlendPoint(dst, (int) ix, (int) iy, SDL_BLENDMODE_BLEND, r, g,
b, a / (rxrx + ryry));
SDL_BlendPoint(dst, (int) ix+1, (int) iy, SDL_BLENDMODE_BLEND, r, g,
b, a / ((1-rx)(1-rx) + ryry));
SDL_BlendPoint(dst, (int) ix, (int) iy+1, SDL_BLENDMODE_BLEND, r, g,
b, a / (rxrx + (1-ry)(1-ry)));
SDL_BlendPoint(dst, (int) ix+1, (int) iy+1, SDL_BLENDMODE_BLEND, r,
g, b, a / ((1-rx)(1-rx) + (1-ry)(1-ry)));
}
And, of course, remember to scale your x and y values before passing
them to PlotPoint.