void dataDump(FILE *file){ unsigned int nfaces = 0; fprintf(file,"v16 __%s_vertex[][3]={ {0,0,0},\n",modelname); while(vertex!=NULL){ max[0] = vertex->x > max[0] ? vertex->x : max[0]; max[1] = vertex->y > max[1] ? vertex->y : max[1]; max[2] = vertex->z > max[2] ? vertex->z : max[2]; min[0] = vertex->x < min[0] ? vertex->x : min[0]; min[1] = vertex->y < min[1] ? vertex->y : min[1]; min[2] = vertex->z < min[2] ? vertex->z : min[2]; fprintf(file," {%d,%d,%d}", floattov16(vertex->x*adjust ), floattov16(vertex->y*adjust ), floattov16(vertex->z*adjust ) ); vertex=vertex->next; if(vertex!=NULL) fprintf(file,",\n"); } fprintf(file,"};\n\n"); fprintf(file,"float __%s_max[3] = { %f, %f, %f };\n",modelname,max[0]*adjust,max[1]*adjust,max[2]*adjust); fprintf(file,"float __%s_min[3] = { %f, %f, %f };\n\n",modelname,min[0]*adjust,min[1]*adjust,min[2]*adjust); fprintf(file,"v16 __%s_texture[][2]={ {0,0},\n",modelname); while(texture!=NULL){ fprintf(file," {%d,%d}",floattov16(texture->x), floattov16(texture->y) ); texture=texture->next; if(texture!=NULL) fprintf(file,",\n"); } fprintf(file,"};\n\n"); fprintf(file,"int __%s_normal[]={ 0,\n",modelname); while(normal!=NULL){ fprintf(file," %d", NORMAL_PACK(floattov10(normal->x), floattov10(normal->y), floattov10(normal->z)) ); normal=normal->next; if(normal!=NULL) fprintf(file,",\n"); } fprintf(file,"};\n\n"); fprintf(file,"int __%s_face[][3][3]={\n",modelname); while(figure!=NULL){ fprintf(file," {{%d,%d,%d},",figure->points[0][0], figure->points[0][1], figure->points[0][2]); fprintf(file," {%d,%d,%d},",figure->points[1][0], figure->points[1][1], figure->points[1][2]); fprintf(file," {%d,%d,%d}}",figure->points[2][0], figure->points[2][1], figure->points[2][2]); figure=figure->next; nfaces++; if(figure!=NULL) fprintf(file,",\n"); } fprintf(file,"};\n\n"); fprintf(file,"unsigned int __%s_nfaces = %u;",modelname,nfaces); fflush(file); }
void logo() { glResetMatrixStack(); glMatrixMode(GL_PROJECTION); gluPerspective(20, 256.0 / 192.0, 0.1, 40); gluLookAt( 0.0, .55, 0.0 , //camera possition 0.0, 0.0, 0.0, //look at 0.0, 0.0, -1.0); //up glLight(0, RGB15(31,31,31), 0, floattov10(1.0)-1, 0); glMatrixMode(GL_TEXTURE); glLoadIdentity(); glMatrixMode(GL_MODELVIEW); glMaterialf(GL_AMBIENT, RGB15(8,8,8)); glMaterialf(GL_DIFFUSE, RGB15(31,31,31)); glMaterialf(GL_SPECULAR, RGB15(31,31,31)); glMaterialf(GL_EMISSION, RGB15(8,8,8)); glMaterialShinyness(); glPolyFmt( POLY_ALPHA(31) | POLY_CULL_BACK | POLY_FORMAT_LIGHT0 ); glGenTextures(1, &logotex); glBindTexture(0, logotex); glTexImage2D(0, 0, GL_RGB, TEXTURE_SIZE_256 , TEXTURE_SIZE_256, 0, TEXGEN_TEXCOORD , (u8*)billkuker_bmp_bin); glBindTexture(0, logotex); glBegin(GL_QUAD); glNormal(NORMAL_PACK(0,inttov10(1),0)); glTexCoord1i(TEXTURE_PACK(0,0)); glVertex3v16(floattov16(-0.5), floattov16(-0.5), floattov16(0.5) ); glTexCoord1i(TEXTURE_PACK(inttot16(256), inttot16(0))); glVertex3v16(floattov16(0.5), floattov16(-0.5), floattov16(0.5) ); glTexCoord1i(TEXTURE_PACK(inttot16(256),inttot16(256))); glVertex3v16(floattov16(0.5), floattov16(-0.5), floattov16(-0.5) ); glTexCoord1i(TEXTURE_PACK(0, inttot16(256))); glVertex3v16(floattov16(-0.5), floattov16(-0.5), floattov16(-0.5) ); glEnd(); glFlush(0); playGenericSound(down_raw, down_raw_size); playGenericSound(up_raw, up_raw_size); swiWaitForVBlank(); iprintf("Press any button"); while( !keysHeld() ) scanKeys(); glResetTextures(); iprintf("\x1b[2J"); }
int main() { int textureID; float rotateX = 0.0; float rotateY = 0.0; //set mode 0, enable BG0 and set it to 3D videoSetMode(MODE_0_3D); // initialize gl glInit(); //enable textures glEnable(GL_TEXTURE_2D); // 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); vramSetBankA(VRAM_A_TEXTURE); glGenTextures(1, &textureID); glBindTexture(0, textureID); glTexImage2D(0, 0, GL_RGB, TEXTURE_SIZE_128 , TEXTURE_SIZE_128, 0, TEXGEN_TEXCOORD, (u8*)texture_bin); //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, 1.0, //camera possition 0.0, 0.0, 0.0, //look at 0.0, 1.0, 0.0); //up while(1) { glMatrixMode(GL_MODELVIEW); glPushMatrix(); //move it away from the camera glTranslate3f32(0, 0, floattof32(-1)); glRotateX(rotateX); glRotateY(rotateY); glMaterialf(GL_AMBIENT, RGB15(16,16,16)); glMaterialf(GL_DIFFUSE, RGB15(16,16,16)); glMaterialf(GL_SPECULAR, BIT(15) | RGB15(8,8,8)); glMaterialf(GL_EMISSION, RGB15(16,16,16)); //ds uses a table for shinyness..this generates a half-ass one glMaterialShinyness(); //not a real gl function and will likely change glPolyFmt(POLY_ALPHA(31) | POLY_CULL_BACK); 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; glBindTexture(0, textureID); //draw the obj glBegin(GL_QUAD); glNormal(NORMAL_PACK(0,inttov10(-1),0)); GFX_TEX_COORD = (TEXTURE_PACK(0, inttot16(128))); glVertex3v16(floattov16(-0.5), floattov16(-0.5), 0 ); GFX_TEX_COORD = (TEXTURE_PACK(inttot16(128),inttot16(128))); glVertex3v16(floattov16(0.5), floattov16(-0.5), 0 ); GFX_TEX_COORD = (TEXTURE_PACK(inttot16(128), 0)); glVertex3v16(floattov16(0.5), floattov16(0.5), 0 ); GFX_TEX_COORD = (TEXTURE_PACK(0,0)); glVertex3v16(floattov16(-0.5), floattov16(0.5), 0 ); glEnd(); glPopMatrix(1); glFlush(0); swiWaitForVBlank(); } return 0; }//end main
5,6,7,4 }; //texture coordinates u32 uv[] = { TEXTURE_PACK(inttot16(128), 0), TEXTURE_PACK(inttot16(128),inttot16(128)), TEXTURE_PACK(0, inttot16(128)), TEXTURE_PACK(0,0) }; u32 normals[] = { NORMAL_PACK(0,floattov10(-.97),0), NORMAL_PACK(0,0,floattov10(.97)), NORMAL_PACK(floattov10(.97),0,0), NORMAL_PACK(0,0,floattov10(-.97)), NORMAL_PACK(floattov10(-.97),0,0), NORMAL_PACK(0,floattov10(.97),0) }; //draw a cube face at the specified color void drawQuad(int poly) { u32 f1 = CubeFaces[poly * 4] ; u32 f2 = CubeFaces[poly * 4 + 1] ; u32 f3 = CubeFaces[poly * 4 + 2] ;
int renderModel(struct MODEL * model) { int v_one, v_two, v_thr; int c_one, c_two, c_thr; //int n_one, n_two, n_thr; int t_one, t_two, t_thr; v16 v_x, v_y, v_z; t16 u_m, v_m; char r, g, b; //v16 n_x, n_y, n_z; int objectC = 0; int triangleC = 0; while(objectC < model->header.objectCount) { glMatrixMode(GL_MODELVIEW); glPushMatrix(); unsigned char mat = model->faces.object[objectC].materialID; unsigned char X = model->materials.material[mat].X; unsigned char Y = model->materials.material[mat].Y; unsigned char TX = model->materials.material[mat].TX; unsigned char TY = model->materials.material[mat].TY; unsigned char A = model->materials.material[mat].alpha; unsigned char C = model->materials.material[mat].culling; glPolyFmt(POLY_ALPHA(A) | C); if(TX != 0 || TY != 0) { glMatrixMode(GL_TEXTURE); glLoadIdentity(); glTranslatef(model->materials.material[mat].scrollX, model->materials.material[mat].scrollY, 0); model->materials.material[mat].scrollX += TX; model->materials.material[mat].scrollY += TY; } glBindTexture(GL_TEXTURE_2D, model->textures[mat]); while(triangleC < model->faces.object[objectC].triangleCount) { v_one = model->faces.object[objectC].triangles[triangleC].triangle[0].v; v_two = model->faces.object[objectC].triangles[triangleC].triangle[1].v; v_thr = model->faces.object[objectC].triangles[triangleC].triangle[2].v; c_one = model->faces.object[objectC].triangles[triangleC].triangle[0].c; c_two = model->faces.object[objectC].triangles[triangleC].triangle[1].c; c_thr = model->faces.object[objectC].triangles[triangleC].triangle[2].c; /*n_one = model->faces.object[objectC].triangles[triangleC].triangle[0].n; n_two = model->faces.object[objectC].triangles[triangleC].triangle[1].n; n_thr = model->faces.object[objectC].triangles[triangleC].triangle[2].n;*/ t_one = model->faces.object[objectC].triangles[triangleC].triangle[0].t; t_two = model->faces.object[objectC].triangles[triangleC].triangle[1].t; t_thr = model->faces.object[objectC].triangles[triangleC].triangle[2].t; glBegin(GL_TRIANGLES); glNormal(NORMAL_PACK( 0, 0, 1<<10)); v_x = model->vertices.vertex[v_one].x; v_y = model->vertices.vertex[v_one].y; v_z = model->vertices.vertex[v_one].z; r = model->colors.color[c_one].r; g = model->colors.color[c_one].g; b = model->colors.color[c_one].b; /*n_x = model->normals.normal[n_one].x; n_y = model->normals.normal[n_one].y; n_z = model->normals.normal[n_one].z; glNormal3f(n_x, n_y, n_z);*/ u_m = model->coordinates.coordinate[t_one].u; v_m = model->coordinates.coordinate[t_one].v; glColor3b(r,g,b); glTexCoord2t16(u_m * X,v_m * Y); glVertex3v16(v_x, v_y, v_z); v_x = model->vertices.vertex[v_two].x; v_y = model->vertices.vertex[v_two].y; v_z = model->vertices.vertex[v_two].z; r = model->colors.color[c_two].r; g = model->colors.color[c_two].g; b = model->colors.color[c_two].b; /*n_x = model->normals.normal[n_two].x; n_y = model->normals.normal[n_two].y; n_z = model->normals.normal[n_two].z; glNormal3f(n_x, n_y, n_z);*/ u_m = model->coordinates.coordinate[t_two].u; v_m = model->coordinates.coordinate[t_two].v; glColor3b(r,g,b); glTexCoord2t16(u_m * X,v_m * Y); glVertex3v16(v_x, v_y, v_z); v_x = model->vertices.vertex[v_thr].x; v_y = model->vertices.vertex[v_thr].y; v_z = model->vertices.vertex[v_thr].z; r = model->colors.color[c_thr].r; g = model->colors.color[c_thr].g; b = model->colors.color[c_thr].b; /*n_x = model->normals.normal[n_thr].x; n_y = model->normals.normal[n_thr].y; n_z = model->normals.normal[n_thr].z; glNormal3f(n_x, n_y, n_z);*/ u_m = model->coordinates.coordinate[t_thr].u; v_m = model->coordinates.coordinate[t_thr].v; glColor3b(r,g,b); glTexCoord2t16(u_m * X,v_m * Y); glVertex3v16(v_x, v_y, v_z); glEnd(); triangleC++; } glPopMatrix(1); triangleC = 0; objectC++; } return 1; }