trouble with line drawing example

Post Reply
zelbo
Posts: 11
Joined: Tue Feb 10, 2009 6:23 am

trouble with line drawing example

Post by zelbo » Sun Apr 12, 2009 2:51 am

i can't get the code from the tutorial to work with this one. Any ideas?

here's the compile log:

Code: Select all

C:\devkitPro\projects\line000>make clean
clean ...

C:\devkitPro\projects\line000>make
main.c
arm-eabi-gcc -MMD -MP -MF /c/devkitPro/projects/line000/build/main.d -g -Wall -O
2 -march=armv5te -mtune=arm946e-s -fomit-frame-pointer -ffast-math -mthumb -mthu
mb-interwork -I/c/devkitPro/projects/line000/include -I/c/devkitPro/libnds/inclu
de -I/c/devkitPro/libnds/include -I/c/devkitPro/projects/line000/build -DARM9 -c
 /c/devkitPro/projects/line000/source/main.c -o main.o
c:/devkitPro/projects/line000/source/main.c: In function 'main':
c:/devkitPro/projects/line000/source/main.c:94: warning: 'getIPC' is deprecated
(declared at c:/devkitPro/libnds/include/nds/ipc.h:64)
c:/devkitPro/projects/line000/source/main.c:95: warning: 'getIPC' is deprecated
(declared at c:/devkitPro/libnds/include/nds/ipc.h:64)
linking line000.elf
built ... line000.arm9

ndstool -c /c/devkitPro/projects/line000/line000.nds -9 /c/devkitPro/projects/li
ne000/line000.arm9 -b /c/devkitPro/libnds/icon.bmp "line000;www.devkitpro.org;ww
w.drunkencoders.com"
Nintendo DS rom tool 1.40 - Feb  4 2009
by Rafael Vuijk, Dave Murphy, Alexei Karpenko
built ... line000.nds

C:\devkitPro\projects\line000>pause
Press any key to continue . . .
and here is the source:

Code: Select all

/*---------------------------------------------------------------------------------

	Basic template code for starting a DS app

---------------------------------------------------------------------------------*/
#include <nds.h>


void DrawLine(int x1, int y1, int x2, int y2, unsigned short color)
{
    int yStep = SCREEN_WIDTH;
    int xStep = 1;      
    int xDiff = x2 - x1;
    int yDiff = y2 - y1;
 
    int errorTerm = 0;
    int offset = y1 * SCREEN_WIDTH + x1; 
    int i; 
    
    //need to adjust if y1 > y2
    if (yDiff < 0)       
    {                  
       yDiff = -yDiff;   //absolute value
       yStep = -yStep;   //step up instead of down   
    }
    
    //same for x
    if (xDiff < 0) 
    {           
       xDiff = -xDiff;            
       xStep = -xStep;            
    }        
 
    //case for changes more in X than in Y	 
    if (xDiff > yDiff) 
    {                            
       for (i = 0; i < xDiff + 1; i++)
       {                           
          VRAM_A[offset] = color;  
 
          offset += xStep;           
 
          errorTerm += yDiff;     
 
          if (errorTerm > xDiff) 
          {  
             errorTerm -= xDiff;     
             offset += yStep;        
          }
       }
    }//end if xdiff > ydiff
    //case for changes more in Y than in X
    else 
    {                       
       for (i = 0; i < yDiff + 1; i++) 
       {  
          VRAM_A[offset] = color;  
 
          offset += yStep;           
 
          errorTerm += xDiff;    
 
          if (errorTerm > yDiff) 
          {     
             errorTerm -= yDiff;  
             offset += xStep;     
 
          }
       }
    }
 
}
int main(void)
{
	int x;
	int y;
	
	int oldX = 0;
	int oldY = 0;
 
	irqInit();
	irqEnable(IRQ_VBLANK);
 
	videoSetMode(MODE_FB0);
	vramSetBankA(VRAM_A_LCD);
 
	lcdMainOnBottom();
 
	while(1)
	{
		scanKeys();
 
// dowhat? deprecated?
		x = IPC->touchXpx;
		y = IPC->touchYpx;
		
		if(!(keysDown() & KEY_TOUCH) && (keysHeld() & KEY_TOUCH))
		{
			DrawLine(oldX, oldY, x, y, rand());				
		}
		
		oldX = x;
		oldY = y;	
 
		swiWaitForVBlank();
	}
 
	return 0;
}


Pete
Posts: 18
Joined: Wed Jan 28, 2009 9:12 pm

Re: trouble with line drawing example

Post by Pete » Sun Apr 12, 2009 12:03 pm

Take a look at some of the examples provided with libNds. You need something involving

touchPosition touch;
touchRead(&touch);

then you can use

touch.px
touch.py

Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests