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
| #include <GL/glfw.h>
#define APP_WIDTH 640
#define APP_HEIGHT 480
int running=GL_TRUE;
double timer1=0;
double x=300;
double y=240;
int main()
{
glfwInit();
if(!glfwOpenWindow(APP_WIDTH,APP_HEIGHT,0,0,0,0,24,8,GLFW_FULLSCREEN))
{
glfwTerminate(); //On quitte si erreur
return 0;
}
glfwSetWindowTitle("Test GL");
//glfwDisable(GLFW_MOUSE_CURSOR);
glfwSetTime(0);
gluOrtho2D(0,APP_WIDTH,APP_HEIGHT,0);
glMatrixMode(GL_PROJECTION);
glEnable(GL_TEXTURE_2D);
GLuint texture1;
texture1 = glfwLoadTexture2D("monster.tga",GLFW_ORIGIN_UL_BIT);
while(running) //Boucle principale
{
if(glfwGetTime()>=timer1+0.01) //Timer 1
{
timer1=glfwGetTime();
//Déplacements basiques de l'objet avec les flèches
if(glfwGetKey(GLFW_KEY_UP)==GL_TRUE){y--;}
if(glfwGetKey(GLFW_KEY_DOWN)==GL_TRUE){y++;}
if(glfwGetKey(GLFW_KEY_LEFT)==GL_TRUE){x--;}
if(glfwGetKey(GLFW_KEY_RIGHT)==GL_TRUE){x++;}
}
//--------------------------- CALCUL DE L'IMAGE ---------------------------
glClear(GL_COLOR_BUFFER_BIT); //Nettoyage de la surface
glPointSize(1.0);
glBegin(GL_TRIANGLE_STRIP);
glBindTexture(GL_TEXTURE_2D, texture1);
glTexCoord2d(0,1); glVertex2d(x-32,y-32);
glTexCoord2d(1,1); glVertex2d(x+32,y-32);
glTexCoord2d(0,0); glVertex2d(x-32,y+32);
glTexCoord2d(1,0); glVertex2d(x+32,y+32);
glEnd();
glFlush();
glfwSwapBuffers();
running=!glfwGetKey(GLFW_KEY_ESC)&&glfwGetWindowParam(GLFW_OPENED); //Si ESC on quitte
}
glfwTerminate();
return 0;
} |
Partager