I already pointed out your main problem and wintermute went one step further and showed you the code change. I suggest you read up on the return value for fread - it is not a pointer to data - which is what glCallList is expecting. the first parameter to fread is the memory address where the data is loaded (your variable named buffer). that is where your display list is - and it is the value you need to pass to glCallList. take another look at wintermute's response and it should make more since. the "-" and "+" at the start of the lines indicate code to remove and the code to replace it with.
now you probably have another issue as well as it appears that fread is failing (the return value should not be 0) are you calling fatInitDefault before trying to open and read files?
loading .bin models from nitrodir
-
- Site Admin
- Posts: 1986
- Joined: Tue Aug 09, 2005 3:21 am
- Location: UK
- Contact:
Re: loading .bin models from nitrodir
You really, really shouldn't be putting code in headers like that ...t377y000 wrote: heres a screencap.
The project archive you linked to still had the model loading in the loop which isn't a great idea. Somehow I doubt malloc & file io will do much for your frame rate in every display loop. Lack of error checking isn't really helping you track down your problem either.
I got your code to work in a couple of minutes but, to be fair, this stuff probably isn't the most obvious. I moved the teapot.bin into the nitrofs folder so it gets added to the filesystem rather than embedded in the binary, then added nitroFSInit(NULL); at the start of the code so the filesystem is initialised. I rearranged your code a bit to take the loading out of the display loop as well.
Code: Select all
#include <nds.h>
#include <filesystem.h>
#include <stdio.h>
//teapot display list provided by Mike260, as well as the display list gl code.
//#include "teapot_bin.h"
int main() {
float rotateX = 0.0;
float rotateY = 0.0;
//set mode 0, enable BG0 and set it to 3D
videoSetMode(MODE_0_3D);
nitroFSInit(NULL);
FILE *pFile; char * buffer; size_t dataInFile; long fileSize;
pFile = fopen("teapot.bin", "rb");
fseek(pFile, 0, SEEK_END);
fileSize = ftell(pFile);
rewind(pFile);
buffer = (char*)malloc(fileSize+1);
//buffer = (char*) malloc (sizeof(char)*fileSize);
dataInFile = fread(buffer, 1, fileSize, pFile);
fclose (pFile);
// initialize gl
glInit();
// enable antialiasing
glEnable(GL_ANTIALIAS);
// setup the rear plane
glClearColor(0,0,0,31); // BG must be opaque for AA to work
glClearPolyID(63); // BG must have a unique polygon ID for AA to work
glClearDepth(0x7FFF);
//this should work the same as the normal gl call
glViewport(0,0,255,191);
//any floating point gl call is being converted to fixed prior to being implemented
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(70, 256.0 / 192.0, 0.1, 40);
gluLookAt( 0.0, 0.0, 3.5, //camera possition
0.0, 0.0, 0.0, //look at
0.0, 1.0, 0.0); //up
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);
//not a real gl function and will likely change
glPolyFmt(POLY_ALPHA(31) | POLY_CULL_BACK | POLY_FORMAT_LIGHT0 | POLY_FORMAT_LIGHT1 |
POLY_FORMAT_LIGHT2 | POLY_FORMAT_LIGHT3 ) ;
while(1)
{
glPushMatrix();
glRotateX(rotateX);
glRotateY(rotateY);
scanKeys();
u16 keys = keysHeld();
if(!(keys & KEY_UP)) rotateX += 3;
if(!(keys & KEY_DOWN)) rotateX -= 3;
if(!(keys & KEY_LEFT)) rotateY += 3;
if(!(keys & KEY_RIGHT)) rotateY -= 3;
glCallList((u32*)buffer);
fclose(pFile);
glPopMatrix(1);
glFlush(0);
}
free(buffer);
return 0;
}//end main
Re: loading .bin models from nitrodir
@wintermute: thanks that appears to work. o.O
sorry i noticed the teapot.bin wasn't in the folder after uploading it.
i wasn't sure how to replace the tile in that post tho? after a certain amount of time can't edit it.
"nitroFSInit(NULL);" was what i was missing it seems.
& i have very huge header files in my main project. i was planning on using this with multiple models & textures in headers for organization. would that be bad tho?
sorry i noticed the teapot.bin wasn't in the folder after uploading it.
i wasn't sure how to replace the tile in that post tho? after a certain amount of time can't edit it.
"nitroFSInit(NULL);" was what i was missing it seems.
& i have very huge header files in my main project. i was planning on using this with multiple models & textures in headers for organization. would that be bad tho?
Who is online
Users browsing this forum: No registered users and 2 guests