loading textured models from fat?

Support for the GBA/DS/Gamecube/Wii media card library
Post Reply
t377y000
Posts: 52
Joined: Wed Jun 02, 2010 3:14 am
Location: United States

loading textured models from fat?

Post by t377y000 » Sat May 19, 2012 12:53 am

hi can anyone could help me with loading models & textures using libfat on DS?

then i compile it seems to just freeze when i try to load a model with texture.

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

Re: loading modeled textures from fat?

Post by elhobbs » Sat May 19, 2012 2:32 am

you need to provide some information if you want people to help you. what have you tried? do you have source code that people could look at?

t377y000
Posts: 52
Joined: Wed Jun 02, 2010 3:14 am
Location: United States

Re: loading modeled textures from fat?

Post by t377y000 » Sat May 19, 2012 2:59 am

elhobbs wrote:you need to provide some information if you want people to help you. what have you tried? do you have source code that people could look at?
heres the source code if you would like to take look at.
im useing the method from "C:\devkitPro\examples\nds\Graphics\Backgrounds\all_in_one"
as a basic menu to select the selection then run the code.

i have the files (models & textures) converted to bin format in a folder called FAT DATA.

Code: Select all

#include <nds.h>

#include <fat.h>
#include <string.h>
#include <dirent.h>

#include <stdio.h>
#include <stdlib.h>
#include <dswifi9.h>
#include <maxmod9.h>
#include "soundbank.h"
#include "soundbank_bin.h"

//objects
int bcartex64_texid;

int cratetex64_texid;
int cratemetaltex64_texid;
int cratet3tex64_texid;
//solo

void map0(void) //test [model viewer]
{
	//camera
	int rx = 0, ry = 0;
	int oldx = 0, oldy = 0;
	int p1xpos = -20, p1ypos =  -0;
	
	//models
	int modelnum = 0;

	touchPosition touchXY;
	videoSetMode(MODE_0_3D);
	
	//initialize the geometry engine
	glInit();
	//enable antialiasing
	glEnable(GL_ANTIALIAS);
	glClearColor(0,128,128,31); glClearPolyID(63); glClearDepth(0x7FFF);
	// Set our viewport to be the same size as the screen
	glViewport(0,0,255,191);
	
	{//textures
	vramSetBankA(VRAM_A_TEXTURE);
	glEnable(GL_TEXTURE_2D);
	//crate texture
	glGenTextures( 1, &cratetex64_texid ); glBindTexture( 0, cratetex64_texid );
	glTexImage2D(0, 0, GL_RGB, TEXTURE_SIZE_64, TEXTURE_SIZE_64, 0, TEXGEN_TEXCOORD, "cratetex64.bin");	
	//crate metal texture
	glGenTextures( 1, &cratemetaltex64_texid ); glBindTexture( 0, cratemetaltex64_texid );
	glTexImage2D(0, 0, GL_RGB, TEXTURE_SIZE_64, TEXTURE_SIZE_64, 0, TEXGEN_TEXCOORD, "cratemetaltex64.bin");
	//crate t3 texture
	glGenTextures( 1, &cratet3tex64_texid ); glBindTexture( 0, cratet3tex64_texid );
	glTexImage2D(0, 0, GL_RGB, TEXTURE_SIZE_64, TEXTURE_SIZE_64, 0, TEXGEN_TEXCOORD, "cratet3tex64.bin");
	//crate t3 texture
	glGenTextures( 1, &bcartex64_texid ); glBindTexture( 0, bcartex64_texid );
	glTexImage2D(0, 0, GL_RGB, TEXTURE_SIZE_64, TEXTURE_SIZE_64, 0, TEXGEN_TEXCOORD, "bcartex64.bin");
	}
	
	{//bottom screen stuff
	videoSetModeSub(MODE_0_2D);
	PrintConsole bottomScreen;
	vramSetBankC(VRAM_C_SUB_BG);
	consoleInit(&bottomScreen, 0,BgType_Text4bpp, BgSize_T_256x256, 31, 0, false, true);
	iprintf("T3-Games-Zero [Model view]");
	printf("\x1b[3;1HPress D-Pad> Movement.");
	printf("\x1b[4;1HTouch> Rotate");	
	
	//main loop
	while (1) {		
		scanKeys(); touchRead(&touchXY);
		int held = keysHeld(), pressed = keysDown();
	
		{//insert to move camera around here
		if(held & KEY_RIGHT && p1ypos > -10)p1ypos -=1;
		if(held & KEY_LEFT && p1ypos < 10)p1ypos +=1;
		if(held & KEY_DOWN && p1xpos > -35)p1xpos -=1;
		if(held & KEY_UP && p1xpos <-5)p1xpos +=1;}
		
		printf("\x1b[5;2HPress L/R> Change Model %d - 1", modelnum);
		{//model change
		if(pressed & KEY_L && modelnum > 0) modelnum -=1;
		if(pressed & KEY_R && modelnum < 2)modelnum +=1;}

		//reset x and y when user touches screen
		if(pressed & KEY_TOUCH){oldx = touchXY.px; oldy = touchXY.py;}

		//if user drags then grab the delta
		if(held & KEY_TOUCH){
			rx += touchXY.px - oldx; oldx = touchXY.px;
			ry += touchXY.py - oldy; oldy = touchXY.py;}
			
		//handle camera
		glMatrixMode(GL_PROJECTION);
		glLoadIdentity();
			gluPerspective(70, 256.0 / 192.0, 0.1, 175);
			glPolyFmt(POLY_ALPHA(31)| POLY_CULL_NONE );
			glMaterialShinyness ();
			
		{//lighting
		glLight(0, RGB15(31,31,31), 0, floattov10(-1.0) , 0);
		glLight(1, RGB15(31,0,31) ,  0,floattov10(1) - 1, 0);
		glLight(2, RGB15(0,31,0)  ,  floattov10(-1.0), 0, 0);
		glLight(3, RGB15(0,0,31)  , floattov10(1.0) - 1,0,0);}
		
		glMatrixMode(GL_MODELVIEW);
		glLoadIdentity();
		
		glTranslatef(0,0,-10);  
		glTranslatef(p1ypos,0,p1xpos); glRotateY(rx);glRotateX(ry);
		
		printf("\x1b[9;5HtestRX:%d    ", rx);
		printf("\x1b[10;6HtestRY:%d    ", ry);
		printf("\x1b[11;7HtestPX:%d   ", touchXY.px);
		printf("\x1b[12;8HtestPY:%d   ", touchXY.px);
		
		if(modelnum == 0){//nothing					
		printf("\x1b[6;2HNothing");
			}//nothing
		
		if(modelnum == 1){//crates			
		//crate		
		printf("\x1b[6;2HCrates     ");
			glPushMatrix();
			glMatrixMode(GL_TEXTURE);
			glLoadIdentity();
			glMatrixMode(GL_MODELVIEW);			
			glPolyFmt(POLY_ALPHA(31) | POLY_CULL_BACK | POLY_FORMAT_LIGHT0 | POLY_FORMAT_LIGHT1 | POLY_FORMAT_LIGHT2 | POLY_FORMAT_LIGHT3 ) ;
			glMaterialf(GL_AMBIENT, RGB15(8,8,8)); 
                        glMaterialf(GL_DIFFUSE, RGB15(16,16,16));
			glMaterialf(GL_SPECULAR, BIT(15) | RGB15(8,8,8));
                        glMaterialf(GL_EMISSION, RGB15(5,5,5));
			glTranslatef(0,0,0); 
			glScalef32(10000,10000,10000);
			glBindTexture( 0, cratetex64_texid );
			glCallList((u32*)"crate64.bin");
			glPopMatrix(1);
			
		//crate	metal
			glPushMatrix();
			glMatrixMode(GL_TEXTURE);
			glLoadIdentity();
			glMatrixMode(GL_MODELVIEW);
			glPolyFmt(POLY_ALPHA(31) | POLY_CULL_BACK | POLY_FORMAT_LIGHT0 | POLY_FORMAT_LIGHT1 | POLY_FORMAT_LIGHT2 | POLY_FORMAT_LIGHT3 ) ;
			glMaterialf(GL_AMBIENT, RGB15(8,8,8));
			glMaterialf(GL_DIFFUSE, RGB15(16,16,16));
			glMaterialf(GL_SPECULAR, BIT(15) | RGB15(8,8,8));
			glMaterialf(GL_EMISSION, RGB15(5,5,5));
			glTranslatef(10,0,-10); //glRotateX(ry); glRotateY(rx);
			glScalef32(10000,10000,10000);
			glBindTexture( 0, cratemetaltex64_texid );
			glCallList((u32*)"crate64.bin");
			glPopMatrix(1);	
			
		//crate	t3
			glPushMatrix();
			glMatrixMode(GL_TEXTURE);
			glLoadIdentity();
			glMatrixMode(GL_MODELVIEW);
			glPolyFmt(POLY_ALPHA(31) | POLY_CULL_BACK | POLY_FORMAT_LIGHT0 | POLY_FORMAT_LIGHT1 | POLY_FORMAT_LIGHT2 | POLY_FORMAT_LIGHT3 ) ;
			glMaterialf(GL_AMBIENT, RGB15(8,8,8));
			glMaterialf(GL_DIFFUSE, RGB15(16,16,16));
			glMaterialf(GL_SPECULAR, BIT(15) | RGB15(8,8,8));
			glMaterialf(GL_EMISSION, RGB15(5,5,5));
			glTranslatef(-10,0,-10); //glRotateX(ry); glRotateY(rx);
			glScalef32(10000,10000,10000);
			glBindTexture( 0, cratet3tex64_texid );
			glCallList((u32*)"crate64.bin");
			glPopMatrix(1);		
			}//crates
			
		if(modelnum == 2){//car					
		printf("\x1b[6;2HCar     ");
			glPushMatrix();
			glMatrixMode(GL_TEXTURE);
			glLoadIdentity();
			glMatrixMode(GL_MODELVIEW);
			glPolyFmt(POLY_ALPHA(31) | POLY_CULL_NONE | POLY_FORMAT_LIGHT0 | POLY_FORMAT_LIGHT1 | POLY_FORMAT_LIGHT2 | POLY_FORMAT_LIGHT3 ) ;
			glMaterialf(GL_AMBIENT, RGB15(8,8,8));
			glMaterialf(GL_DIFFUSE, RGB15(16,16,16));
			glMaterialf(GL_SPECULAR, BIT(15) | RGB15(8,8,8));
			glMaterialf(GL_EMISSION, RGB15(5,5,5));
			glTranslatef(0,0,0); 
			glScalef32(10000,10000,10000);
			glBindTexture( 0, bcartex64_texid );
			glCallList((u32*)"bcar64.bin");
			glPopMatrix(1);
			}//car
					
		swiWaitForVBlank();

		// flush to the screen
		glFlush(0);
	}
}

t377y000
Posts: 52
Joined: Wed Jun 02, 2010 3:14 am
Location: United States

Re: loading textured models from fat?

Post by t377y000 » Wed Nov 07, 2012 10:40 pm

bump bump

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

Re: loading textured models from fat?

Post by elhobbs » Thu Nov 08, 2012 12:35 am

glTexImage2D and glCallList do not take filenames as parameters. where you are specifying filenames they are actually looking for buffers where the data representing the object have been loaded. look at the libfat examples for how to read data from files. of course this assumes that the data in the files you are referencing are already in the expected ds specific formats.

t377y000
Posts: 52
Joined: Wed Jun 02, 2010 3:14 am
Location: United States

Re: loading textured models from fat?

Post by t377y000 » Sat Nov 09, 2013 8:54 pm

the models are converted .bin, & the textures im useing are .pcx.

t377y000
Posts: 52
Joined: Wed Jun 02, 2010 3:14 am
Location: United States

Re: loading textured models from fat?

Post by t377y000 » Fri Dec 06, 2013 7:13 am

what about nitrofs? examples>nds>filesystem>nitrodir

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

Re: loading textured models from fat?

Post by elhobbs » Fri Dec 06, 2013 1:54 pm

what about nitrofs? are you asking if it can be used or suggesting a solution?

the fat and nitrofs examples show to to read data from disk. Is your question "how do I read from disk?" or is it "how do I parse the data in my files"? the first question is answered by the samples. the second question requires more information about how the model was created and what format it is saved in. there are libnds functions for using pcx files for ds textures - look at the examples.

not to be intentionally cruel but it has been over a year since your original post. either you are putting in 0 effort on your part, or you may have no aptitude for the task at hand. you may want to consider taking a basic level C programming course or try programming for a pc instead. there are easier development tools and tutorials/examples for the pc.

Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests