|
Luss
Débutant
Inscription: 11 Juil 2007 23:36 Messages: 4
|
Bonjour à tous, nouveau sur nintendomax, nouveau dans la dev nds, bref je patoge un peu... En attendant de comprendre le fonctionnement de GL_FOG et POLY_FOG, j'ai voulu simuler mon ch'tit brouillard avec plusieurs plans transparents... Mon problème: -le .nds fonctionne sur l'émulateur iDeaS -il ne fonctionne pas sur ma DS (avec R4) voici le code librement adapté de l'exemples No8 de Nehe: (il faut juste récupérer le makefile et le répertoire /data de cet exemple et ca devrait le faire) Code: #include <nds.h> #include <malloc.h> //needed to load pcx files #include <nds/arm9/image.h>
#include "drunkenlogo_pcx.h"
int DrawGLScene();
int atmo = 1;
GLfloat z=-5.0f; // Depth Into The Screen GLfloat xrot; GLfloat yrot;
GLfloat LightAmbient[]= { 0.5f, 0.5f, 0.5f, 1.0f }; GLfloat LightDiffuse[]= { 1.0f, 1.0f, 1.0f, 1.0f }; GLfloat LightPosition[]= { 0.0f, 0.0f, 2.0f, 1.0f };
int texture[3]; // Storage For 3 Textures (only going to use 1 on the DS for this demo)
int LoadGLTextures() // Load PCX files And Convert To Textures { sImage pcx;
//load our texture loadPCX((u8*)drunkenlogo_pcx, &pcx); image8to16(&pcx);
//DS supports no filtering of anykind so no need for more than one texture glGenTextures(1, &texture[0]); glBindTexture(0, texture[0]); glTexImage2D(0, 0, GL_RGB, TEXTURE_SIZE_128 , TEXTURE_SIZE_128, 0, TEXGEN_TEXCOORD, pcx.image.data8);
imageDestroy(&pcx);
return TRUE; }
int main() { // Turn on everything powerON(POWER_ALL); // Setup the Main screen for 3D videoSetMode(MODE_0_3D); vramSetBankA(VRAM_A_TEXTURE); //NEW must set up some memory for textures
// IRQ basic setup irqInit(); irqSet(IRQ_VBLANK, 0);
// initialize the geometry engine glInit(); // enable textures glEnable(GL_TEXTURE_2D); glEnable(GL_BLEND); glEnable(GL_FOG); // enable antialiasing glEnable(GL_ANTIALIAS); // setup the rear plane glClearColor(21,22,31,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); LoadGLTextures(); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(35, 256.0 / 192.0, 0.1, 100); //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, floattov10(-1.0), 0); glColor3f(1,1,1); glMatrixMode(GL_MODELVIEW); //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(); // Set the current matrix to be the model matrix glMatrixMode(GL_MODELVIEW); while (1) { //these little button functions are pretty handy scanKeys(); if (keysHeld() & KEY_UP) { z-=0.1f; } if (keysHeld() & KEY_DOWN) { z+=0.1f; } if (keysHeld() & KEY_L) atmo = 0; if (keysHeld() & KEY_R) atmo = 1; DrawGLScene();
// flush to screen glFlush(0); // wait for the screen to refresh swiWaitForVBlank(); } return 0; }
int DrawGLScene() // Here's Where We Do All The Drawing { glLoadIdentity(); // Reset The View glTranslatef(0.0f,0.0f,z); glRotatef(xrot,1.0f,0.0f,0.0f); glRotatef(yrot,0.0f,1.0f,0.0f); glPolyFmt(POLY_ALPHA(31) | POLY_CULL_NONE | POLY_FORMAT_LIGHT0 | POLY_FOG);
glBindTexture(GL_TEXTURE_2D, texture[0]); //no filters to swtich between glBegin(GL_QUADS); glColor3b(31,31,31); // Front Face glNormal3f( 0.0f, 0.0f, 1.0f); glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 1.0f); glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f, 1.0f); glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, 1.0f); glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, 1.0f); // Back Face glNormal3f( 0.0f, 0.0f,-1.0f); glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f); glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, 1.0f, -1.0f); glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, 1.0f, -1.0f); glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f); // Top Face glNormal3f( 0.0f, 1.0f, 0.0f); glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, -1.0f); glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, 1.0f, 1.0f); glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, 1.0f, 1.0f); glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, -1.0f); // Bottom Face glNormal3f( 0.0f,-1.0f, 0.0f); glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, -1.0f, -1.0f); glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, -1.0f, -1.0f); glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, 1.0f); glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 1.0f); // Right face glNormal3f( 1.0f, 0.0f, 0.0f); glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f); glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, -1.0f); glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, 1.0f, 1.0f); glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, 1.0f); // Left Face glNormal3f(-1.0f, 0.0f, 0.0f); glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f); glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 1.0f); glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, 1.0f, 1.0f); glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, -1.0f); glEnd(); if(atmo==1) { //draw atmosphere glLoadIdentity(); glTranslatef(0.0f,0.0f,-5.0f); glPolyFmt(POLY_ALPHA(5) | POLY_CULL_NONE | POLY_FORMAT_LIGHT0); glBegin(GL_QUADS); glNormal3f( 0.0f, 0.0f, 1.0f); //glColor3b(31,31,31); glTexCoord2f(0.5f, 0.6f); //have a white pixel glVertex3f( -6.0f, -4.0f, -1.0f); glVertex3f( -6.0f, 4.0f, -1.0f); glVertex3f( 6.0f, 4.0f, -1.0f); glVertex3f( 6.0f, -4.0f, -1.0f); glVertex3f( -5.0f, -3.5f, -0.0f); glVertex3f( -5.0f, 3.5f, -0.0f); glVertex3f( 5.0f, 3.5f, -0.0f); glVertex3f( 5.0f, -3.5f, -0.0f); glVertex3f( -4.0f, -3.0f, 1.0f); glVertex3f( -4.0f, 3.0f, 1.0f); glVertex3f( 4.0f, 3.0f, 1.0f); glVertex3f( 4.0f, -3.0f, 1.0f); glVertex3f( -3.0f, -2.2f, 2.0f); glVertex3f( -3.0f, 2.2f, 2.0f); glVertex3f( 3.0f, 2.2f, 2.0f); glVertex3f( 3.0f, -2.2f, 2.0f); glEnd(); } xrot +=1.0f; yrot +=2.0f; return TRUE; }
Voilou... Je n'arrive pas comprendre ce qui va de travers... le code? le R4? la DS? Si quelqu'un pouvait éclairer ma lanterne, ca me sortirait du brouillard dans lequel je suis Merci d'avance!
|