Help fixing drawbitmap function

Understanding the language, error messages, etc.

Help fixing drawbitmap function

Postby Duhjoker » Mon Dec 12, 2016 5:13 am

ok guys im closer to finishing the drawbitmapfromsd functions. but of course I still need help straightening up thcode a lil. the problem lies in the drawpixel command at the end of the drawbitmapA function which was included in mouginos sample code.

Code: Select all
// Draw inverted-color bitmap from SRAM char array
void drawBitmapA(byte x, byte y, char *bitmap, uint16_t color) { // where bitmap[] is the char array containing bitmap data
   byte w = bitmap[0];
   byte h = bitmap[1];
   byte i, j, byteNum, bitNum, byteWidth = (w + 7) >> 3;
   for (i = 0; i < w; i++) {
      byteNum = i / 8; bitNum = i % 8;
      for (j = 0; j < h; j++) {
         if (!((bitmap[2 + j*byteWidth + byteNum]) & (B10000000 >> bitNum))) {
            drawPixel(x + i, y + j, color);
         }
      }
   }
}

// Draw inverted-color bitmaps from SRAM for use with tilemap duhjoker
void drawBitmapB(byte x, byte y, char *bitmap, uint8_t dx, uint8_t dy, uint8_t dw, uint8_t dh, uint16_t color) { // where bitmap[] is the char array containing bitmap data
   byte w = bitmap[0];
   byte h = bitmap[1];
   byte i, j, byteNum, bitNum, byteWidth = (w + 7) >> 3;
   dw += dx;
   dh += dy;
   for (i = 0; i<w; i++) {
      byteNum = i / 8; bitNum = i % 8;
      for (j = 0; j<h; j++) {
         if (!((bitmap[2 + j*byteWidth + byteNum]) & (B10000000 >> bitNum))) {
            int8_t drawX = x + i;
            int8_t drawY = y + j;

            if (drawX >= dx && drawX < dw && drawY >= dy && drawY < dh) {
               drawPixel(x, y, color);
            }
         }
      }
   }
}

// Draw bitmap from SD at position x0, y0
int drawBitmapFromSd(byte x0, byte y0, char *bitmap, uint16_t color) { // where bitmap[] is the name of the bitmap file on SD
   char buf[13]; // max 2 bytes for W/H + 11 bytes of data to cover the 84 pixel width of the  Gamebuino screen
   // 1. open bitmap file
    // open real bitmap on SD
   (pf_open(bitmap)); return BMP_NO_FILE;
   // 2a. read information from bitmap header > identifier
   readNCharsAt(2, 0, buf); // BMP.wIdentifier
   buf[2] = NULL;
   if (strcmp(buf, "BM")) return BMP_NOT_WBM;
   // 2b. read information from bitmap header > bpp, compression and data size
   readNCharsAt(10, 28, buf); // BMP.wBitsPerPixel + BMP.dwCompression + BMP.dwDataSize
   if (WORD(buf, 0) != 1) return BMP_NOT_1BPP; // not a 1bpp bitmap
   if (LONG(buf, 2)) return BMP_ERR_CMP; // not an UNcompressed bitmap
   word datasize = WORD(buf, 6);
   // 2c. read information from bitmap header > data offset
   readNCharsAt(4, 10, buf); // BMP.dwDataOffset
   word offset = WORD(buf, 0);
   // 2d. read information from bitmap header > dimensions
   readNCharsAt(8, 18, buf); // BMP.dwWidth + BMP.dwHeight
   byte w = (byte)buf[0];
   if (w>LCDWIDTH) return BMP_TOO_BIG;
   byte h = (byte)buf[4];
   byte datalen = datasize / h;
   // 3. read and draw bitmap data
   buf[0] = w; buf[1] = 1; // get bitmap data line by line
   for (byte y = 0; y<h; y++) {
      readNCharsAt(datalen, offset + y*datalen, buf + 2);
      drawBitmapA(x0, y0 + (h - 1) - y, buf, color); // and draw it!
   }
   return BMP_OK;
}


ive tried all kinds of stuff like adding or removing brackets but I cannot get the code to declare the drawpixel in the scope.

Code: Select all
Arduino: 1.6.11 (Windows 7), TD: 1.30-beta3, Board: "Teensy 3.2 / 3.1, Serial, 72 MHz optimize speed, US English"

C:\Users\duhjoker\Documents\Arduino\libraries\gamebuinoAPcolorSD\DisplayRGB.cpp: In member function 'void Display::drawBitmap(int8_t, int8_t, int8_t, int8_t, const uint8_t*, uint8_t, uint8_t, uint8_t, uint8_t, uint16_t)':

C:\Users\duhjoker\Documents\Arduino\libraries\gamebuinoAPcolorSD\DisplayRGB.cpp:709:9: warning: unused variable 'largest' [-Wunused-variable]

  int8_t largest = 0;

         ^

C:\Users\duhjoker\Documents\Arduino\libraries\gamebuinoAPcolorSD\DisplayRGB.cpp:710:9: warning: unused variable 'largesty' [-Wunused-variable]

  int8_t largesty = 0;

         ^

C:\Users\duhjoker\Documents\Arduino\libraries\gamebuinoAPcolorSD\DisplayRGB.cpp: In function 'void drawBitmapA(byte, byte, char*, uint16_t)':

C:\Users\duhjoker\Documents\Arduino\libraries\gamebuinoAPcolorSD\DisplayRGB.cpp:734:34: error: 'drawPixel' was not declared in this scope

     drawPixel(x + i, y + j, color);

                                  ^

C:\Users\duhjoker\Documents\Arduino\libraries\gamebuinoAPcolorSD\DisplayRGB.cpp: In function 'void drawBitmapB(byte, byte, char*, uint8_t, uint8_t, uint8_t, uint8_t, uint16_t)':

C:\Users\duhjoker\Documents\Arduino\libraries\gamebuinoAPcolorSD\DisplayRGB.cpp:755:27: error: 'drawPixel' was not declared in this scope

      drawPixel(x, y, color);

                           ^

C:\Users\duhjoker\Documents\Arduino\libraries\gamebuinoAPcolorSD\DisplayRGB.cpp: In function 'int drawBitmapFromSd(byte, byte, char*, uint16_t)':

C:\Users\duhjoker\Documents\Arduino\libraries\gamebuinoAPcolorSD\DisplayRGB.cpp:770:9: warning: converting to non-pointer type 'char' from NULL [-Wconversion-null]

  buf[2] = NULL;

         ^

Error compiling for board Teensy 3.2 / 3.1.

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.



can someone show how to fix these please?!!!
Attachments
gamebuinoAPcolorSD.zip
(33.95 KiB) Downloaded 280 times
User avatar
Duhjoker
 
Posts: 446
Joined: Sat Jul 02, 2016 4:57 am
Location: Where Palm trees grow

Re: Help fixing drawbitmap function

Postby rodot » Mon Dec 12, 2016 8:16 am

It's because you forgot the "Display::" to says the method belongs to the Display class. This way it's just a general scope function, and you can't access the class's methods like drawPixel directly.

For all your new functions, replace
Code: Select all
void drawBitmapA(byte x, byte y, char *bitmap, uint16_t color) {


by
Code: Select all
void Display::drawBitmapA(byte x, byte y, char *bitmap, uint16_t color) {


You already added the methods' prototypes in the .h so you should be all good after that.
User avatar
rodot
Site Admin
 
Posts: 1290
Joined: Mon Nov 19, 2012 11:54 pm
Location: France

Re: Help fixing drawbitmap function

Postby Duhjoker » Tue Dec 13, 2016 4:00 am

Oh my God!! Dude!!! I feel so stupid right now, such a rookie mistake to forget to add the Display:: before the function in cpp. Thank you too. Really thank you!!!

I have another question though......

It's not giving me errors but I was wondering about the drawbitmapFromSD function. It has int in front instead of void. What does that mean? Would it not be better to use void.

Edit:::::: yay it compiles!!!
Had one more problem though that I had to fix. The drawbitmapFromSDA at the end of the actual drawfrom SD command wasn't declaring After that so I just added Display display; at the top and added display. Before it and now it works. Now I don't know if that's proper procedure and say something if it's not please, but it worked.

Also thank you mougino for posting your concept sketch.

Edit:::::::: I just thought of something. In order to use the tilemap and collision parts I you would normally go

Code: Select all
const byte spritesheet[] PROGMEM = {list of sprites};


And then use the tilemap and/or collision stuff. If I'm opening them up from the SD how do I declare the spritesheet list. Do I need a read bitmap name function or something.
User avatar
Duhjoker
 
Posts: 446
Joined: Sat Jul 02, 2016 4:57 am
Location: Where Palm trees grow

Re: Help fixing drawbitmap function

Postby rodot » Tue Dec 13, 2016 7:45 am

The "int" or "void" in front of the function's name is the kind of data that the function will return.

Your sprite list points to different sprites. If you update the sprites with ones loaded from the SD card you won't have to change your sprite list. You sprite can't be const/PROGMEM in that case because you will change them at run time, so you will have to changes the tilemap/collision functions accordingly. Your sprite list can be const if the sprites are always at the same place in the RAM.

You might want to read these, it will answer most of your questions:
http://www.cplusplus.com/doc/tutorial/functions/
http://www.cplusplus.com/doc/tutorial/classes/
User avatar
rodot
Site Admin
 
Posts: 1290
Joined: Mon Nov 19, 2012 11:54 pm
Location: France

Re: Help fixing drawbitmap function

Postby Duhjoker » Tue Dec 13, 2016 9:07 pm

It's good to review stuff thank you.

ok so here's what I'm thinking. I've got 44 terrain tiles and they equal 20.2kb broken down into individual color bitmaps. That's just a small fraction of the Progmem space on the teeny3.2. So it's possible to store a crap load of terrain sprites with out going over budget.

Then all the big bitmaps like for monsters which are all huge and take up tons of Progmem can be displayed from the SD.

Now with character sprites you can also store them on sd too. Unless there's a ton of animation tiles. for instance I have six sprites for each character so Paul Atreades has 1 front, 1 rear, and two each of left or right. The 5th and 6th bitmaps being a bitmap with shuffled feet to look like walking. Since it's just showing the same two bitmaps over and over again to perform a walk, the 32bit processor on the teensy should minimize any miniscule timing glitch.

But really think about this........

Of dune sprites I have a total of

42 monsters
21 people divided
28 general items
43 terrain
134 sprites broken down to 632 individual mono-chrome bitmaps 1 for each color used

That's 211kb for a fairly large sized game if you think about the world map being 350 X 350 tiles for the map. Lol using a teensy 3.5 which has 512kb or a teensy 3.6 which has a whole megabyte, would be hard put to fill up that much Progmem.

Or..or I could figure this out.......

viewtopic.php?f=13&t=3260
User avatar
Duhjoker
 
Posts: 446
Joined: Sat Jul 02, 2016 4:57 am
Location: Where Palm trees grow


Return to Programming Questions

Who is online

Users browsing this forum: No registered users and 14 guests

cron