Browse Source

More shader crap. We can now display a coloured quad. Still disabled.

legacy
Sam Hocevar sam 14 years ago
parent
commit
139555f45c
2 changed files with 45 additions and 3 deletions
  1. +42
    -0
      src/scene.cpp
  2. +3
    -3
      src/video.cpp

+ 42
- 0
src/scene.cpp View File

@@ -136,6 +136,47 @@ void Scene::Render() // XXX: rename to Blit()
#endif
qsort(data->tiles, data->ntiles, sizeof(Tile), SceneData::Compare);

#if SHADER_CRAP
float *vertices = new float[18];
vertices[0] = -0.5f; vertices[1] = -0.5f; vertices[2] = 0.0f;
vertices[3] = -0.5f; vertices[4] = 0.5f; vertices[5] = 0.0f;
vertices[6] = 0.5f; vertices[7] = 0.5f; vertices[8] = 0.0f;

vertices[9] = 0.5f; vertices[10] = -0.5f; vertices[11] = 0.0f;
vertices[12] = -0.5f; vertices[13] = -0.5f; vertices[14] = 0.0f;
vertices[15] = 0.5f; vertices[16] = 0.5f; vertices[17] = 0.0f;

const GLfloat colors[6][3] = {
{ 1.0, 0.0, 0.0 },
{ 0.0, 1.0, 0.0 },
{ 0.0, 0.0, 1.0 },
{ 1.0, 0.0, 0.0 },
{ 0.0, 1.0, 0.0 },
{ 1.0, 1.0, 0.0 } };

GLuint id[3];
glGenVertexArrays(1, &id[0]);
glBindVertexArray(id[0]);
glGenBuffers(2, &id[1]);

glBindBuffer(GL_ARRAY_BUFFER, id[1]);
glBufferData(GL_ARRAY_BUFFER, 18 * sizeof(GLfloat), vertices, GL_STATIC_DRAW);
glVertexAttribPointer((GLuint)0, 3, GL_FLOAT, GL_FALSE, 0, 0);
glEnableVertexAttribArray(0);

glBindBuffer(GL_ARRAY_BUFFER, id[2]);
glBufferData(GL_ARRAY_BUFFER, 18 * sizeof(GLfloat), colors, GL_STATIC_DRAW);
glVertexAttribPointer((GLuint)1, 3, GL_FLOAT, GL_FALSE, 0, 0);
glEnableVertexAttribArray(1);

delete[] vertices;

glUseProgram(prog);
glBindVertexArray(id[0]);
glDrawArrays(GL_TRIANGLES, 0, 6);
glBindVertexArray(0);

#else
// XXX: debug stuff
glPushMatrix();
static float f = 0.0f;
@@ -210,6 +251,7 @@ void Scene::Render() // XXX: rename to Blit()
}

glPopMatrix();
#endif

free(data->tiles);
data->tiles = 0;


+ 3
- 3
src/video.cpp View File

@@ -43,14 +43,14 @@ static char const *vertexshader =
"in vec3 in_Position;\n"
"in vec3 in_Color;\n"
"out vec3 pass_Color;\n"
"//attribute vec4 position;\n"
"uniform mat4 projection_matrix;\n"
"uniform mat4 view_matrix;\n"
"uniform mat4 model_matrix;\n"
"\n"
"void main()\n"
"{\n"
" gl_Position = projection_matrix * view_matrix * model_matrix * vec4(in_Position, 1.0f);\n"
" //gl_Position = projection_matrix * view_matrix * model_matrix * vec4(in_Position, 1.0f);\n"
" gl_Position = vec4(in_Position, 1.0f);\n"
" pass_Color = in_Color;\n"
"}\n";

@@ -62,7 +62,7 @@ static char const *fragmentshader =
"\n"
"void main()\n"
"{\n"
" gl_FragColor = pass_Color;\n"
" gl_FragColor = vec4(pass_Color, 1.0);\n"
"}\n";
#endif



Loading…
Cancel
Save