Falcon4ever
Plugin coder / Betatester
Hello,
For some school exercise I need to draw lines between two points
by calculating the pixels between x,y and x1,y1.
(x0 and y0 is a midpoint)
Normally I program in MSVC7 (and in C++), but for this exercise programming
needs to be done in Linux using C and SDL.
My main problem is as following:
Below you can see a part of my sourcecode
Whenever i do smth with the y value in the while loop. I get the following error message:
Any clue what could be wrong?
For some school exercise I need to draw lines between two points
by calculating the pixels between x,y and x1,y1.
(x0 and y0 is a midpoint)
Normally I program in MSVC7 (and in C++), but for this exercise programming
needs to be done in Linux using C and SDL.
My main problem is as following:
Below you can see a part of my sourcecode
Code:
C code:
void drawline(SDL_Surface *s, int x0, int y0, int x1, int y1, Uint32 colour) {
// Seems like KDevelop is a bit picky on not used variables.
if(x0==0)
{
printf("x0 %d ",x0);
printf("y0 %d ",y0);
printf("x1 %d ",x1);
printf("y1 %d \n",y1);
}
// size from midpoint
int dx = x1 - x0;
int dy = y1 - y0;
// most left pixel
int x = x0 - dx;
int y = y0 - dy;
// slope x
float dydx = ((float)y/(float)x);
printf("dydx %f ",dydx);
// slope y
int i_dydx = (int)round(dydx);
printf("dydx %d \n",i_dydx);
// draw
while(x<x1)
{
PutPixel(s,x,y,colour);
// y++;
x++;
}
.
.
.
...
Whenever i do smth with the y value in the while loop. I get the following error message:
So i've commented it temporarly.error msg:
Fatal signal: Segmentation Fault (SDL Parachute Deployed)
Any clue what could be wrong?