Changeset 770


Ignore:
Timestamp:
Jun 7, 2011, 12:39:21 AM (8 years ago)
Author:
sam
Message:

test: start writing really minimalist GL rendering tests.

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/debugquad.cpp

    r764 r770  
    1414
    1515#include <cmath>
     16#include <cstdio>
    1617
    1718#include "core.h"
     
    3334
    3435private:
     36    vec2 orig, step, aa, bb;
     37
    3538    int initialised;
    3639    float time;
     
    6568    Entity::TickDraw(deltams);
    6669
    67     if (IsDestroying())
    68     {
    69         if (data->initialised)
    70         {
    71             glDeleteBuffers(3, data->buflist);
    72             Shader::Destroy(data->shader);
    73             glDeleteTextures(1, data->texlist);
    74             data->initialised = 0;
    75         }
    76     }
    77     else if (!data->initialised)
     70    if (!data->initialised && !IsDestroying())
    7871    {
    7972        glGenBuffers(3, data->buflist);
    8073
    8174        static char const *vertexshader =
    82             "#version 130\n"
    83             "in vec2 in_Position;\n"
    84             "in vec4 in_Color;\n"
    85             "in vec2 in_TexCoord;\n"
    86             "out vec4 pass_Color;\n"
     75            "//#version 130\n"
     76            "varying vec2 in_Position;\n"
     77            "varying vec4 in_Color;\n"
     78            "varying vec2 in_TexCoord;\n"
     79            "varying vec4 pass_Color;\n"
    8780            "void main()\n"
    8881            "{\n"
     82            "gl_TexCoord[0] = gl_MultiTexCoord0;\n"
    8983            "    gl_Position = vec4(in_Position, 0.0f, 1.0f);\n"
    9084            "    gl_TexCoord[0] = vec4(in_TexCoord, 0.0, 0.0);\n"
     
    9286            "}\n";
    9387        static char const *fragmentshader =
    94             "#version 130\n"
    95             "in vec4 pass_Color;\n"
     88            "//#version 130\n"
     89            "varying vec4 pass_Color;\n"
    9690            "uniform sampler2D in_Texture;\n"
    9791            "void main()\n"
     
    10094            "    vec4 tex = texture2D(in_Texture, vec2(gl_TexCoord[0]));\n"
    10195            "    gl_FragColor = col * tex;\n"
     96            "    gl_FragColor = vec4(1.0, 1.0, 1.0, 0.0);\n"
    10297            "}\n";
    10398        data->shader = Shader::Create(vertexshader, fragmentshader);
     
    123118        data->initialised = 1;
    124119    }
     120    else if (data->initialised && IsDestroying())
     121    {
     122        glDeleteBuffers(3, data->buflist);
     123        Shader::Destroy(data->shader);
     124        glDeleteTextures(1, data->texlist);
     125
     126        data->initialised = 0;
     127    }
    125128
    126129    float const st = sinf(0.0005f * data->time);
     
    214217    glDisableVertexAttribArray(attr_tex);
    215218#endif
     219
     220    /* Reset GL states */
     221    glMatrixMode(GL_PROJECTION);
     222    glLoadIdentity();
     223    glMatrixMode(GL_MODELVIEW);
     224    glLoadIdentity();
     225    glDisable(GL_TEXTURE_2D);
     226    glUseProgram(0);
     227
     228    /* Prepare our quad coordinates */
     229    vec2i const layout(4, 3);
     230    data->step = vec2(2.0f, -2.0f) / (2 * layout + vec2i(1));
     231    data->orig = vec2(-1.0f, 1.0f) + data->step;
     232    data->aa = data->orig;
     233    data->bb = data->orig + data->step;
     234
     235    /* Generate a few random numbers */
     236    float f1 = 0.5f + 0.5f * sinf(0.00034f * data->time);
     237    float f2 = 0.5f + 0.5f * sinf(0.00053f * data->time + 1.0f);
     238    float f3 = 0.5f + 0.5f * sinf(0.00072f * data->time + 4.0f);
     239    float f4 = 0.5f + 0.5f * sinf(0.00091f * data->time + 8.0f);
     240
     241    /* Quad #1: simple glBegin program */
     242    glColor3f(1.0f, 1.0f, 1.0f);
     243    glBegin(GL_TRIANGLES);
     244        glVertex3f(data->aa.x, data->bb.y, 0.0f);
     245        glVertex3f(data->bb.x, data->bb.y, 0.0f);
     246        glVertex3f(data->bb.x, data->aa.y, 0.0f);
     247
     248        glVertex3f(data->bb.x, data->aa.y, 0.0f);
     249        glVertex3f(data->aa.x, data->aa.y, 0.0f);
     250        glVertex3f(data->aa.x, data->bb.y, 0.0f);
     251    glEnd();
     252
     253    Advance();
     254
     255    /* Quad #2: glBegin program with varying color */
     256    glBegin(GL_TRIANGLES);
     257        glColor3f(f1, f2, f3);
     258        glVertex3f(data->aa.x, data->bb.y, 0.0f);
     259        glColor3f(f4, f2, f1);
     260        glVertex3f(data->bb.x, data->bb.y, 0.0f);
     261        glColor3f(f3, f1, f4);
     262        glVertex3f(data->bb.x, data->aa.y, 0.0f);
     263
     264        glVertex3f(data->bb.x, data->aa.y, 0.0f);
     265        glColor3f(f4, f3, f2);
     266        glVertex3f(data->aa.x, data->aa.y, 0.0f);
     267        glColor3f(f1, f2, f3);
     268        glVertex3f(data->aa.x, data->bb.y, 0.0f);
     269    glEnd();
     270
     271    Advance();
     272
     273    /* Quad #3: textured quad */
     274    glEnable(GL_TEXTURE_2D);
     275    glBindTexture(GL_TEXTURE_2D, data->texlist[0]);
     276    glColor3f(1.0f, 1.0f, 1.0f);
     277    glBegin(GL_TRIANGLES);
     278        glTexCoord2f(f1, f3);
     279        glVertex3f(data->aa.x, data->bb.y, 0.0f);
     280        glTexCoord2f(f3, f2);
     281        glVertex3f(data->bb.x, data->bb.y, 0.0f);
     282        glTexCoord2f(f2, f4);
     283        glVertex3f(data->bb.x, data->aa.y, 0.0f);
     284
     285        glTexCoord2f(f2, f4);
     286        glVertex3f(data->bb.x, data->aa.y, 0.0f);
     287        glTexCoord2f(f4, f1);
     288        glVertex3f(data->aa.x, data->aa.y, 0.0f);
     289        glTexCoord2f(f1, f3);
     290        glVertex3f(data->aa.x, data->bb.y, 0.0f);
     291    glEnd();
     292
     293    Advance();
     294
     295    /* Quad #4: vertex buffer */
     296}
     297
     298void DebugQuad::Advance()
     299{
     300    data->aa.x += 2.0f * data->step.x;
     301    data->bb.x += 2.0f * data->step.x;
     302    if (data->bb.x > 1.0f)
     303    {
     304        data->aa.x = data->orig.x;
     305        data->bb.x = data->orig.x + data->step.x;
     306        data->aa.y += 2.0f * data->step.y;
     307        data->bb.y += 2.0f * data->step.y;
     308    }
    216309}
    217310
  • trunk/src/debugquad.h

    r748 r770  
    3535
    3636private:
     37    void Advance();
     38
    3739    DebugQuadData *data;
    3840};
  • trunk/test/debug/quad.cpp

    r769 r770  
    4747    new SdlInput();
    4848#endif
    49     new DebugFps(20, 20);
     49    //new DebugFps(20, 20);
    5050    new DebugQuad();
    5151
Note: See TracChangeset for help on using the changeset viewer.