I am trying to draw simple geomtric shapes. I can get a rectangel to work, but wierd things happen when I do diagonal lines.
The following is the proto for the diaganol lines:
void dline(int x,int y, int len, int col);
void dline1(int x,int y, int len, int col);
Here is the definitons:
void dline(int x, int y, int len, int col)
{
for (int k=0; k<len; k++)
{
video_buffer[y*321+x+k*321] = col;
}
}
void dline1(int x, int y, int len, int col)
{
for (int k=0; k<len; k++)
{
video_buffer[y*319+x+k*319] = col;
}
Each work correctly individually when I draw them on a blank screen.
but when I use the follwing protoype and function to combine them into a shape the diaganol lines do not get placed in the appropriate place on the screen.
void shape(int xco, int yco, int xlen,int ylenr, int ylenl, int col);
void shapetest()
{
wall ( 0,0,20,40,40,blu);
}
void shape(int xco, int yco, int xlen, int ylenr, int ylenl,int col)
{
dline(xco, yco, xlen, col);
dline1(xco, yco+ylenr, xlen, col);
vline(xco, yco+(xlen/2), ylenl/2, col);
vline(xco +xlen, yco, ylenr, col);
}
If the following were an outline of the screen, this would be an example of my results:
--------------------------------
| \ <- (at 0,0)diagonal starts at 0,0 and the 2
| \ vertical lines are in the the upper right corner also
|
| \ <- at 0,30, I would think the diagonal would begin at 0,30
| \ but it doesn't. Both vertical lines in the shape shift lower
| and right and the diagonal appears to start at 40,40
--------------------------------
Any ideas? Because I wnated to be able to show the shape anywhere by changing the xco and yco, but when I do that the rectangles are okay, but the diaganol lines are now strewn all over the screen.