//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 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 initEditor(void) { lcdMainOnBottom(); videoSetMode(MODE_5_3D); videoSetModeSub(MODE_5_2D | DISPLAY_BG3_ACTIVE); vramSetPrimaryBanks(VRAM_A_TEXTURE,VRAM_B_TEXTURE,VRAM_C_SUB_BG,VRAM_D_TEXTURE); glInit(); glEnable(GL_TEXTURE_2D); // glEnable(GL_ANTIALIAS); glEnable(GL_BLEND); glEnable(GL_OUTLINE); glClearPolyID(63); glClearDepth(0x7FFF); glViewport(0,0,255,191); initVramBanks(1); initTextures(); initRoomEdition(); NOGBA("START mem free : %dko (%do)",getMemFree()/1024,getMemFree()); fadeIn(); }
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 initMenu(void) { lcdMainOnTop(); videoSetMode(MODE_5_3D); videoSetModeSub(MODE_5_2D); vramSetPrimaryBanks(VRAM_A_TEXTURE,VRAM_B_TEXTURE,VRAM_C_SUB_BG,VRAM_D_TEXTURE); initD3D(); glInit(); glEnable(GL_TEXTURE_2D); glEnable(GL_ANTIALIAS); glEnable(GL_BLEND); glEnable(GL_OUTLINE); glClearPolyID(63); glClearDepth(0x7FFF); glViewport(0,0,255,191); initVramBanks(2); initTextures(); initMenuScene(); initMenuButtons(); //TEMP glLight(0, RGB15(31,31,31), cosLerp(4096), 0, sinLerp(4096)); 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)); glSetToonTableRange(0, 15, RGB15(8,8,8)); //TEMP? glSetToonTableRange(16, 31, RGB15(24,24,24)); //TEMP? applyCameraState(&menuCamera,&cameraStates[4]); tempState=cameraStates[4]; testTransition=startCameraTransition(&cameraStates[1],&cameraStates[4],64); setupMenuPage(startMenuPage, startMenuPageLength); logoMain=createTexture("logo.pcx", "menu"); logoRotate=createTexture("rotate_logo.pcx", "menu"); logoAlpha=31; glSetOutlineColor(0,RGB15(0,0,0)); //TEMP? glSetOutlineColor(1,RGB15(0,0,0)); //TEMP? glSetOutlineColor(7,RGB15(0,0,0)); //TEMP? NOGBA("END mem free : %dko (%do)",getMemFree()/1024,getMemFree()); fadeIn(); }
void hello_create(helloObjectInstance *me) { glInit(); glEnable(GL_ANTIALIAS); glClearColor(0, 0, 0, 31); glClearPolyID(63); glClearDepth(0x7FFF); glViewport(0, 0, 255, 191); }
//--------------------------------------------------------------------------------- void glInit_C(void) { //--------------------------------------------------------------------------------- glGlob = glGetGlobals(); glGlob->clearColor = 0; // init texture globals glGlob->activeTexture = 0; glGlob->nextBlock = (uint32*)0x06800000; glGlob->nextPBlock = 0; glGlob->nameCount = 1; while (GFX_STATUS & (1<<27)); // wait till gfx engine is not busy // Clear the FIFO GFX_STATUS |= (1<<29); // Clear overflows from list memory glResetMatrixStack(); // prime the vertex/polygon buffers glFlush(0); // reset the control bits GFX_CONTROL = 0; // reset the rear-plane(a.k.a. clear color) to black, ID=0, and opaque glClearColor(0,0,0,31); glClearPolyID(0); // reset stored texture locations glResetTextures(); // reset the depth to it's max glClearDepth(GL_MAX_DEPTH); GFX_TEX_FORMAT = 0; GFX_POLY_FORMAT = 0; glMatrixMode(GL_PROJECTION); glLoadIdentity(); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glMatrixMode(GL_TEXTURE); glLoadIdentity(); }
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 }
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() { 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
void initGame(void) { lcdMainOnTop(); int oldv=getMemFree(); NOGBA("mem free : %dko (%do)",getMemFree()/1024,getMemFree()); NOGBA("initializing..."); videoSetMode(MODE_5_3D | DISPLAY_BG3_ACTIVE); videoSetModeSub(MODE_5_2D | DISPLAY_BG3_ACTIVE); glInit(); vramSetPrimaryBanks(VRAM_A_TEXTURE,VRAM_B_TEXTURE,VRAM_C_LCD,VRAM_D_MAIN_BG_0x06000000); vramSetBankH(VRAM_H_SUB_BG); vramSetBankI(VRAM_I_SUB_BG_0x06208000); glEnable(GL_TEXTURE_2D); // glEnable(GL_ANTIALIAS); glDisable(GL_ANTIALIAS); glEnable(GL_BLEND); glEnable(GL_OUTLINE); glSetOutlineColor(0,RGB15(0,0,0)); //TEMP? glSetOutlineColor(1,RGB15(0,0,0)); //TEMP? glSetOutlineColor(7,RGB15(31,0,0)); //TEMP? glSetToonTableRange(0, 15, RGB15(8,8,8)); //TEMP? glSetToonTableRange(16, 31, RGB15(24,24,24)); //TEMP? glClearColor(31,31,0,31); glClearPolyID(63); glClearDepth(0x7FFF); glViewport(0,0,255,191); // initVramBanks(1); initVramBanks(2); initTextures(); initSound(); initCamera(NULL); initPlayer(NULL); initLights(); initParticles(); initMaterials(); loadMaterialSlices("slices.ini"); loadMaterials("materials.ini"); loadControlConfiguration("config.ini"); initElevators(); initWallDoors(); initTurrets(); initBigButtons(); initTimedButtons(); initEnergyBalls(); initPlatforms(); initCubes(); initEmancipation(); initDoors(); initSludge(); initPause(); initText(); NOGBA("lalala"); getPlayer()->currentRoom=&gameRoom; currentBuffer=false; getVramStatus(); fadeIn(); mainBG=bgInit(3, BgType_Bmp16, BgSize_B16_256x256, 0, 0); bgSetPriority(mainBG, 0); REG_BG0CNT=BG_PRIORITY(3); #ifdef DEBUG_GAME consoleInit(&bottomScreen, 3, BgType_Text4bpp, BgSize_T_256x256, 16, 0, false, true); consoleSelect(&bottomScreen); #endif // glSetToonTableRange(0, 14, RGB15(16,16,16)); // glSetToonTableRange(15, 31, RGB15(26,26,26)); initPortals(); //PHYSICS initPI9(); strcpy(&mapFilePath[strlen(mapFilePath)-3], "map"); newReadMap(mapFilePath, NULL, 255); transferRectangles(&gameRoom); makeGrid(); generateRoomGrid(&gameRoom); gameRoom.displayList=generateRoomDisplayList(&gameRoom, vect(0,0,0), vect(0,0,0), false); getVramStatus(); startPI(); NOGBA("START mem free : %dko (%do)",getMemFree()/1024,getMemFree()); NOGBA("vs mem free : %dko (%do)",oldv/1024,oldv); levelInfoCounter=60; }
int main() { int textureID; int i; 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); //this should work the same as the normal gl call glViewport(0,0,255,191); // 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); vramSetBankB(VRAM_B_LCD); REG_DISPCAPCNT = DCAP_MODE(DCAP_MODE_BLEND) //blend source A and source B //| DCAP_SRC_ADDR //this is not used since we are setting the display to render from VRAM | DCAP_SRC_B(DCAP_SRC_B_VRAM) | DCAP_SRC_A(DCAP_SRC_A_3DONLY) | DCAP_SIZE(DCAP_SIZE_256x192) | DCAP_OFFSET(0) //where to write the captured data within our chosen VRAM bank | DCAP_BANK(DCAP_BANK_VRAM_B) | DCAP_B(12) //blend mostly from B to make a very dramatic effect | DCAP_A(4) //and blend only a little bit from the new scene ; //but, dramatic effects tend to leave some garbage on the screen since the precision of the math is low, //and we're not putting a lot of dampening on the effect. //a more realistic value might be 8 and 8, but perhaps in a more complex 3d scene the garbage isn't such a bad thing //since the scene is changing constantly DisplayEnableMotionBlur(); bool displayBlurred = true; 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) { 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); glPushMatrix(); //move it away from the camera glTranslatef32(0, 0, floattof32(-1)); glRotateX(rotateX); glRotateY(rotateY); glMatrixMode(GL_TEXTURE); glLoadIdentity(); glMatrixMode(GL_MODELVIEW); 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)); //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 | POLY_FORMAT_LIGHT1 | POLY_FORMAT_LIGHT2 | POLY_FORMAT_LIGHT3 ) ; 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; if(keysDown() & KEY_A) { displayBlurred = !displayBlurred; if(displayBlurred) DisplayEnableMotionBlur(); else DisplayEnableNormal(); } glBindTexture(0, textureID); //draw the obj glBegin(GL_QUAD); for(i = 0; i < 6; i++) drawQuad(i); glEnd(); glPopMatrix(1); glFlush(0); swiWaitForVBlank(); if(keys & KEY_START) break; //the display capture enable bit must be set again each frame if you want to continue capturing. REG_DISPCAPCNT |= DCAP_ENABLE; } return 0; }//end main
int main() { // initialize the geometry engine glInit(); // Setup the Main screen for 3D videoSetMode(MODE_0_3D); //map some vram to background for printing vramSetBankC(VRAM_C_MAIN_BG_0x06000000); consoleInit(0,1, BgType_Text4bpp, BgSize_T_256x256, 31,0, true, true); //put bg 0 at a lower priority than the text background bgSetPriority(0, 1); // 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_NONE); // Set the current matrix to be the model matrix glMatrixMode(GL_MODELVIEW); iprintf(" Hello DS World\n"); iprintf(" www.devkitpro.org\n"); iprintf(" www.drunkencoders.com\n"); while (1) { DrawGLScene(); // flush to screen glFlush(0); // wait for the screen to refresh swiWaitForVBlank(); printf("\x1b[15;5H rtri = %f \n", rtri); printf("\x1b[16;5H rquad = %f \n", rquad); rtri+=0.9f; // Increase The Rotation Variable For The Triangle ( NEW ) rquad-=0.75f; // Decrease The Rotation Variable For The Quad ( NEW ) rtri = fmodf( rtri , 360 ); rquad = fmodf( rquad, 360 ); } return 0; }
//------------------------------------------------------- int main() { //------------------------------------------------------- videoSetMode(MODE_0_3D); videoSetModeSub(MODE_5_2D); glInit(); // sub sprites hold the bottom image when 3D directed to top initSubSprites(); // sub background holds the top image when 3D directed to bottom bgInitSub(3, BgType_Bmp16, BgSize_B16_256x256, 0, 0); //------------------------------------------------------- // Setup gl //------------------------------------------------------- glEnable(GL_ANTIALIAS); glClearColor(0,0,0,31); glClearPolyID(63); glClearDepth(0x7FFF); glViewport(0,0,255,191); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(70, 256.0 / 192.0, 0.1, 100); glPolyFmt(POLY_ALPHA(31) | POLY_CULL_NONE); //------------------------------------------------------- // main loop //------------------------------------------------------- bool top = true; while (true) { // wait for capture unit to be ready while(REG_DISPCAPCNT & DCAP_ENABLE); scanKeys(); int keys = keysDown(); if (keys & KEY_START) break; //------------------------------------------------------- // Switch render targets //------------------------------------------------------- top = !top; if(top) { lcdMainOnBottom(); vramSetBankC(VRAM_C_LCD); vramSetBankD(VRAM_D_SUB_SPRITE); REG_DISPCAPCNT = DCAP_BANK(2) | DCAP_ENABLE | DCAP_SIZE(3); } else { lcdMainOnTop(); vramSetBankD(VRAM_D_LCD); vramSetBankC(VRAM_C_SUB_BG); REG_DISPCAPCNT = DCAP_BANK(3) | DCAP_ENABLE | DCAP_SIZE(3); } //------------------------------------------------------- // Render the scene //------------------------------------------------------- glMatrixMode(GL_MODELVIEW); renderScene(top); glFlush(0); } 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; }
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() { int rotateX = 0; int rotateY = 0; //set mode 0, enable BG0 and set it to 3D videoSetMode(MODE_0_3D); // intialize 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); vramSetBankA(VRAM_A_TEXTURE); glEnable(GL_TEXTURE_2D); int cafe_texid; glGenTextures( 1, &cafe_texid ); glBindTexture( 0, cafe_texid ); glTexImage2D( 0, 0, GL_RGB, TEXTURE_SIZE_128 , TEXTURE_SIZE_128, 0, GL_TEXTURE_WRAP_S|GL_TEXTURE_WRAP_T|TEXGEN_NORMAL, (u8*)cafe_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); while(1) { //TEXGEN_NORMAL helpfully pops our normals into this matrix and uses the result as texcoords glMatrixMode(GL_TEXTURE); glLoadIdentity(); GLvector tex_scale = { 64<<16, -64<<16, 1<<16 }; glScalev( &tex_scale ); //scale normals up from (-1,1) range into texcoords glRotateXi(rotateX); //rotate texture-matrix to match the camera glRotateYi(rotateY); glMatrixMode(GL_POSITION); glLoadIdentity(); glTranslatef32(0, 0, floattof32(-3)); glRotateXi(rotateX); glRotateYi(rotateY); glMaterialf(GL_EMISSION, RGB15(31,31,31)); glPolyFmt(POLY_ALPHA(31) | POLY_CULL_BACK ); scanKeys(); u32 keys = keysHeld(); if( keys & KEY_UP ) rotateX += 3<<3; if( keys & KEY_DOWN ) rotateX -= 3<<3; if( keys & KEY_LEFT ) rotateY += 3<<3; if( keys & KEY_RIGHT ) rotateY -= 3<<3; int pen_delta[2]; get_pen_delta( &pen_delta[0], &pen_delta[1] ); rotateY -= pen_delta[0]; rotateX -= pen_delta[1]; glBindTexture( 0, cafe_texid ); glCallList((u32*)teapot_bin); glFlush(0); } return 0; }//end main
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
int main() { // initialize gl glInit(); u32 rotateX = 0; u32 rotateY = 0; //set mode 0, enable BG0 and set it to 3D videoSetMode(MODE_0_3D); // used to hold touched position touchPosition touchXY; lcdMainOnBottom(); // we are going to be touching the 3D display // enable edge outlining, this will be used to show which object is selected glEnable(GL_OUTLINE); //set the first outline color to white glSetOutlineColor(0,RGB15(31,31,31)); int viewport[]={0,0,255,191}; // used later for gluPickMatrix() // setup the rear plane glClearColor(0,0,0,0); // set BG to black and clear glClearPolyID(0); // the BG and polygons will have the same ID unless a polygon is highlighted glClearDepth(0x7FFF); // setup the camera gluLookAt( 0.0, 0.0, 1.0, //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); // setup the light while(1) { // handle key input 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; // get touchscreen position touchRead(&touchXY); glViewport(0,0,255,191); // set the viewport to fullscreen // setup the projection matrix for regular drawing glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(60, 256.0 / 192.0, 0.1, 20); glMatrixMode(GL_MODELVIEW); // use the modelview matrix while drawing glPushMatrix(); // save the state of the current matrix(the modelview matrix) { glTranslatef32(0,0,floattof32(-6)); glRotateXi(rotateX); // add X rotation to the modelview matrix glRotateYi(rotateY); // add Y rotation to the modelview matrix glPushMatrix(); // save the state of the modelview matrix while making the first pass { // draw the scene for displaying glTranslatef32(floattof32(2.9),floattof32(0),floattof32(0)); // translate the modelview matrix to the drawing location if(clicked==CONE) { glPolyFmt(POLY_ALPHA(31) | POLY_CULL_BACK | POLY_FORMAT_LIGHT0 | POLY_ID(1)); // set a poly ID for outlining } else { glPolyFmt(POLY_ALPHA(31) | POLY_CULL_BACK | POLY_FORMAT_LIGHT0 | POLY_ID(0)); // set a poly ID for no outlining (same as BG) } glCallList((u32*)cone_bin); // draw a green cone from a predefined packed command list glTranslatef32(floattof32(-3),floattof32(1.8),floattof32(2)); // translate the modelview matrix to the drawing location if(clicked==CYLINDER) { glPolyFmt(POLY_ALPHA(31) | POLY_CULL_BACK | POLY_FORMAT_LIGHT0 | POLY_ID(1)); // set a poly ID for outlining } else { glPolyFmt(POLY_ALPHA(31) | POLY_CULL_BACK | POLY_FORMAT_LIGHT0 | POLY_ID(0)); // set a poly ID for no outlining (same as BG) } glCallList((u32*)cylinder_bin); // draw a blue cylinder from a predefined packed command list glTranslatef32(floattof32(.5),floattof32(-2.6),floattof32(-4)); // translate the modelview matrix to the drawing location if(clicked==SPHERE) { glPolyFmt(POLY_ALPHA(31) | POLY_CULL_BACK | POLY_FORMAT_LIGHT0 | POLY_ID(1)); // set a poly ID for outlining } else { glPolyFmt(POLY_ALPHA(31) | POLY_CULL_BACK | POLY_FORMAT_LIGHT0 | POLY_ID(0)); // set a poly ID for no outlining (same as BG) } glCallList((u32*)sphere_bin); // draw a red sphere from a predefined packed command list } glPopMatrix(1); // restores the modelview matrix to where it was just rotated // draw the scene again for picking { clicked = NOTHING; //reset what was clicked on closeW = 0x7FFFFFFF; //reset the distance //set the viewport to just off-screen, this hides all rendering that will be done during picking glViewport(0,192,0,192); // setup the projection matrix for picking glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPickMatrix((touchXY.px),(191-touchXY.py),4,4,viewport); // render only what is below the cursor gluPerspective(60, 256.0 / 192.0, 0.1, 20); // this must be the same as the original perspective matrix glMatrixMode(GL_MODELVIEW); // switch back to modifying the modelview matrix for drawing glTranslatef32(floattof32(2.9),floattof32(0),floattof32(0)); // translate the modelview matrix to the drawing location startCheck(); glCallList((u32*)cone_bin); // draw a cone from a predefined packed command list endCheck(CONE); glTranslatef32(floattof32(-3),floattof32(1.8),floattof32(2)); // translate the modelview matrix to the drawing location startCheck(); glCallList((u32*)cylinder_bin); // draw a cylinder from a predefined packed command list endCheck(CYLINDER); glTranslatef32(floattof32(.5),floattof32(-2.6),floattof32(-4)); // translate the modelview matrix to the drawing location startCheck(); glCallList((u32*)sphere_bin); // draw a sphere from a predefined packed command list endCheck(SPHERE); } } glPopMatrix(1); // restores the modelview matrix to its original state glFlush(0); // wait for everything to be drawn before starting on the next frame } return 0; }//end main