summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--frontends/gl/drawable.c3
-rw-r--r--frontends/gl/main.c31
-rw-r--r--frontends/gl/ui.c6
-rw-r--r--frontends/gl/ui.h2
-rw-r--r--lib/cetris.c2
-rw-r--r--lib/rules.c1
-rw-r--r--lib/rules.h3
-rw-r--r--meson_options.txt2
8 files changed, 32 insertions, 18 deletions
diff --git a/frontends/gl/drawable.c b/frontends/gl/drawable.c
index 9b927b5..86f2410 100644
--- a/frontends/gl/drawable.c
+++ b/frontends/gl/drawable.c
@@ -57,7 +57,8 @@ void update_rect(drawable_t *block, GLfloat x, GLfloat y, GLfloat w, GLfloat h,
set_block_texture(&vertices[0], mino);
glBindBuffer(GL_ARRAY_BUFFER, block->vbo);
- glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(vertices), vertices);
+ glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
+ //glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(vertices), vertices);
}
void new_rectangle(drawable_t* drawable) {
diff --git a/frontends/gl/main.c b/frontends/gl/main.c
index 911e5f0..ffd5794 100644
--- a/frontends/gl/main.c
+++ b/frontends/gl/main.c
@@ -7,14 +7,16 @@
#include <SDL.h>
#include <SDL_opengl.h>
-#include "cetris.h"
-#include "rules.h"
-#include "timer.h"
+#include <cetris.h>
+#include <timer.h>
+#include <rules.h>
+
#include "shader.h"
#include "skin.h"
#include "drawable.h"
#include "ui.h"
+static const int FRAME_RATE = 144;
static const int SCREEN_FULLSCREEN = 0;
static const int SCREEN_WIDTH = 400;
static const int SCREEN_HEIGHT = 800;
@@ -85,6 +87,9 @@ int main(void) {
SDL_GL_SetAttribute( SDL_GL_CONTEXT_MAJOR_VERSION, 4 );
SDL_GL_SetAttribute( SDL_GL_CONTEXT_MINOR_VERSION, 5 );
SDL_GL_SetAttribute( SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE );
+
+ SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
+ SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
if (SCREEN_FULLSCREEN) {
window = SDL_CreateWindow(
@@ -108,7 +113,7 @@ int main(void) {
printf("Renderer: %s\n", glGetString(GL_RENDERER));
printf("Version: %s\n", glGetString(GL_VERSION));
- //SDL_GL_SetSwapInterval(1);
+ SDL_GL_SetSwapInterval(1);
cetris_ui ui;
ui.keys = default_keys;
@@ -119,21 +124,22 @@ int main(void) {
new_shader_program(&shaderProgram);
glUseProgram(shaderProgram);
- ui.board.game.config = tetris_ds_config;
+ printf("%i\n", tetris_ds_config.board_x);
+ ui.board.config = tetris_ds_config;
+
+ init_game(&ui.board.game, &ui.board.config);
+ cetris_start_game(&ui.board.game);
load_tetris_board(&ui.board, 50.0f, 155.0f, 150.0f, 645.0f);
-
new_rectangle(&ui.board.block);
load_skin("test", &ui.skin);
- init_game(&ui.board.game, &tetris_ds_config);
- cetris_start_game(&ui.board.game);
-
glBindTexture(GL_TEXTURE_2D, ui.skin.block_texture);
SDL_Event e;
+ int delay = 1000/FRAME_RATE;
for (;;) {
while(SDL_PollEvent(&e)) {
handle_key(e, &ui.keys, &ui.board);
@@ -142,13 +148,16 @@ int main(void) {
glClearColor(0.2f, 0.3f, 0.3f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
- draw_tetris_board(&ui);
+ //draw_tetris_board(&ui);
draw_current(&ui);
SDL_GL_SwapWindow(window);
- SDL_Delay(1);
+ SDL_Delay(delay);
}
+
+ SDL_GL_DeleteContext(maincontext);
+ SDL_DestroyWindow(window);
SDL_Quit();
return 0;
diff --git a/frontends/gl/ui.c b/frontends/gl/ui.c
index 9a2cd63..f21292c 100644
--- a/frontends/gl/ui.c
+++ b/frontends/gl/ui.c
@@ -5,8 +5,10 @@
#include "drawable.h"
void load_tetris_board(tetris_board_t *board, GLfloat x, GLfloat y, GLfloat w, GLfloat h) {
- board->block_width = w / (GLfloat)board->game.config.board_x;
- board->block_height = h / (GLfloat)board->game.config.board_y;
+ board->block_width = w / (GLfloat)board->config.board_x;
+ board->block_height = h / (GLfloat)board->config.board_y;
+ printf("%i, %f, %i, %f\n", board->config.board_x, board->block_width,
+ board->config.board_y, board->block_height);
board->x_offset = x;
board->y_offset = y;
diff --git a/frontends/gl/ui.h b/frontends/gl/ui.h
index 450c41e..4854ab0 100644
--- a/frontends/gl/ui.h
+++ b/frontends/gl/ui.h
@@ -1,4 +1,5 @@
#pragma once
+#include <glad/glad.h>
#include "drawable.h"
#include "skin.h"
@@ -11,6 +12,7 @@ typedef struct {
drawable_t block;
cetris_game game;
+ cetris_config config;
} tetris_board_t;
typedef struct {
diff --git a/lib/cetris.c b/lib/cetris.c
index 82009b2..0fd5705 100644
--- a/lib/cetris.c
+++ b/lib/cetris.c
@@ -486,7 +486,7 @@ CETRIS_EXPORT void init_game(cetris_game *g, cetris_config* c) {
cetris_config config;
if (!c) config = g->config;
- else config = *c;
+ else config = *c;
// check for config errorsa
if (config.next_piece_delay < config.line_delay_clear)
diff --git a/lib/rules.c b/lib/rules.c
index 1a8b930..050a16e 100644
--- a/lib/rules.c
+++ b/lib/rules.c
@@ -43,3 +43,4 @@ cetris_config tetris_ds_config = {
};
+
diff --git a/lib/rules.h b/lib/rules.h
index 9d78086..c5236b2 100644
--- a/lib/rules.h
+++ b/lib/rules.h
@@ -3,8 +3,7 @@
#include <cetris.h>
-cetris_config tetris_ds_config;
-ctick tetris_worlds_levels[20];
+extern cetris_config tetris_ds_config;
bool twenty_line_sprint(cetris_game *g);
bool forty_line_sprint(cetris_game *g);
diff --git a/meson_options.txt b/meson_options.txt
index fd325a7..d0af07a 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -1,3 +1,3 @@
option('curses-frontend', type : 'boolean', value : false)
option('gl-frontend', type : 'boolean', value : true)
-option('sdl-frontend', type : 'boolean', value : true)
+option('sdl-frontend', type : 'boolean', value : false)