void Map2D::DrawTranslucent( const glImage *Tiles ) { TxOff = (TxOff + 1) & 31; glPushMatrix(); glPolyFmt( POLY_ALPHA(15) | POLY_CULL_FRONT | POLY_ID( GlobalManager::Instance()->GetFreePolyID() ) ); for( int y = 0; y < Height; y++ ) { for( int x = 0; x < Width ; x++ ) { int Tile = GetElement(x,y); switch( Tile ) { case WATER: DrawFrontCube( (x * TILE_SIZE_3D) + floattof32(0.5), (y * TILE_SIZE_3D) + floattof32(0.5), 0, 0, -TxOff, &Tiles[0] ); break; case TOP_WATER: DrawFrontTopCube( (x * TILE_SIZE_3D) + floattof32(0.5), (y * TILE_SIZE_3D) + floattof32(0.5), 0, 0, -TxOff, &Tiles[0] ); break; } } } glPolyFmt( POLY_ALPHA(31) | POLY_CULL_NONE | POLY_ID( GlobalManager::Instance()->GetFreePolyID() ) ); glPopMatrix(1); }
void loseRender(Board *b, int step){ glResetMatrixStack(); if ( step > 1000 ) return; glMatrixMode(GL_PROJECTION); gluPerspective(20, 256.0 / 192.0, 0.1, 40); float d = (float)step / 6.0; gluLookAt( 5.0 + d, 5.0 + d, 7.0 + d, //camera possition 1.0, 0.0, 1.5, //look at 0.0, 1.0, 0.0); //up glRotateY(step*3); 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 ); glBindTexture(0, textureID); b->draw(); glFlush(0); swiWaitForVBlank(); }
//This function initializes the device to a "default" setting. //You may begin sending GL commands to the DS after this function executes void blu_impl::GFX_Init3DDevice(){ videoSetMode(MODE_0_3D); // initialize the geometry engine 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); // Set our viewport to be the same size as the screen glViewport(0,0,255,191); // this controls your camera glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(70, 256.0 / 192.0, 0.1, 100); //ds specific, several attributes can be set here glPolyFmt(POLY_ALPHA(31) | POLY_CULL_NONE); // Set the current matrix to be the model matrix glMatrixMode(GL_MODELVIEW); }
void Scene::renderString(const char* str, f32 x, f32 y, int r, int g, int b) { int l = 0; while(str[l] != 0) l++; x -= (l*25) / 2; int i = 0; while(str[i] != 0) { glPolyFmt(POLY_ALPHA(27+rand()%3) | POLY_ID(BG_FX2_POLYID) | POLY_CULL_NONE); int rr = r+irand(80); if(rr < 0) rr = 0; if(rr > 255) rr = 255; int gg = g+irand(80); if(gg < 0) gg = 0; if(gg > 255) gg = 255; int bb = b+irand(80); if(bb < 0) bb = 0; if(bb > 255) bb = 255; glColor3b(rr, gg, bb); renderChar(str[i], x+frand(1), y+frand(2), 10); x += 25; i++; } }
void App_Test::display_Model() { // gluLookAtf32( this->camera.getPosition()->get_vec_ox(),this->camera.getPosition()->get_vec_oy(),this->camera.getPosition()->get_vec_oz(), // this->camera.getLookAt()->get_vec_ox(),this->camera.getLookAt()->get_vec_oy(),this->camera.getLookAt()->get_vec_oz(), // 0,4096,0 // ); // glLoadIdentity(); glEnable(GL_TEXTURE_2D); glEnable(GL_ANTIALIAS); glEnable(GL_OUTLINE); glLight(0, RGB15(31,31,31) , 0, floattov10(-6.0), floattov10(-1.0)); glSetOutlineColor(0,RGB15(0,0,0)); glPolyFmt(POLY_ID(0) | POLY_ALPHA(31)|POLY_CULL_NONE | POLY_FORMAT_LIGHT0 | POLY_TOON_HIGHLIGHT); // glPolyFmt(POLY_ALPHA(31)|POLY_CULL_NONE | POLY_FORMAT_LIGHT0); glColor3b(31,31,31); glBindTexture(GL_TEXTURE_2D, this->textureID[0]); glTranslatef(0,-6,0); glRotatef(90,-1,0,0); glRotatef(-90,0,0,1); glCallList( (u32 *) this->model_selected); glEnd(); }
// Setup viewport to a 1 pixel window where the user clicked. // Set the "pickMode" flag and call draw to find out what piece of the grid was drawn. bool MapDraw::pickPoint(int x, int y, Camera &cam) { // This flag makes it so "startCheck" and "endCheck" are called // before and after every polygon is drawn pickMode = true; int viewport[]={0,0,255,191}; // used later for gluPickMatrix() //change ortho vs perspective glViewport(0,192,0,192); // set the viewport to fullscreen glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPickMatrix(x,(191-y),4,4,viewport); // render only what is below the cursor cam.Perspective(); glMatrixMode(GL_MODELVIEW); // opaque polygons, no culling, this fixes my problems. glPolyFmt(POLY_ALPHA(31) | POLY_CULL_NONE); // Un-mark the last one. if (picked) picked->picked = false; // pick mode flags will do the magic & return picked patch. picked = draw(); // Mark the new one (which may still be the last one btw) if (picked) picked->picked = true; // Turn off pick mode. pickMode = false; return endCheck(); }
void init3DSettings() { glInit(); glEnable(GL_TEXTURE_2D | GL_ANTIALIAS | GL_BLEND); glClearColor(31, 31, 31, 0); glClearPolyID(63); glClearDepth(GL_MAX_DEPTH); glViewport(0, 0, 255, 191); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glFrustum(-6.4, 6.4, -4.8, 4.8, 6.4, 25); glMaterialf(GL_AMBIENT, RGB15(8, 8, 8)); glMaterialf(GL_DIFFUSE, RGB15(23, 23, 23)); glMaterialf(GL_SPECULAR, BIT(15) | RGB15(8, 8, 8)); glMaterialf(GL_EMISSION, RGB15(5, 5, 5)); glMaterialShinyness(); glLight(0, RGB15(31, 31, 31), floattov10(4.0), 0, floattov10(-0.8)); glLight(1, RGB15(31, 31, 31), floattov10(-4.0), 0, floattov10(-0.8)); glLight(2, RGB15(31, 31, 31), 0, floattov10(-4.0), floattov10(-0.8)); glLight(3, RGB15(31, 31, 31), 0, floattov10(4.0), floattov10(-0.8)); glPolyFmt(POLY_ALPHA(31) | POLY_CULL_BACK | POLY_FORMAT_LIGHT0 | POLY_FORMAT_LIGHT1 | POLY_FORMAT_LIGHT2 | POLY_FORMAT_LIGHT3); }
void CharActor::renderUnrotated() { glPolyFmt(POLY_ALPHA(27+rand()%3) | POLY_ID(BG_FX2_POLYID) | POLY_CULL_NONE); glColor3b(255, 160+irand(80), 0); renderChar(c, x+frand(1), y+frand(2), size); }
int main() { // Setup the Main screen for 3D videoSetMode(MODE_0_3D); // initialize the geometry engine 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); // Set our viewport to be the same size as the screen glViewport(0,0,255,191); // setup the view glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(70, 256.0 / 192.0, 0.1, 100); //ds specific, several attributes can be set here glPolyFmt(POLY_ALPHA(31) | POLY_CULL_NONE); while (1) { // Set the current matrix to be the model matrix glMatrixMode(GL_MODELVIEW); glColor3f(1, 1, 1); // Set the color..not in nehe source...ds gl default will be black //Push our original Matrix onto the stack (save state) glPushMatrix(); DrawGLScene(); // Pop our Matrix from the stack (restore state) glPopMatrix(1); //a handy little built in function to wait for a screen refresh swiWaitForVBlank(); // flush to screen glFlush(0); scanKeys(); int pressed = keysDown(); if(pressed & KEY_START) break; } return 0; }
void drawTurretStuff(turret_struct* t) { if(!t || !t->used || t->dead)return; drawLaser(t->laserOrigin,t->laserDestination); if(t->laserThroughPortal)drawLaser(t->laserOrigin2,t->laserDestination2); //TEMP TEST BILLBOARD vect3D u1=vect(t->OBB->transformationMatrix[0],t->OBB->transformationMatrix[3],t->OBB->transformationMatrix[6]); vect3D u2=vect(t->OBB->transformationMatrix[1],t->OBB->transformationMatrix[4],t->OBB->transformationMatrix[7]); vect3D u3=vect(t->OBB->transformationMatrix[2],t->OBB->transformationMatrix[5],t->OBB->transformationMatrix[8]); glPolyFmt(POLY_ALPHA(31) | POLY_CULL_BACK | POLY_ID(63)); GFX_COLOR=RGB15(31,31,31); applyMTL(turretShotTexture); if(t->drawShot[0]) { glPushMatrix(); glTranslatef32(t->laserOrigin.x, t->laserOrigin.y, t->laserOrigin.z); glTranslatef32(u3.x/128, u3.y/128, u3.z/128); glTranslatef32(u1.x/32, u1.y/32, u1.z/32); glScalef32(inttof32(1)/16,inttof32(1)/16,inttof32(1)/16); glRotatef32i(t->shotAngle[0],u3.x,u3.y,u3.z); glBegin(GL_QUADS); GFX_TEX_COORD = TEXTURE_PACK(inttot16(0), inttot16(0)); glVertex3v16(-u1.x/2-u2.x, -u1.y/2-u2.y, -u1.z/2-u2.z); GFX_TEX_COORD = TEXTURE_PACK(inttot16(32), inttot16(0)); glVertex3v16(+u1.x/2-u2.x, +u1.y/2-u2.y, +u1.z/2-u2.z); GFX_TEX_COORD = TEXTURE_PACK(inttot16(32), inttot16(64)); glVertex3v16(+u1.x/2+u2.x, +u1.y/2+u2.y, +u1.z/2+u2.z); GFX_TEX_COORD = TEXTURE_PACK(inttot16(0), inttot16(64)); glVertex3v16(-u1.x/2+u2.x, -u1.y/2+u2.y, -u1.z/2+u2.z); glPopMatrix(1); } if(t->drawShot[1]) { glPushMatrix(); glTranslatef32(t->laserOrigin.x, t->laserOrigin.y, t->laserOrigin.z); glTranslatef32(u3.x/128, u3.y/128, u3.z/128); glTranslatef32(-u1.x/32, -u1.y/32, -u1.z/32); glScalef32(inttof32(1)/16,inttof32(1)/16,inttof32(1)/16); glRotatef32i(t->shotAngle[1],u3.x,u3.y,u3.z); glBegin(GL_QUADS); GFX_TEX_COORD = TEXTURE_PACK(inttot16(0), inttot16(0)); glVertex3v16(-u1.x/2-u2.x, -u1.y/2-u2.y, -u1.z/2-u2.z); GFX_TEX_COORD = TEXTURE_PACK(inttot16(32), inttot16(0)); glVertex3v16(+u1.x/2-u2.x, +u1.y/2-u2.y, +u1.z/2-u2.z); GFX_TEX_COORD = TEXTURE_PACK(inttot16(32), inttot16(64)); glVertex3v16(+u1.x/2+u2.x, +u1.y/2+u2.y, +u1.z/2+u2.z); GFX_TEX_COORD = TEXTURE_PACK(inttot16(0), inttot16(64)); glVertex3v16(-u1.x/2+u2.x, -u1.y/2+u2.y, -u1.z/2+u2.z); glPopMatrix(1); } }
void drawLogo(void) { glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrthof32(inttof32(0), inttof32(255), inttof32(191), inttof32(0), -inttof32(1), inttof32(1)); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glPushMatrix(); glPolyFmt(POLY_ALPHA(31) | POLY_CULL_NONE); applyMTL(logoMain); glScalef32(inttof32(256),inttof32(128),inttof32(1)); glBegin(GL_QUADS); GFX_TEX_COORD = TEXTURE_PACK(inttot16(0), inttot16(0)); glVertex3v16(inttof32(0), inttof32(0), inttof32(0)); GFX_TEX_COORD = TEXTURE_PACK(inttot16(256), inttot16(0)); glVertex3v16(inttof32(1), inttof32(0), inttof32(0)); GFX_TEX_COORD = TEXTURE_PACK(inttot16(256), inttot16(128)); glVertex3v16(inttof32(1), inttof32(1), inttof32(0)); GFX_TEX_COORD = TEXTURE_PACK(inttot16(0), inttot16(128)); glVertex3v16(inttof32(0), inttof32(1), inttof32(0)); glPopMatrix(1); glPushMatrix(); glPolyFmt(POLY_ALPHA(31) | POLY_CULL_NONE); applyMTL(logoRotate); glTranslate3f32(inttof32(90+32),inttof32(28+32),-inttof32(1)/16); glRotateZi(logoAngle+=32); glTranslate3f32(-inttof32(32),-inttof32(32),0); glScalef32(inttof32(64),inttof32(64),inttof32(1)); glBegin(GL_QUADS); GFX_TEX_COORD = TEXTURE_PACK(inttot16(0), inttot16(0)); glVertex3v16(inttof32(0), inttof32(0), inttof32(0)); GFX_TEX_COORD = TEXTURE_PACK(inttot16(64), inttot16(0)); glVertex3v16(inttof32(1), inttof32(0), inttof32(0)); GFX_TEX_COORD = TEXTURE_PACK(inttot16(64), inttot16(64)); glVertex3v16(inttof32(1), inttof32(1), inttof32(0)); GFX_TEX_COORD = TEXTURE_PACK(inttot16(0), inttot16(64)); glVertex3v16(inttof32(0), inttof32(1), inttof32(0)); glPopMatrix(1); }
//--------------------------------------------------------------------------------- void BoxTest_Asynch(v16 x, v16 y, v16 z, v16 width, v16 height, v16 depth) //--------------------------------------------------------------------------------- { glPolyFmt(BIT(12) | BIT(13)); glBegin(GL_TRIANGLES); glEnd(); GFX_BOX_TEST = VERTEX_PACK(x, y); GFX_BOX_TEST = VERTEX_PACK(z, width); GFX_BOX_TEST = VERTEX_PACK(height, depth); }
void drawLaser(vect3D orig, vect3D target) { unbindMtl(); glPolyFmt(POLY_ID(63)); GFX_COLOR=RGB15(31,0,0); glPushMatrix(); vect3D v=vectDifference(target,orig); glBegin(GL_TRIANGLES); glTranslatef32(orig.x, orig.y, orig.z); glVertex3v16(0, 0, 0); glTranslatef32(v.x, v.y, v.z); glVertex3v16(0, 0, 0); glVertex3v16(0, 0, 0); glPopMatrix(1); }
//--------------------------------------------------------------------------------- int BoxTest(v16 x, v16 y, v16 z, v16 width, v16 height, v16 depth) //--------------------------------------------------------------------------------- { glPolyFmt(BIT(12) | BIT(13)); glBegin(GL_TRIANGLES); glEnd(); GFX_BOX_TEST = VERTEX_PACK(x, y); GFX_BOX_TEST = VERTEX_PACK(z, width); GFX_BOX_TEST = VERTEX_PACK(height, depth); while(GFX_STATUS & BIT(0)); return (GFX_STATUS & BIT(1)); }
void hello_loop(helloObjectInstance *me) { glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(70, 256.0 / 192.0, 0.1, 10); glPolyFmt(POLY_ALPHA(31) | POLY_CULL_FRONT); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glTranslatef(0, 0, -5); glRotateX(ry++); glRotateY(rx++); DSGM_DrawCube(-1, -1, -1, 2, 2, 2); }
void SeaActor::renderPerspective() { glPolyFmt(POLY_ALPHA(20) | POLY_ID(BG_FX1_POLYID) | POLY_CULL_NONE); glColor3b(10, 50, 255); setTexture(13); ydelta = 0; renderSea(-6, 6, -10, -5, 1, false); renderSea(-10, 10, -5, -2, 1, true); renderSea(-18, 18, -2, 5, 2, true); renderSea(-20, 22, 6, 12, 4, true); }
static void setup() { consoleDemoInit(); //put 3D on top lcdMainOnTop(); //set mode 0, enable BG0 and set it to 3D videoSetMode(MODE_0_3D); // 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); // Set our viewport to be the same size as the screen glViewport(0,0,255,191); glColor3b(255,255,0); glLight(0, RGB15(0,31,0) , 0, floattov10(-1.0), 0); //need to set up some material properties since DS does not have them set by default glMaterialf(GL_AMBIENT, RGB15(5,5,5)); glMaterialf(GL_DIFFUSE, RGB15(15,15,15)); glMaterialf(GL_SPECULAR, RGB15(8,8,8)); glMaterialf(GL_EMISSION, RGB15(5,5,5)); //ds uses a table for shinyness..this generates a half-assed one glMaterialShinyness(); //ds specific, several attributes can be set here glPolyFmt( POLY_ALPHA(31) | POLY_CULL_NONE | POLY_FORMAT_LIGHT0 ); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(60, (float)W / H, Znear, Zfar); lookAtSelectedModel(); }
void init3D(void) { videoSetMode(MODE_0_3D); glInit(); glEnable( GL_TEXTURE_2D | GL_ANTIALIAS ); 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( GL_MAX_DEPTH ); glViewport(0,0,255,191); // set the viewport to screensize glColor( 0x7FFF ); // max color glPolyFmt( POLY_ALPHA(31) | POLY_CULL_NONE ); // geen dingen laten verdwijnen glMatrixMode( GL_PROJECTION ); glLoadIdentity(); // reset view glOrthof32( 0, SCREEN_WIDTH, SCREEN_HEIGHT, 0, -1 << 12, 1 << 12 ); gluLookAt( 0.0, 0.0, 1.0, //camera possition 0.0, 0.0, 0.0, //look at 0.0, 1.0, 0.0); //up }
void Starfield_Draw(Starfield *starfield) { glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrthof32(0, inttof32(4), 0, inttof32(3), 0, inttof32(40)); glMatrixMode(GL_MODELVIEW); glPushMatrix(); gluLookAtf32(0, 0, inttof32(1), 0, 0, 0, 0, inttof32(1), 0); glPolyFmt(POLY_ALPHA(0x1f) | POLY_CULL_NONE); for (int i = 0; i < num_stars; i++) { StarfieldStar *star = &starfield->stars[i]; Starfield_DrawStar(star); } glPopMatrix(1); }
void gameLoop(){ iprintf("\x1b[2J"); int frame = 0; Board b(7); Player* p; p = new Player(b.space(5,4)); //iprintf("Entering Main Loop.\n"); int rot = 0; while( !b.full() ) { iprintf("\x1b[22;18HFrame: %d\n\x1b[0;0H", ++frame); glResetMatrixStack(); //any floating point gl call is being converted to fixed prior to being implemented glMatrixMode(GL_PROJECTION); gluPerspective(20, 256.0 / 192.0, 0.1, 40); gluLookAt( 5.0, 5.0, 7.0, //camera possition 1.0, 0.0, 1.5, //look at 0.0, 1.0, 0.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)); //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 | POLY_FORMAT_LIGHT0 ); //glPolyFmt(POLY_ALPHA(15) | POLY_CULL_BACK | POLY_FORMAT_LIGHT0 ); glRotateY(rot); glBindTexture(0, textureID); b.draw(); glFlush(0); b.tick(); Player::tickPlayers(); scanKeys(); u16 keys = keysHeld(); p->setDir(NODIR); if((keys & KEY_UP)) p->setDir(NORTH); if((keys & KEY_DOWN)) p->setDir(SOUTH); if((keys & KEY_LEFT)) p->setDir(WEST); if((keys & KEY_RIGHT)) p->setDir(EAST); if (( keys & KEY_R )) rot++; if (( keys & KEY_L )) rot--; swiWaitForVBlank(); } lose(&b); }
int main(void) { float x_angle = 0, y_angle = 0; float x_speed = 0, y_speed = 0; float distance = 1; powerON(POWER_ALL); irqInit(); irqEnable(IRQ_VBLANK); videoSetMode(MODE_0_3D); consoleDemoInit(); /* Set up a timer to count FPS */ TIMER3_DATA = TIMER_FREQ_1024(1); TIMER3_CR = TIMER_DIV_1024 | TIMER_IRQ_REQ; irqSet(IRQ_TIMER3, fps_timer_irq); irqEnable(IRQ_TIMER3); glViewPort(0, 0, SCREEN_WIDTH-1, SCREEN_HEIGHT-1); glClearColor(0, 0, 0); glClearDepth(GL_MAX_DEPTH); iprintf("Hello World!\n\n"); glReset(); gluPerspective(35, SCREEN_WIDTH / (float) SCREEN_HEIGHT, 0.1, 40.0); gluLookAt(0.0, 0.0, 1.0, /* Eye */ 0.0, 0.0, 0.0, /* Look at */ 0.0, 1.0, 0.0); /* Up */ 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)); glMaterialShinyness(); glColor(RGB15(31, 31, 31)); glLight(0, RGB15(20, 15, 15), floattov10(-0.9), floattov10( 0.9), floattov10( 0.2)); glLight(1, RGB15(15, 15, 20), floattov10( 0.4), floattov10( 0.9), floattov10( 0.2)); glPolyFmt(POLY_ALPHA(31) | POLY_CULL_BACK | POLY_FORMAT_LIGHT0 | POLY_FORMAT_LIGHT1); while (1) { scanKeys(); if (keysHeld() & KEY_START) Loader_Exit9(); if (keysHeld() & KEY_UP) x_speed += 0.05; if (keysHeld() & KEY_DOWN) x_speed -= 0.05; if (keysHeld() & KEY_LEFT) y_speed += 0.05; if (keysHeld() & KEY_RIGHT) y_speed -= 0.05; if (keysHeld() & KEY_R) distance += 0.05; if (keysHeld() & KEY_L) distance -= 0.05; glPushMatrix(); glTranslate3f32(floattof32( 0.0), floattof32( 0.0), floattof32(-distance)); glRotateX(x_angle += x_speed); glRotateY(y_angle += y_speed); glCallList(display_list_bin); glPopMatrix(1); glFlush(); frames++; swiWaitForVBlank(); } return 0; }
int main() { int rotateX = 0; int rotateY = 0; //set mode 0, enable BG0 and set it to 3D videoSetMode(MODE_0_3D); // 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); //toon-table entry 0 is for completely unlit pixels, going up to entry 31 for completely lit //We block-fill it in two halves, we get cartoony 2-tone lighting glSetToonTableRange( 0, 15, RGB15(8,8,8) ); glSetToonTableRange( 16, 31, RGB15(24,24,24) ); //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); //NB: When toon-shading, the hw ignores lights 2 and 3 //Also note that the hw uses the RED component of the lit vertex to index the toon-table glLight(0, RGB15(16,16,16) , 0, floattov10(-1.0), 0); glLight(1, RGB15(16,16,16), floattov10(-1.0), 0, 0); gluLookAt( 0.0, 0.0, -3.0, //camera possition 0.0, 0.0, 0.0, //look at 0.0, 1.0, 0.0); //up while(1) { glMatrixMode(GL_MODELVIEW); glPushMatrix(); glRotateXi(rotateX); glRotateYi(rotateY); glMaterialf(GL_AMBIENT, RGB15(8,8,8)); glMaterialf(GL_DIFFUSE, RGB15(24,24,24)); glMaterialf(GL_SPECULAR, RGB15(0,0,0)); glMaterialf(GL_EMISSION, RGB15(0,0,0)); glPolyFmt(POLY_ALPHA(31) | POLY_CULL_BACK | POLY_FORMAT_LIGHT0 | POLY_FORMAT_LIGHT1 | POLY_TOON_HIGHLIGHT); scanKeys(); u32 keys = keysHeld(); if( keys & KEY_UP ) rotateX += 1; if( keys & KEY_DOWN ) rotateX -= 1; if( keys & KEY_LEFT ) rotateY += 1; if( keys & KEY_RIGHT ) rotateY -= 1; int pen_delta[2]; get_pen_delta( &pen_delta[0], &pen_delta[1] ); rotateY -= pen_delta[0]; rotateX -= pen_delta[1]; glCallList((u32*)statue_bin); glPopMatrix(1); glFlush(0); swiWaitForVBlank(); } return 0; }
int main() { // Setup the Main screen for 3D videoSetMode(MODE_0_3D); vramSetBankA(VRAM_A_TEXTURE); //NEW must set up some memory for textures // initialize the geometry engine 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); // enable textures glEnable(GL_TEXTURE_2D); // enable alpha blending glEnable(GL_BLEND); // Set our viewport to be the same size as the screen glViewport(0,0,255,191); LoadGLTextures(); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(70, 256.0 / 192.0, 0.1, 100); glColor3f(1,1,1); //set up a directional ligth arguments are light number (0-3), light color, //and an x,y,z vector that points in the direction of the light glLight(0, RGB15(31,31,31) , 0, 0,floattov10(-1.0)); //need to set up some material properties since DS does not have them set by default 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(); glPolyFmt(POLY_ALPHA(15) | POLY_CULL_BACK | POLY_FORMAT_LIGHT0); glMatrixMode(GL_MODELVIEW); while (1) { DrawGLScene(); // flush to screen glFlush(0); // wait for the screen to refresh swiWaitForVBlank(); } return 0; }
void Map2D::DrawDebug( const glImage *Tiles ) { glPushMatrix(); glPolyFmt( POLY_ALPHA(31) | POLY_CULL_FRONT | POLY_ID( GlobalManager::Instance()->GetFreePolyID() ) ); for( int y = 0; y < Height; y++ ) { for( int x = 0; x < Width ; x++ ) { int Tile = GetElement(x,y); switch( Tile ) { case BRICK: // offset by 0.5 so that (0,0) is top left of tile like standard 2D //DrawCube( x * TILE_SIZE_3D + floattof32(0.5), y * TILE_SIZE_3D + floattof32(0.5), 0, &Tiles[4] ); break; case TOP_BRICK: //DrawCube( x * TILE_SIZE_3D + floattof32(0.5), y * TILE_SIZE_3D + floattof32(0.5), 0, &Tiles[0] ); break; case TOP_BRICK_MOSS_TOP: //DrawCube( x * TILE_SIZE_3D + floattof32(0.5), y * TILE_SIZE_3D + floattof32(0.5), 0, &Tiles[0] ); //glSprite3D( x * TILE_SIZE_3D, y * TILE_SIZE_3D, 10 + TILE_SIZE_3D/2, GL_FLIP_NONE, &Tiles[7] ); break; case BRICK_MOSS_BOTTOM: //DrawCube( x * TILE_SIZE_3D + floattof32(0.5), y * TILE_SIZE_3D + floattof32(0.5), 0, &Tiles[4] ); //glSprite3D( x * TILE_SIZE_3D, y * TILE_SIZE_3D, 10 + TILE_SIZE_3D/2, GL_FLIP_NONE, &Tiles[6] ); break; case SPIKE: //glSprite3D( x * TILE_SIZE_3D, y * TILE_SIZE_3D, -TILE_SIZE_3D/2, GL_FLIP_NONE, &Tiles[2] ); //glSprite3D( x * TILE_SIZE_3D, y * TILE_SIZE_3D, 0, GL_FLIP_NONE, &Tiles[2] ); //glSprite3D( x * TILE_SIZE_3D, y * TILE_SIZE_3D, TILE_SIZE_3D/2, GL_FLIP_NONE, &Tiles[2] ); break; case INVISIBLE: glSprite3D( x * TILE_SIZE_3D, y * TILE_SIZE_3D, 8+ TILE_SIZE_3D, GL_FLIP_NONE, &Tiles[2] ); break; case LADDER: //glSprite3D( x * TILE_SIZE_3D, y * TILE_SIZE_3D, -64, GL_FLIP_NONE, &Tiles[1] ); break; case TOP_LADDER: //glSprite3D( x * TILE_SIZE_3D, y * TILE_SIZE_3D, -64, GL_FLIP_NONE, &Tiles[1] ); break; case TOP_LADDER_HANDLE: //glSprite3D( x * TILE_SIZE_3D, y * TILE_SIZE_3D, -64, GL_FLIP_NONE, &Tiles[5] ); break; case SIGN: //glSprite3D( x * TILE_SIZE_3D, y * TILE_SIZE_3D, TILE_SIZE_3D/2, GL_FLIP_NONE, &Tiles[3] ); break; case MOSS_BOTTOM: //glSprite3D( x * TILE_SIZE_3D, y * TILE_SIZE_3D, 10 + TILE_SIZE_3D/2, GL_FLIP_NONE, &Tiles[6] ); break; case BLOCK_COLLIDE: glSprite3D( x * TILE_SIZE_3D, y * TILE_SIZE_3D, -TILE_SIZE_3D/2, GL_FLIP_NONE, &Tiles[2] ); break; } } } glPopMatrix(1); }
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() { struct touchPosition pos; float rotateX = 0.0; float rotateY = 0.0; powerON(POWER_ALL); consoleDemoInit(); //set mode 0, enable BG0 and set it to 3D videoSetMode(MODE_0_3D); //irqs are nice irqInit(); irqEnable(IRQ_VBLANK); // 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(35, 256.0 / 192.0, 0.1, 100); 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) { float px, py; pos = touchReadXY(); px = pos.px; py = pos.py; px = (px * 5) / 256; py = (py * 3) / 192; px -= 2.5; py -= 1.5; glPushMatrix(); //move it away from the camera glTranslate3f32(0, 0, floattof32(-1)); glRotateX(rotateX); glRotateY(rotateY); glMatrixMode(GL_MODELVIEW); //not a real gl function and will likely change glPolyFmt(POLY_ALPHA(31) | POLY_CULL_NONE); 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; //draw the obj glBegin(GL_TRIANGLE); glColor3b(255,0,0); glVertex3v16(inttov16(-1),inttov16(-1),0); glColor3b(0,255,0); glVertex3v16(inttov16(1), inttov16(-1), 0); glColor3b(0,0,255); glVertex3v16(inttov16(0), inttov16(1), 0); glEnd(); glLoadIdentity(); glTranslatef(px,-py,-3.0); glBegin(GL_TRIANGLE); glVertex3f( 0.0, 1.0, 0.0); glVertex3f(-1.0,-1.0, 0.0); glVertex3f( 1.0,-1.0, 0.0); glEnd(); glPopMatrix(1); glFlush(0); swiWaitForVBlank(); } return 0; }//end main
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
int main() { defaultExceptionHandler(); // Setup the Main screen for 3D videoSetMode(MODE_0_3D); // initialize the geometry engine 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); // Set our viewport to be the same size as the screen glViewport(0,0,255,191); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(70, 256.0 / 192.0, 0.1, 100); //ds specific, several attributes can be set here glPolyFmt(POLY_ALPHA(31) | POLY_CULL_FRONT); // Set the current matrix to be the model matrix glMatrixMode(GL_MODELVIEW); float x,y,z; float yOrbit; glClearColor(255,0,255,255); while (1) { // draw the scene glPushMatrix(); glTranslatef(x,y,z); //gluLookAt(x,y,z,x,y,z+10,0,1,0); glRotatef(yOrbit,0,1,0); DrawGLScene(); glPopMatrix(1); // flush to screen glFlush(0); scanKeys(); if(keysHeld() & (KEY_UP)) { z+=.05; }else if(keysHeld() & (KEY_DOWN)) { z-=.05; } if(keysHeld() & (KEY_X)) { y-=.05; }else if(keysHeld() & (KEY_B)) { y+=.05; } if(keysHeld() & (KEY_LEFT|KEY_Y)) { x+=.05; }else if(keysHeld() & (KEY_RIGHT|KEY_A)) { x-=.05; } if(keysHeld() & KEY_L) { yOrbit-=1; } if(keysHeld() & KEY_R) { yOrbit+=1; } // wait for the screen to refresh swiWaitForVBlank(); } return 0; }
int main() { 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 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, 1.0, //camera possition 0.0, 0.0, 0.0, //look at 0.0, 1.0, 0.0); //up while(1) { glPushMatrix(); //move it away from the camera glTranslatef32(0, 0, floattof32(-1)); glRotateX(rotateX); glRotateY(rotateY); glMatrixMode(GL_MODELVIEW); //not a real gl function and will likely change glPolyFmt(POLY_ALPHA(31) | POLY_CULL_NONE); 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; //draw the obj glBegin(GL_QUAD); glColor3b(255,0,0); glVertex3v16(inttov16(-1),inttov16(-1),0); glColor3b(0,255,0); glVertex3v16(inttov16(1), inttov16(-1), 0); glColor3b(0,0,255); glVertex3v16(inttov16(1), inttov16(1), 0); glColor3b(255,0,255); glVertex3v16(inttov16(-1), inttov16(1), 0); glEnd(); glPopMatrix(1); glFlush(0); swiWaitForVBlank(); if(keys & KEY_START) break; } return 0; }//end main
//void drawVBO(float * verts,int* idx,int polyCount,int xOffset,int yOffset, int zOffset,int width) //{ // for (int i=0; i<polyCount; i++) // { // glBegin(GL_TRIANGLE); // for (int k=0; k<3; k++) { // // int vi1 = idx[i*3 +k]; // // // glNormal3f (-Pickmin_vertex[vi1][2], -Pickmin_vertex[vi1][3],-Pickmin_vertex[vi1][4]); // glVertex3f(PikminLeaf_vertex[vi1*width +xOffset], // PikminLeaf_vertex[vi1*width +yOffset], // PikminLeaf_vertex[vi1*width +zOffset] // ); // } // glEnd(); // // } //} void drawPikmin(int LOD) { if(LOD >0) { for (int i=0; i<Pikmin_LOD1_polygoncount; i++) { glBegin(GL_TRIANGLE); for (int k=0; k<3; k++) { int vi1 = Pikmin_LOD1_index[i][k]; glColor3f(1, fmax(Pikmin_LOD1_vertex[vi1][3]*1.5 ,.1), 0 ); // glNormal3f (-Pickmin_vertex[vi1][2], -Pickmin_vertex[vi1][3],-Pickmin_vertex[vi1][4]); glVertex3f(Pikmin_LOD1_vertex[vi1][5], Pikmin_LOD1_vertex[vi1][6], Pikmin_LOD1_vertex[vi1][7] ); } glEnd(); } } else { for (int i=0; i<Pikmin_polygoncount; i++) { glBegin(GL_TRIANGLE); for (int k=0; k<3; k++) { int vi1 = Pikmin_index[i][k]; glColor3f(1, fmax(Pikmin_vertex[vi1][3]*1.5 ,.1), 0 ); // glNormal3f (-Pickmin_vertex[vi1][2], -Pickmin_vertex[vi1][3],-Pickmin_vertex[vi1][4]); glVertex3f(Pikmin_vertex[vi1][5], Pikmin_vertex[vi1][6], Pikmin_vertex[vi1][7] ); } glEnd(); } } glPolyFmt(POLY_ALPHA(31) | POLY_CULL_NONE); glColor3f(.1, leafGreen, .1 ); for (int i=0; i<PikminLeaf_polygoncount; i++) { glBegin(GL_TRIANGLE); for (int k=0; k<3; k++) { int vi1 = PikminLeaf_index[i][k]; // glNormal3f (-Pickmin_vertex[vi1][2], -Pickmin_vertex[vi1][3],-Pickmin_vertex[vi1][4]); glVertex3f(PikminLeaf_vertex[vi1][5], PikminLeaf_vertex[vi1][6], PikminLeaf_vertex[vi1][7] ); } glEnd(); } glPolyFmt(POLY_ALPHA(31) | POLY_CULL_FRONT); glColor3f(1,1,1); for (int i=0; i<PikminEyes_polygoncount; i++) { glBegin(GL_TRIANGLE); for (int k=0; k<3; k++) { int vi1 = PikminEyes_index[i][k]; // glNormal3f (-Pickmin_vertex[vi1][2], -Pickmin_vertex[vi1][3],-Pickmin_vertex[vi1][4]); glVertex3f(PikminEyes_vertex[vi1][5], PikminEyes_vertex[vi1][6], PikminEyes_vertex[vi1][7] ); } glEnd(); } // //glTranslatef(0.0,,0.5f); // glColor3f(.01,.01,.01); // glScalef(.7,.7,.7); // for (int i=0; i<PikminEyes_polygoncount; i++) // { // glBegin(GL_TRIANGLE); // for (int k=0; k<3; k++) { // // int vi1 = PikminEyes_index[i][k]; // // // glNormal3f (-Pickmin_vertex[vi1][2], -Pickmin_vertex[vi1][3],-Pickmin_vertex[vi1][4]); // glVertex3f(PikminEyes_vertex[vi1][5], // PikminEyes_vertex[vi1][6], // PikminEyes_vertex[vi1][7] // ); // } // glEnd(); // // } }