Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWade Brainerd <wadetb@gmail.com>2008-03-05 16:30:49 (GMT)
committer Wade Brainerd <wadetb@gmail.com>2008-03-05 16:30:49 (GMT)
commit17d20662e8fbd801cea01bd19dfdd78a60b7f5c1 (patch)
tree7511d0d5981c06ea4ccc849ec81350b42019b708
parentdb43c166d23bd0758712f42c7f9102f3f15a5d79 (diff)
Line drawing fixed for now. No AA, probably not needed on XO.
Still need to get Cairo drawing working again.
-rw-r--r--MANIFEST2
-rw-r--r--pong.py10
-rw-r--r--src/pongc.cpp33
3 files changed, 24 insertions, 21 deletions
diff --git a/MANIFEST b/MANIFEST
index d54a48e..e659c3a 100644
--- a/MANIFEST
+++ b/MANIFEST
@@ -1,5 +1,7 @@
pong.py
setup.py
+pongc.py
+_pongc.so
MANIFEST
NEWS
activity/3dpong.svg
diff --git a/pong.py b/pong.py
index 1f762ae..71032d6 100644
--- a/pong.py
+++ b/pong.py
@@ -155,7 +155,7 @@ def line3d(x0, y0, z0, x1, y1, z1, c):
game.drawimage,
project_x(x0, y0, z0), project_y(x0, y0, z0),
project_x(x1, y1, z1), project_y(x1, y1, z1),
- int(c*31.0))
+ int(c*255.0))
def rect3d(rect, depth, c):
x0 = project_x(rect.left, rect.top, depth) + 1
@@ -163,10 +163,10 @@ def rect3d(rect, depth, c):
x1 = project_x(rect.right, rect.bottom, depth) - 1
y1 = project_y(rect.right, rect.bottom, depth) - 1
- draw_line_2x(game.drawimage, x0, y0, x1, y0, int(c*31.0))
- draw_line_2x(game.drawimage, x1, y0, x1, y1, int(c*31.0))
- draw_line_2x(game.drawimage, x1, y1, x0, y1, int(c*31.0))
- draw_line_2x(game.drawimage, x0, y1, x0, y0, int(c*31.0))
+ draw_line_2x(game.drawimage, x0, y0, x1, y0, int(c*255.0))
+ draw_line_2x(game.drawimage, x1, y0, x1, y1, int(c*255.0))
+ draw_line_2x(game.drawimage, x1, y1, x0, y1, int(c*255.0))
+ draw_line_2x(game.drawimage, x0, y1, x0, y0, int(c*255.0))
def circle3d(x, y, z, radius, c):
pass
diff --git a/src/pongc.cpp b/src/pongc.cpp
index 6660438..6114bc9 100644
--- a/src/pongc.cpp
+++ b/src/pongc.cpp
@@ -26,7 +26,7 @@ float frac(float x)
void draw_point_2x(GdkImage* img, int x, int y, uint16_t c)
{
- if (c>31) c=31;
+ c >>= 3;
unsigned short* pixels = (unsigned short*)img->mem;
int pitch = img->bpl/sizeof(unsigned short);
int ofs = pitch*y*2+x*2;
@@ -34,7 +34,7 @@ void draw_point_2x(GdkImage* img, int x, int y, uint16_t c)
pixels[ofs] = pix;
pixels[ofs+1] = pix;
pixels[ofs+pitch] = pix;
- pixels[ofs+pitch*2+1] = pix;
+ pixels[ofs+pitch+1] = pix;
}
void clear_image(GdkImage* img)
@@ -92,7 +92,6 @@ void draw_line_2x(GdkImage* img, int x0, int y0, int x1, int y1, int color)
}
else if (dx == dy) // Diagonal line
{
- return;
do
{
x0 += xdir;
@@ -103,24 +102,24 @@ void draw_line_2x(GdkImage* img, int x0, int y0, int x1, int y1, int color)
else // Line is not horizontal, diagonal, or vertical.
{
// Initialize the line error accumulator to 0
- uint32_t ErrorAcc = 0;
+ uint16_t ErrorAcc = 0;
// # of bits by which to shift ErrorAcc to get intensity level
- uint32_t IntensityShift = 16 - 5;
+ uint16_t IntensityShift = 16 - 8;
// Mask used to flip all bits in an intensity weighting, producing the result (1 - intensity weighting)
- uint32_t WeightingComplementMask = 32 - 1;
+ uint16_t WeightingComplementMask = 256 - 1;
// Is this an X-major or Y-major line?
if (dy > dx)
{
// Y-major line; calculate 16-bit fixed-point fractional part of a pixel that X advances each time Y advances
// 1 pixel, truncating the result so that we won't overrun the endpoint along the X axis
- uint32_t ErrorAdj = ((unsigned long) dx << 16) / (unsigned long) dy;
+ uint16_t ErrorAdj = ((unsigned long) dx << 16) / (unsigned long) dy;
// Draw all pixels other than the first and last
while (--dy)
{
- uint32_t ErrorAccTemp = ErrorAcc; /* remember currrent accumulated error */
+ uint16_t ErrorAccTemp = ErrorAcc; /* remember currrent accumulated error */
ErrorAcc += ErrorAdj; /* calculate error for next pixel */
if (ErrorAcc <= ErrorAccTemp)
{
@@ -130,9 +129,10 @@ void draw_line_2x(GdkImage* img, int x0, int y0, int x1, int y1, int color)
y0++; // Y-major, so always advance Y
// The IntensityBits most significant bits of ErrorAcc give us the intensity weighting for this pixel, and the
// complement of the weighting for the paired pixel
- uint32_t Weighting = ErrorAcc >> IntensityShift;
- draw_point_2x(img, x0, y0, color + Weighting);
- draw_point_2x(img, x0 + xdir, y0, color + (Weighting ^ WeightingComplementMask));
+ uint16_t Weighting = ErrorAcc >> IntensityShift;
+ //draw_point_2x(img, x0, y0, (color * Weighting) >> 8);
+ //draw_point_2x(img, x0 + xdir, y0, (color * (Weighting ^ WeightingComplementMask)) >> 8);
+ draw_point_2x(img, x0, y0, color);
}
// Draw the final pixel, which is always exactly intersected by the line and so needs no weighting
draw_point_2x(img, x1, y1, color);
@@ -141,11 +141,11 @@ void draw_line_2x(GdkImage* img, int x0, int y0, int x1, int y1, int color)
{
// It's an X-major line; calculate 16-bit fixed-point fractional part of a pixel that Y advances each time X
// advances 1 pixel, truncating the result to avoid overrunning the endpoint along the X axis
- uint32_t ErrorAdj = ((unsigned long) dy << 16) / (unsigned long) dx;
+ uint16_t ErrorAdj = ((unsigned long) dy << 16) / (unsigned long) dx;
// Draw all pixels other than the first and last
while (--dx)
{
- uint32_t ErrorAccTemp = ErrorAcc; // remember currrent accumulated error
+ uint16_t ErrorAccTemp = ErrorAcc; // remember currrent accumulated error
ErrorAcc += ErrorAdj; // calculate error for next pixel
if (ErrorAcc <= ErrorAccTemp)
{
@@ -155,9 +155,10 @@ void draw_line_2x(GdkImage* img, int x0, int y0, int x1, int y1, int color)
x0 += xdir; // X-major, so always advance X
// The IntensityBits most significant bits of ErrorAcc give us the intensity weighting for this pixel, and the
// complement of the weighting for the paired pixel
- uint32_t Weighting = ErrorAcc >> IntensityShift;
- draw_point_2x(img, x0, y0, color + Weighting);
- draw_point_2x(img, x0, y0 + 1, color + (Weighting ^ WeightingComplementMask));
+ uint16_t Weighting = ErrorAcc >> IntensityShift;
+ //draw_point_2x(img, x0, y0, (color * Weighting) >> 8);
+ //draw_point_2x(img, x0, y0 + 1, (color * (Weighting ^ WeightingComplementMask)) >> 8);
+ draw_point_2x(img, x0, y0, color);
}
// Draw the final pixel, which is always exactly intersected by the line and so needs no weighting
draw_point_2x(img, x1, y1, color);