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.

Beginners > Mode 3 picture problem...

#14750 - Dan_attacker - Mon Jan 12, 2004 9:36 am

Hello. I just started trying out GBA programming today. I'm having a problem with displaying an image on the screen using mode 3. The first image is the original test image, and the second is the compiled program running in VisualBoyAdvance...
Image 1 - Original Image
Image 2 - Running in Program

Here is the code...

Code:
#include "gba.h"
#include "bilde.h"

int main()

{
            u16 x;
            SetMode( MODE_3 | BG2_ENABLE );         
            for (x=0; x<(240*160); x++)
            {
                        FrontBuffer[x] = bildedata[x] ;
            }
            return 0;
}


I used PCX2GBA to convert the PCX image into a C header file. Is there something wrong with the code, or did PCX2GBA not convert the image correctly?

Oh, I got my code by slightly modifying this code from a tutorial...
Code:
#include "gba.h"
#include "bilde.h"

int main()

{
            u16 loop, x;
            SetMode( MODE_4 | BG2_ENABLE );       
            for(loop=0;loop<256;loop++)
            {
                        BG_PaletteMem[loop]=bildePalette[loop];     
}
            for (x=0; x<(120*160); x++)
            {
                        FrontBuffer[y] = bildeData[y] ;
            }
            return 0;
}

This guy looks like he was typing too fast or something because I never really programmed in C++ but I can already tell that this program has problems.[/url]


Last edited by Dan_attacker on Mon Jan 12, 2004 11:27 pm; edited 1 time in total

#14753 - Cearn - Mon Jan 12, 2004 12:41 pm

As long as both FrontBuffer and bildedata are u16 arrays the code should work. This looks a lot like an alignment problem somewhere, are you sure the original picture is 240 wide and not 239? If all scanlines are padded to 16bit boundaries you'd end up with something like the right picture.

You may want to try with something simpler like a hollow rectangle, then you can see where pcx2gba puts the scanline boundaries. Or you could give the original PCX to me and I'll try to figure it out; I've been looking for PCXs that may cause trouble.

#14767 - tepples - Mon Jan 12, 2004 5:56 pm

The misalignment looks like it occurs only on a few scanlines, which makes me think it's a compression or decompression problem. In fact, it could be a problem in your graphics program's PCX export filter. Have you tried loading up the PCX files that your graphics program writes in another graphics program such as GIMP 2.0-pre1?
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#14824 - Dan_attacker - Mon Jan 12, 2004 11:45 pm

I made the pcx file in Photoshop 6, and I tried it in GIMP and I get the same image. I did change one line in the header file but I don't know if it effected anything.

const USHORT bildedata[] = {...}

I changed USHORT to u16 to make the program compile. Does that change anything?

Here's the pcx file if anyone wants to look at it...

http://pokemania.outloud.net/pic.pcx

#14828 - dagamer34 - Tue Jan 13, 2004 2:35 am

Well, you are loading data differently that the tutorial does it. That's the only thing i can find. But that really shouldn't be the problem.

Stick the picture in a tutorial program and see if you get the same problem. If so, then I have no clue. Otherwise, it's probably what i just pointed out to you.
_________________
Little kids and Playstation 2's don't mix. :(

#14836 - yaustar - Tue Jan 13, 2004 3:46 am

I have just tried it and it works fine. There seems to be nothing wrong with your code. Mine looks like this:
Code:

//////////////////////////////////////////////////////////////////////////
// File:    imagedisp.cpp                                           //
// Description: A program that displays an image on the GBA      //
// Author:   gbajunkie (with lots of code from dovoto)        //
// Date:    15th March 2002                                         //
//////////////////////////////////////////////////////////////////////////
#include "gba.h"        //GBA register definitions
#include "dispcnt.h"    //REG_DISPCNT register definitions
#include "junkie.h"   //holds the image information in an array

u16* Video = (u16*)0x6000000;

int main()

{
            SetMode( MODE_3 | BG2_ENABLE );         
            for(int loop=0; loop < 240*160; loop++)
            {
               Video[loop] = junkiedata[loop];
       }
            return 0;      
}

Try pcx->gba by Jesder.

The only other thing I had done was to save the pcx as a bmp, put it down to 8 bit and back to a pcx again
_________________
[Blog] [Portfolio]