Changeset 656


Ignore:
Timestamp:
Feb 17, 2011, 1:53:38 AM (11 years ago)
Author:
sam
Message:

More shader crap. Texture coordinates now work. Still disabled.

Location:
trunk/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/scene.cpp

    r654 r656  
    139139#if SHADER_CRAP
    140140    float *vertices = new float[18];
    141     vertices[0] = -0.5f; vertices[1] = -0.5f; vertices[2] = 0.0f;
    142     vertices[3] = -0.5f; vertices[4] = 0.5f; vertices[5] = 0.0f;
    143     vertices[6] = 0.5f; vertices[7] = 0.5f; vertices[8] = 0.0f;
     141    vertices[0] = -0.5f; vertices[1] = 0.5f; vertices[2] = 0.0f;
     142    vertices[3] = 0.5f; vertices[4] = 0.5f; vertices[5] = 0.0f;
     143    vertices[6] = -0.5f; vertices[7] = -0.5f; vertices[8] = 0.0f;
    144144
    145145    vertices[9] = 0.5f; vertices[10] = -0.5f; vertices[11] = 0.0f;
     
    148148
    149149    const GLfloat colors[6][3] = {
    150     {  1.0,  0.0,  0.0  },
    151     {  0.0,  1.0,  0.0  },
    152150    {  0.0,  0.0,  1.0  },
    153151    {  1.0,  0.0,  0.0  },
    154152    {  0.0,  1.0,  0.0  },
    155     {  1.0,  1.0,  0.0  } };
    156 
    157     GLuint id[3];
     153    {  1.0,  1.0,  0.0  },
     154    {  0.0,  1.0,  0.0  },
     155    {  1.0,  0.0,  0.0  } };
     156
     157    const GLfloat tex[6][2] = {
     158    {  0.0,  0.0  },
     159    {  1.0,  0.0  },
     160    {  0.0,  1.0  },
     161    {  1.0,  1.0  },
     162    {  0.0,  1.0  },
     163    {  1.0,  0.0  } };
     164
     165    GLuint id[4];
    158166    glGenVertexArrays(1, &id[0]);
    159167    glBindVertexArray(id[0]);
    160     glGenBuffers(2, &id[1]);
     168    glGenBuffers(3, &id[1]);
    161169
    162170    glBindBuffer(GL_ARRAY_BUFFER, id[1]);
     
    170178    glEnableVertexAttribArray(1);
    171179
     180    glBindBuffer(GL_ARRAY_BUFFER, id[3]);
     181    glBufferData(GL_ARRAY_BUFFER, 12 * sizeof(GLfloat), tex, GL_STATIC_DRAW);
     182    glVertexAttribPointer((GLuint)2, 2, GL_FLOAT, GL_FALSE, 0, 0);
     183    glEnableVertexAttribArray(2);
     184
    172185    delete[] vertices;
    173186
    174187    glUseProgram(prog);
    175188    glBindVertexArray(id[0]);
     189    Tiler::Bind(1 << 16);
    176190    glDrawArrays(GL_TRIANGLES, 0, 6);
    177191    glBindVertexArray(0);
  • trunk/src/video.cpp

    r654 r656  
    4343    "in vec3 in_Position;\n"
    4444    "in vec3 in_Color;\n"
     45    "in vec2 in_TexCoord;\n"
    4546    "out vec3 pass_Color;\n"
    4647    "uniform mat4 projection_matrix;\n"
     
    5152    "{\n"
    5253    "    //gl_Position = projection_matrix * view_matrix * model_matrix * vec4(in_Position, 1.0f);\n"
    53     "    gl_Position = vec4(in_Position, 1.0f);\n"
     54    "    gl_Position = projection_matrix * view_matrix * model_matrix * vec4(in_Position, 1.0f);\n"
     55    "    gl_TexCoord[0] = vec4(in_TexCoord, 0.0, 0.0);\n"
    5456    "    pass_Color = in_Color;\n"
    5557    "}\n";
     
    5860    "#version 130\n"
    5961    "\n"
     62    "uniform sampler2D in_Texture;\n"
    6063    "in vec3 pass_Color;\n"
    6164    "out vec4 out_Color;\n"
     
    6366    "void main()\n"
    6467    "{\n"
    65     "    gl_FragColor = vec4(pass_Color, 1.0);\n"
     68    "    gl_FragColor = 0.5 * (texture2D(in_Texture, vec2(gl_TexCoord[0]))\n"
     69    "                           + vec4(pass_Color, 1.0));\n"
    6670    "}\n";
    6771#endif
     
    107111    glBindAttribLocation(prog, 0, "in_Position");
    108112    glBindAttribLocation(prog, 1, "in_Color");
     113    glBindAttribLocation(prog, 2, "in_TexCoord");
    109114    glLinkProgram(prog);
    110115    glValidateProgram(prog);
     
    123128    float width = GetWidth();
    124129    float height = GetHeight();
    125     float near = -width - height;
    126     float far = width + height;
     130    //float near = -width - height;
     131    //float far = width + height;
     132    float near = 20.0f;
     133    float far = 0.1f;
    127134    projection_matrix = float4x4::perspective(theta, width, height, near, far);
    128135#else
     
    187194    view_matrix = float4x4(1.0f);
    188195    view_matrix[3][0] = 0.0f;
    189     view_matrix[3][0] = 0.0f;
    190     view_matrix[3][0] = -5.0f;
     196    view_matrix[3][1] = 0.0f;
     197    view_matrix[3][2] = -5.0f;
    191198
    192199    model_matrix = float4x4(1.0f);
     
    209216#endif
    210217
    211     SetFov(0.0f);
     218#if SHADER_CRAP
     219    static float time;
     220    time += 0.01f;
     221    SetFov(1.0f + sinf(time));
     222#else
     223    SetFov(0.5f);
     224#endif
    212225}
    213226
Note: See TracChangeset for help on using the changeset viewer.