Good morning dear friends, I apologize for my ignorance, but what is happening in my code, because I can only move once in my triangle, by pressing the key, I need to always move to the left side …
I’m a rookie myself, please help me …
#include<windows.h>
#include<gl/GL.h>
#include<gl/glu.h>
#include<gl/glut.h>
#include <stdio.h>
typedef struct {
GLint x,y;
}ponto;
void desenha();
void inicializacao();
void GerenciaTeclado(unsigned char key, int x, int y);
void desenha_triangulo();
int main(int argc, char **argv){
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGBA);
glutInitWindowSize(800,600);
glutInitWindowPosition(0,0);
glutCreateWindow("Trabalho 1");
glutKeyboardFunc(GerenciaTeclado);
inicializacao();
glutDisplayFunc(desenha);
glutMainLoop();
return 0;
}
void inicializacao(void){
glClearColor(1.0f,1.0f,1.0f,1.0f); // cor de fundo branca
glPointSize(8.0); // tamanho dos pontos de cada pixels
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0,800,0,600);
glLineWidth(4.0);
}
void desenha(){
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0,0.1,0.1);
desenha_triangulo();
}
void desenha_triangulo(){
//desenha um retangulo vermelho
glBegin(GL_TRIANGLES);
glVertex2i(100,100);
glVertex2i(200,200);
glVertex2i(300,100);
glEnd();
glFlush(); //envia toda a saída para a exibição
}
void GerenciaTeclado(unsigned char key, int x, int y){
printf("Tecla Pressionada %d
",key);
if ((key == 97) || (key ==65)){ // tecla A mover para a esquerda
glPushMatrix();
glTranslated(-20,0,1.0); // translação de -10 para mover para a esquerda
desenha();
glPopMatrix();
// glutPostRedisplay();
}
}