Changeset 1045
- Timestamp:
- Oct 31, 2011, 5:51:34 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/tutorial/tut02.cpp
r1043 r1045 33 33 Cube() 34 34 { 35 m_angle = 0; 36 35 37 /* Front */ 36 38 m_vertices[0] = vec3(-1.0, -1.0, 1.0); … … 69 71 virtual void TickGame(float deltams) 70 72 { 71 real x(4.08f); x.print();72 73 WorldEntity::TickGame(deltams); 73 74 74 m_angle += deltams ;75 m_angle += deltams / 1000.0f * 45.0f; 75 76 76 vec3 axis_y(0, 1, 0); 77 mat4 anim = mat4::rotate(m_angle * 0.0001f, axis_y); 77 mat4 anim = mat4::rotate(m_angle, vec3(0, 1, 0)); 78 78 mat4 model = mat4::translate(vec3(0, 0, -4)); 79 79 mat4 view = mat4::lookat(vec3(0, 2, 0), vec3(0, 0, -4), vec3(0, 1, 0)); 80 mat4 proj = mat4::perspective(M_PI / 4, 640.0f, 480.0f, -10.0f, 10.0f); 81 anim = mat4(1.0f); 82 model = mat4(1.0f); 83 view = mat4(1.0f); 80 mat4 proj = mat4::perspective(45.0f, 640.0f, 480.0f, 0.1f, 10.0f); 81 84 82 m_matrix = proj * view * model * anim; 85 proj.printf();86 view.printf();87 model.printf();88 anim.printf();89 printf("\n");90 m_matrix.printf();91 printf("\n");92 m_vertices[0].printf();93 (m_matrix * vec4(m_vertices[0], 1)).printf();94 printf("\n");95 83 } 96 84 … … 103 91 m_shader = Shader::Create( 104 92 "#version 120\n" 105 "attribute vec3 coord3d;" 106 "attribute vec3 v_color;" 107 "uniform mat4 mvp;" 108 "varying vec3 f_color;" 93 "attribute vec3 in_Vertex;" 94 "attribute vec3 in_Color;" 95 "uniform mat4 in_Matrix;" 96 "varying vec3 pass_Color;" 97 "" 109 98 "void main(void) {" 110 " gl_Position = mvp * vec4(coord3d, 1.0);"111 " f_color = v_color;"99 " gl_Position = in_Matrix * vec4(in_Vertex, 1.0);" 100 " pass_Color = in_Color;" 112 101 "}", 113 102 114 103 "#version 120\n" 115 "varying vec3 f_color;" 104 "varying vec3 pass_Color;" 105 "" 116 106 "void main(void) {" 117 " gl_FragColor = vec4(f_color, 1.0);" 118 " gl_FragColor = vec4(1.0, 1.0, 0.0, 1.0);" 107 " gl_FragColor = vec4(pass_Color, 1.0);" 119 108 "}"); 120 m_coord = m_shader->GetAttribLocation(" coord3d");121 m_color = m_shader->GetAttribLocation(" v_color");122 m_mvp = m_shader->GetUniformLocation(" mvp");109 m_coord = m_shader->GetAttribLocation("in_Vertex"); 110 m_color = m_shader->GetAttribLocation("in_Color"); 111 m_mvp = m_shader->GetUniformLocation("in_Matrix"); 123 112 m_ready = true; 124 113 … … 144 133 145 134 m_shader->Bind(); 135 m_shader->SetUniform(m_mvp, m_matrix); 146 136 #if !defined __CELLOS_LV2__ && !defined __ANDROID__ && !defined __APPLE__ 147 137 glEnableVertexAttribArray(m_coord); … … 157 147 glGetBufferParameteriv(GL_ELEMENT_ARRAY_BUFFER, GL_BUFFER_SIZE, &size); 158 148 159 glDrawElements(GL_TRIANGLES, size / sizeof(GLushort), GL_UNSIGNED_SHORT, 0); 149 150 glDrawElements(GL_TRIANGLES, size / sizeof(uint16_t), GL_UNSIGNED_SHORT, 0); 160 151 161 152 glDisableVertexAttribArray(m_coord);
Note: See TracChangeset
for help on using the changeset viewer.