I'm currently just trying to get my sample project to display on my Dreamcast. The project mounts a Romdisk, loads in some MD2 files, and then draws the objects on the screen, allowing the user to provide input to move the camera around.
Everything works perfectly in NullDC and Demul. However, once I started trying it on real hardware, I started getting issues. The disc never really loads. It goes past the Dreamcast boot screen, the "SEGA" screen, and then I get a black screen. I've tried burning other sample projects, such as the PNG sample and the Lerabot01 GLdc sample, and both of those work perfectly, it's just my project that won't load.
I can't show all my code, because it's scattered between a ton of different files, but I've narrowed it down to loading the files. It's not the Romdisk, it's not OpenGL/GLdc, it's somewhere in my load functions. What I do is load in the MD2 file into memory, then convert that over to another generic "model" object I've created, and render that on the screen (this way I can create support for multiple model file types in the future, if I so choose, and draw from my generic model struct instead of having to write rendering algorithms for each type of file).
Before loading anything in, though, I first init OpenGL. During that, I set the screen to grey. I noticed if I comment out my loading functions, the screen will turn grey on the Dreamcast hardware. However, if I keep the loading functions, the screen will remain black and nothing will appear on the screen.
Please keep in mind I'm not going for optimization right now, I'm just trying to get this to work. I know my code is a nightmare.
Reading the MD2 file:
Code: Select all
void FileManager::ReadMD2(const char* path, model_t* m){
FILE* fp;
int i;
md2_model_t* mdl = (md2_model_t*)malloc(sizeof(md2_model_t));
printf("Opening file: %s\n", path);
fp = fopen(path,"rb");
if (!fp){
printf("Error: Couldn't open %s\n",path);
return;
}
fread(&mdl->header, 1, sizeof(md2_header_t), fp);
if ((mdl->header.ident != 844121161) || (mdl->header.version != 8)){
printf("Error: Bad version or identifier\n");
fclose(fp);
return;
}
mdl->skins = (md2_skin_t*) malloc(sizeof(md2_skin_t)*mdl->header.num_skins);
mdl->texcoords = (md2_texCoord_t*) malloc(sizeof(md2_texCoord_t)*mdl->header.num_st);
mdl->tris = (md2_triangle_t*) malloc(sizeof(md2_triangle_t)*mdl->header.num_tris);
mdl->frames = (md2_frame_t*) malloc(sizeof(md2_frame_t)*mdl->header.num_frames);
mdl->glcmds = (int*)malloc(sizeof(int)*mdl->header.num_glcmds);
fseek(fp, mdl->header.offset_skins, SEEK_SET);
fread (mdl->skins, sizeof(md2_skin_t), mdl->header.num_skins, fp);
fseek(fp, mdl->header.offset_st, SEEK_SET);
fread (mdl->texcoords,sizeof(md2_texCoord_t),mdl->header.num_st, fp);
fseek(fp, mdl->header.offset_tris,SEEK_SET);
fread(mdl->tris,sizeof(md2_triangle_t),mdl->header.num_tris,fp);
fseek(fp, mdl->header.offset_glcmds,SEEK_SET);
fread(mdl->glcmds, sizeof(int),mdl->header.num_glcmds,fp);
fseek(fp,mdl->header.offset_frames,SEEK_SET);
for(i=0;i<mdl->header.num_frames;i++){
mdl->frames[i].verts = (md2_vertex_t*)malloc(sizeof(md2_vertex_t) * mdl->header.num_vertices);
fread(&mdl->frames[i].scale,sizeof(Vector3f), 1, fp);
fread(&mdl->frames[i].translate,sizeof(Vector3f),1, fp);
fread(mdl->frames[i].name, sizeof(char),16, fp);
fread(mdl->frames[i].verts,sizeof(md2_vertex_t),mdl->header.num_vertices,fp);
}
fclose (fp);
fp = NULL;
ConvertMD2Data(m, mdl);
UnloadMD2(mdl);
}
Code: Select all
void FileManager::ConvertMD2Data(model_t* m, md2_model_t* mdl){
int i;
printf("Starting conversion\n");
md2_frame_t* tFrame = &mdl->frames[0];
m->num_verts = mdl->header.num_vertices;
m->num_uvs = mdl->header.num_st;
m->num_faces = mdl->header.num_tris;
m->verts = (Vector3f*) malloc (sizeof(Vector3f) * m->num_verts);
m->uvs = (uv_t*) malloc (sizeof(uv_t) * m->num_uvs);
m->faces = (face_t*) malloc (sizeof(face_t) * m->num_faces);
for (i = 0; i < m->num_verts; i++){
m->verts[i].x = (tFrame->scale.x * (float) tFrame->verts[i].v[0]) + tFrame->translate.x;
m->verts[i].y = (tFrame->scale.y * (float) tFrame->verts[i].v[1]) + tFrame->translate.y;
m->verts[i].z = (tFrame->scale.z * (float) tFrame->verts[i].v[2]) + tFrame->translate.z;
}
printf("Verts converted\n");
//free(tFrame->verts);
for (i = 0; i < m->num_uvs; i++){
m->uvs[i].u = (GLfloat) mdl->texcoords[i].s / (GLfloat) (mdl->header.skinwidth);
m->uvs[i].v = (GLfloat) mdl->texcoords[i].t / (GLfloat) (mdl->header.skinheight);
//printf("U: %f\n V: %f\n", m->uvs[i].u, m->uvs[i].v);
}
printf("UVs converted\n");
//free (mdl->texcoords);
for (i = 0; i < m->num_faces; i++){
m->faces[i].vertIndex[0] = mdl->tris[i].vertex[0];
m->faces[i].vertIndex[1] = mdl->tris[i].vertex[1];
m->faces[i].vertIndex[2] = mdl->tris[i].vertex[2];
m->faces[i].uvIndex[0] = mdl->tris[i].st[0];
m->faces[i].uvIndex[1] = mdl->tris[i].st[1];
m->faces[i].uvIndex[2] = mdl->tris[i].st[2];
}
printf("Faces converted\n");
m->material = (material_t*) malloc(sizeof(material_t));
m->material->filename = mdl->skins[0].name;
m->material->uOffset = 0.0f;
m->material->vOffset = 0.0f;
//if (m->material->filename)
//LoadBMP(m->material->filename,&m->material->texId);
}
Code: Select all
void FileManager::UnloadMD2(md2_model_t* mdl){
int i;
if (mdl->skins)
free(mdl->skins);
if (mdl->tris)
free(mdl->tris);
if (mdl->texcoords)
free(mdl->texcoords);
if (mdl->frames){
for (i=0;i<mdl->header.num_frames;i++)
if (mdl->frames[i].verts)
free(mdl->frames[i].verts);
free(mdl->frames);
}
if (mdl->glcmds)
free(mdl->glcmds);
if (mdl->indices)
free(mdl->indices);
if (mdl)
free(mdl);
}
Thanks!