From f7625d9207279607a729eb2e07860b3575941d86 Mon Sep 17 00:00:00 2001 From: Arves100 Date: Thu, 28 Jun 2018 23:27:18 +0200 Subject: [PATCH 1/5] Fixed compilation for C<99 --- src/config.c | 3 ++- src/opengl/extensions.c | 3 +-- src/opengl/ogl_bitmap.c | 3 ++- src/opengl/ogl_fbo.c | 26 ++++++++++++++++++-------- src/win/wgl_disp.c | 5 ++++- 5 files changed, 27 insertions(+), 13 deletions(-) diff --git a/src/config.c b/src/config.c index 1848d5e753..f16773c195 100644 --- a/src/config.c +++ b/src/config.c @@ -706,13 +706,14 @@ bool al_remove_config_key(ALLEGRO_CONFIG *config, char const *section, ALLEGRO_USTR const *ukey = al_ref_cstr(&key_info, key); void *value; ALLEGRO_CONFIG_ENTRY * e; + ALLEGRO_CONFIG_SECTION *s; if (section == NULL) section = ""; usection = al_ref_cstr(§ion_info, section); - ALLEGRO_CONFIG_SECTION *s = find_section(config, usection); + s = find_section(config, usection); if (!s) return false; diff --git a/src/opengl/extensions.c b/src/opengl/extensions.c index 91857b6154..588c43ea03 100644 --- a/src/opengl/extensions.c +++ b/src/opengl/extensions.c @@ -133,6 +133,7 @@ static uint32_t parse_opengl_version(const char *s) /* Reads version info out of glGetString(GL_VERSION) */ static uint32_t _al_ogl_version(void) { + const char *str; char const *value = al_get_config_value(al_get_system_config(), "opengl", "force_opengl_version"); if (value) { @@ -145,8 +146,6 @@ static uint32_t _al_ogl_version(void) return v; } - const char *str; - str = (const char *)glGetString(GL_VERSION); if (str) { #ifdef ALLEGRO_CFG_OPENGLES diff --git a/src/opengl/ogl_bitmap.c b/src/opengl/ogl_bitmap.c index 5d100b6d49..c715c1f53c 100644 --- a/src/opengl/ogl_bitmap.c +++ b/src/opengl/ogl_bitmap.c @@ -1145,6 +1145,7 @@ GLuint al_get_opengl_texture(ALLEGRO_BITMAP *bitmap) */ void al_remove_opengl_fbo(ALLEGRO_BITMAP *bitmap) { + ALLEGRO_FBO_INFO *info; ALLEGRO_BITMAP_EXTRA_OPENGL *ogl_bitmap; if (bitmap->parent) bitmap = bitmap->parent; @@ -1157,7 +1158,7 @@ void al_remove_opengl_fbo(ALLEGRO_BITMAP *bitmap) ASSERT(ogl_bitmap->fbo_info->fbo_state > FBO_INFO_UNUSED); ASSERT(ogl_bitmap->fbo_info->fbo != 0); - ALLEGRO_FBO_INFO *info = ogl_bitmap->fbo_info; + info = ogl_bitmap->fbo_info; _al_ogl_del_fbo(info); if (info->fbo_state == FBO_INFO_PERSISTENT) { diff --git a/src/opengl/ogl_fbo.c b/src/opengl/ogl_fbo.c index 2dea528a63..89fca399b6 100644 --- a/src/opengl/ogl_fbo.c +++ b/src/opengl/ogl_fbo.c @@ -174,15 +174,18 @@ static void attach_depth_buffer(ALLEGRO_FBO_INFO *info) ALLEGRO_DISPLAY *display = _al_get_bitmap_display(info->owner); int w = al_get_bitmap_width(info->owner); int h = al_get_bitmap_height(info->owner); + int samples = 0; + bool extension_supported; + GLint e; if (bits == 24) gldepth = GL_DEPTH_COMPONENT24; glGenRenderbuffersEXT(1, &rb); glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, rb); - int samples = al_get_bitmap_samples(info->owner); + samples = al_get_bitmap_samples(info->owner); - bool extension_supported; + #ifdef ALLEGRO_CFG_OPENGLES (void)display; extension_supported = al_have_opengl_extension("EXT_multisampled_render_to_texture"); @@ -206,7 +209,7 @@ static void attach_depth_buffer(ALLEGRO_FBO_INFO *info) info->buffers.dw = w; info->buffers.dw = h; info->buffers.depth = bits; - GLint e = glGetError(); + e = glGetError(); if (e) { ALLEGRO_ERROR("glRenderbufferStorage failed! bits=%d w=%d h=%d (%s)\n", bits, w, h, _al_gl_error_string(e)); @@ -232,6 +235,7 @@ static void attach_multisample_buffer(ALLEGRO_FBO_INFO *info) { #if !defined ALLEGRO_RASPBERRYPI && (!defined ALLEGRO_ANDROID || defined ALLEGRO_CFG_OPENGLES3) ALLEGRO_BITMAP *b = info->owner; + ALLEGRO_DISPLAY *display = NULL; int samples = al_get_bitmap_samples(b); if (info->buffers.multisample_buffer != 0) { @@ -245,7 +249,7 @@ static void attach_multisample_buffer(ALLEGRO_FBO_INFO *info) if (!samples) return; - ALLEGRO_DISPLAY *display = _al_get_bitmap_display(info->owner); + display = _al_get_bitmap_display(info->owner); if (!display->ogl_extras->extension_list->ALLEGRO_GL_EXT_framebuffer_multisample) return; @@ -505,20 +509,26 @@ void _al_ogl_setup_fbo(ALLEGRO_DISPLAY *display, ALLEGRO_BITMAP *bitmap) void _al_ogl_finalize_fbo(ALLEGRO_DISPLAY *display, ALLEGRO_BITMAP *bitmap) { + ALLEGRO_FBO_INFO *info = NULL; ALLEGRO_BITMAP_EXTRA_OPENGL *extra = bitmap->extra; + +#ifndef ALLEGRO_CFG_OPENGLES + int w, h; + GLuint blit_fbo; +#endif + if (!extra) return; - ALLEGRO_FBO_INFO *info = extra->fbo_info; + info = extra->fbo_info; (void)display; if (!info) return; if (!info->buffers.multisample_buffer) return; #ifndef ALLEGRO_CFG_OPENGLES - int w = al_get_bitmap_width(bitmap); - int h = al_get_bitmap_height(bitmap); + w = al_get_bitmap_width(bitmap); + h = al_get_bitmap_height(bitmap); - GLuint blit_fbo; glGenFramebuffersEXT(1, &blit_fbo); glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, blit_fbo); glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, diff --git a/src/win/wgl_disp.c b/src/win/wgl_disp.c index e7952a553e..7c6e4cc74e 100644 --- a/src/win/wgl_disp.c +++ b/src/win/wgl_disp.c @@ -919,6 +919,7 @@ static bool create_display_internals(ALLEGRO_DISPLAY_WGL *wgl_disp) WGL_DISPLAY_PARAMETERS ndp; int window_x, window_y; int major, minor; + bool fc = false; /* The window is created in a separate thread so we need to pass this * TLS on @@ -967,7 +968,9 @@ static bool create_display_internals(ALLEGRO_DISPLAY_WGL *wgl_disp) if ((disp->flags & ALLEGRO_OPENGL_3_0) || major != 0) { if (major == 0) major = 3; - bool fc = (disp->flags & ALLEGRO_OPENGL_FORWARD_COMPATIBLE) != 0; + if ((disp->flags & ALLEGRO_OPENGL_FORWARD_COMPATIBLE) != 0) + fc = true; + wgl_disp->glrc = init_ogl_context_ex(wgl_disp->dc, fc, major, minor); } From 0b9f74f62e1dc8dea48053438991b9715510facb Mon Sep 17 00:00:00 2001 From: Arves100 Date: Fri, 29 Jun 2018 13:34:21 +0200 Subject: [PATCH 2/5] Fixed some things --- src/opengl/ogl_fbo.c | 2 +- src/win/wgl_disp.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/opengl/ogl_fbo.c b/src/opengl/ogl_fbo.c index 89fca399b6..19f3ac1ecd 100644 --- a/src/opengl/ogl_fbo.c +++ b/src/opengl/ogl_fbo.c @@ -174,7 +174,7 @@ static void attach_depth_buffer(ALLEGRO_FBO_INFO *info) ALLEGRO_DISPLAY *display = _al_get_bitmap_display(info->owner); int w = al_get_bitmap_width(info->owner); int h = al_get_bitmap_height(info->owner); - int samples = 0; + int samples = 0; bool extension_supported; GLint e; diff --git a/src/win/wgl_disp.c b/src/win/wgl_disp.c index 7c6e4cc74e..07524f1d19 100644 --- a/src/win/wgl_disp.c +++ b/src/win/wgl_disp.c @@ -968,7 +968,7 @@ static bool create_display_internals(ALLEGRO_DISPLAY_WGL *wgl_disp) if ((disp->flags & ALLEGRO_OPENGL_3_0) || major != 0) { if (major == 0) major = 3; - if ((disp->flags & ALLEGRO_OPENGL_FORWARD_COMPATIBLE) != 0) + if (disp->flags & ALLEGRO_OPENGL_FORWARD_COMPATIBLE) fc = true; wgl_disp->glrc = init_ogl_context_ex(wgl_disp->dc, fc, major, From 52813f9499a334b8cb17911ac21167e118a8c757 Mon Sep 17 00:00:00 2001 From: Arves100 Date: Fri, 29 Jun 2018 13:39:24 +0200 Subject: [PATCH 3/5] Inconsistency whitespace fix --- src/opengl/ogl_fbo.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/opengl/ogl_fbo.c b/src/opengl/ogl_fbo.c index 19f3ac1ecd..b51764c6f6 100644 --- a/src/opengl/ogl_fbo.c +++ b/src/opengl/ogl_fbo.c @@ -175,8 +175,8 @@ static void attach_depth_buffer(ALLEGRO_FBO_INFO *info) int w = al_get_bitmap_width(info->owner); int h = al_get_bitmap_height(info->owner); int samples = 0; - bool extension_supported; - GLint e; + bool extension_supported; + GLint e; if (bits == 24) gldepth = GL_DEPTH_COMPONENT24; From fc6b22b8fdf144a70f2a17eba4a6ff37f515dec9 Mon Sep 17 00:00:00 2001 From: Arves100 Date: Fri, 29 Jun 2018 14:51:25 +0200 Subject: [PATCH 4/5] Fixed colors, image, font addon --- addons/color/color.c | 37 ++++++++++++++++++------------------- addons/font/bmfont.c | 39 ++++++++++++++++++++++++--------------- addons/image/jpg.c | 3 ++- addons/image/pcx.c | 3 ++- addons/image/png.c | 3 ++- 5 files changed, 48 insertions(+), 37 deletions(-) diff --git a/addons/color/color.c b/addons/color/color.c index 224535a522..f00dbdcded 100644 --- a/addons/color/color.c +++ b/addons/color/color.c @@ -764,27 +764,26 @@ double al_color_distance_ciede2000(ALLEGRO_COLOR color1, * http://www.ece.rochester.edu/~gsharma/ciede2000/ciede2000noteCRNA.pdf */ float l1, a1, b1, l2, a2, b2; + double pi = ALLEGRO_PI, dl, ml, c1, c2, mc, fac, g, dc, h1, h2, dh = 0, mh, t, sl, mls, sc, sh, rt; al_color_rgb_to_lab(color1.r, color1.g, color1.b, &l1, &a1, &b1); al_color_rgb_to_lab(color2.r, color2.g, color2.b, &l2, &a2, &b2); - double pi = ALLEGRO_PI; - double dl = l1 - l2; - double ml = (l1 + l2) / 2; - double c1 = sqrt(a1 * a1 + b1 * b1); - double c2 = sqrt(a2 * a2 + b2 * b2); - double mc = (c1 + c2) / 2; - double fac = sqrt(pow(mc, 7) / (pow(mc, 7) + tf7)); - double g = 0.5 * (1 - fac); + dl = l1 - l2; + ml = (l1 + l2) / 2; + c1 = sqrt(a1 * a1 + b1 * b1); + c2 = sqrt(a2 * a2 + b2 * b2); + mc = (c1 + c2) / 2; + fac = sqrt(pow(mc, 7) / (pow(mc, 7) + tf7)); + g = 0.5 * (1 - fac); a1 *= 1 + g; a2 *= 1 + g; c1 = sqrt(a1 * a1 + b1 * b1); c2 = sqrt(a2 * a2 + b2 * b2); - double dc = c2 - c1; + dc = c2 - c1; mc = (c1 + c2) / 2; fac = sqrt(pow(mc, 7) / (pow(mc, 7) + tf7)); - double h1 = fmod(2 * pi + atan2(b1, a1), 2 * pi); - double h2 = fmod(2 * pi + atan2(b2, a2), 2 * pi); - double dh = 0; - double mh = h1 + h2; + h1 = fmod(2 * pi + atan2(b1, a1), 2 * pi); + h2 = fmod(2 * pi + atan2(b2, a2), 2 * pi); + mh = h1 + h2; if (c1 * c2 != 0) { dh = h2 - h1; if (dh > pi) dh -= 2 * pi; @@ -794,13 +793,13 @@ double al_color_distance_ciede2000(ALLEGRO_COLOR color1, else mh = (h1 + h2 - 2 * pi) / 2; } dh = 2 * sqrt(c1 * c2) * sin(dh / 2); - double t = 1 - 0.17 * cos(mh - pi / 6) + 0.24 * cos(2 * mh) + + t = 1 - 0.17 * cos(mh - pi / 6) + 0.24 * cos(2 * mh) + 0.32 * cos(3 * mh + pi / 30) - 0.2 * cos(4 * mh - pi * 7 / 20); - double mls = pow(ml - 0.5, 2); - double sl = 1 + 1.5 * mls / sqrt(0.002 + mls); - double sc = 1 + 4.5 * mc; - double sh = 1 + 1.5 * mc * t; - double rt = -2 * fac * sin(pi / 3 * + mls = pow(ml - 0.5, 2); + sl = 1 + 1.5 * mls / sqrt(0.002 + mls); + sc = 1 + 4.5 * mc; + sh = 1 + 1.5 * mc * t; + rt = -2 * fac * sin(pi / 3 * exp(-pow(mh / pi * 36 / 5 - 11, 2))); return sqrt(pow(dl / sl, 2) + pow(dc / sc, 2) + pow(dh / sh, 2) + rt * dc / sc * dh / sh); diff --git a/addons/font/bmfont.c b/addons/font/bmfont.c index e0f7f95939..eec2a6b473 100644 --- a/addons/font/bmfont.c +++ b/addons/font/bmfont.c @@ -126,8 +126,9 @@ static void add_codepoint(BMFONT_PARSER *parser, int codepoint) { return; } if (codepoint == range->first + range->count) { + BMFONT_RANGE * range2; append_char(parser, range); - BMFONT_RANGE *range2 = range->next; + range2 = range->next; if (range2 != NULL && codepoint == range2->first - 1) { combine_ranges(data, range, range2); } @@ -154,11 +155,12 @@ static BMFONT_CHAR *find_codepoint(BMFONT_DATA *data, int codepoint) { static void add_page(BMFONT_PARSER *parser, char const *filename) { ALLEGRO_FONT *font = parser->font; BMFONT_DATA *data = font->data; + ALLEGRO_BITMAP *page; data->pages_count++; data->pages = al_realloc(data->pages, data->pages_count * sizeof *data->pages); al_set_path_filename(parser->path, filename); - ALLEGRO_BITMAP *page = al_load_bitmap_flags( + page = al_load_bitmap_flags( al_path_cstr(parser->path, '/'), data->flags); data->pages[data->pages_count - 1] = page; } @@ -244,8 +246,8 @@ static int font_descent(const ALLEGRO_FONT *f) { } static int get_kerning(BMFONT_CHAR *prev, int c) { - if (!prev) return 0; int i; + if (!prev) return 0; for (i = 0; i < prev->kerning_pairs; i++) { if (prev->kerning[i].second == c) { int a = prev->kerning[i].amount; @@ -278,12 +280,14 @@ static int each_character(const ALLEGRO_FONT *f, ALLEGRO_COLOR color, static int measure_char(const ALLEGRO_FONT *f, ALLEGRO_COLOR color, int ch, float x, float y, ALLEGRO_GLYPH *glyph) { - (void)color; - (void)y; - BMFONT_DATA *data = f->data; - BMFONT_CHAR *c = find_codepoint(data, ch); + BMFONT_DATA *data; + BMFONT_CHAR *c; int advance = 0; int xo = 0, yo = 0, w = 0, h = 0; + (void)color; + (void)y; + data = f->data; + c = find_codepoint(data, ch); if (c) { advance = c->xadvance; xo = c->xoffset; @@ -378,12 +382,13 @@ static int text_length(const ALLEGRO_FONT *f, const ALLEGRO_USTR *text) { static int render_char(const ALLEGRO_FONT *f, ALLEGRO_COLOR color, int ch, float x, float y) { BMFONT_DATA *data = f->data; BMFONT_CHAR *c = find_codepoint(data, ch); + ALLEGRO_BITMAP *page; if (!c) { if (f->fallback) return f->fallback->vtable->render_char( f->fallback, color, ch, x, y); return 0; } - ALLEGRO_BITMAP *page = data->pages[c->page]; + page = data->pages[c->page]; al_draw_tinted_bitmap_region(page, color, c->x, c->y, c->width, c->height, x + c->xoffset, y + c->yoffset, 0); return c->xadvance; @@ -413,13 +418,13 @@ static void destroy_range(BMFONT_RANGE *range) { static void destroy(ALLEGRO_FONT *f) { BMFONT_DATA *data = f->data; BMFONT_RANGE *range = data->range_first; + int i; while (range) { BMFONT_RANGE *next = range->next; destroy_range(range); range = next; } - int i; for (i = 0; i < data->pages_count; i++) { al_destroy_bitmap(data->pages[i]); } @@ -479,29 +484,33 @@ static ALLEGRO_FONT_VTABLE _al_font_vtable_xml = { ALLEGRO_FONT *_al_load_bmfont_xml(const char *filename, int size, int font_flags) { + ALLEGRO_FILE *f; + BMFONT_PARSER _parser; + BMFONT_PARSER *parser; + BMFONT_DATA *data; + ALLEGRO_FONT *font; + int i; (void)size; - ALLEGRO_FILE *f = al_fopen(filename, "r"); + f = al_fopen(filename, "r"); if (!f) { ALLEGRO_DEBUG("Could not open %s.\n", filename); return NULL; } - BMFONT_DATA *data = al_calloc(1, sizeof *data); - BMFONT_PARSER _parser; - BMFONT_PARSER *parser = &_parser; + data = al_calloc(1, sizeof *data); + parser = &_parser; parser->tag = al_ustr_new(""); parser->attribute = al_ustr_new(""); parser->path = al_create_path(filename); data->flags = font_flags; - ALLEGRO_FONT *font = al_calloc(1, sizeof *font); + font = al_calloc(1, sizeof *font); font->vtable = &_al_font_vtable_xml; font->data = data; parser->font = font; _al_xml_parse(f, xml_callback, parser); - int i; for (i = 0; i < data->kerning_pairs; i++) { BMFONT_KERNING *k = data->kerning + i; BMFONT_CHAR *c = find_codepoint(data, k->first); diff --git a/addons/image/jpg.c b/addons/image/jpg.c index 7eca9719dd..7766ae1f5d 100644 --- a/addons/image/jpg.c +++ b/addons/image/jpg.c @@ -298,6 +298,7 @@ static void save_jpg_entry_helper(ALLEGRO_FILE *fp, ALLEGRO_BITMAP *bmp, { struct jpeg_compress_struct cinfo; struct my_err_mgr jerr; + const char *level; ALLEGRO_LOCKED_REGION *lock; data->error = false; @@ -325,7 +326,7 @@ static void save_jpg_entry_helper(ALLEGRO_FILE *fp, ALLEGRO_BITMAP *bmp, cinfo.in_color_space = JCS_RGB; jpeg_set_defaults(&cinfo); - const char* level = al_get_config_value(al_get_system_config(), "image", "jpeg_quality_level"); + level = al_get_config_value(al_get_system_config(), "image", "jpeg_quality_level"); jpeg_set_quality(&cinfo, level ? strtol(level, NULL, 10) : 75, true); jpeg_start_compress(&cinfo, 1); diff --git a/addons/image/pcx.c b/addons/image/pcx.c index d9464eaa2e..bb883c2537 100644 --- a/addons/image/pcx.c +++ b/addons/image/pcx.c @@ -21,13 +21,14 @@ ALLEGRO_BITMAP *_al_load_pcx_f(ALLEGRO_FILE *f, int flags) unsigned char *buf; PalEntry pal[256]; bool keep_index; + char color_plane; ASSERT(f); al_fgetc(f); /* skip manufacturer ID */ al_fgetc(f); /* skip version flag */ al_fgetc(f); /* skip encoding flag */ - char color_plane = al_fgetc(f); + color_plane = al_fgetc(f); if (color_plane != 8) { /* we like 8 bit color planes */ ALLEGRO_ERROR("Invalid color plane %d.\n", color_plane); return NULL; diff --git a/addons/image/png.c b/addons/image/png.c index 1c984cbf01..6e092263a8 100644 --- a/addons/image/png.c +++ b/addons/image/png.c @@ -506,6 +506,7 @@ bool _al_save_png_f(ALLEGRO_FILE *fp, ALLEGRO_BITMAP *bmp) png_structp png_ptr = NULL; png_infop info_ptr = NULL; int colour_type; + int z_level; /* Create and initialize the png_struct with the * desired error handler functions. @@ -545,7 +546,7 @@ bool _al_save_png_f(ALLEGRO_FILE *fp, ALLEGRO_BITMAP *bmp) colour_type = PNG_COLOR_TYPE_RGB_ALPHA; /* Set compression level. */ - int z_level = translate_compression_level( + z_level = translate_compression_level( al_get_config_value(al_get_system_config(), "image", "png_compression_level") ); png_set_compression_level(png_ptr, z_level); From 6187893e4ece9258136d864bf4b99cb9371d56c5 Mon Sep 17 00:00:00 2001 From: Arves100 Date: Fri, 29 Jun 2018 14:58:05 +0200 Subject: [PATCH 5/5] Fixed ttf for old c --- addons/ttf/ttf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/ttf/ttf.c b/addons/ttf/ttf.c index 8d78de5dfb..c9545b91e7 100644 --- a/addons/ttf/ttf.c +++ b/addons/ttf/ttf.c @@ -222,6 +222,7 @@ static unsigned char *alloc_glyph_region(ALLEGRO_TTF_FONT_DATA *data, bool lock_whole_page) { ALLEGRO_BITMAP *page; + REGION lock_rect; int w4 = align4(w); int h4 = align4(h); int glyph_size = w4 > h4 ? w4 : h4; @@ -264,7 +265,6 @@ static unsigned char *alloc_glyph_region(ALLEGRO_TTF_FONT_DATA *data, data->page_line_height = h4; } - REGION lock_rect; if (lock_whole_page) { lock_rect.x = 0; lock_rect.y = 0;