summaryrefslogtreecommitdiff
path: root/frontends/gl
diff options
context:
space:
mode:
Diffstat (limited to 'frontends/gl')
-rw-r--r--frontends/gl/drawable.c32
-rw-r--r--frontends/gl/main.c11
-rw-r--r--frontends/gl/shader.c6
3 files changed, 22 insertions, 27 deletions
diff --git a/frontends/gl/drawable.c b/frontends/gl/drawable.c
index 9abdd31..75c1ca5 100644
--- a/frontends/gl/drawable.c
+++ b/frontends/gl/drawable.c
@@ -8,11 +8,11 @@
#include <stdlib.h>
GLfloat vertices[] = {
- // Position Color Texcoords
- 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, // Top-left
- 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, // Top-right
- 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, // Bottom-right
- 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f // Bottom-left
+ // Position Texcoords
+ 0.0f, 0.0f, 0.0f, 0.0f, // Top-left
+ 0.0f, 0.0f, 1.0f, 0.0f, // Top-right
+ 0.0f, 0.0f, 1.0f, 1.0f, // Bottom-right
+ 0.0f, 0.0f, 0.0f, 1.0f // Bottom-left
};
GLuint elements[] = {
@@ -21,10 +21,10 @@ GLuint elements[] = {
};
void calc_pos(GLfloat *rect, GLfloat x, GLfloat y, GLfloat w, GLfloat h) {
- rect[0] = rect[24] = -1.0f + (x / 200.0f);
- rect[1] = rect[9] = 1.0f - (y / 400.0f);
- rect[17] = rect[25] = rect[1] - (h) / 400.0f;
- rect[8] = rect[16] = rect[0] + (w) / 200.0f;
+ rect[0] = rect[12] = -1.0f + (x / 200.0f);
+ rect[1] = rect[5] = 1.0f - (y / 400.0f);
+ rect[9] = rect[13] = rect[1] - (h) / 400.0f;
+ rect[4] = rect[8] = rect[0] + (w) / 200.0f;
}
bool load_image(char* file_name, drawable_t *drawable) {
@@ -47,8 +47,8 @@ bool load_image(char* file_name, drawable_t *drawable) {
void set_block_texture(drawable_t *drawable, uint8_t mino) {
GLfloat index = (mino + 2) * .0625f;
- drawable->vertices[6] = drawable->vertices[30] = index;
- drawable->vertices[14] = drawable->vertices[22] = index + .0625f;
+ drawable->vertices[2] = drawable->vertices[14] = index;
+ drawable->vertices[6] = drawable->vertices[10] = index + .0625f;
//vertices[5] = vertices[13] = vertices[21] = vertices[29] = opacity;
}
@@ -77,13 +77,13 @@ void new_rectangle(drawable_t* drawable) {
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, drawable->ebo);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(elements), elements, GL_DYNAMIC_DRAW);
- glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 8 * sizeof(GLfloat), (void*)0);
+ glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(GLfloat), (void*)0);
glEnableVertexAttribArray(0);
- glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE, 8 * sizeof(GLfloat), (void*)(2* sizeof(GLfloat)));
- glEnableVertexAttribArray(1);
+ //glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE, 8 * sizeof(GLfloat), (void*)(2* sizeof(GLfloat)));
+ //glEnableVertexAttribArray(1);
- glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, 8 * sizeof(GLfloat), (void*)(6 * sizeof(GLfloat)));
- glEnableVertexAttribArray(2);
+ glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(GLfloat), (void*)(2 * sizeof(GLfloat)));
+ glEnableVertexAttribArray(1);
}
diff --git a/frontends/gl/main.c b/frontends/gl/main.c
index 7e1aa66..e3aa591 100644
--- a/frontends/gl/main.c
+++ b/frontends/gl/main.c
@@ -119,6 +119,7 @@ int main(void) {
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+ glClearColor(0.21f, 0.12f, 0.11f, 1.0f);
glEnable(GL_DEPTH_TEST);
glClearDepth(1.0);
glDepthFunc(GL_LEQUAL);
@@ -142,15 +143,13 @@ int main(void) {
int delay = 1000/FRAME_RATE;
for (;;) {
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+
while(SDL_PollEvent(&e)) {
handle_key(e, &ui.keys, &ui.board);
}
-
- glClearColor(0.21f, 0.12f, 0.11f, 1.0f);
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
-
- //draw_current(&ui);
- draw_tetris_board(&ui);
+
+ draw_tetris_board(&ui);
SDL_GL_SwapWindow(window);
diff --git a/frontends/gl/shader.c b/frontends/gl/shader.c
index 8d66106..7e9ef3c 100644
--- a/frontends/gl/shader.c
+++ b/frontends/gl/shader.c
@@ -2,20 +2,16 @@
const char *vertex_shader_source = "#version 450 core\n"
"layout (location = 0) in vec2 aPos;\n"
- "layout (location = 1) in vec4 aColor;\n"
- "layout (location = 2) in vec2 aTexCoord;\n"
- "out vec4 ourColor;\n"
+ "layout (location = 1) in vec2 aTexCoord;\n"
"out vec2 TexCoord;\n"
"void main()\n"
"{\n"
" gl_Position = vec4(aPos, 0.0, 1.0);\n"
- " ourColor = aColor;\n"
" TexCoord = aTexCoord;\n"
"}\0";
const char *fragment_shader_source = "#version 450 core\n"
"out vec4 FragColor;\n"
- "in vec4 ourColor;\n"
"in vec2 TexCoord;\n"
"uniform sampler2D tex;\n"
"vec4 layer(vec4 foreground, vec4 background) {\n"