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
|
const GLfloat cubeVertices[] = {
// face de devant
-0.5, 0.5, -0.5,
-0.5, -0.5, -0.5,
0.5, -0.5, -0.5,
0.5, 0.5, -0.5,
// haut
-0.5, 0.5, -0.5,
-0.5, 0.5, 0.5,
0.5, 0.5, 0.5,
0.5, 0.5, -0.5,
// arrière
0.5, 0.5, 0.5,
0.5, -0.5, 0.5,
-0.5, -0.5, 0.5,
-0.5, 0.5, 0.5,
// dessous
-0.5, -0.5, 0.5,
-0.5, -0.5, -0.5,
0.5, -0.5, -0.5,
0.5, -0.5, 0.5,
// gauche
-0.5, 0.5, -0.5,
-0.5, 0.5, 0.5,
-0.5, -0.5, 0.5,
-0.5, -0.5, -0.5,
// droit
0.5, 0.5, 0.5,
0.5, 0.5, -0.5,
0.5, -0.5, -0.5,
0.5, -0.5, 0.5
};
static const GLubyte squareColors[] = {
0, 0, 204, 255,
0, 204, 0, 255,
204, 0, 0, 255,
204, 0, 204, 255,
0, 0, 204, 255,
0, 204, 0, 255,
204, 0, 0, 255,
204, 0, 204, 255,
0, 0, 204, 255,
0, 204, 0, 255,
204, 0, 0, 255,
204, 0, 204, 255,
0, 0, 204, 255,
0, 204, 0, 255,
204, 0, 0, 255,
204, 0, 204, 255,
0, 0, 204, 255,
0, 204, 0, 255,
204, 0, 0, 255,
204, 0, 204, 255,
0, 0, 204, 255,
0, 204, 0, 255,
204, 0, 0, 255,
204, 0, 204, 255,
};
-(void)render{
Mat4x4 cameraView = Camera::getInstance()->gluLookAtMatrix();
Mat4x4 proj = Mat4x4::setPerspective((float)(768.0f/1024.0f), 60.0f, 1.0, 20.0f);
//Mat4x4::setOrtho(proj, -4.0f, 4.0f, -6.0f, 6.0f, -4.0f, 4.0f);
Mat4x4 rot,trans = Mat4x4::setTranslation(0.0f, 1.0f, 5.0f);
rot.rotY(r_angle);
Mat4x4 mvp = cameraView * proj * rot * trans;
r_angle += 0.05f;
glUseProgram([s_loader getProgramIdentifier]);
glVertexAttribPointer(attribPositionOnShader, 3, GL_FLOAT, 0, 0, cubeVertices);
glEnableVertexAttribArray(attribPositionOnShader);
glVertexAttribPointer(attribColorOnShader, 4, GL_UNSIGNED_BYTE, 1, 0, squareColors);
glEnableVertexAttribArray(attribColorOnShader);
glUniformMatrix4fv(projMatOnShader, 16, GL_FALSE, mvp.toArray());
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
glDrawArrays(GL_TRIANGLE_FAN, 4, 4);
glDrawArrays(GL_TRIANGLE_FAN, 8, 4);
glDrawArrays(GL_TRIANGLE_FAN, 12, 4);
glDrawArrays(GL_TRIANGLE_FAN, 16, 4);
glDrawArrays(GL_TRIANGLE_FAN, 20, 4);
glUseProgram(0);
glBindBuffer(GL_ARRAY_BUFFER, 0);
} |
Partager