|
Mise à jour : 14/10/2009
Difficulté :
Intermédiaire
282 visites depuis 7 jours,
classé 354/786
|
.
), la libnds. La 3D ne peut être utilisée uniquement sur l'écran tactile. Il faut tout d'abord initialiser OpenGL avec void glInit();
. Ensuite, on va définir notre caméra en plein écran avec void glViewport(uint8 x1, uint8 y1, uint8 x2, uint8 y2);
, nous allons tout le temps l'utiliser comme ceci :1 | glViewport(0,0,255,191); |
1 | glClearColor(0,0,0,31); |
1 2 3 | glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(70,(double)256/192,0.1,1000); |
1 | glPolyFmt(POLY_ALPHA(31) | POLY_CULL_NONE ); |
1 2 | glMatrixMode( GL_MODELVIEW ); glLoadIdentity(); |
1 | void gluLookAt(float eyex, float eyey, float eyez,float lookAtx, float lookAty, float lookAtz, float upx, float upy, float upz); |
1 | glFlush(0); |
!1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 | #include <PA9.h> #define LARGEUR_ECRAN 256 #define HAUTEUR_ECRAN 192 int main(int argc, char ** argv) { int i=0; PA_Init(); PA_InitVBL(); videoSetMode(MODE_0_3D); glInit(); glViewport(0,0,LARGEUR_ECRAN-1,HAUTEUR_ECRAN-1); glClearColor(0,0,0,31); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(70,(double)LARGEUR_ECRAN/HAUTEUR_ECRAN,.1,1000); glPolyFmt(POLY_ALPHA(31) | POLY_CULL_NONE ); while(1) { glMatrixMode( GL_MODELVIEW ); glLoadIdentity( ); gluLookAt(3,4,2,0,0,0,0,0,1); glRotatef(i,0,0,1); glBegin(GL_QUADS); glColor3b(255,0,0); //face rouge glVertex3f(1,1,1); glVertex3f(1,1,-1); glVertex3f(-1,1,-1); glVertex3f(-1,1,1); glColor3b(0,255,0); //face verte glVertex3f(1,-1,1); glVertex3f(1,-1,-1); glVertex3f(1,1,-1); glVertex3f(1,1,1); glColor3b(0,0,255); //face bleue glVertex3f(-1,-1,1); glVertex3f(-1,-1,-1); glVertex3f(1,-1,-1); glVertex3f(1,-1,1); glColor3b(255,255,0); //face jaune glVertex3f(-1,1,1); glVertex3f(-1,1,-1); glVertex3f(-1,-1,-1); glVertex3f(-1,-1,1); glColor3b(0,255,255); //face cyan glVertex3f(1,1,-1); glVertex3f(1,-1,-1); glVertex3f(-1,-1,-1); glVertex3f(-1,1,-1); glColor3b(255,0,255); //face magenta glVertex3f(1,-1,1); glVertex3f(1,1,1); glVertex3f(-1,1,1); glVertex3f(-1,-1,1); glEnd(); i++; i%=360; glFlush(0); PA_WaitForVBL(); } return 0; } |
.
.
).


1 | vramSetMainBanks(VRAM_A_TEXTURE,VRAM_B_TEXTURE,VRAM_C_LCD,VRAM_D_LCD); |
. Si certaines textures ne s'affichent pas, c'est qu'il n'y a pas assez de mémoire texture, donc vous pouvez initialiser d'autres VRAM en mode texture.1 | glEnable(GL_TEXTURE_2D); |
1 2 3 4 5 6 7 8 9 10 11 | #include "tex_1.h" int texture; // Contiendra notre texture sImage pcx; // Représente l'image loadPCX((u8*)tex_1, &pcx); // On charge l'image image8to16(&pcx); // Obligatoire sinon un rendu bizarre :) // On alloue de la mémoire pour la texture glGenTextures(1, &texture); glBindTexture(0, texture); // On crée la texture glTexImage2D(0, 0, GL_RGB, TEXTURE_SIZE_128 , TEXTURE_SIZE_128, 0, TEXGEN_TEXCOORD, pcx.image.data8); imageDestroy(&pcx); // On détruit l'image (mais pas la texture :p ) |
1 | glBindTexture(GL_TEXTURE_2D, texture); |
1 | glTexCoord2f(x,y); glVertex3f(x1,y1,z); |
1 2 3 4 5 6 7 8 9 10 11 12 | int chargerTexture(const u8 *tex,GL_TEXTURE_SIZE_ENUM width,GL_TEXTURE_SIZE_ENUM height) { sImage pcx; int texture; loadPCX((u8*)tex, &pcx); image8to16(&pcx); glGenTextures(1, &texture); glBindTexture(0, texture); glTexImage2D(0, 0, GL_RGB, width , height, 0, TEXGEN_TEXCOORD, pcx.image.data8); imageDestroy(&pcx); return texture; } |
1 2 | #include "tex_1.h" // La texture int texture=chargerTexture(tex_1,TEXTURE_SIZE_128,TEXTURE_SIZE_128); |
) : télécharger le pack.1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 | #include <PA9.h> #include "tex_1.h" #include "tex_2.h" #include "tex_3.h" #include "tex_4.h" #include "tex_5.h" #include "tex_6.h" #define LARGEUR_ECRAN 256 #define HAUTEUR_ECRAN 192 int chargerTexture(const u8 *tex,GL_TEXTURE_SIZE_ENUM width,GL_TEXTURE_SIZE_ENUM height); int main(int argc, char ** argv) { int x1=0,x2=0,y1=0,y2=0,c=0; int texture[6]; float rotationX=0.,rotationZ=0.; PA_Init(); PA_InitVBL(); videoSetMode(MODE_0_3D); vramSetMainBanks(VRAM_A_TEXTURE,VRAM_B_TEXTURE,VRAM_C_LCD,VRAM_D_LCD); glInit(); glEnable(GL_TEXTURE_2D); glViewport(0,0,LARGEUR_ECRAN-1,HAUTEUR_ECRAN-1); glClearColor(0,0,0,31); texture[0]=chargerTexture(tex_1,TEXTURE_SIZE_128,TEXTURE_SIZE_128); texture[1]=chargerTexture(tex_2,TEXTURE_SIZE_128,TEXTURE_SIZE_128); texture[2]=chargerTexture(tex_3,TEXTURE_SIZE_128,TEXTURE_SIZE_128); texture[3]=chargerTexture(tex_4,TEXTURE_SIZE_128,TEXTURE_SIZE_128); texture[4]=chargerTexture(tex_5,TEXTURE_SIZE_128,TEXTURE_SIZE_128); texture[5]=chargerTexture(tex_6,TEXTURE_SIZE_128,TEXTURE_SIZE_128); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(70,(double)LARGEUR_ECRAN/HAUTEUR_ECRAN,.1,1000); glPolyFmt(POLY_ALPHA(31) | POLY_CULL_NONE ); while(1) { glMatrixMode( GL_MODELVIEW ); glLoadIdentity( ); gluLookAt(3,4,2,0,0,0,0,0,1); glRotatef(rotationX,1,0,0); glRotatef(rotationZ,0,0,1); glColor3b(255,255,255); glBindTexture(GL_TEXTURE_2D, texture[0]); glBegin(GL_QUADS); glTexCoord2f(0,0);glVertex3f(1,1,1); glTexCoord2f(0,1);glVertex3f(1,1,-1); glTexCoord2f(1,1);glVertex3f(-1,1,-1); glTexCoord2f(1,0);glVertex3f(-1,1,1); glEnd(); glBindTexture(GL_TEXTURE_2D, texture[1]); glBegin(GL_QUADS); glTexCoord2f(0,0);glVertex3f(1,-1,1); glTexCoord2f(0,1);glVertex3f(1,-1,-1); glTexCoord2f(1,1);glVertex3f(1,1,-1); glTexCoord2f(1,0);glVertex3f(1,1,1); glEnd(); glBindTexture(GL_TEXTURE_2D, texture[5]); glBegin(GL_QUADS); glTexCoord2f(0,0);glVertex3f(-1,-1,1); glTexCoord2f(0,1);glVertex3f(-1,-1,-1); glTexCoord2f(1,1);glVertex3f(1,-1,-1); glTexCoord2f(1,0);glVertex3f(1,-1,1); glEnd(); glBindTexture(GL_TEXTURE_2D, texture[4]); glBegin(GL_QUADS); glTexCoord2f(0,0);glVertex3f(-1,1,1); glTexCoord2f(0,1);glVertex3f(-1,1,-1); glTexCoord2f(1,1);glVertex3f(-1,-1,-1); glTexCoord2f(1,0);glVertex3f(-1,-1,1); glEnd(); glBindTexture(GL_TEXTURE_2D, texture[2]); glBegin(GL_QUADS); glTexCoord2f(0,0);glVertex3f(1,1,-1); glTexCoord2f(0,1);glVertex3f(1,-1,-1); glTexCoord2f(1,1);glVertex3f(-1,-1,-1); glTexCoord2f(1,0);glVertex3f(-1,1,-1); glEnd(); glBindTexture(GL_TEXTURE_2D, texture[3]); glBegin(GL_QUADS); glTexCoord2f(0,0);glVertex3f(1,-1,1); glTexCoord2f(0,1);glVertex3f(1,1,1); glTexCoord2f(1,1);glVertex3f(-1,1,1); glTexCoord2f(1,0);glVertex3f(-1,-1,1); glEnd(); if(Stylus.Held) { if(!(c%2)) { x1=Stylus.X; y1=Stylus.Y; } else { x2=Stylus.X; y2=Stylus.Y; rotationZ+=x1-x2; rotationX+=(y2-y1)*LARGEUR_ECRAN/HAUTEUR_ECRAN; } c++; } else if(Stylus.Released) c=0; glFlush(0); PA_WaitForVBL(); } return 0; } int chargerTexture(const u8 *tex,GL_TEXTURE_SIZE_ENUM width,GL_TEXTURE_SIZE_ENUM height) { sImage pcx; int texture; loadPCX((u8*)tex, &pcx); image8to16(&pcx); glGenTextures(1, &texture); glBindTexture(0, texture); glTexImage2D(0, 0, GL_RGB, width , height, 0, TEXGEN_TEXCOORD, pcx.image.data8); imageDestroy(&pcx); return texture; } |
?
).1 | #include "OBJlib.h"
|
1 | MeshObj obj; |
1 | charger_obj(&obj,"modele.obj",TEXTURE_SIZE_128,TEXTURE_SIZE_128); |
!