gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

DS development > Stylus drawing on top of an image.

#125238 - FugitivePuppeT - Thu Apr 12, 2007 8:38 am

First post, please bear with me, I'm not the greatest coder, and am just learning coding for the DS.

Anyways, my problem is that I learned how to create a simple drawing program that creates a "Rainbow" type of line wherever the stylus is used.

Code:
#include<nds.h>
#include<stdlib.h>
 
void clear_screen(void){
unsigned short color;
color = RGB15(0,0,0);
int i;
for(i = 0; i < 256*192; i++)
         VRAM_A[i] = color;
}

int main(void)
{
   touchPosition touch;
 
   videoSetMode(MODE_FB0);
   vramSetBankA(VRAM_A_LCD);
       
        //notice we make sure the main graphics engine renders
        //to the lower lcd screen as it would be hard to draw if the
        //pixels did not show up directly benieth the pen
   lcdMainOnBottom();
 
   while(1)
   {
      scanKeys();
 
      if(keysHeld() & KEY_TOUCH)
      {
         // read the touchscreen coordinates
         touch=touchReadXY();
         
         VRAM_A[touch.px + touch.py * 256] = rand();
      }
      
      if(keysHeld() & KEY_A)
         clear_screen();
   }
 
   return 0;
}


Then after some work, I finnaly got my first image displayed on the DS (The name of my image is "beer")

Code:
   // Including libnds’ set of defines
#include <nds.h>
#include<stdlib.h>
   // Include basic memory functions
#include <string.h>

   // Including our converted graphics
#include "beerTiles_bin.h"
#include "beerMap_bin.h"
#include "beerPal_bin.h"

int main()
{
      // Powering up the DS 2D hardware
   REG_POWERCNT = POWER_ALL_2D;
   
      // Setting up video mode
   DISPLAY_CR = MODE_0_2D | DISPLAY_BG0_ACTIVE;
   BG0_CR = BG_32x32 | BG_COLOR_256 | BG_MAP_BASE(0) | BG_TILE_BASE(1);
   
      // Setting VRAM Bank A for Background display
   VRAM_A_CR = VRAM_ENABLE | VRAM_A_MAIN_BG;
   
      // Copying the tiles to tile base 1
   memcpy((void*)BG_TILE_RAM(1), beerTiles_bin, beerTiles_bin_size);
      // Copying the map to map base 0
   memcpy((void*)BG_MAP_RAM(0), beerMap_bin, beerMap_bin_size);
      // Copying the palette to the palette area
   memcpy((void*)BG_PALETTE, beerPal_bin, beerPal_bin_size);
     
      // Infinate loop to keep the program running
   while(1)
}


What I was attempting to do is sort of combine the two, and draw on top of the image. I think my problem is that I'm using different video modes for each example. Any help would be great. Here is the combined code.

Code:
   // Including libnds’ set of defines
#include <nds.h>
#include<stdlib.h>
   // Include basic memory functions
#include <string.h>

   // Including our converted graphics
#include "beerTiles_bin.h"
#include "beerMap_bin.h"
#include "beerPal_bin.h"

//This function simply makes the screen white. Will replace later.
void clear_screen(void){
unsigned short color;
color = RGB15(0,0,0);
int i;
for(i = 0; i < 256*192; i++)
         VRAM_A[i] = color;
}

int main()
{
   touchPosition touch;
      // Powering up the DS 2D hardware
   REG_POWERCNT = POWER_ALL_2D;
   
      // Setting up video mode
   DISPLAY_CR = MODE_0_2D | DISPLAY_BG0_ACTIVE;
   BG0_CR = BG_32x32 | BG_COLOR_256 | BG_MAP_BASE(0) | BG_TILE_BASE(1);
   
      // Setting VRAM Bank A for Background display
   VRAM_A_CR = VRAM_ENABLE | VRAM_A_MAIN_BG;
   
      // Copying the tiles to tile base 1
   memcpy((void*)BG_TILE_RAM(1), beerTiles_bin, beerTiles_bin_size);
      // Copying the map to map base 0
   memcpy((void*)BG_MAP_RAM(0), beerMap_bin, beerMap_bin_size);
      // Copying the palette to the palette area
   memcpy((void*)BG_PALETTE, beerPal_bin, beerPal_bin_size);
     
      // Infinate loop
   while(1)
   {
      scanKeys();
 
      if(keysHeld() & KEY_TOUCH)
      {
         // read the touchscreen coordinates
         touch=touchReadXY();
         
         VRAM_A[touch.px + touch.py * 256] = rand();
      }
      
      if(keysHeld() & KEY_L & KEY_R)
         clear_screen();
   }
   
   return 0;
}

#125402 - FugitivePuppeT - Fri Apr 13, 2007 3:10 am

Any help would be great!

#125404 - HyperHacker - Fri Apr 13, 2007 3:15 am

Your beer image is tile-based? You need to select a video mode with at least one Extended Rotation layer and one tile ("text") layer. Put the beer image on the tile layer, and the EXR layer above it. Anywhere a pixel on the EXR layer doesn't have the highest bit set, the beer image should show through.
_________________
I'm a PSP hacker now, but I still <3 DS.

#125424 - FugitivePuppeT - Fri Apr 13, 2007 5:40 am

Alright, I cant figure out how to set the order of the layers. Any examples someone can point me to (or just tell me?) Thanks again!

#125448 - tepples - Fri Apr 13, 2007 12:52 pm

You set the layer order in the BGxCNT registers.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.