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
|
#include "stdafx.h"
#include "NeptuneV003.h"
#include "ZoneCarte.h"
#include "Texture.h"
#include <math.h>
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
///////////////////////////////////////////////////////////////////////////////
// Call-back : gestion des touches speciales du clavier.
//-----------------------------------------------------------------------------
// Paramètres :
// key (in) : code ascii de la touche utilisée.
// x,y (in) : coordonnées de la souris.
// Retour :
// _
///////////////////////////////////////////////////////////////////////////////
GLvoid ZoneCarte::callback_special(int key, int x, int y)
{
float speed = 1.0f; // Vitesse de déplacement de la caméra
switch (key)
{
case GLUT_KEY_UP: // Flèche vers le haut :
//zpos -= speed; // on déplace la caméra selon z-
//glTranslatef(-1.5f,0.0f,-6.0f);
x++;
break;
case GLUT_KEY_DOWN: // Flèche vers le bas :
//zpos += speed; // on déplace la caméra selon z+
x--;
break;
case GLUT_KEY_LEFT: // Flèche vers la gauche :
//xpos -= speed; // on déplace la caméra selon x-
y++;
break;
case GLUT_KEY_RIGHT: // Flèche vers la droite :
//xpos += speed; // on déplace la caméra selon x+
y--;
break;
}
}
///////////////////////////////////////////////////////////////////////////////
// Call-back : déclenche l'affichage même en l'absence d'évènements souris ou
// clavier
//-----------------------------------------------------------------------------
// Paramètres :
// _
// Retour :
// _
///////////////////////////////////////////////////////////////////////////////
GLvoid ZoneCarte::callback_idle()
{
glutPostRedisplay();
}
int ZoneCarte::InitGL()
{
//carte1.charger("S077_047.tga",false);
carte1.definit_filtrage(GL_TEXTURE_MIN_FILTER,GL_LINEAR);
carte1.definit_filtrage(GL_TEXTURE_MAG_FILTER,GL_LINEAR);
carte1.definit_bouclage(GL_TEXTURE_WRAP_S,GL_REPEAT);
carte1.definit_bouclage(GL_TEXTURE_WRAP_T,GL_REPEAT);
//carte1.definit_melange(GL_MODULATE);
glShadeModel(GL_SMOOTH);
glClearColor(0.0f, 0.0f, 0.0f, 0.5f);
glClearDepth(1.0f);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
xpos = 0;
ypos = 0;
zpos = 0;
return TRUE;
}
void ZoneCarte::OnDraw(CDC* pDC)
{
CDocument* pDoc = GetDocument();
pDC->TextOut(10,10,"ZoneCarte") ;
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here CPaintDC dc(this); // Obligatoire
// Utile dans les MDI
HWND hWnd = GetSafeHwnd();
HDC hDC = ::GetDC(hWnd);
wglMakeCurrent(hDC,m_hglrc);
// je dessine
glLoadIdentity();
glTranslatef(-1.5f,0.0f,-6.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
//glTranslatef(xpos,ypos,zpos);
glEnable(GL_TEXTURE_2D);
carte1.utilise();
glNormal3f( 0.0f, 0.0f, 1.0f);
glBegin(GL_QUADS);
glTexCoord2f(0,0);
glVertex3d(0+x, 0+y, 0);
glTexCoord2f(1,0);
glVertex3d(1+x, 0+y, 0);
glTexCoord2f(1,1);
glVertex3d( 1+x,1+y, 0);
glTexCoord2f(0,1);
glVertex3d( 0+x,1+y, 0);
glEnd();
glDisable(GL_TEXTURE_2D);
// On utilise le double buffer donc après avoir dessiné on échange le back-buffer et le front-buffer pour voir le résultat du back buffer à l'écran
SwapBuffers(m_hgldc);
} |
Partager