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
|
public void loadShader() {
//new Shader2 appelle la méthode glCreateShader([I]type[\I])
Shader2 vertexShader = new Shader2(GL20.GL_VERTEX_SHADER);
Shader2 fragmentShader = new Shader2(GL20.GL_FRAGMENT_SHADER);
//Lecture du fichier vbo.vs, le charge dans un String et appelle la
//méthode glShaderSource(idShader, source)
vertexShader.source("./shaders/vbo.vs");
fragmentShader.source("./shaders/vbo.fs");
//compile les shader avec glCompileShader(idShader)
vertexShader.compile();
//test si le shader est compilé en récupérant la valeur de
//glGetShader(idShader, GL_COMPILE_STATUS)
vertexShader.isCompile();
fragmentShader.compile();
fragmentShader.isCompile();
//new ShaderProgram2() fait appel à glCreateProgram()
shaderProgram = new ShaderProgram2();
//On attache les deux shader dans le programme
//(glAttachShader(idProgram, idShader)).
shaderProgram.attachShader(vertexShader);
shaderProgram.attachShader(fragmentShader);
//On lie le programme
shaderProgram.linkProgramShader();
//On récupère l'identifiant de la matrice de notre scène
uniformModelViewProjectionMatrix = shaderProgram.getUniformLocation("ModelViewProjectionMatrix");
//On récupère l'id pour les couleurs, les position et les normales.
vertexColorAttrib = shaderProgram.getAttribLocation("VertexColor");
vertexPositionAttrib = shaderProgram.getAttribLocation("VertexPosition");
vertexNormalAttrib = shaderProgram.getAttribLocation("VertexNormal");
// Affiche : uniformModelViewProjectionMatrix: 0
System.out.println("uniformModelViewProjectionMatrix: " + uniformModelViewProjectionMatrix);
// Affiche: vertexColorAttrib: -1
System.out.println("vertexColorAttrib: " + vertexColorAttrib);
// Affiche: vertexNormalAttrib: -1
System.out.println("vertexNormalAttrib: " + vertexNormalAttrib);
//Affiche: vertexPositionAttrib: 0
System.out.println("vertexPositionAttrib: " + vertexPositionAttrib);
} |
Partager