#171724 - cy.bear - Thu Dec 17, 2009 5:53 pm
Hi,
eventhough i'm not new to programming (not that skilled in c though) loops on the gba are giving me a hard time.
First thing i don't really understand: I'm using mode 4 on BG2 and want to display an image in fullscreen. (The image was converted using dovoto's pcx2gba, result header file contains 1 palette and 1 (1d) data array).
I load the palette using:
For drawing (fullscreen; 240 x 160 px) I use:
I know this works (works really great actually) but i don't see why I have to half the width of my screen. I read somewhere that the GBA writes 2 pixels at once. But that doesn't really make sense as it would only show half of the picture then anyway.
The loops say "for each line of all 160 and half of the elements per line draw the specified pixel".
Does every entry in my data array specify two pixels? how would i draw an uneven number of pixels then?
Second thing that goes terribly wrong: I want to crete a 2d array as a map. I have tiles of type int defined as tileWall and tileFloor. (Tilesize 16x16px so 15 x 10 for fullscreen).
i have a map[][] array (large enough). And supply values mapHeight and mapWidth. To generate the map I use the following code:
The map is supposed to look like this * <- wall
Yet the output is terribly crippled: [Images not permitted - Click here to view it]
I think the drawing code could also be responsible for this result so here it is:
Any ideas about my problem? Any references to tutorials, websites ?
I'm glad about everything that can help me.
Thanks in advance and greetings
cy
PS: Already spent hours searching ;)
EDIT: Forgot to mention that plotPixel is as simple as this:
Just noticed that this also sees lines of 120 which supports the assumption that image data array holds info on 2px width for each entry.
Last edited by cy.bear on Thu Dec 17, 2009 6:20 pm; edited 1 time in total
eventhough i'm not new to programming (not that skilled in c though) loops on the gba are giving me a hard time.
First thing i don't really understand: I'm using mode 4 on BG2 and want to display an image in fullscreen. (The image was converted using dovoto's pcx2gba, result header file contains 1 palette and 1 (1d) data array).
I load the palette using:
Code: |
int x, y; for(x = 0; x < 256; x++) paletteMem[x] = titlePalette[x]; |
For drawing (fullscreen; 240 x 160 px) I use:
Code: |
for(y = 0; y < 160; y++){ for(x = 0; x < 240/2; x++){ plotPixel(x,y,titleData[y*240/2+x]); } } |
I know this works (works really great actually) but i don't see why I have to half the width of my screen. I read somewhere that the GBA writes 2 pixels at once. But that doesn't really make sense as it would only show half of the picture then anyway.
The loops say "for each line of all 160 and half of the elements per line draw the specified pixel".
Does every entry in my data array specify two pixels? how would i draw an uneven number of pixels then?
Second thing that goes terribly wrong: I want to crete a 2d array as a map. I have tiles of type int defined as tileWall and tileFloor. (Tilesize 16x16px so 15 x 10 for fullscreen).
i have a map[][] array (large enough). And supply values mapHeight and mapWidth. To generate the map I use the following code:
Code: |
for(y = 0; y < mapHeight; y++){ for(x = 0; x < mapWidth; x++){ if(y == 0 || y == mapHeight-1 || x == 0 || x == mapWidth-1){ // tile is border make it a wall map[y][x] = tileWall; } else if(y == 1 || y == (mapHeight -2) || x == 1 || x == (mapWidth -2)){ // tile next to outer border, so it's a floor map[y][x] = tileFloor; } else { // decide randomly if tile is to be wall or floor (about 1/3 walls) // for now: floor map[y][x] = tileFloor; } } } |
The map is supposed to look like this * <- wall
Quote: |
***************
*.............* *.............* *.............* *.............* *.............* *.............* *.............* *.............* *************** |
Yet the output is terribly crippled: [Images not permitted - Click here to view it]
I think the drawing code could also be responsible for this result so here it is:
Code: |
int xOffset = 0;
int yOffset = 0; const u16 * graphxData; for(y=0; y < lastMapHeight; y++){ for(x=0; x < lastMapWidth; x++){ switch (map[y][x]){ case tileFloor: ; graphxData = floorData; break; case tileWall: ; graphxData = wallData; break; default: ; graphxData = blankData; break; } int tileData_x, tileData_y; for(tileData_y = 0; tileData_y < tileHeight; tileData_y++){ for(tileData_x = 0; tileData_x < tileWidth/2; tileData_x++){ plotPixel(tileData_x+xOffset, tileData_y+yOffset, graphxData[tileData_y*tileWidth/2 +tileData_x]); } } xOffset += tileWidth; } xOffset = 0; yOffset += tileHeight; } |
Any ideas about my problem? Any references to tutorials, websites ?
I'm glad about everything that can help me.
Thanks in advance and greetings
cy
PS: Already spent hours searching ;)
EDIT: Forgot to mention that plotPixel is as simple as this:
Code: |
void plotPixel(int x,int y, unsigned short int c){ videoBuffer[(y) *120 + (x)] = (c); } |
Just noticed that this also sees lines of 120 which supports the assumption that image data array holds info on 2px width for each entry.
Last edited by cy.bear on Thu Dec 17, 2009 6:20 pm; edited 1 time in total