[newbie] Have idea planned out, is it workable?

fcg
Posts: 16
Joined: Wed Nov 24, 2010 10:51 pm

[newbie] Have idea planned out, is it workable?

Post by fcg » Fri Nov 26, 2010 2:06 pm

Hi,

Super-disclaimer: most of my current questions are extremely newbie-questions. Some of the answers to them I will find in the docs or by looking at examples, some don't. If you have an urge to reply: RTFM please just ignore the thread. If you otoh like to help out a slow paced newbie please read on.
  • Revisions (current in bold):
  • 0. Initial post, backstory, rough plans
  • 1. Refined questions about layers, tiles and timers
  • 2. Removed a question about non-power-of-2-tiles
Current list of questions (feel free to read the post before answering):
I put the questions first, so they are easier to find and leave the rest of the post for when you need more info before answering
  • Do you think it is worth it to first learn how to draw to a screen pixel by pixel or is it smarter to go for the layered and tiled approach directly?
    - I went with the 'pixel-by-pixel approach, see the code below...
  • (Currently moot: rewritten to use 8x8 tiles for now:) How do I use tiles of a non-standard dimension keeping an offset while drawing?
  • How do I draw tiles?
  • How do I draw the "background", "board" and "beads" on different layers?
  • How do I (re)draw on a layer with a delay? (I want to create a small incremental animation of the "beads" in the splash-screen)
I am one of those total newbies, that don't really understand the hardware or know C. I do have some programming under my belt and I'm currently working through the tutorials at dev-scene. While doing it I had an idea for a game that I will use to learn the ways of the DS and specifically of the libnds. I understand if you are tired of people coming here and asking for help in a "Help me, just must write my code"-way. That is not what I am asking for, so please hear me out before dismissing me...

My idea is to make a game of beads (like these), it will consist of three areas:
  • Composer
  • Minigames
  • Adventure game
And, no, I have no intention of creating this this weekend, I just want to get started with a splash-screen atm, the other things will come later at a slow pace...I just write it here to let you know

Before I go into the details of any of the above I need a cool splash-screen :D, and that is what I hope to get help with. I know how I want it to look but I need some[2] pointers in the right direction for how to accomplish it. I have layed out a basic version using the code below:

Image

I hope this pic shows some basic properties that I want my 'beadengine' to have:
  • each bead is a tile 8*8 pixels (with one color and transparent pixels in the corner and center)
  • the board consists of a background color, border and evenly positioned pins to put beads on.
  • the maximum board is 30*22 pins surrounded by a border
  • beads can be placed on the pins
  • etc (things I have in my head but can't formulate, feel free to ask questions...
So, now I coded my splash-screen, drawing it 'pixel by pixel' (basically just copied a arm9 template from the examples and changed the code in main to this) :

Code: Select all

#include <nds.h>

/* These are the "border and pin"-tiles 
	- they are refered to in the "board"-array
	- the color values mean:
		0 = no color
		X = taken from the palette
*/
// border and pin tile - border-top
u8 bpTop[64] = {
	0,0,0,0,0,0,0,0,
	0,0,0,0,0,0,0,0,
	0,0,0,0,0,0,0,0,
	0,0,0,0,0,0,0,0,
	2,2,2,2,2,2,2,2,
	2,2,2,2,2,2,2,2,
	0,0,0,0,0,0,0,0,
	0,0,0,0,0,0,0,0
};
// border and pin tile - border-right
u8 bpRight[64] = {
	0,0,2,2,0,0,0,0,
	0,0,2,2,0,0,0,0,
	0,0,2,2,0,0,0,0,
	0,0,2,2,0,0,0,0,
	0,0,2,2,0,0,0,0,
	0,0,2,2,0,0,0,0,
	0,0,2,2,0,0,0,0,
	0,0,2,2,0,0,0,0,
};
// border and pin tile - border-bottom
u8 bpBottom[64] = {
	0,0,0,0,0,0,0,0,
	0,0,0,0,0,0,0,0,
	2,2,2,2,2,2,2,2,
	2,2,2,2,2,2,2,2,
	0,0,0,0,0,0,0,0,
	0,0,0,0,0,0,0,0,
	0,0,0,0,0,0,0,0,
	0,0,0,0,0,0,0,0
};
// border and pin tile - border-left
u8 bpLeft[64] = {
	0,0,0,0,2,2,0,0,
	0,0,0,0,2,2,0,0,
	0,0,0,0,2,2,0,0,
	0,0,0,0,2,2,0,0,
	0,0,0,0,2,2,0,0,
	0,0,0,0,2,2,0,0,
	0,0,0,0,2,2,0,0,
	0,0,0,0,2,2,0,0,
};
// border and pin tile - pin
u8 bpPin[64] = {
	0,0,0,0,0,0,0,0,
	0,0,0,0,0,0,0,0,
	0,0,0,0,0,0,0,0,
	0,0,0,2,2,0,0,0,
	0,0,0,2,2,0,0,0,
	0,0,0,0,0,0,0,0,
	0,0,0,0,0,0,0,0,
	0,0,0,0,0,0,0,0,
};
// border and pin tile - Corner: north-west
u8 bpcNW[64] = {
	0,0,0,0,0,0,0,0,
	0,0,0,0,0,0,0,0,
	0,0,0,0,0,0,0,0,
	0,0,0,0,0,0,0,0,
	0,0,0,0,0,0,0,2,
	0,0,0,0,0,2,2,2,
	0,0,0,0,0,2,2,0,
	0,0,0,0,2,2,0,0
};
// border and pin tile - Corner: north-east
u8 bpcNE[64] = {
	0,0,0,0,0,0,0,0,
	0,0,0,0,0,0,0,0,
	0,0,0,0,0,0,0,0,
	0,0,0,0,0,0,0,0,
	2,0,0,0,0,0,0,0,
	2,2,2,0,0,0,0,0,
	0,2,2,0,0,0,0,0,
	0,0,2,2,0,0,0,0,
};
// border and pin tile - Corner: south-west
u8 bpcSW[64] = {
	0,0,0,0,2,2,0,0,
	0,0,0,0,0,2,2,0,
	0,0,0,0,0,2,2,2,
	0,0,0,0,0,0,0,2,
	0,0,0,0,0,0,0,0,
	0,0,0,0,0,0,0,0,
	0,0,0,0,0,0,0,0,
	0,0,0,0,0,0,0,0,
};
// border and pin tile - Corner: south-east
u8 bpcSE[64] = {
	0,0,2,2,0,0,0,0,
	0,2,2,0,0,0,0,0,
	2,2,2,0,0,0,0,0,
	2,0,0,0,0,0,0,0,
	0,0,0,0,0,0,0,0,
	0,0,0,0,0,0,0,0,
	0,0,0,0,0,0,0,0,
	0,0,0,0,0,0,0,0,
};

/* This is the "board", it consists of 32*24 "border and pin"-tiles = 768 tiles in total

	Border and Pin codes:
	0 = nothing
	1 = bpTop
	2 = bpRight
	3 = bpBottom
	4 = bpLeft
	5 = bpPin
	6 = bpcNW
	7 = bpcNE
	8 = bpcSW	
	9 = bpcSE	
	
*/
u8 board[768] = {
	6,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,7,
	4,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,2,
	4,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5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,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,2,
	4,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,2,
	4,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,2,
	4,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,2,
	4,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,2,
	8,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,9
};

/* This is the "bead"-tile
	- they are put on the "board"
	- they are refered to in the "beads" array
	- the values mean:
		0 = no color
		1 = color taken from the value in the "beads" array
*/
u8 bead[64] = {
	0,1,1,1,1,1,1,0,
	1,1,1,1,1,1,1,1,
	1,1,1,1,1,1,1,1,
	1,1,1,0,0,1,1,1,
	1,1,1,0,0,1,1,1,
	1,1,1,1,1,1,1,1,
	1,1,1,1,1,1,1,1,
	0,1,1,1,1,1,1,0
};

/* These are the beads, they take up 32*24 tiles = 768 tiles in total
	(notice the border of emptiness!)

	Bead codes:
	0 = nothing
	X = color talen from palette
*/
u8 beads_template[768] = {
	0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
	0,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,0,
	0,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,0,
	0,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,0,
	0,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,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3,3,3,4,3,0,
	0,3,3,3,3,3,4,4,4,3,3,4,4,4,4,3,4,3,3,4,3,4,4,4,3,3,4,4,4,3,3,0,
	0,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,0,
	0,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,0,
	0,3,3,3,0,3,0,0,0,3,3,0,0,0,0,3,3,0,3,3,3,0,0,3,3,3,3,0,0,3,3,0,
	0,3,3,3,0,3,0,3,3,0,3,0,3,3,3,3,0,3,0,3,3,0,3,0,3,3,0,3,3,3,3,0,
	0,3,3,3,0,3,0,0,0,3,3,0,0,0,3,3,0,3,3,0,3,0,3,3,0,3,3,0,0,3,3,0,
	0,3,3,3,0,3,0,3,3,0,3,0,3,3,3,3,0,0,0,0,3,0,3,3,0,3,3,3,3,0,3,0,
	0,3,3,3,3,3,0,3,3,0,3,0,3,3,3,3,0,3,3,0,3,0,3,3,0,3,3,3,3,0,3,0,
	0,3,3,3,0,3,0,0,0,3,3,0,0,0,0,3,0,3,3,0,3,0,0,0,3,3,0,0,0,3,3,0,
	0,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,0,
	0,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,0,
	0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
};

//---------------------------------------------------------------------------------
int main(void)
{
	// pixel coordinates
	int x;
 	int y;
 	
 	// tile coordinates
 	// we have 32 * 24 tiles of the size 8*8 pixels.
 	int x_tile;
 	int y_tile;
 	
	//initialize the DS Dos-like functionality
	consoleDemoInit();
 
	//set frame buffer mode 0
	videoSetMode(MODE_FB0);
 
	//enable VRAM A for writing by the cpu and use 
	//as a framebuffer by video hardware
	vramSetBankA(VRAM_A_LCD);
 
 	//load our palette
 	BG_PALETTE[0] = RGB15(0,0,31);		// Debug
	BG_PALETTE[1] = RGB15(4,4,0); 		// Background
	BG_PALETTE[2] = RGB15(27,27,19); 	// Border % pins
	BG_PALETTE[3] = RGB15(31,0,0);		// Red
	BG_PALETTE[4] = RGB15(0,31,0);		// Green
	
	// draw the background
	for(y = 0; y < 192; y++) {
		for (x = 0; x < 256; x++) {
			VRAM_A[x+(y*256)] = BG_PALETTE[1];
		}
	}
	
	// draw the board
	for(y_tile = 0; y_tile < 24; y_tile++) {
		for(x_tile = 0; x_tile < 32; x_tile++) {
			if(board[x_tile+(y_tile*32)] != 0) {
				if(board[x_tile+(y_tile*32)] == 1) {
					for(y = 0; y < 8; y++) {
						for (x = 0; x < 8; x++) {
							if(bpTop[x+y*8] != 0) {
								VRAM_A[((x_tile*8+x))+((y_tile*8+y)*(32*8))] = BG_PALETTE[bpTop[x+y*8]];
							}							
						}
					}
				}
				if(board[x_tile+(y_tile*32)] == 2) {
					for(y = 0; y < 8; y++) {
						for (x = 0; x < 8; x++) {
							if(bpRight[x+y*8] != 0) {
								VRAM_A[((x_tile*8+x))+((y_tile*8+y)*(32*8))] = BG_PALETTE[bpRight[x+y*8]];
							}							
						}
					}
				}
				if(board[x_tile+(y_tile*32)] == 3) {
					for(y = 0; y < 8; y++) {
						for (x = 0; x < 8; x++) {
							if(bpBottom[x+y*8] != 0) {
								VRAM_A[((x_tile*8+x))+((y_tile*8+y)*(32*8))] = BG_PALETTE[bpBottom[x+y*8]];
							}							
						}
					}
				}
				if(board[x_tile+(y_tile*32)] == 4) {
					for(y = 0; y < 8; y++) {
						for (x = 0; x < 8; x++) {
							if(bpLeft[x+y*8] != 0) {
								VRAM_A[((x_tile*8+x))+((y_tile*8+y)*(32*8))] = BG_PALETTE[bpLeft[x+y*8]];
							}							
						}
					}
				}
				if(board[x_tile+(y_tile*32)] == 5) {
					for(y = 0; y < 8; y++) {
						for (x = 0; x < 8; x++) {
							if(bpPin[x+y*8] != 0) {
								VRAM_A[((x_tile*8+x))+((y_tile*8+y)*(32*8))] = BG_PALETTE[bpPin[x+y*8]];
							}							
						}
					}
				}
				if(board[x_tile+(y_tile*32)] == 6) {
					for(y = 0; y < 8; y++) {
						for (x = 0; x < 8; x++) {
							if(bpcNW[x+y*8] != 0) {
								VRAM_A[((x_tile*8+x))+((y_tile*8+y)*(32*8))] = BG_PALETTE[bpcNW[x+y*8]];
							}							
						}
					}
				}
				if(board[x_tile+(y_tile*32)] == 7) {
					for(y = 0; y < 8; y++) {
						for (x = 0; x < 8; x++) {
							if(bpcNE[x+y*8] != 0) {
								VRAM_A[((x_tile*8+x))+((y_tile*8+y)*(32*8))] = BG_PALETTE[bpcNE[x+y*8]];
							}							
						}
					}
				}
				if(board[x_tile+(y_tile*32)] == 8) {
					for(y = 0; y < 8; y++) {
						for (x = 0; x < 8; x++) {
							if(bpcSW[x+y*8] != 0) {
								VRAM_A[((x_tile*8+x))+((y_tile*8+y)*(32*8))] = BG_PALETTE[bpcSW[x+y*8]];
							}							
						}
					}
				}
				if(board[x_tile+(y_tile*32)] == 9) {
					for(y = 0; y < 8; y++) {
						for (x = 0; x < 8; x++) {
							if(bpcSE[x+y*8] != 0) {
								VRAM_A[((x_tile*8+x))+((y_tile*8+y)*(32*8))] = BG_PALETTE[bpcSE[x+y*8]];
							}							
						}
					}
				}
			}
		}
	}

	// draw the beads
	for(y_tile = 0; y_tile < 24; y_tile++) {
		for(x_tile = 0; x_tile < 32; x_tile++) {
			if(beads[x_tile+(y_tile*32)] != 0) {
				for(y = 0; y < 8; y++) {
					for (x = 0; x < 8; x++) {
						if(bead[x+y*8] != 0) {
							VRAM_A[((x_tile*8+x))+((y_tile*8+y)*(32*8))] = BG_PALETTE[beads[x_tile+(y_tile*32)]];
						}							
					}
				}
			}
		}
	}

	while(1) {
		swiWaitForVBlank();
	}
 
	return 0;
}
Thanks for your time and effort, not only in this thread but overall in the community.

With high expectations,
fcg

[Edit] Changed some question, adjusted post to 8x8 tiles instead of 6x6 ones - that comes later

[1] I'll leave the question here anyway, as I think this is a good start to keep a record of my doings
[2] This is probably an understatement, but since I'm new to these boards I don't really have a feel for the value of 'some' :lol:
Attachments
Pantallazo.png
console-version-8x8-tiles-sort-of
(1.84 KiB) Not downloaded yet
Last edited by fcg on Wed Dec 01, 2010 11:21 pm, edited 1 time in total.

relminator
Posts: 84
Joined: Sun Apr 11, 2010 10:43 am

Re: [newbie] Have idea planned out, is it workable?

Post by relminator » Tue Nov 30, 2010 12:49 am

Well, here's what I did:

1. Tried it pixel by pixel http://rel.betterwebber.com/junk.php?id=98 . Found out it it was too slow, so...
2. Messed with the OAM http://rel.betterwebber.com/junk.php?id=105 . Found out it's cumbersome to use and has a 128 sprite limit so...
3. Used the 3D core to draw 2D stuff http://devkitpro.org/viewtopic.php?f=25&t=2333 . Found out it was fast, easier to use, d can do more than what the OAM can, and it is used by almost all the commercial games I like. So this is what I use now.

That said, since your tiles and sprites are non-power of 2, you would want to really use the 3D engine. I would only limit my OAM use to the bottom screen for menus and such.

User avatar
PypeBros
Posts: 40
Joined: Thu Nov 25, 2010 12:00 pm
Location: In a galaxy far, far away
Contact:

Re: [newbie] Have idea planned out, is it workable?

Post by PypeBros » Tue Nov 30, 2010 10:23 am

Unless I haven't fully understood your constraints, it looks like a regular tiled background, but scaled so that a 8x8 tile occupy 6x6 pixels could have worked as well.
NDS is the neatest piece of hardware since the C=64! Thanks for making it programmable ^_^

zeromus
Posts: 212
Joined: Wed Mar 31, 2010 6:05 pm

Re: [newbie] Have idea planned out, is it workable?

Post by zeromus » Tue Nov 30, 2010 10:12 pm

thats clever. id like to see that done.

fcg
Posts: 16
Joined: Wed Nov 24, 2010 10:51 pm

Re: [newbie] Have idea planned out, is it workable?

Post by fcg » Wed Dec 01, 2010 9:44 pm

Thanks for your replies.
relminator wrote:Well, here's what I did:

1. Tried it pixel by pixel http://rel.betterwebber.com/junk.php?id=98 . Found out it it was too slow, so...
2. Messed with the OAM http://rel.betterwebber.com/junk.php?id=105 . Found out it's cumbersome to use and has a 128 sprite limit so...
3. Used the 3D core to draw 2D stuff http://devkitpro.org/viewtopic.php?f=25&t=2333 . Found out it was fast, easier to use, d can do more than what the OAM can, and it is used by almost all the commercial games I like. So this is what I use now.

That said, since your tiles and sprites are non-power of 2, you would want to really use the 3D engine. I would only limit my OAM use to the bottom screen for menus and such.
In the end I will probably go this route, unfortunately I like to really understand what I am doing so I will most likely go the OAM-route first - but redrawing my sprites in 8x8 (one small step at the time...).
PypeBros wrote:Unless I haven't fully understood your constraints, it looks like a regular tiled background, but scaled so that a 8x8 tile occupy 6x6 pixels could have worked as well.
You got it right, I think, and I'll reply almost like I did to relminator: thanks for your thoughts, but atm I think I will instead redraw my sprites to 8x8, later on I might either scale things down or use the 3D engine.

First post will be updated soon.

Thankfully,
fcg

WinterMute
Site Admin
Posts: 1845
Joined: Tue Aug 09, 2005 3:21 am
Location: UK
Contact:

Re: [newbie] Have idea planned out, is it workable?

Post by WinterMute » Mon Dec 06, 2010 12:30 pm

The scaling engine operates by nearest neighbour so it ends up looking absolutely horrible if you use non power of two. I tried this a while ago when I was helping someone to port a game which used 12x12 tiles - scaling down from 16x16 looked awful and we ended up using 24x24 tiles composed of the native 8x8 tiles.

The best method here is, as relminator says, using the 3d engine.
Help keep devkitPro toolchains free, Donate today

Personal Blog

Jordan_Gray
Posts: 23
Joined: Sat Jun 12, 2010 3:31 am

Re: [newbie] Have idea planned out, is it workable?

Post by Jordan_Gray » Mon Dec 06, 2010 11:35 pm

This game looks pretty cool. Have you got the graphics for it yet?

zeromus
Posts: 212
Joined: Wed Mar 31, 2010 6:05 pm

Re: [newbie] Have idea planned out, is it workable?

Post by zeromus » Tue Dec 07, 2010 5:45 am

WinterMute wrote:The scaling engine operates by nearest neighbour so it ends up looking absolutely horrible if you use non power of two. I tried this a while ago when I was helping someone to port a game which used 12x12 tiles - scaling down from 16x16 looked awful and we ended up using 24x24 tiles composed of the native 8x8 tiles.
Here is a demo of it: http://dl.dropbox.com/u/4260750/temp/8x ... ne_6x6.zip

relminator
Posts: 84
Joined: Sun Apr 11, 2010 10:43 am

Re: [newbie] Have idea planned out, is it workable?

Post by relminator » Tue Dec 07, 2010 7:44 am

fcg: I couldn't resist converting your code to use the 3D engine.

You declared beads as *u8 so I had to use 256 colors for the bead sprite. Also I had to "waste" pal memory to make it behave like your rendering system. You might want to look at Grit and make your tiles from an actual tile editing software. I used 16 colors for each of the 5 palettes (when 1 color would suffice) because the 3d engine can't do single color palettes.

Needed library could be found here:
http://devkitpro.org/viewtopic.php?f=25&t=2333

Code: Select all

#include <nds.h>
#include "gl2d.h"



    /* This is the "bead"-tile
       - they are put on the "board"
       - they are refered to in the "beads" array
       - the values mean:
          0 = no color
          1 = color taken from the value in the "beads" array
    */
    u8 bead[64] = {
       0,1,1,1,1,1,1,0,
       1,1,1,1,1,1,1,1,
       1,1,1,1,1,1,1,1,
       1,1,1,0,0,1,1,1,
       1,1,1,0,0,1,1,1,
       1,1,1,1,1,1,1,1,
       1,1,1,1,1,1,1,1,
       0,1,1,1,1,1,1,0
    };

    /* These are the beads, they take up 32*24 tiles = 768 tiles in total
       (notice the border of emptiness!)

       Bead codes:
       0 = nothing
       X = color talen from palette
    */
    u8 beads_template[768] = {
       0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
       0,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,0,
       0,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,0,
       0,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,0,
       0,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,0,
       0,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,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3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,0,
       0,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,0,
       0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
    };
    u8 beads[768] = {
       0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
       0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
       0,0,0,0,3,3,3,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
       0,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,0,3,3,3,3,3,3,3,3,3,0,0,0,0,
       0,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,0,0,0,0,
       0,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,0,0,0,
       0,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,0,0,
       0,3,3,3,3,3,4,4,4,3,3,4,4,4,4,3,3,4,3,3,3,4,4,3,3,3,3,4,4,3,3,0,
       0,3,3,3,3,3,4,3,3,4,3,4,3,3,3,3,4,3,4,3,3,4,3,4,3,3,4,3,3,3,3,0,
       0,3,3,3,3,3,4,4,4,3,3,4,4,4,3,3,4,3,3,4,3,4,3,3,4,3,3,4,4,3,3,0,
       0,3,3,3,3,3,4,3,3,4,3,4,3,3,3,3,4,4,4,4,3,4,3,3,4,3,3,3,3,4,3,0,
       0,3,3,3,3,3,4,3,3,4,3,4,3,3,3,3,4,3,3,4,3,4,3,3,4,3,3,3,3,4,3,0,
       0,3,3,3,3,3,4,4,4,3,3,4,4,4,4,3,4,3,3,4,3,4,4,4,3,3,4,4,4,3,3,0,
       0,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,0,
       0,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,0,
       0,3,3,3,0,3,0,0,0,3,3,0,0,0,0,3,3,0,3,3,3,0,0,3,3,3,3,0,0,3,3,0,
       0,3,3,3,0,3,0,3,3,0,3,0,3,3,3,3,0,3,0,3,3,0,3,0,3,3,0,3,3,3,3,0,
       0,3,3,3,0,3,0,0,0,3,3,0,0,0,3,3,0,3,3,0,3,0,3,3,0,3,3,0,0,3,3,0,
       0,3,3,3,0,3,0,3,3,0,3,0,3,3,3,3,0,0,0,0,3,0,3,3,0,3,3,3,3,0,3,0,
       0,3,3,3,3,3,0,3,3,0,3,0,3,3,3,3,0,3,3,0,3,0,3,3,0,3,3,3,3,0,3,0,
       0,3,3,3,0,3,0,0,0,3,3,0,0,0,0,3,0,3,3,0,3,0,0,0,3,3,0,0,0,3,3,0,
       0,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,0,
       0,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,0,
       0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
    };


	glImage bead_image[1];
	
    //---------------------------------------------------------------------------------
    int main(void)
    {
       // pixel coordinates
       //int x;
       //int y;
       
       // tile coordinates
       // we have 32 * 24 tiles of the size 8*8 pixels.
       int x_tile;
       int y_tile;
       
       //initialize the DS Dos-like functionality
       consoleDemoInit();

       //set frame buffer mode 0
       //videoSetMode(MODE_FB0);

		videoSetMode( MODE_5_3D );
   
    // Set up enough texture memory for our textures
	// Bank A is 128kb. (enough for our needs)
	// since the sprite we're using is just
	// 2 kb 
	vramSetBankA( VRAM_A_TEXTURE );     
    
	
	// Initialize GL2D
    glScreen2D();
   
	
	// load our single image
	// sprite.
	// Note that glLoadTileset can also 
	// load single images.
	glLoadTileSet( bead_image,			// pointer to glImage array
				   8,				// sprite width
				   8,				// sprite height
				   8,				// bitmap image width
				   8,				// bitmap image height
				   GL_RGB256,		// texture type for glTexImage2D() in videoGL.h 16 colors
				   TEXTURE_SIZE_8,	// sizeX for glTexImage2D() in videoGL.h
				   TEXTURE_SIZE_8,	// sizeY for glTexImage2D() in videoGL.h
									// Set texture params setting color 0 as transparent
				   GL_TEXTURE_WRAP_S|GL_TEXTURE_WRAP_T|TEXGEN_OFF|GL_TEXTURE_COLOR0_TRANSPARENT,
				   (u8*)bead // image data generated by GRIT
				 );


	// very wastefull way to set up the palette
	// You might want to use up all the 16 colors of each
	// pal entry
	// actually these pal should be 256 colors but
	// it pains me to see waste vram when 1 color could work.
	// I made it this way to accomodate your style

	unsigned short *Pal0 = malloc( 16 * sizeof(unsigned short) );
	unsigned short *Pal1 = malloc( 16 * sizeof(unsigned short) );
	unsigned short *Pal2 = malloc( 16 * sizeof(unsigned short) );
	unsigned short *Pal3 = malloc( 16 * sizeof(unsigned short) );
	unsigned short *Pal4 = malloc( 16 * sizeof(unsigned short) );
	
	int i;
	for( i = 0; i < 16; i++ )
	{
		Pal0[i] = RGB15(0,0,31);
		Pal1[i] = RGB15(4,4,0);
		Pal2[i] = RGB15(27,27,19);
		Pal3[i] = RGB15(31,0,0);
		Pal4[i] = RGB15(0,31,0);
	}
	
	//load our palette
	//Pal[0] = RGB15(0,0,31);      // Debug
	//Pal[1] = RGB15(4,4,0);       // Background
	//Pal[2] = RGB15(27,27,19);    // Border % pins
	//Pal[3] = RGB15(31,0,0);      // Red
	//Pal[4] = RGB15(0,31,0);      // Green

	
	// Load the palette
	// shuttlePal, shuttlePalLen are found in a GRIT generated header
	int Pal[5];
	Pal[0] = gluTexLoadPal( Pal0, 32, GL_RGB16 );
	Pal[1] = gluTexLoadPal( Pal1, 32, GL_RGB16 );
	Pal[2] = gluTexLoadPal( Pal2, 32, GL_RGB16 );
	Pal[3] = gluTexLoadPal( Pal3, 32, GL_RGB16 );
	Pal[4] = gluTexLoadPal( Pal4, 32, GL_RGB16 );

	free( Pal0 );
	free( Pal1 );
	free( Pal2 );
	free( Pal3 );
	free( Pal4 );


	   glBegin2D();
		  	
		
       // draw the beads
       for(y_tile = 0; y_tile < 24; y_tile++) {
          for(x_tile = 0; x_tile < 32; x_tile++) {
             if(beads[x_tile+(y_tile*32)] != 0) {
				
				
				glColorTable( GL_RGB16, Pal[beads[x_tile+(y_tile*32)]] );
				
				glSprite( x_tile*8, y_tile*8,  GL_FLIP_NONE, bead_image );
	         }
          }
       }
		
		
		// end 2D rendering mode
        glEnd2D();
   
        glFlush(0);                    
        
       while(1) {
		  
          swiWaitForVBlank();
       }

       return 0;
    }
	
	
	
	
	


fcg
Posts: 16
Joined: Wed Nov 24, 2010 10:51 pm

Re: [newbie] Have idea planned out, is it workable?

Post by fcg » Wed Dec 08, 2010 5:37 pm

zeromus wrote:
WinterMute wrote:The scaling engine operates by nearest neighbour so it ends up looking absolutely horrible if you use non power of two. I tried this a while ago when I was helping someone to port a game which used 12x12 tiles - scaling down from 16x16 looked awful and we ended up using 24x24 tiles composed of the native 8x8 tiles.
Here is a demo of it: http://dl.dropbox.com/u/4260750/temp/8x ... ne_6x6.zip
Thanks, and as Wintermute already said: it looks awful ;)

Anyway, it contains some bits of information that will move me forward.
relminator wrote:fcg: I couldn't resist converting your code to use the 3D engine.

You declared beads as *u8 so I had to use 256 colors for the bead sprite. Also I had to "waste" pal memory to make it behave like your rendering system. You might want to look at Grit and make your tiles from an actual tile editing software. I used 16 colors for each of the 5 palettes (when 1 color would suffice) because the 3d engine can't do single color palettes.
Hehe, temptations, temptations...

Well, I like how you assume that I have any idea of what I'm doing, thanks. For future reference: it is completely safe to rewrite my code in a way that is better.

Unfortunately your code doesn't compile on my system, arm-eabi-g++ chokes on lines 143-147:

Code: Select all

unsigned short *Pal0 = malloc( 16 * sizeof(unsigned short) );
unsigned short *Pal1 = malloc( 16 * sizeof(unsigned short) );
unsigned short *Pal2 = malloc( 16 * sizeof(unsigned short) );
unsigned short *Pal3 = malloc( 16 * sizeof(unsigned short) );
unsigned short *Pal4 = malloc( 16 * sizeof(unsigned short) );
Complaining about:

Code: Select all

..xx../main.cpp:143:60: error: invalid conversion from 'void*' to 'short unsigned int*'
..xx../main.cpp:144:60: error: invalid conversion from 'void*' to 'short unsigned int*'
..xx../main.cpp:145:60: error: invalid conversion from 'void*' to 'short unsigned int*'
..xx../main.cpp:146:60: error: invalid conversion from 'void*' to 'short unsigned int*'
..xx../main.cpp:147:60: error: invalid conversion from 'void*' to 'short unsigned int*'
It probably is an easy fix, for c-enabled minds, but not for me.

/fcg

Post Reply

Who is online

Users browsing this forum: Google [Bot] and 12 guests