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 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207
| void gener_texture(GLuint *texture, unsigned char *image, GLuint width, GLuint height) {
// Generation et attribution du nom de texture
glGenTextures (1, texture);
// creation et utilisation de la texture
glBindTexture(GL_TEXTURE_2D, *texture);
// charge les parametres des textures
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
// definition des textures
glTexImage2D (GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA,
GL_UNSIGNED_BYTE, image);
}
static Bool
dockpInitScreen (CompPlugin *p,
CompScreen *s)
{
int i, j, c;
DOCKP_DISPLAY (s->display);
BenchScreen *bs = (BenchScreen *) calloc (1, sizeof (BenchScreen) );
s->base.privates[bd->screenPrivateIndex].ptr = bs;
WRAP (bs, s, paintOutput, dockpPaintOutput);
WRAP (bs, s, preparePaintScreen, dockpPreparePaintScreen);
WRAP (bs, s, donePaintScreen, dockpDonePaintScreen);
bs->width = 1280;
bs->height = 1024;
bs->alpha = 0.0;
glViewport(-(bs->width / 2), -(bs->height / 2), bs->width * 2, bs->height * 2);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
// definit les modes de stockages des pixels
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
// allocation des indexes contigus
fontOffset = glGenLists(256);
for(i = 0; i < 256; i++) {
// specifie le debut de la liste d affichage
glNewList(fontOffset + i, GL_COMPILE);
glBitmap(8, 16, 0.0, 2.0, 10.0, 0.0, letters[i]);
glEndList();
}
gener_texture(&bs->halotTex0, image_halot_0, 128, 128);
gener_texture(&bs->halotTex1, image_halot_1, 128, 128);
gener_texture(&bs->iconeTex[0], image_icone0, 200, 200);
gener_texture(&bs->iconeTex[1], image_icone1, 200, 200);
gener_texture(&bs->backTex, image_data, dock.width, dock.height);
// definit les proprietes de matiere des objets de la scene
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, material.specular);
glMaterialfv(GL_FRONT, GL_SPECULAR, material.specular);
//glMaterialfv(GL_FRONT, GL_SHININESS, material.shininess);
// definit les proprietes de la lumiere
glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient);
for(i = 0; i < 10; i++) {
etoile.halot[i].actif = 0;
}
bs->curseur = XCreateFontCursor(s->display->display, XC_center_ptr);
GLERR;
return TRUE;
}
static Bool
dockpPaintOutput (CompScreen *s,
const ScreenPaintAttrib *sa,
const CompTransform *transform,
Region region,
CompOutput *output,
unsigned int mask)
{
Bool status;
CompTransform sTransform = *transform;
unsigned int i;
char str[] = "Bonjour";
DOCKP_SCREEN (s);
UNWRAP (bs, s, paintOutput);
status = (*s->paintOutput) (s, sa, transform, region, output, mask);
WRAP (bs, s, paintOutput, dockpPaintOutput);
if(bs->alpha <= 0.0)
return status;
glGetError();
glPushAttrib (GL_LIST_BIT | GL_COLOR_BUFFER_BIT | GL_TEXTURE_BIT);
GLERR;
transformToScreenSpace (s, output, -DEFAULT_Z_CAMERA, &sTransform);
glPushMatrix ();
glLoadMatrixf (sTransform.m);
glOrtho(-1, 1, -1, 1, -200, 200);
glShadeModel(GL_SMOOTH);
// activation du blending
glEnable (GL_BLEND);
// blending alpha
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
// parametre les fonctions combinatoires de texturage
glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
// Transformation de translation
glTranslatef (dockpGetPositionX (s->display) - (float)dock.width + dock.decallage,
dockpGetPositionY (s->display), 0);
// activations
glEnable (GL_TEXTURE_2D);
glEnable (GL_MAP1_VERTEX_3);
glColor4f (1.0, 1.0, 1.0, 1.0);
glRasterPos2i(200, 200);
glListBase(fontOffset);
glCallLists(8, GL_UNSIGNED_BYTE, str);
if(etoile.actif) {
// creation et utilisation de la texture
glBindTexture (GL_TEXTURE_2D, bs->halotTex1);
// affichage du halot avec sa texture
texture_4p(etoile.halot[0].alpha, (float)etoile.halot[0].b[0], (float)etoile.halot[0].b[1],
etoile.size + (float)etoile.halot[0].b[0], etoile.size + (float)etoile.halot[0].b[1],
(float)etoile.halot[0].b[2]);
// creation et utilisation de la texture
glBindTexture (GL_TEXTURE_2D, bs->halotTex0);
// affichage du halot avec sa texture
for(i = 1; i < 20; i++)
if(etoile.halot[i].actif) {
texture_4p(etoile.halot[i].alpha, (float)etoile.halot[i].b[0], (float)etoile.halot[i].b[1],
-(float)i * 1 + etoile.size + (float)etoile.halot[i].b[0], -(float)i * 2 + etoile.size
+ (float)etoile.halot[i].b[1], (float)etoile.halot[i].b[2]);
}
}
// creation et utilisation de la texture
glBindTexture (GL_TEXTURE_2D, bs->backTex);
// affichage du plan avec sa texture
texture_4p(1.0, 0.0, 0.0, dock.width, dock.height, 0.0);
// affichage des lumieres
glLightfv(GL_LIGHT0, GL_POSITION, light[0].position);
glLightfv(GL_LIGHT0, GL_SPECULAR, light[0].color);
glLightfv(GL_LIGHT0, GL_DIFFUSE, light[0].color);
glEnable (GL_LIGHTING);
glEnable (GL_LIGHT0);
glTranslatef(icone[0].x, 0, -25);
glScalef(1, 1, 1);
for(i=0; i < NBR_ICONES; i++) {
glTranslatef(0, 125, 0);
glScalef(.25 + icone[i].size, .25 + icone[i].size, .25);
glBindTexture (GL_TEXTURE_2D, bs->iconeTex[i]);
// specifie les donnees du tableau, vertices + normales + textures
glInterleavedArrays(GL_T2F_N3F_V3F, 0, vicone);
// affichage des icones
glDrawElements(GL_TRIANGLES, NBR_VERTICES_ICONE, GL_UNSIGNED_BYTE, indices_icone);
glScalef(1/(.25 + icone[i].size), 1/(.25 + icone[i].size), 1/.25);
}
// on detruit la texture 2D
glBindTexture (GL_TEXTURE_2D, 0);
glDisable (GL_BLEND);
glDisable (GL_TEXTURE_2D);
glDisable (GL_LIGHTING);
glDisable (GL_LIGHT0);
glDisable (GL_MAP1_VERTEX_3);
glPopMatrix();
glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
glColor4f (1.0, 1.0, 1.0, 1.0);
glPopAttrib();
glGetError();
return status;
} |
Partager