Changeset 1045


Ignore:
Timestamp:
Oct 31, 2011, 5:51:34 PM (12 years ago)
Author:
gary
Message:

test: clean up tutorial #2.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/tutorial/tut02.cpp

    r1043 r1045  
    3333    Cube()
    3434    {
     35        m_angle = 0;
     36
    3537        /* Front */
    3638        m_vertices[0] = vec3(-1.0, -1.0,  1.0);
     
    6971    virtual void TickGame(float deltams)
    7072    {
    71 real x(4.08f); x.print();
    7273        WorldEntity::TickGame(deltams);
    7374
    74         m_angle += deltams;
     75        m_angle += deltams / 1000.0f * 45.0f;
    7576
    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));
    7878        mat4 model = mat4::translate(vec3(0, 0, -4));
    7979        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
    8482        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");
    9583    }
    9684
     
    10391            m_shader = Shader::Create(
    10492                "#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                ""
    10998                "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;"
    112101                "}",
    113102
    114103                "#version 120\n"
    115                 "varying vec3 f_color;"
     104                "varying vec3 pass_Color;"
     105                ""
    116106                "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);"
    119108                "}");
    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");
    123112            m_ready = true;
    124113
     
    144133
    145134        m_shader->Bind();
     135        m_shader->SetUniform(m_mvp, m_matrix);
    146136#if !defined __CELLOS_LV2__ && !defined __ANDROID__ && !defined __APPLE__
    147137        glEnableVertexAttribArray(m_coord);
     
    157147        glGetBufferParameteriv(GL_ELEMENT_ARRAY_BUFFER, GL_BUFFER_SIZE, &size);
    158148
    159         glDrawElements(GL_TRIANGLES, size / sizeof(GLushort), GL_UNSIGNED_SHORT, 0);
     149
     150        glDrawElements(GL_TRIANGLES, size / sizeof(uint16_t), GL_UNSIGNED_SHORT, 0);
    160151
    161152        glDisableVertexAttribArray(m_coord);
Note: See TracChangeset for help on using the changeset viewer.