Index: ppapi/examples/compositor/spinning_cube.cc |
diff --git a/ppapi/examples/gles2_spinning_cube/spinning_cube.cc b/ppapi/examples/compositor/spinning_cube.cc |
similarity index 88% |
copy from ppapi/examples/gles2_spinning_cube/spinning_cube.cc |
copy to ppapi/examples/compositor/spinning_cube.cc |
index c4d33ddc87ec46b3c372dd1aeb9c906966134c2e..236fd3b2be3fd4a3bb050a1789b11624c61f9b81 100644 |
--- a/ppapi/examples/gles2_spinning_cube/spinning_cube.cc |
+++ b/ppapi/examples/compositor/spinning_cube.cc |
@@ -14,7 +14,7 @@ |
// http://www.opengles-book.com |
// |
-#include "ppapi/examples/gles2_spinning_cube/spinning_cube.h" |
+#include "ppapi/examples/compositor/spinning_cube.h" |
#include <math.h> |
#include <stdlib.h> |
@@ -34,29 +34,13 @@ int GenerateCube(GLuint *vbo_vertices, |
const GLfloat cube_vertices[] = { |
-0.5f, -0.5f, -0.5f, |
+ 0.5f, -0.5f, -0.5f, |
+ 0.5f, -0.5f, 0.5f, |
-0.5f, -0.5f, 0.5f, |
- 0.5f, -0.5f, 0.5f, |
- 0.5f, -0.5f, -0.5f, |
-0.5f, 0.5f, -0.5f, |
+ 0.5f, 0.5f, -0.5f, |
+ 0.5f, 0.5f, 0.5f, |
-0.5f, 0.5f, 0.5f, |
- 0.5f, 0.5f, 0.5f, |
- 0.5f, 0.5f, -0.5f, |
- -0.5f, -0.5f, -0.5f, |
- -0.5f, 0.5f, -0.5f, |
- 0.5f, 0.5f, -0.5f, |
- 0.5f, -0.5f, -0.5f, |
- -0.5f, -0.5f, 0.5f, |
- -0.5f, 0.5f, 0.5f, |
- 0.5f, 0.5f, 0.5f, |
- 0.5f, -0.5f, 0.5f, |
- -0.5f, -0.5f, -0.5f, |
- -0.5f, -0.5f, 0.5f, |
- -0.5f, 0.5f, 0.5f, |
- -0.5f, 0.5f, -0.5f, |
- 0.5f, -0.5f, -0.5f, |
- 0.5f, -0.5f, 0.5f, |
- 0.5f, 0.5f, 0.5f, |
- 0.5f, 0.5f, -0.5f, |
}; |
const GLushort cube_indices[] = { |
@@ -64,14 +48,14 @@ int GenerateCube(GLuint *vbo_vertices, |
0, 3, 2, |
4, 5, 6, |
4, 6, 7, |
- 8, 9, 10, |
- 8, 10, 11, |
- 12, 15, 14, |
- 12, 14, 13, |
- 16, 17, 18, |
- 16, 18, 19, |
- 20, 23, 22, |
- 20, 22, 21 |
+ 3, 6, 2, |
+ 3, 7, 6, |
+ 0, 1, 5, |
+ 0, 5, 4, |
+ 0, 7, 3, |
+ 0, 4, 7, |
+ 1, 2, 6, |
+ 1, 6, 5, |
}; |
if (vbo_vertices) { |
@@ -365,17 +349,23 @@ void SpinningCube::Init(uint32_t width, uint32_t height) { |
const char vertext_shader_source[] = |
"uniform mat4 u_mvpMatrix; \n" |
"attribute vec4 a_position; \n" |
+ "varying vec4 v_color; \n" |
"void main() \n" |
"{ \n" |
" gl_Position = u_mvpMatrix * a_position; \n" |
+ " v_color = vec4(a_position.x + 0.5, \n" |
+ " a_position.y + 0.5, \n" |
+ " a_position.z + 0.5, \n" |
+ " 0.8); \n" |
"} \n"; |
const char fragment_shader_source[] = |
- "precision mediump float; \n" |
- "void main() \n" |
- "{ \n" |
- " gl_FragColor = vec4( 0.0, 0.0, 1.0, 1.0 ); \n" |
- "} \n"; |
+ "precision mediump float; \n" |
+ "varying vec4 v_color; \n" |
+ "void main() \n" |
+ "{ \n" |
+ " gl_FragColor = v_color; \n" |
+ "} \n"; |
state_->program_object_ = LoadProgram( |
vertext_shader_source, fragment_shader_source); |
@@ -383,8 +373,8 @@ void SpinningCube::Init(uint32_t width, uint32_t height) { |
state_->program_object_, "a_position"); |
state_->mvp_location_ = glGetUniformLocation( |
state_->program_object_, "u_mvpMatrix"); |
- state_->num_indices_ = GenerateCube( |
- &state_->vbo_vertices_, &state_->vbo_indices_); |
+ state_->num_indices_ = GenerateCube(&state_->vbo_vertices_, |
+ &state_->vbo_indices_); |
glClearColor(0.0f, 0.0f, 0.0f, 0.0f); |
} |
@@ -430,24 +420,27 @@ void SpinningCube::UpdateForDragDistance(float distance) { |
void SpinningCube::Draw() { |
glViewport(0, 0, width_, height_); |
- glClear(GL_COLOR_BUFFER_BIT); |
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); |
+ glEnable(GL_DEPTH_TEST); |
glUseProgram(state_->program_object_); |
+ |
glBindBuffer(GL_ARRAY_BUFFER, state_->vbo_vertices_); |
- glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, state_->vbo_indices_); |
glVertexAttribPointer(state_->position_location_, |
- 3, |
- GL_FLOAT, |
- GL_FALSE, 3 * sizeof(GLfloat), |
- 0); |
+ 3, |
+ GL_FLOAT, |
+ GL_FALSE, 3 * sizeof(GLfloat), |
+ 0); |
glEnableVertexAttribArray(state_->position_location_); |
+ |
glUniformMatrix4fv(state_->mvp_location_, |
- 1, |
- GL_FALSE, |
- (GLfloat*) &state_->mvp_matrix_.m[0][0]); |
+ 1, |
+ GL_FALSE, |
+ (GLfloat*) &state_->mvp_matrix_.m[0][0]); |
+ glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, state_->vbo_indices_); |
glDrawElements(GL_TRIANGLES, |
- state_->num_indices_, |
- GL_UNSIGNED_SHORT, |
- 0); |
+ state_->num_indices_, |
+ GL_UNSIGNED_SHORT, |
+ 0); |
} |
void SpinningCube::Update() { |