remove gl4d stuff

This commit is contained in:
Mylloon 2022-11-16 09:24:07 +01:00
parent 8abd8aafa1
commit c324fba1f5
Signed by: Anri
GPG key ID: A82D63DFF8D1317F
9 changed files with 4 additions and 207 deletions

4
.gitignore vendored
View file

@ -1,6 +1,2 @@
compile_flags.txt
*.o
othello
fonts/

View file

@ -1,7 +1,6 @@
CC = gcc
CFLAGS = -I. -I/usr/include/SDL2 -std=c11 -O3
CFLAGS = -std=c11 -O3
RM = rm
LDFLAGS = -lm -lGL -lGL4Dummies -lSDL2 -lSDL2_ttf
SOURCES = $(wildcard src/*.c)
OBJECTS = $(patsubst %.c,%.c.o,$(notdir $(SOURCES)))
@ -15,7 +14,6 @@ main: compilation
dev: CFLAGS += -Wall -Wextra -Wshadow -Wcast-align -Wstrict-prototypes
dev: CFLAGS += -fanalyzer -fsanitize=undefined -pedantic -g
dev: LDFLAGS += -fsanitize=undefined
dev: compilation
compilation: $(OBJECTS)

View file

View file

@ -1,26 +1,7 @@
#ifndef OTHELLO_MAIN_H
#define OTHELLO_MAIN_H 1
#include <GL4D/gl4dp.h>
#include <GL4D/gl4duw_SDL2.h>
#include <SDL_ttf.h>
#include "text.h"
// Plateau
static Table *table = NULL;
static TTF_Font *font = NULL;
// Initialise le programme
static void init(void);
// Série d'évènement pendant chaque rendu de frame
static void job(void);
// Dessine dans la fenêtre
static void draw(void);
// Quitte le programme
static void quit(void);
#include <stdio.h>
#include <stdlib.h>
#endif

View file

@ -1,41 +0,0 @@
#ifndef OTHELLO_PLATEAU_H
#define OTHELLO_PLATEAU_H 1
#include <stdio.h>
#include <stdlib.h>
#include <GL4D/gl4dp.h>
#include <GL4D/gl4du.h>
// Position d'un point x, y
struct pos {
GLuint x, y;
};
typedef struct pos Pos;
// Plateau
struct table {
GLuint width;
GLuint height;
int nb_row;
int nb_columns;
// TODO: Use Pos ? add center to the struct?
// Need malloc for each struct
int *lines;
Uint32 color;
};
typedef struct table Table;
// Génère une structure de plateau
Table *generate_table(GLuint width, GLuint height, Pos origin, Uint32 color);
// Libère le plateau en mémoire
void free_table(Table *table);
/* Dessine le plateau */
void draw_table(Table *);
#endif

View file

@ -1,18 +0,0 @@
#ifndef OTHELLO_TEXT_H
#define OTHELLO_TEXT_H 1
#include <SDL_ttf.h>
#include "plateau.h"
// Charge la police d'écriture
TTF_Font *load_font(int quality);
// Écrit du texte à une certaine position
void write_text(TTF_Font *font, char *text, GLfloat *s, GLfloat *t,
Uint32 color);
// Décharge la police
void unload_font(TTF_Font *font);
#endif

View file

@ -1,43 +1,7 @@
#include "../includes/main.h"
int padding_title = 80;
int main(int argc, char *argv[]) {
assert(GL_TRUE == gl4duwCreateWindow(argc, argv, "Othello", 10, 10, 800,
800, GL4DW_SHOWN));
init();
gl4duwDisplayFunc(draw);
gl4duwMainLoop();
printf("Othello\n");
return EXIT_SUCCESS;
}
void init(void) {
gl4dpInitScreen();
font = load_font(60);
table = generate_table(gl4dpGetWidth(), gl4dpGetHeight() - padding_title,
(Pos){0, 0}, RGB(255, 255, 255));
atexit(quit);
}
void quit(void) {
free_table(table);
unload_font(font);
}
void draw(void) {
job();
gl4dpUpdateScreen(NULL);
}
void job(void) {
char title[21];
sprintf(title, "Othello - tour des %c", 'B');
write_text(font, title, (GLfloat[2]){.6, -.1}, (GLfloat[2]){.3, 10.},
RGB(255, 255, 255));
draw_table(table);
}

View file

@ -1,58 +0,0 @@
#include "../includes/plateau.h"
Table *generate_table(GLuint width, GLuint height, Pos origin, Uint32 color) {
Table *table = malloc(sizeof(Table));
assert(table != NULL);
table->width = width;
table->height = height;
table->color = color;
table->nb_columns = table->nb_row = 8;
GLuint wPas = table->width / table->nb_columns,
hPas = table->height / table->nb_row, wMax = table->width - wPas,
hMax = table->height - hPas;
// Calcul l'espace neccessaire
int space_needed = 1;
for (GLuint i = wPas; i <= wMax; i += wPas, space_needed += 4) {
for (GLuint j = hPas; j <= hMax; j += hPas, space_needed += 4) {
}
}
assert(space_needed != 0);
table->lines = malloc(space_needed * sizeof(int));
assert(table->lines != NULL);
int *tmp = table->lines;
for (GLuint i = wPas; i <= wMax; i += wPas, tmp += 4) {
for (GLuint j = hPas; j <= hMax; j += hPas, tmp += 4) {
*tmp = table->width;
*(tmp + 1) = j;
*(tmp + 2) = origin.x;
*(tmp + 3) = j;
}
*tmp = i;
*(tmp + 1) = origin.y;
*(tmp + 2) = i;
*(tmp + 3) = table->height;
}
*tmp = -1;
return table;
}
void free_table(Table *table) {
free(table->lines);
free(table);
}
void draw_table(Table *table) {
gl4dpSetColor(table->color);
for (int *ptr = table->lines; *ptr != -1; ptr += 4) {
gl4dpLine(*ptr, *(ptr + 1), *(ptr + 2), *(ptr + 3));
}
}

View file

@ -1,25 +0,0 @@
#include "../includes/text.h"
#include "SDL_ttf.h"
#include <GL4D/gl4duw_SDL2.h>
TTF_Font *load_font(int quality) {
if (TTF_Init() == -1) {
fprintf(stderr, "TTF_Init: %s\n", TTF_GetError());
exit(EXIT_FAILURE);
}
return TTF_OpenFont("fonts/Hubot-Sans-Regular.ttf", quality);
}
void write_text(TTF_Font *font, char *text, GLfloat *s, GLfloat *t,
Uint32 color) {
SDL_Surface *surface = TTF_RenderText_Solid(
font, text,
(SDL_Color){RED(color), GREEN(color), BLUE(color), ALPHA(color)});
gl4dpCopyFromSDLSurfaceWithTransforms(surface, s, t);
SDL_FreeSurface(surface);
}
void unload_font(TTF_Font *font) { TTF_CloseFont(font); }