Ignore:
Timestamp:
Feb 16, 2011, 7:04:11 PM (9 years ago)
Author:
sam
Message:

More shader crap for GLSL 1.30. Still disabled.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/video.cpp

    r615 r653  
    1414
    1515#include <cmath>
     16#include <cstdio>
    1617
    1718#ifdef WIN32
     
    2728
    2829#include "core.h"
     30
     31#if SHADER_CRAP
     32#   define ATTRIB_POSITION 42 /* arbitrary id */
     33    GLuint prog, sh1, sh2;
     34    GLint uni_m1, uni_m2, uni_m3;
     35
     36    float4x4 projection_matrix, view_matrix, model_matrix;
     37#endif
     38
     39#if SHADER_CRAP
     40static char const *vertexshader =
     41    "#version 130\n"
     42    "\n"
     43    "in vec3 in_Position;\n"
     44    "in vec3 in_Color;\n"
     45    "out vec3 pass_Color;\n"
     46    "//attribute vec4 position;\n"
     47    "uniform mat4 projection_matrix;\n"
     48    "uniform mat4 view_matrix;\n"
     49    "uniform mat4 model_matrix;\n"
     50    "\n"
     51    "void main()\n"
     52    "{\n"
     53    "    gl_Position = projection_matrix * view_matrix * model_matrix * vec4(in_Position, 1.0f);\n"
     54    "    pass_Color = in_Color;\n"
     55    "}\n";
     56
     57static char const *fragmentshader =
     58    "#version 130\n"
     59    "\n"
     60    "in vec3 pass_Color;\n"
     61    "out vec4 out_Color;\n"
     62    "\n"
     63    "void main()\n"
     64    "{\n"
     65    "    gl_FragColor = pass_Color;\n"
     66    "}\n";
     67#endif
    2968
    3069/*
     
    4382
    4483    glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
     84
     85#if SHADER_CRAP
     86    sh1 = glCreateShader(GL_VERTEX_SHADER);
     87    glShaderSource(sh1, 1, &vertexshader, NULL);
     88    glCompileShader(sh1);
     89
     90    char buf[4096];
     91    GLsizei dummy;
     92    glGetShaderInfoLog(sh1, 4096, &dummy, buf);
     93    fprintf(stderr, "sh1 %i: %s", sh1, buf);
     94
     95    sh2 = glCreateShader(GL_FRAGMENT_SHADER);
     96    glShaderSource(sh2, 1, &fragmentshader, NULL);
     97    glCompileShader(sh2);
     98
     99    glGetShaderInfoLog(sh2, 4096, &dummy, buf);
     100    fprintf(stderr, "sh2 %i: %s", sh2, buf);
     101
     102    prog = glCreateProgram();
     103    glAttachShader(prog, sh1);
     104    glAttachShader(prog, sh2);
     105
     106    //glBindAttribLocation(prog, ATTRIB_POSITION, "position");
     107    glBindAttribLocation(prog, 0, "in_Position");
     108    glBindAttribLocation(prog, 1, "in_Color");
     109    glLinkProgram(prog);
     110    glValidateProgram(prog);
     111
     112    uni_m1 = glGetUniformLocation(prog, "projection_matrix");
     113    uni_m2 = glGetUniformLocation(prog, "view_matrix");
     114    uni_m3 = glGetUniformLocation(prog, "model_matrix");
     115
     116    glClearColor(0.4f, 0.6f, 0.9f, 0.0f);
     117#endif
    45118}
    46119
    47120void Video::SetFov(float theta)
    48121{
     122#if SHADER_CRAP
     123    float width = GetWidth();
     124    float height = GetHeight();
     125    float near = -width - height;
     126    float far = width + height;
     127    projection_matrix = float4x4::perspective(theta, width, height, near, far);
     128#else
    49129#undef near /* Fuck Microsoft */
    50130#undef far /* Fuck Microsoft again */
     
    88168    glMatrixMode(GL_MODELVIEW);
    89169    glLoadIdentity();
     170#endif
    90171}
    91172
     
    100181void Video::Clear()
    101182{
     183#if SHADER_CRAP
     184    glViewport(0, 0, GetWidth(), GetHeight());
     185    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
     186
     187    view_matrix = float4x4(1.0f);
     188    view_matrix[3][0] = 0.0f;
     189    view_matrix[3][0] = 0.0f;
     190    view_matrix[3][0] = -5.0f;
     191
     192    model_matrix = float4x4(1.0f);
     193    model_matrix[0][0] = 0.5f;
     194    model_matrix[1][1] = 0.5f;
     195    model_matrix[2][2] = 0.5f;
     196
     197    glUniformMatrix4fv(uni_m1, 1, GL_FALSE, &projection_matrix[0][0]);
     198    glUniformMatrix4fv(uni_m2, 1, GL_FALSE, &view_matrix[0][0]);
     199    glUniformMatrix4fv(uni_m3, 1, GL_FALSE, &model_matrix[0][0]);
     200#else
    102201    glEnable(GL_DEPTH_TEST);
    103202    glDepthFunc(GL_LEQUAL);
     
    108207
    109208    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
     209#endif
    110210
    111211    SetFov(0.0f);
     212}
     213
     214void Video::Destroy()
     215{
     216#if SHADER_CRAP
     217    glDetachShader(prog, sh1);
     218    glDetachShader(prog, sh2);
     219    glDeleteShader(sh1);
     220    glDeleteShader(sh2);
     221    glDeleteProgram(prog);
     222#endif
    112223}
    113224
Note: See TracChangeset for help on using the changeset viewer.