* add padding for title
* clear screen with rgb color * better detection of endloop * assert if malloc 0
This commit is contained in:
parent
1e237fbaeb
commit
252d228cb6
2 changed files with 7 additions and 6 deletions
|
@ -1,5 +1,4 @@
|
||||||
#include "../includes/main.h"
|
#include "../includes/main.h"
|
||||||
#include <assert.h>
|
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
assert(GL_TRUE == gl4duwCreateWindow(argc, argv, "Othello", 10, 10, 800,
|
assert(GL_TRUE == gl4duwCreateWindow(argc, argv, "Othello", 10, 10, 800,
|
||||||
|
@ -15,8 +14,10 @@ int main(int argc, char *argv[]) {
|
||||||
void init(void) {
|
void init(void) {
|
||||||
gl4dpInitScreen();
|
gl4dpInitScreen();
|
||||||
|
|
||||||
table = generate_table(gl4dpGetWidth(), gl4dpGetHeight(), (Pos){0, 0},
|
int padding_title = 80;
|
||||||
RGB(255, 255, 255));
|
|
||||||
|
table = generate_table(gl4dpGetWidth(), gl4dpGetHeight() - padding_title,
|
||||||
|
(Pos){0, 0}, RGB(255, 255, 255));
|
||||||
|
|
||||||
atexit(quit);
|
atexit(quit);
|
||||||
}
|
}
|
||||||
|
@ -24,7 +25,7 @@ void init(void) {
|
||||||
void quit(void) { free_table(table); }
|
void quit(void) { free_table(table); }
|
||||||
|
|
||||||
void draw(void) {
|
void draw(void) {
|
||||||
gl4dpClearScreen();
|
gl4dpClearScreenWith(RGB(0, 0, 0));
|
||||||
job();
|
job();
|
||||||
gl4dpUpdateScreen(NULL);
|
gl4dpUpdateScreen(NULL);
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,6 +21,7 @@ Table *generate_table(GLuint width, GLuint height, Pos origin, Uint32 color) {
|
||||||
for (GLuint j = hPas; j < hMax; j += hPas, 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));
|
table->lines = malloc(space_needed * sizeof(int));
|
||||||
assert(table->lines != NULL);
|
assert(table->lines != NULL);
|
||||||
|
@ -39,7 +40,6 @@ Table *generate_table(GLuint width, GLuint height, Pos origin, Uint32 color) {
|
||||||
*(tmp + 2) = i;
|
*(tmp + 2) = i;
|
||||||
*(tmp + 3) = table->height;
|
*(tmp + 3) = table->height;
|
||||||
}
|
}
|
||||||
*(tmp) = -1;
|
|
||||||
|
|
||||||
return table;
|
return table;
|
||||||
}
|
}
|
||||||
|
@ -52,7 +52,7 @@ void free_table(Table *table) {
|
||||||
void draw_table(Table *table) {
|
void draw_table(Table *table) {
|
||||||
gl4dpSetColor(table->color);
|
gl4dpSetColor(table->color);
|
||||||
|
|
||||||
for (int *ptr = table->lines; *(ptr) != -1; ptr += 4) {
|
for (int *ptr = table->lines; *ptr; ptr += 4) {
|
||||||
gl4dpLine(*ptr, *(ptr + 1), *(ptr + 2), *(ptr + 3));
|
gl4dpLine(*ptr, *(ptr + 1), *(ptr + 2), *(ptr + 3));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue