Changeset 662


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

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

Location:
trunk/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/scene.cpp

    r659 r662  
    3939extern Shader *stdshader;
    4040#endif
     41extern float4x4 projection_matrix, view_matrix, model_matrix;
    4142
    4243/*
     
    135136    qsort(data->tiles, data->ntiles, sizeof(Tile), SceneData::Compare);
    136137
     138    // XXX: debug stuff
     139    model_matrix = float4x4::translate(320.0f, 240.0f, 0.0f);
     140    model_matrix = model_matrix * float4x4::rotate(-data->angle, 1.0f, 0.0f, 0.0f);
     141#if 0
     142    static float f = 0.0f;
     143    f += 0.01f;
     144    model_matrix = model_matrix * float4x4::rotate(0.1f * sinf(f), 1.0f, 0.0f, 0.0f);
     145    model_matrix = model_matrix * float4x4::rotate(0.3f * cosf(f), 0.0f, 0.0f, 1.0f);
     146#endif
     147    model_matrix = model_matrix * float4x4::translate(-320.0f, -240.0f, 0.0f);
     148    // XXX: end of debug stuff
     149
    137150#if LOL_EXPERIMENTAL
     151    GLuint uni;
     152    uni = stdshader->GetUniformLocation("model_matrix");
     153    glUniformMatrix4fv(uni, 1, GL_FALSE, &model_matrix[0][0]);
     154
    138155    float *vertices = new float[18];
    139     vertices[0] = -0.5f; vertices[1] = 0.5f; vertices[2] = 0.0f;
    140     vertices[3] = 0.5f; vertices[4] = 0.5f; vertices[5] = 0.0f;
    141     vertices[6] = -0.5f; vertices[7] = -0.5f; vertices[8] = 0.0f;
    142 
    143     vertices[9] = 0.5f; vertices[10] = -0.5f; vertices[11] = 0.0f;
    144     vertices[12] = -0.5f; vertices[13] = -0.5f; vertices[14] = 0.0f;
    145     vertices[15] = 0.5f; vertices[16] = 0.5f; vertices[17] = 0.0f;
     156    vertices[0] = 0.0f; vertices[1] = 480.0f; vertices[2] = 0.0f;
     157    vertices[3] = 640.0f; vertices[4] = 480.0f; vertices[5] = 0.0f;
     158    vertices[6] = 0.0f; vertices[7] = 0.0f; vertices[8] = 0.0f;
     159
     160    vertices[9] = 640.0f; vertices[10] = 0.0f; vertices[11] = 0.0f;
     161    vertices[12] = 0.0f; vertices[13] = 0.0f; vertices[14] = 0.0f;
     162    vertices[15] = 640.0f; vertices[16] = 480.0f; vertices[17] = 0.0f;
    146163
    147164    const GLfloat colors[6][3] = {
     
    194211
    195212#else
    196     // XXX: debug stuff
    197     glPushMatrix();
    198     static float f = 0.0f;
    199     f += 0.05f;
    200     glTranslatef(320.0f, 240.0f, 0.0f);
    201     glRotatef(-data->angle, 1.0f, 0.0f, 0.0f);
    202 #if 0
    203     glRotatef(3.0f * sinf(f), 1.0f, 0.0f, 0.0f);
    204     glRotatef(8.0f * cosf(f), 0.0f, 0.0f, 1.0f);
    205 #endif
    206     glTranslatef(-320.0f, -240.0f, 0.0f);
    207     // XXX: end of debug stuff
     213    glLoadIdentity();
     214    glMultMatrixf(&model_matrix[0][0]);
    208215
    209216    for (int buf = 0, i = 0, n; i < data->ntiles; i = n, buf += 2)
     
    255262        free(texture);
    256263    }
    257 
    258     glPopMatrix();
    259264#endif
    260265
  • 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.