#20007 - mymateo - Thu Apr 29, 2004 9:22 pm
It's me again, throwing myself at the mercy of smarter, more experienced people.
I would like to know how to place a single pixel at a time. Before you reply, read through.
Here's my entire source code for you gurus to pick at. I don't see anything wrong, except for the excrutiating slow PutPixel routine. I was having troubles getting it to place an odd X numbered pixel on the screen in an odd X numbered spot, and even X's in even X's spot. I thought this would work, but it doesn't. Don't worry, I would never commit such a haneous crime against fast code in a real game or demo.
--- BEGIN CODE ---
// Program to demonstrate plotting "one" pixel.
typedef unsigned int u8;
typedef unsigned short u16;
typedef unsigned long u32;
u16* Palette = (u16*)0x05000000;
u16* videoBuffer = (u16*)0x06000000;
u32* VideoMode = (u32*)0x04000000;
void SetPalette(u8 PalNum,u8 R,u8 G,u8 B){Palette[PalNum] = ((B<<10) | (G<<5) | R);}
void PutPixel(u8 pX,u8 pY,u16 C)
{
int x,y,TempX;
x = 0;
for (y = 0; y < pX; y++)
{
x = 1 - x; // Switches between "1" and "0" alternating -- Fake binary
}
TempX = pX / 2; //Change to "TempX = pX;" and see what happens!
if (x = 0){videoBuffer[(pY * 120) + TempX] = C | 0 << 8; } // First pixel
if (x = 1){videoBuffer[(pY * 120) + TempX] = 0 | C << 8; } // Second pixel
//For some reason, the result looks like "x" is ALWAYS 1 no matter what...
}
void AgbMain()
{
int X, Y;
*VideoMode = 0x0404;
SetPalette( 0, 5, 5, 5);
SetPalette( 1,20,20,20);
for (X = 0; X < 100; X++)
{
Y = X;
PutPixel(X,Y,1); // Having Y is redundant, but for pity's sake
}
while(1); // Let's not have any hoo-haw here
}
--- END CODE ---
SO, if anyone sees anything wrong, maybe you could help me out? I'm all for figuring out something for myself, but I've stared at this until I've gone blind. If you don't want to give away the farm, then I'm happy as a clam just to get a hint as to where to look. But I'm not proud, either. I'll take a free hand-out if someone wants to fix my code and hand it back!
Anyway, thanks everyone. This forum has so many helpful people on it! (I wish I could be one...)
I would like to know how to place a single pixel at a time. Before you reply, read through.
Here's my entire source code for you gurus to pick at. I don't see anything wrong, except for the excrutiating slow PutPixel routine. I was having troubles getting it to place an odd X numbered pixel on the screen in an odd X numbered spot, and even X's in even X's spot. I thought this would work, but it doesn't. Don't worry, I would never commit such a haneous crime against fast code in a real game or demo.
--- BEGIN CODE ---
// Program to demonstrate plotting "one" pixel.
typedef unsigned int u8;
typedef unsigned short u16;
typedef unsigned long u32;
u16* Palette = (u16*)0x05000000;
u16* videoBuffer = (u16*)0x06000000;
u32* VideoMode = (u32*)0x04000000;
void SetPalette(u8 PalNum,u8 R,u8 G,u8 B){Palette[PalNum] = ((B<<10) | (G<<5) | R);}
void PutPixel(u8 pX,u8 pY,u16 C)
{
int x,y,TempX;
x = 0;
for (y = 0; y < pX; y++)
{
x = 1 - x; // Switches between "1" and "0" alternating -- Fake binary
}
TempX = pX / 2; //Change to "TempX = pX;" and see what happens!
if (x = 0){videoBuffer[(pY * 120) + TempX] = C | 0 << 8; } // First pixel
if (x = 1){videoBuffer[(pY * 120) + TempX] = 0 | C << 8; } // Second pixel
//For some reason, the result looks like "x" is ALWAYS 1 no matter what...
}
void AgbMain()
{
int X, Y;
*VideoMode = 0x0404;
SetPalette( 0, 5, 5, 5);
SetPalette( 1,20,20,20);
for (X = 0; X < 100; X++)
{
Y = X;
PutPixel(X,Y,1); // Having Y is redundant, but for pity's sake
}
while(1); // Let's not have any hoo-haw here
}
--- END CODE ---
SO, if anyone sees anything wrong, maybe you could help me out? I'm all for figuring out something for myself, but I've stared at this until I've gone blind. If you don't want to give away the farm, then I'm happy as a clam just to get a hint as to where to look. But I'm not proud, either. I'll take a free hand-out if someone wants to fix my code and hand it back!
Anyway, thanks everyone. This forum has so many helpful people on it! (I wish I could be one...)