3D on both screen + console print + indexed texture

Post Reply
panini21
Posts: 3
Joined: Wed Aug 04, 2010 3:28 pm

3D on both screen + console print + indexed texture

Post by panini21 » Wed Aug 04, 2010 4:10 pm

Hi, i'm working on a project on nds and i have a problem with the print console.

actualy, i use 3D on the 2 screen and use indexed texture for rendering.
But, I notice that i can't use the print console when i use indexed texture...

according to : devkitPro\examples\nds\Graphics\3D\Mixed_Text_3D\source\main.cpp

here is parts of my code :


-> initialisation code

Code: Select all

        ...
	glInit();

	// Setup screen for 3D
	videoSetMode(MODE_0_3D);
	videoSetModeSub(MODE_5_2D);
	
        //set up some memory for textures
	vramSetBankA(VRAM_A_TEXTURE);
	vramSetBankB(VRAM_B_TEXTURE);


        vramSetBankE(VRAM_E_MAIN_BG);
	//vramSetBankF(VRAM_F_TEX_PALETTE);
	console = consoleInit(0, 1, BgType_Text4bpp, BgSize_T_256x256, 31,0, true, true);

	bgSetPriority(0, 1);


	// sub sprites hold the bottom image when 3D directed to top
        initSubSprites(); // see devkitPro\examples\nds\Graphics\3D\Mixed_Text_3D\source\main.cpp for this fonction
 
        // sub background holds the top image when 3D directed to bottom
        bgInitSub(3, BgType_Bmp16, BgSize_B16_256x256, 0, 0);

	glEnable( GL_TEXTURE_2D | GL_BLEND | GL_ANTIALIAS | POLY_FORMAT_LIGHT0 | POLY_FORMAT_LIGHT1);

-> some printing fonctions:

Code: Select all

static inline void DBG( int posX, int posY, const char* text)
{
#if DEBUG
	char localStrBuf[100];
	snprintf(localStrBuf, 100, "%s%d%s%d%s%s\n", "\x1b[", posY,";", posX,"H ",text);
	printf(localStrBuf);
#endif
}

static inline void DBGi( const char* text) 
{
#if DEBUG
	iprintf("%s\n", text);
#endif
}

-> texture manager code for indexed texture:

Code: Select all

CTextureIndexed::CTextureIndexed(const u16 widthSize, 
	const u16 heightSize, const u8* imgData, 
	const int pal_ID, const int pal_Number,
	const GL_TEXTURE_TYPE_ENUM format,
	bool randomTransparence)
		: CTexture( widthSize, heightSize, format)//, m_image(0)
{
        ...
	glBindTexture(0, m_textureID);
	glTexImage2D(0, 0, m_texFormat, getTexSize(m_width), getTexSize(m_height), 0, TEXGEN_TEXCOORD| GL_TEXTURE_WRAP_S | GL_TEXTURE_WRAP_T, imgData);

	m_pal_addr = new uint32[pal_Number];
	for (int i=0;i<pal_Number; ++i)
	{
		u16* palData = (u16*)paletteList[pal_ID+i];
		m_pal_addr[i] = gluTexLoadPal( palData, getPalSize(m_texFormat), m_texFormat );
	}
}

Well, I notice that if i comment

Code: Select all

             m_pal_addr[i] = gluTexLoadPal( palData, getPalSize(m_texFormat), m_texFormat );
the console print normaly, but no texture render correctly, of course.

And, i try to uncomment

Code: Select all

	//vramSetBankF(VRAM_F_TEX_PALETTE);
because i think that gluTexLoadPal() "clear the console memory", or something like that... but in this case, the texture is not rendered, and the console print not too.

any sugestion? help welcome ^^

elhobbs
Posts: 358
Joined: Thu Jul 02, 2009 1:19 pm

Re: 3D on both screen + console print + indexed texture

Post by elhobbs » Wed Aug 04, 2010 6:22 pm

you cannot use VRAM_E for the main background without using custom palette loading code to load to VRAM_F. libnds is hardcoded to use VRAM_E for palettes.

panini21
Posts: 3
Joined: Wed Aug 04, 2010 3:28 pm

Re: 3D on both screen + console print + indexed texture

Post by panini21 » Wed Aug 04, 2010 8:25 pm

hi elhobbs, thanks for kelp

I understand that :

VRAM_E is "reserved", and reserved for what i need (palettes) so i better have to don't touch it. So, my first idea was to change the initialisation code:

Code: Select all

   vramSetBankE(VRAM_E_MAIN_BG);
   //vramSetBankF(VRAM_F_TEX_PALETTE);
   console = consoleInit(0, 1, BgType_Text4bpp, BgSize_T_256x256, 31,0, true, true);
to :

Code: Select all

   vramSetBankF(VRAM_F_MAIN_BG);
   console = consoleInit(0, 1, BgType_Text4bpp, BgSize_T_256x256, 31,0, true, true);
in order to set MAIN_BG into VRAM_F (vramSetBankF(VRAM_F_MAIN_BG)). -> indexed textures are OK but the console text still not appear.

my second idea was to load a custum font (and also costum pallette) for the print console to clear the problem : it's like i use the costum font as one of the texture i already use, according to :
devkitPro\examples\nds\Graphics\Printing\custom_font\source\main.cpp
Unfortunately, FreeImage.dll (...) is missing at compilation. working on it.

thx to tell me if i'm in a wrong way.

elhobbs
Posts: 358
Joined: Thu Jul 02, 2009 1:19 pm

Re: 3D on both screen + console print + indexed texture

Post by elhobbs » Thu Aug 05, 2010 5:00 pm

VRAM_F should work as main background but it is only 16k. so you will need to adjust the map from 31 to 7

Code: Select all

vramSetBankF(VRAM_F_MAIN_BG);
console = consoleInit(0, 1, BgType_Text4bpp, BgSize_T_256x256, 7,0, true, true);
you may also have a priority issue as well - set the text on top of the 3D display

Code: Select all

bgSetPriority(0,1);
bgSetPriority(1,0);

panini21
Posts: 3
Joined: Wed Aug 04, 2010 3:28 pm

Re: 3D on both screen + console print + indexed texture

Post by panini21 » Fri Aug 06, 2010 1:17 pm

that's it!
thx you elhobbs for your help!
I spend so many time with this... maybe i sould pay more attention to the DS memory management, the real difficulty of the DS, anyway...
thx

Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 0 guests