Ignore:
Timestamp:
Feb 18, 2011, 1:09:21 AM (9 years ago)
Author:
sam
Message:

Merge more code from the experimental MVP refactor into the old GL code.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/video.cpp

    r659 r662  
    3131#if LOL_EXPERIMENTAL
    3232Shader *stdshader;
    33 
    34     float4x4 projection_matrix, view_matrix, model_matrix;
    35 #endif
     33#endif
     34float4x4 projection_matrix, view_matrix, model_matrix;
    3635
    3736#if LOL_EXPERIMENTAL
     
    9291void Video::SetFov(float theta)
    9392{
    94 #if LOL_EXPERIMENTAL
    95     float width = GetWidth();
    96     float height = GetHeight();
    97     //float near = -width - height;
    98     //float far = width + height;
    99     float near = 20.0f;
    100     float far = 0.1f;
    101     projection_matrix = float4x4::perspective(theta, width, height, near, far);
    102 #else
    10393#undef near /* Fuck Microsoft */
    10494#undef far /* Fuck Microsoft again */
    105     glMatrixMode(GL_PROJECTION);
    106     glLoadIdentity();
     95    float4x4 proj;
    10796
    10897    float width = GetWidth();
     
    115104    {
    116105        /* The easy way: purely orthogonal projection. */
    117         glOrtho(0, width, 0, height, near, far);
     106        proj = float4x4::ortho(0, width, 0, height, near, far);
    118107    }
    119108    else
     
    135124        }
    136125
    137         glFrustum(-near * t1, near * t1, -near * t2, near * t2, near, far);
    138         glTranslatef(-0.5f * width, -0.5f * height, -dist);
     126        proj = float4x4::frustum(-near * t1, near * t1,
     127                                 -near * t2, near * t2, near, far)
     128             * float4x4::translate(-0.5f * width, -0.5f * height, -dist);
    139129    }
     130
     131#if LOL_EXPERIMENTAL
     132    projection_matrix = proj;
     133    view_matrix = float4x4(1.0f);
     134#else
     135    glMatrixMode(GL_PROJECTION);
     136    glLoadIdentity();
     137    glMultMatrixf(&proj[0][0]);
    140138
    141139    /* Reset the model view matrix, just in case */
     
    158156    glViewport(0, 0, GetWidth(), GetHeight());
    159157    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
    160 
    161     view_matrix = float4x4(1.0f);
    162     view_matrix[3][0] = 0.0f;
    163     view_matrix[3][1] = 0.0f;
    164     view_matrix[3][2] = -5.0f;
    165 
    166     model_matrix = float4x4(1.0f);
    167     model_matrix[0][0] = 0.5f;
    168     model_matrix[1][1] = 0.5f;
    169     model_matrix[2][2] = 0.5f;
    170158
    171159    GLuint uni;
     
    174162    uni = stdshader->GetUniformLocation("view_matrix");
    175163    glUniformMatrix4fv(uni, 1, GL_FALSE, &view_matrix[0][0]);
    176     uni = stdshader->GetUniformLocation("model_matrix");
    177     glUniformMatrix4fv(uni, 1, GL_FALSE, &model_matrix[0][0]);
    178164#else
    179165    glEnable(GL_DEPTH_TEST);
     
    187173#endif
    188174
    189 #if LOL_EXPERIMENTAL
    190     static float time;
    191     time += 0.01f;
    192     SetFov(1.0f + sinf(time));
    193 #else
    194     SetFov(0.5f);
    195 #endif
     175    SetFov(0.0f);
    196176}
    197177
Note: See TracChangeset for help on using the changeset viewer.