[TRANSLATION:] Using gl glut only I can move the objects through the keyboard, but using shader and glew does not work, if you have some example that uses shader and glew, thank you.
[ORIGINAL TEXT:] Usando apenas gl glut eu posso mover os objetos através do teclado, mas usando shader e glew não funciona, se tiver algum exemplo que usa shader e glew, obrigado.
#include <iostream>
#include "principal.h"
#include "vetor.h"
#include <GL / glut.h>
#include <iostream>
#include <stdlib.h>
usando o namespace Principal;
usando namespace std;
enum VAO_IDs {Triangles, NumVAOs};
enum Buffer_IDs {ArrayBuffer, NumBuffers};
float valor_x = 0,0;
float valor_y = 0,0;
GLUint VAOs [NumVAOs];
Buffers de brilho [NumBuffers];
const Gluint NumVertices = 3;
Teclado void (tecla de caractere não assinado, int x,
interruptor (chave)
{
caso 033:
sair (EXIT_SUCCESS);
pausa;
}
}
Vazio specialTecla (chave, int x, int y)
{
if (GLUT_KEY_DOWN == chave)
{valor_y = valor_y-0,1;
}
if (chave == GLUT_KEY_LEFT)
{
valor_x = valor_x-0.1;
}
if (chave == GLUT_KEY_UP)
{
valor_ua = valor_y + 0,1;
}
if (chave == GLUT_KEY_RIGHT)
{
valor_x = valor_x + 0,1;
}
glutPostRedisplay ();
}
void init (void)
{
Vértices Vetor2D [NumVertices] =
{
Vetor2D (-0,3, -0,3),
Vetor2D (0,3, -0,3),
Vetor2D (0,0, 0,3)
};
GLuint programa = InitShader ("vshader.glsl", "fshader.glsl");
glUseProgram (programa);
glGenVertexArrays (NumVAOs, VAOs);
glBindVertexArray (VAOs [Triângulos]); //
glGenBuffers (NumBuffers, Buffers);
glBindBuffer (GL_ARRAY_BUFFER, Buffers [ArrayBuffer]);
glBufferData (GL_ARRAY_BUFFER, sizeof (vértices), vértices, GL_STATIC_DRAW); //
GLuint loc = glGetAttribLocation (programa, "vPosition");
glEnableVertexAttribArray (loc);
glVertexAttribPointer (loc,
2,
GL_FLOAT,
GL_FALSE,
0,
BUFFER_OFFSET (0)
);
}
void display (void)
{
glClear (GL_COLOR_BUFFER_BIT);
glDrawArrays (GL_TRIANGLES,
0, //
NumVertices //
);
glFlush ();
}
int main (argc int, char ** argv)
{
glutInit (& argc, argv);
glutInitDisplayMode (GLUT_SINGLE | GLUT_RGBA);
glutInitWindowSize (500, 500);
glutInitContextVersion (3, 0);
glutInitContextProfile (GLUT_CORE_PROFILE);
glutCreateWindow ("Main"); // argv [0]
glewInit ();
nisso ( );
glutSpecialFunc (specialTecla);
glutKeyboardFunc (teclado);
glutDisplayFunc (exibição);
glutMainLoop ();
return EXIT_SUCCESS;
}
#versão 130 // fumeira
fora vec4 fColor;
void main ()
{
fColor = vec4 (1.0f, 0,5f, 0,2f, 1,0f);
}
#versão 130 // vshader
em vec4 vPosição;
void main ()
{
gl_Position = vPosition;
}