IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

GLUT Discussion :

superposition image / texte


Sujet :

GLUT

  1. #1
    Futur Membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Février 2012
    Messages
    8
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Février 2012
    Messages : 8
    Points : 8
    Points
    8
    Par défaut superposition image / texte
    Bonjour à tous,

    J'ai un soucis avec glut.
    Je n'arrive pas à afficher du texte par dessus une image..
    Le texte décale l'image
    Savez vous d'ou vient le problème ?

    J'affiche l'image et le texte à la fin de la fonction display.

    Merci.

    Code:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    void display(void)
    {
    	actualiseCase(mapLabyrinthe, &caseX, &caseY);
     
    	//printf("%d %d %f %f %d\n", caseX, caseY, pos[0], pos[2], *getPixel(mapLabyrinthe, caseX, caseY));
    	//printf("%f %f %f %f\n", lastx, lasty, xrot, yrot);
    	//lastx = (int) lastx % 360;
    	//lasty = (int) lasty % 360;
    	//glutWarpPointer((int) lastx, (int) lasty);
     
    	// Effacement des tampons de couleur et de profondeur
    	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
     
    	// Sauvegarde de la matrice de transformations
    	glPushMatrix();
     
    	if(skeys[GLUT_KEY_UP])
    	{
    		if(*getPixel(mapLabyrinthe, caseX, caseY) == 0)
    		{
    			pos[0] = tmpPosition[0];
    			pos[2] = tmpPosition[2];
     
    			return;
    		}
     
    		tmpPosition[0] = pos[0];
    		tmpPosition[2] = pos[2];
     
    		pos[0] += sin(yrot * PIOVER180) * MOVE_STEP;
    		pos[2] -= cos(yrot * PIOVER180) * MOVE_STEP;
    	}
    	else if(skeys[GLUT_KEY_DOWN])
    	{
    		if(*getPixel(mapLabyrinthe, caseX, caseY) == 0)
    		{
    			pos[0] = tmpPosition[0];
    			pos[2] = tmpPosition[2];
     
    			return;
    		}
     
    		tmpPosition[0] = pos[0];
    		tmpPosition[2] = pos[2];
     
    		pos[0] -= sin(yrot * PIOVER180) * MOVE_STEP;
    		pos[2] += cos(yrot * PIOVER180) * MOVE_STEP;
    	}
     
    	if(skeys[GLUT_KEY_LEFT])
    	{
    		if(*getPixel(mapLabyrinthe, caseX, caseY) == 0)
    		{
    			pos[0] = tmpPosition[0];
    			pos[2] = tmpPosition[2];
     
    			return;
    		}
     
    		tmpPosition[0] = pos[0];
    		tmpPosition[2] = pos[2];
     
    		pos[0] -= cos(yrot * PIOVER180) * MOVE_STEP;
    		pos[2] -= sin(yrot * PIOVER180) * MOVE_STEP;
    	}
    	else if(skeys[GLUT_KEY_RIGHT])
    	{
    		if(*getPixel(mapLabyrinthe, caseX, caseY) == 0)
    		{
    			pos[0] = tmpPosition[0];
    			pos[2] = tmpPosition[2];
     
    			return;
    		}
     
    		tmpPosition[0] = pos[0];
    		tmpPosition[2] = pos[2];
     
    		pos[0] += cos(yrot * PIOVER180) * MOVE_STEP;
    		pos[2] += sin(yrot * PIOVER180) * MOVE_STEP;
    	}
     
    	// Transformations pour positionner le point de vue du joueur
    	mouseMovement(lastx, lasty);
    	glRotatef(xrot, 1.0f, 0.0f, 0.0f);
    	glRotatef(yrot, 0.0f, 1.0f, 0.0f);
    	glTranslated(-pos[0],-pos[1],-pos[2]);
     
    	int i, j, pixel;
     
    	// Dessin de la scene
    	for(i = 0; i < mapLabyrinthe->h; i++)
    	{
    		for(j = 0; j < mapLabyrinthe->w; j++)
    		{
    			pixel = *getPixel(mapLabyrinthe, i, j);
     
    			if(pixel != 0)
    				drawTestScene(i, j, (mapLabyrinthe->rapport) / 2, -((mapLabyrinthe->rapport) / 4));
    		}
    	}
     
    	// Activer affichage 2D
      	begin2D();
     
    		// Adapter la barre de stats
    		glPixelZoom((float) DEFAULT_WINDOW_WIDTH / (float) statsLabyrinthe->w, 1.0f);
     
    		// Dessin de la barre de stats
    		glDrawPixels(statsLabyrinthe->w, statsLabyrinthe->h, GL_RGB, GL_UNSIGNED_BYTE, statsLabyrinthe->data);
     
    		// Dessin du texte a l'écran
    		renderString(20.0f, 20.0f, GLUT_BITMAP_HELVETICA_18, "100%", 255.0f, 0.0f, 0.0f, 1.0f);
     
    	// Désactivation affichage 2D
      	end2D();
     
    	// Restauration de la matrice de transformations
    	glPopMatrix();
     
    	// Affichage du contenu du tampon de couleur
    	glutSwapBuffers( );
     
    	// On force manuellement un evenement affichage
    	glutPostRedisplay();
    }
     
    void reshape(int w, int h)
    {
    	windowWidth = w;
    	windowHeight = h;
    	glViewport(0, 0, w, h);
    	glMatrixMode(GL_PROJECTION);
    	glLoadIdentity();
    	glFrustum(-0.05f, 0.05f, -0.05f, 0.05f, 0.05f, 1000.0f);
    	glMatrixMode(GL_MODELVIEW);
    	glLoadIdentity();
    }
     
    void begin2D()
    {
    	glMatrixMode(GL_PROJECTION);
    	glPushMatrix();
     
    	glLoadIdentity();
    	glOrtho(0, DEFAULT_WINDOW_WIDTH, 0, DEFAULT_WINDOW_HEIGHT, -1.0f, 1.0f);
     
    	glMatrixMode(GL_MODELVIEW);
    	glLoadIdentity();
    }
     
    void end2D()
    {
    	glMatrixMode(GL_PROJECTION);
    	glPopMatrix();
    	glMatrixMode(GL_MODELVIEW);
    }
     
    void renderString(float x, float y, void* font, char* text, float r, float g, float b, float a)
    {
    	if(!text || !strlen(text))
    		return;
     
    	bool blending = false;
     
    	if(glIsEnabled(GL_BLEND))
    		blending = true;
     
    	glEnable(GL_BLEND);
    	glColor4f(r, g, b, a);
    	glRasterPos2f(x, y);
     
    	while(*text)
    	{
    		glutBitmapCharacter(font, *text);
    		text++;
    	}
     
    	if(!blending)
    		glDisable(GL_BLEND);
    }

  2. #2
    Responsable 2D/3D/Jeux


    Avatar de LittleWhite
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Mai 2008
    Messages
    26 859
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Ingénieur développement logiciels

    Informations forums :
    Inscription : Mai 2008
    Messages : 26 859
    Points : 218 580
    Points
    218 580
    Billets dans le blog
    120
    Par défaut
    Bonjour,

    Pouvez vous être plus précis, en joignant une image ?
    Je pensais que c'était des glPushMatrix / glPopMatrix qu'il manquait, mais au final j'ai cru les voir.
    Est ce que le décalage augment à chaque frame ?
    Vous souhaitez participer à la rubrique 2D/3D/Jeux ? Contactez-moi

    Ma page sur DVP
    Mon Portfolio

    Qui connaît l'erreur, connaît la solution.

Discussions similaires

  1. Superposition Image et texte pour une newsletter
    Par xoco dans le forum Mise en page CSS
    Réponses: 2
    Dernier message: 24/02/2012, 16h07
  2. Réponses: 2
    Dernier message: 02/06/2008, 14h29
  3. Réponses: 5
    Dernier message: 15/04/2005, 14h22
  4. [HTML]/[CSS] soulignage de lien (image + texte)
    Par Antickriszt dans le forum Mise en page CSS
    Réponses: 5
    Dernier message: 31/03/2005, 20h55
  5. [JLabel] texte + image + texte
    Par soad dans le forum Composants
    Réponses: 6
    Dernier message: 11/02/2005, 18h49

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo