Пример #1
0
void display(void)
{
    // Update our time
    static float t = 0.0f;

    static uint32_t dwTimeStart = 0;
    uint32_t dwTimeCur = GetTickCount();
    if( dwTimeStart == 0 )
        dwTimeStart = dwTimeCur;
    t = ( dwTimeCur - dwTimeStart ) / 1000.0f;

    gWorld = Matrix4::rotationY(t);

    glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);

    mTessEffect.Enable();

    gGlobals.InnerFactor = 1+t/2;
    gGlobals.OuterFactor = 1+t/2;

    SetFloatArray(gWorld, gGlobals.World);
    SetFloatArray(gView, gGlobals.View);
    SetFloatArray(gProjection, gGlobals.Projection);

    mTessEffect.SetVec4(std::string("Globals"), GlobalsVec4Count, (float*)&gGlobals);

    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, gIndexBuffer);
    glBindBuffer(GL_ARRAY_BUFFER, gVertexBuffer);
    glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(SimpleVertex), 0);
    glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, sizeof(SimpleVertex), (void*)(sizeof(float)*3));

    glPatchParameteri(GL_PATCH_VERTICES, 4);
    glDrawElements(GL_PATCHES, 24, GL_UNSIGNED_INT, 0);
    glutSwapBuffers();
}
Пример #2
0
void display(void)
{
    // Update our time
    static float t = 0.0f;

    static uint32_t dwTimeStart = 0;
    uint32_t dwTimeCur = GetTickCount();
    if( dwTimeStart == 0 )
        dwTimeStart = dwTimeCur;
    t = ( dwTimeCur - dwTimeStart ) / 1000.0f;

    gWorld = Matrix4::rotationY(t);

    Vector4 vLightDirs[2] =
    {
        Vector4(-0.577f, 0.577f, -0.577f, 1.0f),
        Vector4(0.0f, 0.0f, -1.0f, 1.0f),
    };
    Vector4 vLightColors[2] =
    {
        Vector4(0.5f, 0.5f, 0.5f, 1.0f),
        Vector4(0.5f, 0.0f, 0.0f, 1.0f),
    };

    Matrix3 rotate;
    Vector4 vOutDir;
    rotate = Matrix3::rotationY(-2.0f * t);
    vLightDirs[1].setXYZ(rowMul (vLightDirs[1].getXYZ(), rotate));

    glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    mLambertLitEffect.Enable();

    SetFloatArray(gWorld, gGlobals.World);
    SetFloatArray(gView, gGlobals.View);
    SetFloatArray(gProjection, gGlobals.Projection);
    SetFloatArray(vLightDirs[0], &gGlobals.vLightDir[0]);
    SetFloatArray(vLightDirs[1], &gGlobals.vLightDir[4]);
    SetFloatArray(vLightColors[0], &gGlobals.vLightColor[0]);
    SetFloatArray(vLightColors[1], &gGlobals.vLightColor[4]);

#if UBO
    glBindBuffer(GL_UNIFORM_BUFFER, ubo);
    glBufferSubData(GL_UNIFORM_BUFFER, 0, sizeof(gGlobals), &gGlobals);
    mLambertLitEffect.SetUniformBlock(std::string("SharedConsts"), 0, ubo);
#else
    mLambertLitEffect.SetVec4(std::string("SharedConsts"), GlobalsVec4Count, (float*)&gGlobals);
#endif 
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, gIndexBuffer);
    glBindBuffer(GL_ARRAY_BUFFER, gVertexBuffer);
    glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(SimpleVertex), 0);
    glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, sizeof(SimpleVertex), (void*)(sizeof(float)*3));

    glDrawElements(GL_TRIANGLES, 36, GL_UNSIGNED_INT, 0);

    mSolidColour.Enable();

    for(int m = 0; m < 2; m++)
    {
        Matrix4 light;
        Matrix4 lightScale;
        Vector4 vLightPos = vLightDirs[m] * 5.0f;
        light = Matrix4::translation(vLightPos.getXYZ());
        lightScale = Matrix4::scale(Vector3(2.0f, 2.0f, 2.0f));
        light = lightScale * light;

        SetFloatArray(light, gGlobals.World);
        SetFloatArray(vLightColors[m], &gGlobals.vOutputColor[0]);

#if UBO
        glBindBuffer(GL_UNIFORM_BUFFER, ubo2);
        glBufferSubData(GL_UNIFORM_BUFFER, 0, sizeof(gGlobals), &gGlobals);
        mSolidColour.SetUniformBlock(std::string("SharedConsts"), 1, ubo2);
#else
        mSolidColour.SetVec4(std::string("SharedConsts"), GlobalsVec4Count, (float*)&gGlobals);
#endif
        glDrawElements(GL_TRIANGLES, 36, GL_UNSIGNED_INT, 0);
    }

    glutSwapBuffers();
}