From 97186e586e0468d45bc0c26e665d26cc6bcee932 Mon Sep 17 00:00:00 2001 From: Aloz1 Date: Tue, 26 Jul 2016 23:16:26 +1000 Subject: [PATCH 1/2] Added pixbuf as a new data type. Pixbuf has been added as a new data type. This massively increases the speed of drawing individual pixels. --- Backend/Core/include/sgBackendTypes.h | 2 +- Backend/Core/include/sgInterfaces.h | 12 + Backend/SGSDL2/src/SGSDL2Core.cpp | 1 + Backend/SGSDL2/src/SGSDL2Graphics.cpp | 482 ++++++++++++++++++++++---- Backend/SGSDL2/src/SGSDL2Graphics.h | 16 +- Backend/SGSDL2/src/SGSDL2Input.cpp | 6 +- Backend/Test/src/main.cpp | 36 +- 7 files changed, 465 insertions(+), 90 deletions(-) diff --git a/Backend/Core/include/sgBackendTypes.h b/Backend/Core/include/sgBackendTypes.h index f9dc5909..1a8976df 100644 --- a/Backend/Core/include/sgBackendTypes.h +++ b/Backend/Core/include/sgBackendTypes.h @@ -24,7 +24,7 @@ typedef enum sg_drawing_surface_kind { SGDS_Unknown = 0, // Unknown, so do not draw onto this! SGDS_Window = 1, // A window - SGDS_Bitmap = 2 // A surface, bitmap, or texture + SGDS_Pixbuf = 3 } sg_drawing_surface_kind; // diff --git a/Backend/Core/include/sgInterfaces.h b/Backend/Core/include/sgInterfaces.h index d5b4acbc..8bc83359 100644 --- a/Backend/Core/include/sgInterfaces.h +++ b/Backend/Core/include/sgInterfaces.h @@ -162,6 +162,17 @@ extern "C" { sg_drawing_surface_surface_proc * draw_bitmap; } sg_image_interface; + // Pixbuf related functions + // + // = creating and drawing pixbufs + // + typedef struct sg_pixbuf_interface + { + sg_create_surface_fn * create_pixbuf; + sg_drawing_surface_surface_proc * draw_pixbuf; + + } sg_pixbuf_interface; + // // Audio related functions // @@ -403,6 +414,7 @@ extern "C" { sg_audio_interface audio; sg_graphics_interface graphics; sg_image_interface image; + sg_pixbuf_interface pixbuf; sg_input_interface input; sg_text_interface text; sg_utils_interface utils; diff --git a/Backend/SGSDL2/src/SGSDL2Core.cpp b/Backend/SGSDL2/src/SGSDL2Core.cpp index a3ff10ab..26904921 100644 --- a/Backend/SGSDL2/src/SGSDL2Core.cpp +++ b/Backend/SGSDL2/src/SGSDL2Core.cpp @@ -215,6 +215,7 @@ sg_interface * sg_load(sg_input_callbacks callbacks) sgsdl2_load_audio_fns(&_functions); sgsdl2_load_graphics_fns(&_functions); sgsdl2_load_image_fns(&_functions); + sgsdl2_load_pixbuf_fns(&_functions); sgsdl2_load_input_fns(&_functions); sgsdl2_load_text_fns(&_functions); sgsdl2_load_util_fns(&_functions); diff --git a/Backend/SGSDL2/src/SGSDL2Graphics.cpp b/Backend/SGSDL2/src/SGSDL2Graphics.cpp index ff7b62d0..4b84797e 100644 --- a/Backend/SGSDL2/src/SGSDL2Graphics.cpp +++ b/Backend/SGSDL2/src/SGSDL2Graphics.cpp @@ -35,6 +35,9 @@ static unsigned int _sgsdl2_num_open_windows = 0; static sg_bitmap_be ** _sgsdl2_open_bitmaps = NULL; static unsigned int _sgsdl2_num_open_bitmaps = 0; +static sg_pixbuf_be ** _sgsdl2_open_pixbufs = NULL; +static unsigned int _sgsdl2_num_open_pixbufs = 0; + // // Misc // @@ -616,6 +619,189 @@ void _sgsdl2_destroy_bitmap(sg_bitmap_be *bitmap_be) free(bitmap_be); } +// +// Add the pixbuf to the array +// +void _sgsdl2_add_pixbuf(sg_pixbuf_be *sfc) +{ + _sgsdl2_num_open_pixbufs++; + sg_pixbuf_be **new_arr = static_cast(realloc(_sgsdl2_open_pixbufs, sizeof(sg_pixbuf_be *) * _sgsdl2_num_open_pixbufs)); + + if (!new_arr) exit(-1); // out of memory + + _sgsdl2_open_pixbufs = new_arr; + new_arr[_sgsdl2_num_open_pixbufs-1] = sfc; +} + +// +// Remove the pixbuf... +// +void _sgsdl2_remove_pixbuf(sg_pixbuf_be *pixbuf_be) +{ + unsigned int idx = 0; + for (idx = 0; idx < _sgsdl2_num_open_pixbufs; idx++) + { + if ( _sgsdl2_open_pixbufs[idx] == pixbuf_be ) break; + } + + if ( idx >= _sgsdl2_num_open_pixbufs ) + { + //unable to locate pixbuf being closed! + exit(-1); + } + + // Shuffle pixbufs left + for (unsigned int i = idx; i < _sgsdl2_num_open_pixbufs -1; i++) + { + _sgsdl2_open_pixbufs[i] = _sgsdl2_open_pixbufs[i + 1]; + } + + // Remove the pixbuf + _sgsdl2_num_open_pixbufs--; + if (_sgsdl2_num_open_pixbufs > 0) + { + sg_pixbuf_be ** temp = static_cast(realloc(_sgsdl2_open_pixbufs, sizeof(sg_pixbuf_be *) * _sgsdl2_num_open_pixbufs)); + + if (!temp) + { + exit(-1); + } + else + { + _sgsdl2_open_pixbufs = temp; + } + } + else + { + free(_sgsdl2_open_pixbufs); + _sgsdl2_open_pixbufs = NULL; + } + + if ( _sgsdl2_num_open_pixbufs > 0 && ! _sgsdl2_num_open_pixbufs ) + { + // Error reducing memory allocation? + exit(-1); + } +} + +void _sgsdl2_destroy_pixbuf(sg_pixbuf_be *pixbuf_be) +{ + _sgsdl2_remove_pixbuf(pixbuf_be); + + if (pixbuf_be->surface) + { + SDL_FreeSurface(pixbuf_be->surface); + } + + pixbuf_be->surface = NULL; + + free(pixbuf_be); +} + +// +// Pixel Functions +// + +Uint32 _get_pixel(SDL_Surface *surface, int x, int y) +{ + Uint8 *p; + + if(!surface->pixels) return 0; + + p = static_cast(surface->pixels) + + y * surface->pitch + + x * surface->format->BytesPerPixel; + + if(x < 0 || y < 0 || x >= surface->w || y >= surface->h) return 0; + + uint32_t color; + + switch(surface->format->BytesPerPixel) { + case 1: + color = *p; + break; + case 2: + color = *reinterpret_cast(p); + break; + case 3: +#if SDL_BYTEORDER == SDL_BIG_ENDIAN + color = static_cast(p[0] << 16 | p[1] << 8 | p[2]); +#else + color = static_cast(p[0] | p[1] << 8 | p[2] << 16); +#endif + break; + case 4: + color = *reinterpret_cast(p); + break; + default: + color = 0; + } + + uint8_t r, g, b, a; + + SDL_GetRGBA(color, surface->format, &r, &g, &b, &a); + return (uint32_t)(r << 24 | g << 16 | b << 8 | a); + +// switch(surface->format->BytesPerPixel) { +// case 1: +// return *p; +// case 2: +// return *(Uint16 *)p; +// case 3: +//#if SDL_BYTEORDER == SDL_BIG_ENDIAN +// return static_cast(p[0] << 16 | p[1] << 8 | p[2]); +//#else +// return static_cast(p[0] | p[1] << 8 | p[2] << 16); +//#endif +// case 4: +// uint32_t color; +// uint8_t r, g, b, a; +// color = *(Uint32 *)p; +// +// r = (uint8_t)((color & surface->format->Rmask) >> (surface->format->Rshift)); +// g = (uint8_t)((color & surface->format->Gmask) >> (surface->format->Gshift)); +// b = (uint8_t)((color & surface->format->Bmask) >> (surface->format->Bshift)); +// a = (uint8_t)((color & surface->format->Amask) >> (surface->format->Ashift)); +// return (uint32_t)(r << 24 | g << 16 | b << 8 | a); +// default: +// return 0; +// } +} + +void _set_pixel(SDL_Surface *surface, sg_color clr, int x, int y) +{ + Uint8 *p; + + if(!surface->pixels) return; + + p = static_cast(surface->pixels) + + y * surface->pitch + + x * surface->format->BytesPerPixel; + + if(x < 0 || y < 0 || x >= surface->w || y >= surface->h) return; + + Uint32 pixel = SDL_MapRGBA( + surface->format, + static_cast(clr.r * 255), + static_cast(clr.g * 255), + static_cast(clr.b * 255), + static_cast(clr.a * 255) + ); + + // Convert Uint32 into 4 bytes (now in the correct order, as dictated by SDL_MapRGBA) +#if SDL_BYTEORDER == SDL_BIG_ENDIAN + p[0] = static_cast(pixel>>24); + p[1] = static_cast(pixel>>16); + p[2] = static_cast(pixel>>8); + p[3] = static_cast(pixel); +#else + p[0] = static_cast(pixel); + p[1] = static_cast(pixel>>8); + p[2] = static_cast(pixel>>16); + p[3] = static_cast(pixel>>24); +#endif +} + //-------------------------------------------------------------------------------------- // @@ -623,6 +809,7 @@ void _sgsdl2_destroy_bitmap(sg_bitmap_be *bitmap_be) // //-------------------------------------------------------------------------------------- + bool _sgsdl2_open_window(const char *title, int width, int height, unsigned int options, sg_window_be *window_be) { if( _sgsdl2_has_initial_window ) @@ -741,6 +928,10 @@ void sgsdl2_close_drawing_surface(sg_drawing_surface *surface) _sgsdl2_destroy_bitmap(static_cast(surface->_data)); break; + case SGDS_Pixbuf: + _sgsdl2_destroy_pixbuf(static_cast(surface->_data)); + break; + case SGDS_Unknown: break; } @@ -774,6 +965,21 @@ void _sgsdl2_clear_window(sg_drawing_surface *window, sg_color clr) } } +void _sgsdl2_clear_sdl_surface(SDL_Surface *surface, sg_color clr) +{ + if (surface) + { + for(int y = 0; y < surface->h; y++) + { + for(int x = 0; x < surface->w; x++) + { + _set_pixel(surface, clr, x, y); + } + } + } +} + + void _sgsdl2_clear_bitmap(sg_drawing_surface *bitmap, sg_color clr) { sg_bitmap_be * bitmap_be = static_cast(bitmap->_data); @@ -796,6 +1002,12 @@ void _sgsdl2_clear_bitmap(sg_drawing_surface *bitmap, sg_color clr) } } +void _sgsdl2_clear_pixbuf(sg_drawing_surface *surface, sg_color clr) +{ + sg_pixbuf_be * pixbuf_be = static_cast(surface->_data); + _sgsdl2_clear_sdl_surface( pixbuf_be->surface, clr ); +} + void sgsdl2_clear_drawing_surface(sg_drawing_surface *surface, sg_color clr) { if ( ! surface ) return; @@ -810,6 +1022,10 @@ void sgsdl2_clear_drawing_surface(sg_drawing_surface *surface, sg_color clr) _sgsdl2_clear_bitmap(surface, clr); break; + case SGDS_Pixbuf: + _sgsdl2_clear_pixbuf(surface, clr); + break; + case SGDS_Unknown: break; } @@ -859,6 +1075,7 @@ SDL_Renderer * _sgsdl2_prepared_renderer(sg_drawing_surface *surface, unsigned i else return NULL; } + case SGDS_Pixbuf: case SGDS_Unknown: return NULL; } @@ -874,6 +1091,7 @@ void _sgsdl2_complete_render(sg_drawing_surface *surface, unsigned int idx) if (idx < _sgsdl2_num_open_windows) _sgsdl2_restore_default_render_target(_sgsdl2_open_windows[idx], static_cast(surface->_data)); break; + case SGDS_Pixbuf: case SGDS_Unknown: break; } @@ -889,6 +1107,7 @@ unsigned int _sgsdl2_renderer_count(sg_drawing_surface *surface) // Drawing to a bitmap... so ensure that there is at least one window if ( _sgsdl2_num_open_windows == 0 ) _sgsdl2_create_initial_window(); return _sgsdl2_num_open_windows; + case SGDS_Pixbuf: case SGDS_Unknown: return 0; } @@ -1195,6 +1414,12 @@ void sgsdl2_draw_pixel(sg_drawing_surface *surface, sg_color clr, float *data, i // 2 values = 1 point int x1 = static_cast(data[0]), y1 = static_cast(data[1]); + if (surface->kind == SGDS_Pixbuf) + { + _set_pixel(static_cast(surface->_data)->surface, clr, x1, y1); + return; + } + unsigned int count = _sgsdl2_renderer_count(surface); for (unsigned int i = 0; i < count; i++) @@ -1424,6 +1649,22 @@ void sgsdl2_set_clip_rect(sg_drawing_surface *surface, float *data, int data_sz) break; } + case SGDS_Pixbuf: + { + sg_pixbuf_be *pixbuf_be; + pixbuf_be = static_cast(surface->_data); + + pixbuf_be->clipped = true; + + #ifdef WINDOWS + pixbuf_be->clip = { x1, y1, w, h }; + #else + //HACK: Current hack to fix SDL clip rect error + pixbuf_be->clip = { x1, surface->height - h - y1, w, h }; + #endif + + break; + } case SGDS_Unknown: break; @@ -1465,77 +1706,23 @@ void sgsdl2_clear_clip_rect(sg_drawing_surface *surface) break; } - case SGDS_Unknown: - break; - } -} - -Uint32 _get_pixel(SDL_Surface *surface, int x, int y) -{ - Uint8 *p; - - if(!surface->pixels) return 0; - - p = static_cast(surface->pixels) - + y * surface->pitch - + x * surface->format->BytesPerPixel; - - if(x < 0 || y < 0 || x >= surface->w || y >= surface->h) return 0; + case SGDS_Pixbuf: + { + sg_pixbuf_be *pixbuf_be; + pixbuf_be = static_cast(surface->_data); - uint32_t color; + pixbuf_be->clipped = false; + pixbuf_be->surface->clip_rect = { 0, 0, surface->width, surface->height }; - switch(surface->format->BytesPerPixel) { - case 1: - color = *p; - break; - case 2: - color = *reinterpret_cast(p); - break; - case 3: -#if SDL_BYTEORDER == SDL_BIG_ENDIAN - color = static_cast(p[0] << 16 | p[1] << 8 | p[2]); -#else - color = static_cast(p[0] | p[1] << 8 | p[2] << 16); -#endif break; - case 4: - color = *reinterpret_cast(p); + } + + case SGDS_Unknown: break; - default: - color = 0; } - - uint8_t r, g, b, a; - - SDL_GetRGBA(color, surface->format, &r, &g, &b, &a); - return (uint32_t)(r << 24 | g << 16 | b << 8 | a); - -// switch(surface->format->BytesPerPixel) { -// case 1: -// return *p; -// case 2: -// return *(Uint16 *)p; -// case 3: -//#if SDL_BYTEORDER == SDL_BIG_ENDIAN -// return static_cast(p[0] << 16 | p[1] << 8 | p[2]); -//#else -// return static_cast(p[0] | p[1] << 8 | p[2] << 16); -//#endif -// case 4: -// uint32_t color; -// uint8_t r, g, b, a; -// color = *(Uint32 *)p; -// -// r = (uint8_t)((color & surface->format->Rmask) >> (surface->format->Rshift)); -// g = (uint8_t)((color & surface->format->Gmask) >> (surface->format->Gshift)); -// b = (uint8_t)((color & surface->format->Bmask) >> (surface->format->Bshift)); -// a = (uint8_t)((color & surface->format->Amask) >> (surface->format->Ashift)); -// return (uint32_t)(r << 24 | g << 16 | b << 8 | a); -// default: -// return 0; -// } } + // // To Pixels // @@ -1577,6 +1764,21 @@ void sgsdl2_to_pixels(sg_drawing_surface *surface, int *pixels, int sz) } } } + + break; + } + + case SGDS_Pixbuf: + { + sg_pixbuf_be* pixbuf_be = static_cast(surface->_data); + for (int y = 0; y < surface->height; y++) + { + for(int x = 0; x < surface->width; x++) + { + pixels[y * surface->width + x] = static_cast(_get_pixel(pixbuf_be->surface, x, y)); + } + } + break; } @@ -1607,8 +1809,7 @@ void sgsdl2_show_border(sg_drawing_surface *surface, int border) } case SGDS_Bitmap: - break; - + case SGDS_Pixbuf: case SGDS_Unknown: break; } @@ -1631,8 +1832,7 @@ void sgsdl2_show_fullscreen(sg_drawing_surface *surface, int fullscreen) } case SGDS_Bitmap: - break; - + case SGDS_Pixbuf: case SGDS_Unknown: break; } @@ -1830,6 +2030,7 @@ sg_drawing_surface sgsdl2_create_bitmap(int width, int height) sg_drawing_surface result = { SGDS_Unknown, 0, 0, NULL }; result.kind = SGDS_Bitmap; + sg_bitmap_be *data = static_cast(malloc(sizeof(sg_bitmap_be))); result._data = data; @@ -1849,7 +2050,7 @@ sg_drawing_surface sgsdl2_create_bitmap(int width, int height) SDL_SetTextureBlendMode(data->texture[i], SDL_BLENDMODE_BLEND); _sgsdl2_set_renderer_target(i, data); - SDL_SetRenderDrawColor(_sgsdl2_open_windows[i]->renderer, 255, 255, 255, 0); + SDL_SetRenderDrawColor(_sgsdl2_open_windows[i]->renderer, 255, 255, 255, 255); SDL_RenderClear(_sgsdl2_open_windows[i]->renderer); _sgsdl2_restore_default_render_target(i, data); } @@ -1871,6 +2072,7 @@ sg_drawing_surface sgsdl2_load_bitmap(const char * filename) std::cout << "error loading image " << IMG_GetError() << std::endl; return result; } + sg_bitmap_be *data = static_cast(malloc(sizeof(sg_bitmap_be))); result._data = data; @@ -1992,6 +2194,148 @@ void sgsdl2_load_image_fns(sg_interface *functions) functions->image.draw_bitmap = & sgsdl2_draw_bitmap; } + +//-------------------------------------------------------------------------------------- +// +// Pixbufs +// +//-------------------------------------------------------------------------------------- + + +sg_drawing_surface sgsdl2_create_pixbuf(int width, int height) +{ + if ( ! _sgsdl2_has_initial_window ) _sgsdl2_create_initial_window(); + + sg_drawing_surface result = { SGDS_Unknown, 0, 0, NULL }; + + result.kind = SGDS_Pixbuf; + + sg_pixbuf_be *data = static_cast(malloc(sizeof(sg_pixbuf_be))); + + result._data = data; + result.width = width; + result.height = height; + + data->clipped = false; + data->surface->clip_rect = {0, 0, width, height}; + + int bpp; + uint32_t r; + uint32_t g; + uint32_t b; + uint32_t a; + + //SDL_PixelFormatEnumToMasks(SDL_PIXELFORMAT_ARGB8888, &bpp, &r, &g, &b, &a); + SDL_PixelFormatEnumToMasks(SDL_PIXELFORMAT_RGBA8888, &bpp, &r, &g, &b, &a); + + data->surface = SDL_CreateRGBSurface( + 0, width, height, bpp, + r, + g, + b, + a + ); + + _sgsdl2_add_pixbuf(data); + + return result; +} + +// x, y is the position to draw the pixbuf to. As pixbufs scale around their centre, (x, y) is the top-left of the pixbuf IF and ONLY IF scale = 1. +// Angle is in degrees, 0 being right way up +// Centre is the point to rotate around, relative to the pixbuf centre (therefore (0,0) would rotate around the centre point) +void sgsdl2_draw_pixbuf( sg_drawing_surface * src, sg_drawing_surface * dst, float * src_data, int src_data_sz, float * dst_data, int dst_data_sz, sg_renderer_flip flip ) +{ + if ( ! src || ! dst || src->kind != SGDS_Bitmap ) + return; + + if ( dst_data_sz != 7 ) + return; + + // dst_data must be 7 values + float x = dst_data[0]; + float y = dst_data[1]; + float angle = dst_data[2]; + float centre_x = dst_data[3]; + float centre_y = dst_data[4]; + float scale_x = dst_data[5]; + float scale_y = dst_data[6]; + + if ( src_data_sz != 4) + return; + + // src_data must be + float src_x = src_data[0]; + float src_y = src_data[1]; + float src_w = src_data[2]; + float src_h = src_data[3]; + + // Other locals + SDL_Texture *srcT; + + // Create destination rect from scale values + SDL_Rect dst_rect = { + static_cast(x - (src_w * scale_x / 2.0) + src_w/2.0), + static_cast(y - (src_h * scale_y / 2.0) + src_h/2.0), //fix the drawing position as scaling broke it + static_cast(src_w * scale_x), + static_cast(src_h * scale_y) + }; //scale bitmap + + SDL_Rect src_rect = { + static_cast(src_x), + static_cast(src_y), + static_cast(src_w), + static_cast(src_h) + }; + + // check if any size is 0... and return if nothing is to be drawn + if ( 0 == dst_rect.w || 0 == dst_rect.h || 0 == src_rect.w || 0 == src_rect.h ) return; + + // Adjust centre to be relative to the bitmap centre rather than top-left + centre_x = (centre_x * scale_x) + dst_rect.w / 2.0f; + centre_y = (centre_y * scale_y) + dst_rect.h / 2.0f; + + unsigned int count = _sgsdl2_renderer_count(dst); + + for (unsigned int i = 0; i < count; i++) + { + SDL_Renderer *renderer = _sgsdl2_prepared_renderer(dst, i); + + // if its a window, dont use the renderer index to get the texture + if (dst->kind == SGDS_Window) + { + unsigned int idx = static_cast(dst->_data)->idx; + srcT = static_cast(src->_data)->texture[ idx ]; + } + //else if(dst->kind == SGDS_Pixbuf) + //{ + //srcT = SDL_CreateTextureFromSurface(renderer, static_cast(src->_data)->surface); + //} + else + { + srcT = static_cast(src->_data)->texture[ i ]; + } + + //Convert parameters to format SDL_RenderCopyEx expects + SDL_Point centre = { + static_cast(centre_x), + static_cast(centre_y) + }; + SDL_RendererFlip sdl_flip = static_cast((flip == SG_FLIP_BOTH) ? (SDL_FLIP_HORIZONTAL | SDL_FLIP_VERTICAL) : flip); //SDL does not have a FLIP_BOTH + + //Render + SDL_RenderCopyEx(renderer, srcT, &src_rect, &dst_rect, angle, ¢re, sdl_flip); + + _sgsdl2_complete_render(dst, i); + } +} + +void sgsdl2_load_pixbuf_fns(sg_interface *functions) +{ + functions->pixbuf.create_pixbuf = &sgsdl2_create_pixbuf; + functions->pixbuf.draw_pixbuf = &sgsdl2_draw_pixbuf; +} + void sgsdl2_finalise_graphics() { // Close all bitmaps diff --git a/Backend/SGSDL2/src/SGSDL2Graphics.h b/Backend/SGSDL2/src/SGSDL2Graphics.h index 3d105799..32e69624 100644 --- a/Backend/SGSDL2/src/SGSDL2Graphics.h +++ b/Backend/SGSDL2/src/SGSDL2Graphics.h @@ -44,14 +44,20 @@ typedef struct sg_window_be typedef struct sg_bitmap_be { // 1 texture per open window - SDL_Texture ** texture; - SDL_Surface * surface; - bool clipped; - SDL_Rect clip; + SDL_Texture ** texture; + SDL_Surface * surface; + bool clipped; + SDL_Rect clip; - bool drawable; // can be drawn on + bool drawable; // can be drawn on } sg_bitmap_be; +typedef struct sg_pixbuf_be +{ + SDL_Surface * surface; + bool clipped; +} sg_pixbuf_be; + sg_window_be *_sgsdl2_get_window_with_id(unsigned int window_id); sg_window_be *_sgsdl2_get_window_with_pointer(pointer p); diff --git a/Backend/SGSDL2/src/SGSDL2Input.cpp b/Backend/SGSDL2/src/SGSDL2Input.cpp index 9d74eb6c..8bdf3017 100644 --- a/Backend/SGSDL2/src/SGSDL2Input.cpp +++ b/Backend/SGSDL2/src/SGSDL2Input.cpp @@ -247,8 +247,7 @@ void sgsdl2_warp_mouse(sg_drawing_surface *surface, int x, int y) } case SGDS_Bitmap: - break; - + case SGDS_Pixbuf: case SGDS_Unknown: break; } @@ -276,8 +275,7 @@ void sgsdl2_window_position(sg_drawing_surface *surface, int *x, int *y) } case SGDS_Bitmap: - break; - + case SGDS_Pixbuf: case SGDS_Unknown: break; } diff --git a/Backend/Test/src/main.cpp b/Backend/Test/src/main.cpp index 59842305..5ae7cf07 100644 --- a/Backend/Test/src/main.cpp +++ b/Backend/Test/src/main.cpp @@ -43,17 +43,19 @@ enum test_options enum test_drawing_options { TEST_COLORS = 1, - TEST_READ_PIXELS = 2, - TEST_POSITIONS = 4, - TEST_ALPHA = 8, - TEST_CLIP = 16, - TEST_PIXELS = 32, - TEST_SHAPES = 64, - TEST_RESIZE = 128, + TEST_READ_PIXELS = 2, + TEST_POSITIONS = 4, + TEST_ALPHA = 8, + TEST_CLIP = 16, + TEST_PIXELS = 32, + TEST_SHAPES = 64, + TEST_RESIZE = 128, TEST_LINES = 256, - TEST_BITMAPS = 512, + TEST_BITMAPS = 512, TEST_INPUT = 1024, - TEST_FULLSCREEN = 2048 + TEST_FULLSCREEN = 2048, + TEST_DIRECT_PIXSPEED = 4096, + TEST_PIXBUF = 8192 }; void print_options() @@ -83,6 +85,8 @@ void print_drawing_options() cout << "512: test bitmaps " << endl; cout << "1024: test input " << endl; cout << "2048: test fullscreen " << endl; + cout << "4096: test direct pixel drawing speed " << endl; + cout << "8192: test pixbuf " << endl; } @@ -921,13 +925,23 @@ bool test_basic_drawing(int drawing_test_run) { test_pixels( &window, 1); } + + if (drawing_test_run & TEST_DIRECT_PIXSPEED) + { + test_direct_pixel_speed( &window, 1); + } + + if (drawing_test_run & TEST_PIXBUF) + { + test_pixbuf( &window, 1); + } if (drawing_test_run & TEST_FULLSCREEN) { _sg_functions->graphics.show_fullscreen(&window, true); test_rects( &window, 1); - + _sg_functions->graphics.show_fullscreen(&window, false); } @@ -1174,7 +1188,7 @@ int main(int argc, const char * argv[]) int test_run = 0; int test_drawing_run = INT_MAX; scanf("%d", &test_run); - + if (test_run == 0) { test_run |= 255; From 0b50cca43547f85882d79a849f3b732e29ceb607 Mon Sep 17 00:00:00 2001 From: Aloz1 Date: Thu, 4 Aug 2016 13:33:37 +1000 Subject: [PATCH 2/2] Fixed issues caused by rebase This commit fixes some logic and code errors caused by the rebase from v4_backend to devel --- Backend/Core/include/sgBackendTypes.h | 17 +- Backend/SGSDL2/src/SGSDL2Graphics.cpp | 18 +- Backend/SGSDL2/src/SGSDL2Graphics.h | 5 +- Backend/Test/src/main.cpp | 561 +++++++++++++++----------- 4 files changed, 348 insertions(+), 253 deletions(-) diff --git a/Backend/Core/include/sgBackendTypes.h b/Backend/Core/include/sgBackendTypes.h index 1a8976df..ec69b772 100644 --- a/Backend/Core/include/sgBackendTypes.h +++ b/Backend/Core/include/sgBackendTypes.h @@ -24,6 +24,7 @@ typedef enum sg_drawing_surface_kind { SGDS_Unknown = 0, // Unknown, so do not draw onto this! SGDS_Window = 1, // A window + SGDS_Bitmap = 2, SGDS_Pixbuf = 3 } sg_drawing_surface_kind; @@ -38,7 +39,7 @@ typedef struct sg_drawing_surface sg_drawing_surface_kind kind; int width; int height; - + // private data used by the backend void * _data; } sg_drawing_surface; @@ -65,7 +66,7 @@ typedef struct sg_display unsigned int format; unsigned int num_modes; sg_mode * modes; - + // private data used by the backend void * _data; } sg_display; @@ -84,7 +85,7 @@ typedef struct sg_system_data unsigned int num_displays; sg_display * displays; sg_audiospec audio_specs; - + } sg_system_data; typedef enum sg_font_kind @@ -114,7 +115,7 @@ typedef enum sg_sound_kind typedef struct sg_sound_data { sg_sound_kind kind; - + // private data used by backend void * _data; } sg_sound_data; @@ -129,12 +130,12 @@ typedef enum sg_connection_kind typedef struct sg_network_connection { sg_connection_kind kind; - + // private data used by the backend void * _socket; } sg_network_connection; - + typedef void *pointer; typedef struct sg_window_data @@ -144,11 +145,11 @@ typedef struct sg_window_data int mouse_over; int shown; } sg_window_data; - + #ifdef __cplusplus } #endif - + // Stop aligning structs to one byte boundaries //#pragma pack(pop) diff --git a/Backend/SGSDL2/src/SGSDL2Graphics.cpp b/Backend/SGSDL2/src/SGSDL2Graphics.cpp index 4b84797e..9b5355d7 100644 --- a/Backend/SGSDL2/src/SGSDL2Graphics.cpp +++ b/Backend/SGSDL2/src/SGSDL2Graphics.cpp @@ -1025,7 +1025,7 @@ void sgsdl2_clear_drawing_surface(sg_drawing_surface *surface, sg_color clr) case SGDS_Pixbuf: _sgsdl2_clear_pixbuf(surface, clr); break; - + case SGDS_Unknown: break; } @@ -1419,7 +1419,7 @@ void sgsdl2_draw_pixel(sg_drawing_surface *surface, sg_color clr, float *data, i _set_pixel(static_cast(surface->_data)->surface, clr, x1, y1); return; } - + unsigned int count = _sgsdl2_renderer_count(surface); for (unsigned int i = 0; i < count; i++) @@ -1657,10 +1657,10 @@ void sgsdl2_set_clip_rect(sg_drawing_surface *surface, float *data, int data_sz) pixbuf_be->clipped = true; #ifdef WINDOWS - pixbuf_be->clip = { x1, y1, w, h }; + pixbuf_be->surface->clip_rect = { x1, y1, w, h }; #else //HACK: Current hack to fix SDL clip rect error - pixbuf_be->clip = { x1, surface->height - h - y1, w, h }; + pixbuf_be->surface->clip_rect = { x1, surface->height - h - y1, w, h }; #endif break; @@ -1716,7 +1716,7 @@ void sgsdl2_clear_clip_rect(sg_drawing_surface *surface) break; } - + case SGDS_Unknown: break; } @@ -2030,7 +2030,7 @@ sg_drawing_surface sgsdl2_create_bitmap(int width, int height) sg_drawing_surface result = { SGDS_Unknown, 0, 0, NULL }; result.kind = SGDS_Bitmap; - + sg_bitmap_be *data = static_cast(malloc(sizeof(sg_bitmap_be))); result._data = data; @@ -2072,7 +2072,7 @@ sg_drawing_surface sgsdl2_load_bitmap(const char * filename) std::cout << "error loading image " << IMG_GetError() << std::endl; return result; } - + sg_bitmap_be *data = static_cast(malloc(sizeof(sg_bitmap_be))); result._data = data; @@ -2294,7 +2294,7 @@ void sgsdl2_draw_pixbuf( sg_drawing_surface * src, sg_drawing_surface * dst, flo // Adjust centre to be relative to the bitmap centre rather than top-left centre_x = (centre_x * scale_x) + dst_rect.w / 2.0f; centre_y = (centre_y * scale_y) + dst_rect.h / 2.0f; - + unsigned int count = _sgsdl2_renderer_count(dst); for (unsigned int i = 0; i < count; i++) @@ -2322,7 +2322,7 @@ void sgsdl2_draw_pixbuf( sg_drawing_surface * src, sg_drawing_surface * dst, flo static_cast(centre_y) }; SDL_RendererFlip sdl_flip = static_cast((flip == SG_FLIP_BOTH) ? (SDL_FLIP_HORIZONTAL | SDL_FLIP_VERTICAL) : flip); //SDL does not have a FLIP_BOTH - + //Render SDL_RenderCopyEx(renderer, srcT, &src_rect, &dst_rect, angle, ¢re, sdl_flip); diff --git a/Backend/SGSDL2/src/SGSDL2Graphics.h b/Backend/SGSDL2/src/SGSDL2Graphics.h index 32e69624..cc6a5086 100644 --- a/Backend/SGSDL2/src/SGSDL2Graphics.h +++ b/Backend/SGSDL2/src/SGSDL2Graphics.h @@ -21,6 +21,7 @@ void sgsdl2_load_graphics_fns(sg_interface *functions); void sgsdl2_load_image_fns(sg_interface *functions); +void sgsdl2_load_pixbuf_fns(sg_interface *functions); void sgsdl2_finalise_graphics(); unsigned int _sgsdl2_renderer_count(sg_drawing_surface *surface); @@ -35,7 +36,7 @@ typedef struct sg_window_be bool clipped; SDL_Rect clip; unsigned int idx; - + // Event data store sg_window_data event_data; sg_drawing_surface *surface; @@ -48,7 +49,7 @@ typedef struct sg_bitmap_be SDL_Surface * surface; bool clipped; SDL_Rect clip; - + bool drawable; // can be drawn on } sg_bitmap_be; diff --git a/Backend/Test/src/main.cpp b/Backend/Test/src/main.cpp index 5ae7cf07..678982a0 100644 --- a/Backend/Test/src/main.cpp +++ b/Backend/Test/src/main.cpp @@ -29,18 +29,18 @@ sg_interface * _sg_functions = NULL; sg_drawing_surface img, img2; sg_drawing_surface bmp; -enum test_options -{ +enum test_options +{ BASIC_DRAWING = 1, - WINDOW_OPERATIONS = 2, - BITMAP_DRAWING = 4, + WINDOW_OPERATIONS = 2, + BITMAP_DRAWING = 4, AUDIO = 8, INPUT = 16, TEXT = 32, NETWORK = 64 -}; +}; -enum test_drawing_options +enum test_drawing_options { TEST_COLORS = 1, TEST_READ_PIXELS = 2, @@ -58,35 +58,35 @@ enum test_drawing_options TEST_PIXBUF = 8192 }; -void print_options() +void print_options() { - cout << "0: all " << endl; - cout << "1: basic drawing functions" << endl; - cout << "2: window operations" << endl; - cout << "4: bitmap drawing" << endl; - cout << "8: audio " << endl; - cout << "16: input " << endl; + cout << "0: all " << endl; + cout << "1: basic drawing functions" << endl; + cout << "2: window operations" << endl; + cout << "4: bitmap drawing" << endl; + cout << "8: audio " << endl; + cout << "16: input " << endl; cout << "32: text " << endl; cout << "64: network " << endl; } -void print_drawing_options() +void print_drawing_options() { - cout << "0: all " << endl; - cout << "1: colors" << endl; - cout << "2: read pixels" << endl; - cout << "4: test positions" << endl; - cout << "8: test alpha" << endl; - cout << "16: test clip" << endl; - cout << "32 test pixels" << endl; - cout << "64: test shapes" << endl; - cout << "128: test resize " << endl; - cout << "256: test lines " << endl; - cout << "512: test bitmaps " << endl; - cout << "1024: test input " << endl; - cout << "2048: test fullscreen " << endl; - cout << "4096: test direct pixel drawing speed " << endl; - cout << "8192: test pixbuf " << endl; + cout << "0: all " << endl; + cout << "1: colors" << endl; + cout << "2: read pixels" << endl; + cout << "4: test positions" << endl; + cout << "8: test alpha" << endl; + cout << "16: test clip" << endl; + cout << "32 test pixels" << endl; + cout << "64: test shapes" << endl; + cout << "128: test resize " << endl; + cout << "256: test lines " << endl; + cout << "512: test bitmaps " << endl; + cout << "1024: test input " << endl; + cout << "2048: test fullscreen " << endl; + cout << "4096: test direct pixel drawing speed " << endl; + cout << "8192: test pixbuf " << endl; } @@ -95,21 +95,21 @@ void print_drawing_options() // and initialised? // bool test_core_functions() -{ +{ cout << "Testing Core Functions!" << endl; - + cout << "Calling load_sg..." << endl; _sg_functions = sg_load(get_input_callbacks()); - + if ( !_sg_functions ) { cout << "Failed to load functions!" << endl; return false; } - + cout << "Calling init..." << endl; _sg_functions->init(); - + return false == _sg_functions->has_error; } @@ -126,10 +126,10 @@ void refresh_or_draw(sg_drawing_surface *surf) // if we are refreshing a window... do normal processing if (surf->kind == SGDS_Window) { - _sg_functions->input.process_events(); + _sg_functions->input.process_events(); if (_sg_functions->input.window_close_requested(surf)) - { - exit(0); + { + exit(0); } _sg_functions->graphics.refresh_window(surf); @@ -150,7 +150,7 @@ void refresh_or_draw(sg_drawing_surface *surf) void test_colors(sg_drawing_surface *window_arr, int sz) { cout << "Testing Colors" << endl; - + for (int w = 0; w < sz; w++) { cout << " - Clearning the surface to..." << endl; @@ -158,22 +158,22 @@ void test_colors(sg_drawing_surface *window_arr, int sz) _sg_functions->graphics.clear_drawing_surface(&window_arr[w], {1.0, 0.0, 0.0, 1.0}); refresh_or_draw(&window_arr[w]); _sg_functions->utils.delay(200); - + cout << " - WHITE" << endl; _sg_functions->graphics.clear_drawing_surface(&window_arr[w], {1.0, 1.0, 1.0, 1.0}); refresh_or_draw(&window_arr[w]); _sg_functions->utils.delay(500); - + cout << " - GREEN" << endl; _sg_functions->graphics.clear_drawing_surface(&window_arr[w], {0.0, 1.0, 0.0, 1.0}); refresh_or_draw(&window_arr[w]); _sg_functions->utils.delay(200); - + cout << " - BLUE" << endl; _sg_functions->graphics.clear_drawing_surface(&window_arr[w], {0.0, 0.0, 1.0, 1.0}); refresh_or_draw(&window_arr[w]); _sg_functions->utils.delay(200); - + cout << " - WHITE" << endl; _sg_functions->graphics.clear_drawing_surface(&window_arr[w], {1.0, 1.0, 1.0, 1.0}); refresh_or_draw(&window_arr[w]); @@ -184,22 +184,22 @@ void test_colors(sg_drawing_surface *window_arr, int sz) void test_read_pixels(sg_drawing_surface *window) { cout << "Testing Reading of Pixel data" << endl; - - + + _sg_functions->graphics.clear_drawing_surface(window, {1.0, 0.0, 0.0, 1.0}); sg_color clr = _sg_functions->graphics.read_pixel(window, 10, 10); - + cout << " - Color at 10,10 is RGBA " << clr.r << "," << clr.g << "," << clr.b << "," << clr.a << endl; cout << " - Match 1,0,0,1" << endl; - + clr = _sg_functions->graphics.read_pixel(window, -10, -10); cout << " - Color at -10,-10 is RGBA " << clr.r << "," << clr.g << "," << clr.b << "," << clr.a << endl; cout << " Match 0,0,0,0" << endl; - + _sg_functions->graphics.clear_drawing_surface(window, {1.0, 1.0, 1.0, 1.0}); refresh_or_draw(window); clr = _sg_functions->graphics.read_pixel(window, 10, 10); - + cout << " - Color at 10,10 is RGBA " << clr.r << "," << clr.g << "," << clr.b << "," << clr.a << endl; cout << " - Match 1,1,1,1" << endl; } @@ -220,7 +220,7 @@ void test_rects(sg_drawing_surface *window_arr, int sz) { _sg_functions->graphics.clear_drawing_surface(&window_arr[w], {1.0, 1.0, 1.0, 1.0}); } - + for (int i = 0; i < SHAPE_COUNT; i++) { float data[] = { rand() / (float)RAND_MAX * 800, @@ -228,7 +228,7 @@ void test_rects(sg_drawing_surface *window_arr, int sz) rand() / (float)RAND_MAX * 100, rand() / (float)RAND_MAX * 100 }; - + for (int w = 0; w < sz; w++) { _sg_functions->graphics.draw_aabb_rect(&window_arr[w], random_color(), data, 4 ); @@ -240,7 +240,7 @@ void test_rects(sg_drawing_surface *window_arr, int sz) { _sg_functions->graphics.clear_drawing_surface(&window_arr[w], {1.0, 1.0, 1.0, 1.0}); } - + for (int i = 0; i < SHAPE_COUNT; i++) { float data[] = { rand() / (float)RAND_MAX * 800, @@ -248,57 +248,57 @@ void test_rects(sg_drawing_surface *window_arr, int sz) rand() / (float)RAND_MAX * 100, rand() / (float)RAND_MAX * 100 }; - + for (int w = 0; w < sz; w++) { _sg_functions->graphics.fill_aabb_rect(&window_arr[w], random_color(), data, 4 ); refresh_or_draw(&window_arr[w]); } } - + for (int w = 0; w < sz; w++) { _sg_functions->graphics.clear_drawing_surface(&window_arr[w], {1.0, 1.0, 1.0, 1.0}); } - + for (int i = 0; i < SHAPE_COUNT; i++) { float x, y; - + x = rand() / (float)RAND_MAX * 800; y = rand() / (float)RAND_MAX * 600; - + float data[] = { x, y, x + 100, y, x, y + 100, x + 100, y + 100 }; - + for (int w = 0; w < sz; w++) { _sg_functions->graphics.draw_rect(&window_arr[w], random_color(), data, 8 ); refresh_or_draw(&window_arr[w]); } } - + for (int w = 0; w < sz; w++) { _sg_functions->graphics.clear_drawing_surface(&window_arr[w], {1.0, 1.0, 1.0, 1.0}); } - + for (int i = 0; i < SHAPE_COUNT; i++) { float x = rand() / (float)RAND_MAX * 800; float y = rand() / (float)RAND_MAX * 600; - + float data[] = { x, y, x + 100, y, x, y + 100, x + 100, y + 100 }; - + for (int w = 0; w < sz; w++) { _sg_functions->graphics.fill_rect(&window_arr[w], random_color(), data, 8 ); @@ -318,7 +318,7 @@ void test_triangles(sg_drawing_surface *window_arr, int sz) refresh_or_draw(&window_arr[w]); } - + for (int i = 0; i < SHAPE_COUNT; i++) { float data[] = { rand() / (float)RAND_MAX * 800, @@ -328,19 +328,19 @@ void test_triangles(sg_drawing_surface *window_arr, int sz) rand() / (float)RAND_MAX * 800, rand() / (float)RAND_MAX * 600 }; - + for (int w = 0; w < sz; w++) { _sg_functions->graphics.draw_triangle(&window_arr[w], random_color(), data, 6 ); refresh_or_draw(&window_arr[w]); } } - + for (int w = 0; w < sz; w++) { _sg_functions->graphics.clear_drawing_surface(&window_arr[w], {1.0, 1.0, 1.0, 1.0}); } - + for (int i = 0; i < SHAPE_COUNT; i++) { float data[] = { rand() / (float)RAND_MAX * 800, @@ -350,7 +350,7 @@ void test_triangles(sg_drawing_surface *window_arr, int sz) rand() / (float)RAND_MAX * 800, rand() / (float)RAND_MAX * 600 }; - + for (int w = 0; w < sz; w++) { _sg_functions->graphics.fill_triangle(&window_arr[w], random_color(), data, 6 ); @@ -369,7 +369,7 @@ void test_pixels(sg_drawing_surface *window_arr, int sz) refresh_or_draw(&window_arr[w]); _sg_functions->input.process_events(); } - + _sg_functions->input.process_events(); for (int i = 0; i < SHAPE_COUNT; i++) { @@ -384,21 +384,21 @@ void test_pixels(sg_drawing_surface *window_arr, int sz) _sg_functions->graphics.draw_pixel(&window_arr[w], clr, data, 2 ); } - + _sg_functions->input.process_events(); refresh_or_draw(&window_arr[w]); } } - + _sg_functions->input.process_events(); for (int w = 0; w < sz; w++) { sg_drawing_surface *wnd = &window_arr[w]; int sz = window_arr[w].width * window_arr[w].height; int pixels[sz]; - + _sg_functions->graphics.to_pixels(wnd, pixels, sz); - + int count = 0; for (int x = 0; x < window_arr[w].width; x++) { @@ -409,11 +409,99 @@ void test_pixels(sg_drawing_surface *window_arr, int sz) _sg_functions->input.process_events(); } cout << "Window " << w << " has " << count << " white pixels" << endl; - + _sg_functions->graphics.clear_drawing_surface(&window_arr[w], {1.0, 1.0, 1.0, 1.0}); refresh_or_draw(&window_arr[w]); - _sg_functions->input.process_events(); + _sg_functions->input.process_events(); + } +} + + +void test_direct_pixel_speed(sg_drawing_surface *window_arr, int sz) +{ + cout << "Testing Direct pixel drawing speed" << endl; + _sg_functions->input.process_events(); + for (int cnt = 0; cnt < 5; cnt++) + { + for (int w = 0; w < sz; w++) + { + float data[] = {0,0}; + int start_time = _sg_functions->utils.get_ticks(); + for (int y = 0; y < (120 * cnt); y++) + { + for (int x = 0; x < 800; x++) + { + data[0] = x; + data[1] = y; + _sg_functions->graphics.draw_pixel(&window_arr[w], {1.0,0,0,1.0}, data, 2 ); + } + } + + int end_time = _sg_functions->utils.get_ticks(); + + _sg_functions->input.process_events(); + refresh_or_draw(&window_arr[w]); + + cout << " Direct pixel drawing time for window " << w + << " with area of 800x" << cnt * 120 << " was " << end_time - start_time << "ms" << endl; + } + } + cout << endl; +} + +void test_pixbuf(sg_drawing_surface *window_arr, int sz) +{ + cout << "Testing pixbuf drawing speed" << endl; + _sg_functions->input.process_events(); + + for (int w = 0; w < sz; w++) + { + _sg_functions->graphics.clear_drawing_surface(&window_arr[w], {1.0, 1.0, 1.0, 1.0}); + refresh_or_draw(&window_arr[w]); + _sg_functions->input.process_events(); + } + + _sg_functions->input.process_events(); + sg_drawing_surface pixbuf = _sg_functions->pixbuf.create_pixbuf(800, 600); + + for (int cnt = 0; cnt < 5; cnt++) + { + for (int w = 0; w < sz; w++) + { + float data[2]; + int start_time = _sg_functions->utils.get_ticks(); + + _sg_functions->graphics.clear_drawing_surface( &pixbuf, {1,1,1,1} ); + + for (int y = 0; y < (120 * cnt); y++) + { + for (int x = 0; x < 800; x++) + { + data[0] = x; + data[1] = y; + _sg_functions->graphics.draw_pixel(&pixbuf, {0,0,1,1}, data, 2 ); + } + } + + int mid_time = _sg_functions->utils.get_ticks(); + + float srcDat[] = { 0, 0, 0, 0, 0, 1, 1 }; + float dstDat[] = { 0, 0, 0, 0 }; + + _sg_functions->image.draw_bitmap(&pixbuf, &window_arr[w],srcDat,7,dstDat,4,SG_FLIP_NONE); + + int end_time = _sg_functions->utils.get_ticks(); + + _sg_functions->input.process_events(); + refresh_or_draw(&window_arr[w]); + + cout << " Pixel drawing time to pixbuf was " << mid_time - start_time << "ms" << endl; + cout << " Drawing time from pixbuf to window " << w << " was " + << end_time - mid_time << "ms" << endl; + } } + _sg_functions->graphics.close_drawing_surface(&pixbuf); + cout << endl; } @@ -423,33 +511,33 @@ void test_circles(sg_drawing_surface *window_arr, int sz) { _sg_functions->graphics.clear_drawing_surface(&window_arr[w], {1.0, 1.0, 1.0, 1.0}); } - + for (int i = 0; i < SHAPE_COUNT; i++) { float data[] = { rand() / (float)RAND_MAX * 800, rand() / (float)RAND_MAX * 600, rand() / (float)RAND_MAX * 100 }; - + for (int w = 0; w < sz; w++) { _sg_functions->graphics.draw_circle(&window_arr[w], random_color(), data, 3 ); refresh_or_draw(&window_arr[w]); } } - + for (int w = 0; w < sz; w++) { _sg_functions->graphics.clear_drawing_surface(&window_arr[w], {1.0, 1.0, 1.0, 1.0}); } - + for (int i = 0; i < SHAPE_COUNT; i++) { float data[] = { rand() / (float)RAND_MAX * 800, rand() / (float)RAND_MAX * 600, rand() / (float)RAND_MAX * 100 }; - + for (int w = 0; w < sz; w++) { _sg_functions->graphics.fill_circle(&window_arr[w], random_color(), data, 3 ); @@ -464,7 +552,7 @@ void test_ellipses(sg_drawing_surface *window_arr, int sz) { _sg_functions->graphics.clear_drawing_surface(&window_arr[w], {1.0, 1.0, 1.0, 1.0}); } - + for (int i = 0; i < SHAPE_COUNT; i++) { float data[] = { rand() / (float)RAND_MAX * 800, @@ -472,19 +560,19 @@ void test_ellipses(sg_drawing_surface *window_arr, int sz) rand() / (float)RAND_MAX * 100, rand() / (float)RAND_MAX * 100 }; - + for (int w = 0; w < sz; w++) { _sg_functions->graphics.draw_ellipse(&window_arr[w], random_color(), data, 4 ); refresh_or_draw(&window_arr[w]); } } - + for (int w = 0; w < sz; w++) { _sg_functions->graphics.clear_drawing_surface(&window_arr[w], {1.0, 1.0, 1.0, 1.0}); } - + for (int i = 0; i < SHAPE_COUNT; i++) { float data[] = { rand() / (float)RAND_MAX * 800, @@ -492,7 +580,7 @@ void test_ellipses(sg_drawing_surface *window_arr, int sz) rand() / (float)RAND_MAX * 100, rand() / (float)RAND_MAX * 100 }; - + for (int w = 0; w < sz; w++) { _sg_functions->graphics.fill_ellipse(&window_arr[w], random_color(), data, 4 ); @@ -507,7 +595,7 @@ void test_lines(sg_drawing_surface *window_arr, int sz) { _sg_functions->graphics.clear_drawing_surface(&window_arr[w], {1.0, 1.0, 1.0, 1.0}); } - + for (int i = 0; i < SHAPE_COUNT; i++) { float data[] = { rand() / (float)RAND_MAX * 800, @@ -516,7 +604,7 @@ void test_lines(sg_drawing_surface *window_arr, int sz) rand() / (float)RAND_MAX * 600, 1 + rand() / (float)RAND_MAX * 30 }; - + for (int w = 0; w < sz; w++) { _sg_functions->graphics.draw_line(&window_arr[w], random_color(), data, 5 ); @@ -528,34 +616,34 @@ void test_lines(sg_drawing_surface *window_arr, int sz) void test_clip(sg_drawing_surface *window_arr, int sz) { cout << "Testing Clipping" << endl; - + for (int w = 0; w < sz; w++) { _sg_functions->graphics.clear_drawing_surface(&window_arr[w], {0.0, 0.0, 1.0, 1.0}); - + float data[] = { 0.0f, 0.0f, window_arr[w].width * 0.9f, window_arr[w].height * 0.9f }; - + for (int c = 0; c < 8; c++) { data[2] = window_arr[w].width * (0.9 - c * 0.1); data[3] = window_arr[w].height * (0.9 - c * 0.1); - + _sg_functions->graphics.set_clip_rect(&window_arr[w], data, 4); _sg_functions->graphics.clear_drawing_surface(&window_arr[w], {1.0f - c * 0.1f, 0.0, 0.0, 1.0}); } refresh_or_draw(&window_arr[w]); - + data[2] = window_arr[w].width * 0.4; data[3] = window_arr[w].height * 0.4; _sg_functions->graphics.set_clip_rect(&window_arr[w], data, 4); _sg_functions->graphics.clear_drawing_surface(&window_arr[w], {0.0, 1.0f, 0.0, 1.0f}); } - + _sg_functions->utils.delay(3000); - + for (int w = 0; w < sz; w++) { _sg_functions->graphics.clear_clip_rect(&window_arr[w]); @@ -568,22 +656,22 @@ bool test_positions(sg_drawing_surface *window_arr, int sz) for (int i = 0; i < sz; i++) { _sg_functions->graphics.clear_drawing_surface(&window_arr[i], {1.0, 1.0, 1.0, 1.0}); - + float data[] = {0.0f, 0.0f, 50.0f, 50.0f}; float data1[] = {window_arr[i].width - 50.0f, 0.0f, 50.0f, 50.0f}; float data2[] = {0.0f, window_arr[i].height - 50.0f, 50.0f, 50.0f}; float data3[] = {window_arr[i].width - 50.0f, window_arr[i].height - 50.0f, 50.0f, 50.0f}; - + _sg_functions->graphics.fill_aabb_rect(&window_arr[i], {1.0f, 0.0f, 0.0f, 1.0f}, data, 4); _sg_functions->graphics.fill_aabb_rect(&window_arr[i], {0.0f, 1.0f, 0.0f, 1.0f}, data1, 4); _sg_functions->graphics.fill_aabb_rect(&window_arr[i], {0.0f, 0.0f, 1.0f, 1.0f}, data2, 4); _sg_functions->graphics.fill_aabb_rect(&window_arr[i], {0.0f, 0.0f, 0.0f, 1.0f}, data3, 4); - + refresh_or_draw(&window_arr[i]); } _sg_functions->utils.delay(2000); - + return true; } @@ -592,7 +680,7 @@ bool test_alpha(sg_drawing_surface *window_arr, int sz) for (int i = 0; i < sz; i++) { _sg_functions->graphics.clear_drawing_surface(&window_arr[i], {1.0, 1.0, 1.0, 1.0}); - + float data[] = {0.0f, 0.0f, window_arr[i].width / 11.0f, window_arr[i].height * 1.0f}; for (int j = 0; j < 11; j++) @@ -600,12 +688,12 @@ bool test_alpha(sg_drawing_surface *window_arr, int sz) data[0] = j * data[2]; _sg_functions->graphics.fill_ellipse(&window_arr[i], {1.0f, 0.0f, 0.0f, 0.1f * j}, data, 4); } - + refresh_or_draw(&window_arr[i]); } - + _sg_functions->utils.delay(2000); - + return true; } @@ -617,12 +705,12 @@ void test_resize(sg_drawing_surface * window_arr, int sz) int w, h; w = window_arr[i].width; h = window_arr[i].height; - + _sg_functions->graphics.resize(&window_arr[i], 320, 240); _sg_functions->graphics.clear_drawing_surface(&window_arr[i], random_color()); _sg_functions->graphics.refresh_window(&window_arr[i]); _sg_functions->utils.delay(1000); - + _sg_functions->graphics.resize(&window_arr[i], 640, 480); _sg_functions->graphics.clear_drawing_surface(&window_arr[i], random_color()); _sg_functions->graphics.refresh_window(&window_arr[i]); @@ -632,14 +720,14 @@ void test_resize(sg_drawing_surface * window_arr, int sz) _sg_functions->graphics.clear_drawing_surface(&window_arr[i], random_color()); _sg_functions->graphics.refresh_window(&window_arr[i]); _sg_functions->utils.delay(1000); - + _sg_functions->graphics.resize(&window_arr[i], 1024, 768); _sg_functions->graphics.clear_drawing_surface(&window_arr[i], random_color()); _sg_functions->graphics.refresh_window(&window_arr[i]); _sg_functions->graphics.clear_drawing_surface(&window_arr[i], random_color()); _sg_functions->graphics.refresh_window(&window_arr[i]); _sg_functions->utils.delay(1000); - + _sg_functions->graphics.resize(&window_arr[i], w, h); _sg_functions->graphics.clear_drawing_surface(&window_arr[i], {1.0f, 1.0f, 1.0f, 1.0f}); _sg_functions->graphics.refresh_window(&window_arr[i]); @@ -653,7 +741,7 @@ void test_bitmaps(sg_drawing_surface * window_arr, int sz) float src_data[] = {0, 0, static_cast(img.width), static_cast(img.height)}; float bmp_src_data[] = {0, 0, static_cast(bmp.width), static_cast(bmp.height)}; float dst_data[] = {0, 0, 0, 0, 0, 1, 1}; - + //Draw at TOP LEFT (shows that the scaling of the draw coordinates works) for (int i = 0; i < sz; i++) { @@ -662,15 +750,15 @@ void test_bitmaps(sg_drawing_surface * window_arr, int sz) _sg_functions->image.draw_bitmap( &bmp, &window_arr[i], bmp_src_data, 4, dst_data, 7, SG_FLIP_NONE); _sg_functions->graphics.refresh_window(&window_arr[i]); _sg_functions->utils.delay(5000); - + _sg_functions->image.draw_bitmap( &img, &window_arr[i], src_data, 4, dst_data, 7, SG_FLIP_NONE); _sg_functions->graphics.refresh_window(&window_arr[i]); _sg_functions->utils.delay(1000); } - + dst_data[0] = 300.0f; dst_data[1] = 300.0f; - + //Test rotation (should rotate around centre) for (int u = 0; u <= 360; u += 4) { @@ -678,12 +766,12 @@ void test_bitmaps(sg_drawing_surface * window_arr, int sz) { //use sin _sg_functions->graphics.clear_drawing_surface(&window_arr[i], {1, 1, 1, 1}); - + dst_data[2] = static_cast(u); - + _sg_functions->image.draw_bitmap( &img, &window_arr[i], src_data, 4, dst_data, 7, SG_FLIP_NONE); _sg_functions->image.draw_bitmap( &img2, &window_arr[i], src_data, 4, dst_data, 7, SG_FLIP_NONE); - _sg_functions->graphics.refresh_window(&window_arr[i]); + _sg_functions->graphics.refresh_window(&window_arr[i]); } } _sg_functions->utils.delay(200); @@ -691,9 +779,9 @@ void test_bitmaps(sg_drawing_surface * window_arr, int sz) dst_data[0] = 150.0f; dst_data[1] = 150.0f; dst_data[2] = 0; - + //Test scale - for (int u = 0; u <= 90; u++) + for (int u = 0; u <= 90; u++) { for (int i = 0; i < sz; i++) { @@ -708,9 +796,9 @@ void test_bitmaps(sg_drawing_surface * window_arr, int sz) _sg_functions->graphics.refresh_window(&window_arr[i]); } } - + //Test rotate and scale (should rotate around centre) - for (int u = 0; u <= 360; u += 2) + for (int u = 0; u <= 360; u += 2) { for (int i = 0; i < sz; i++) { @@ -734,7 +822,7 @@ void test_bitmaps(sg_drawing_surface * window_arr, int sz) dst_data[2] = static_cast(u * 2); dst_data[5] = static_cast(u / 360.0); dst_data[6] = static_cast((720 - u) / 360.0); - + //use sin _sg_functions->graphics.clear_drawing_surface(&window_arr[i], {1, 1, 1, 1}); _sg_functions->image.draw_bitmap( &img, &window_arr[i], src_data, 4, dst_data, 7, SG_FLIP_NONE); @@ -751,7 +839,7 @@ void test_bitmaps(sg_drawing_surface * window_arr, int sz) dst_data[2] = static_cast(u * 2); dst_data[5] = static_cast(u / 360.0); dst_data[6] = static_cast((720 - u) / 360.0); - + //use sin _sg_functions->graphics.clear_drawing_surface(&window_arr[i], {1, 1, 1, 1}); _sg_functions->image.draw_bitmap( &img, &window_arr[i], src_data, 4, dst_data, 7, SG_FLIP_NONE); @@ -759,11 +847,11 @@ void test_bitmaps(sg_drawing_surface * window_arr, int sz) _sg_functions->graphics.refresh_window(&window_arr[i]); } } - + dst_data[2] = 0; dst_data[5] = 1; dst_data[6] = 1; - + //Test flip for (int u = 0; u < 240; u++) { @@ -776,7 +864,7 @@ void test_bitmaps(sg_drawing_surface * window_arr, int sz) _sg_functions->graphics.refresh_window(&window_arr[i]); } } - + //Test pretty // double scale; for (int u = 0; u <= 720; u += 4) @@ -785,18 +873,18 @@ void test_bitmaps(sg_drawing_surface * window_arr, int sz) { // scale = sin(u/90.0) + 0.5; // scale = scale > 0.2 ? scale : 0.2; - + dst_data[2] = u; dst_data[3] = 100 + sin(u/60.0)*100; dst_data[4] = -u; - + //use sin _sg_functions->graphics.clear_drawing_surface(&window_arr[i], {1, 1, 1, 1}); _sg_functions->image.draw_bitmap( &img, &window_arr[i], src_data, 4, dst_data, 7, SG_FLIP_NONE); - _sg_functions->graphics.refresh_window(&window_arr[i]); + _sg_functions->graphics.refresh_window(&window_arr[i]); } } - + _sg_functions->utils.delay(300); _sg_functions->input.process_events(); } @@ -806,19 +894,19 @@ bool test_draw_bitmap_without_window() sg_drawing_surface window; cout << "Creating bitmap" << endl; - + bmp = _sg_functions->image.create_bitmap(100, 100); cout << "Drawing to bitmap" << endl; - + _sg_functions->graphics.clear_drawing_surface(&bmp, {1.0f, 0.0f, 0.0f, 1.0f}); float data_t[] = {0.0f, 99.0f, 99.0f, 99.0f, 50.0f, 1.0f}; _sg_functions->graphics.fill_triangle(&bmp, {1.0,1.0,1.0,1.0}, data_t, 6 ); - + float data[] = {0.0f, 20.0f, 80.0f, 20.0f}; _sg_functions->graphics.fill_aabb_rect(&bmp, {0.0f, 1.0f, 0.0f, 1.0f}, data, 4); - + data[1] = 40.0f; data[2] = 60.0f; _sg_functions->graphics.fill_aabb_rect(&bmp, {0.0f, 0.0f, 1.0f, 1.0f}, data, 4); @@ -832,7 +920,7 @@ bool test_draw_bitmap_without_window() _sg_functions->graphics.fill_aabb_rect(&bmp, {1.0f, 1.0f, 0.0f, 1.0f}, data, 4); cout << "Saving bitmap" << endl; - + #ifdef WINDOWS _sg_functions->graphics.save_png(&bmp, "c:\\Users\\acain\\Desktop\\test1.png"); #else @@ -840,35 +928,35 @@ bool test_draw_bitmap_without_window() #endif float src_data[] = {0, 0, static_cast(bmp.width), static_cast(bmp.height)}; float dst_data[] = {0, 0, 0, 0, 0, 1, 1}; - + window = _sg_functions->graphics.open_window("Test Bitmap Drawing", 600, 600); _sg_functions->graphics.clear_drawing_surface(&window, {0.0f, 0.0f, 0.0f, 1.0f}); _sg_functions->image.draw_bitmap( &bmp, &window, src_data, 4, dst_data, 7, SG_FLIP_NONE); _sg_functions->graphics.refresh_window(&window); - + _sg_functions->input.process_events(); _sg_functions->utils.delay(2000); - + #ifdef WINDOWS _sg_functions->graphics.save_png(&window, "c:\\Users\\acain\\Desktop\\test2.png"); #else _sg_functions->graphics.save_png(&window, "/Users/acain/Desktop/test2.png"); -#endif +#endif sg_color clr = _sg_functions->graphics.read_pixel(&bmp, 5, 5); cout << "Bmp Color is : " << clr.r << ":" << clr.g << ":" << clr.b << ":" << clr.a << endl; clr = _sg_functions->graphics.read_pixel(&window, 0, 0); cout << "Wnd Color is : " << clr.r << ":" << clr.g << ":" << clr.b << ":" << clr.a << endl; - + _sg_functions->graphics.close_drawing_surface(&window); - + #ifdef WINDOWS _sg_functions->graphics.save_png(&bmp, "c:\\Users\\acain\\Desktop\\test3.png"); -#else +#else _sg_functions->graphics.save_png(&bmp, "/Users/acain/Desktop/test3.png"); #endif - + window = _sg_functions->graphics.open_window("Draw in new window!", 600, 600); _sg_functions->input.process_events(); @@ -876,7 +964,7 @@ bool test_draw_bitmap_without_window() _sg_functions->image.draw_bitmap( &bmp, &window, src_data, 4, dst_data, 7, SG_FLIP_NONE); _sg_functions->graphics.refresh_window(&window); _sg_functions->utils.delay(2000); - + _sg_functions->graphics.close_drawing_surface(&window); return true; @@ -885,8 +973,13 @@ bool test_draw_bitmap_without_window() bool test_basic_drawing(int drawing_test_run) { cout << "Testing Basic Drawing!" << endl; - cout << drawing_test_run << endl; - + cout << drawing_test_run << endl; + + if (!drawing_test_run) + { + drawing_test_run = -1; + } + sg_drawing_surface window; window = _sg_functions->graphics.open_window("Test Basic Drawing", 800, 600); @@ -895,48 +988,38 @@ bool test_basic_drawing(int drawing_test_run) img2 = _sg_functions->image.create_bitmap(100, 50); _sg_functions->graphics.clear_drawing_surface(&img2, {1.0f, 0.0f, 0.0f, 1.0f}); - - if (drawing_test_run & TEST_COLORS) + + if (drawing_test_run & TEST_COLORS) { test_colors(&window, 1); } - if (drawing_test_run & TEST_PIXELS) + if (drawing_test_run & TEST_PIXELS) { test_read_pixels(&window); } - if (drawing_test_run & TEST_POSITIONS) + if (drawing_test_run & TEST_POSITIONS) { test_positions(&window, 1); } - if (drawing_test_run & TEST_ALPHA) + if (drawing_test_run & TEST_ALPHA) { test_alpha(&window, 1); } - if (drawing_test_run & TEST_CLIP) + if (drawing_test_run & TEST_CLIP) { test_clip( &window, 1); } - - if (drawing_test_run & TEST_PIXELS) - { - test_pixels( &window, 1); - } - if (drawing_test_run & TEST_DIRECT_PIXSPEED) + if (drawing_test_run & TEST_PIXELS) { - test_direct_pixel_speed( &window, 1); + test_pixels( &window, 1); } - if (drawing_test_run & TEST_PIXBUF) - { - test_pixbuf( &window, 1); - } - - if (drawing_test_run & TEST_FULLSCREEN) + if (drawing_test_run & TEST_FULLSCREEN) { _sg_functions->graphics.show_fullscreen(&window, true); @@ -944,28 +1027,28 @@ bool test_basic_drawing(int drawing_test_run) _sg_functions->graphics.show_fullscreen(&window, false); } - - if (drawing_test_run & TEST_SHAPES) + + if (drawing_test_run & TEST_SHAPES) { test_triangles( &window, 1); } - if (drawing_test_run & TEST_SHAPES) + if (drawing_test_run & TEST_SHAPES) { test_circles( &window, 1); } - - if (drawing_test_run & TEST_RESIZE) + + if (drawing_test_run & TEST_RESIZE) { test_resize(&window, 1); } - - if (drawing_test_run & TEST_SHAPES) + + if (drawing_test_run & TEST_SHAPES) { test_ellipses( &window, 1); } - if (drawing_test_run & TEST_LINES) + if (drawing_test_run & TEST_LINES) { test_lines( &window, 1); } @@ -978,14 +1061,24 @@ bool test_basic_drawing(int drawing_test_run) _sg_functions->graphics.clear_drawing_surface(&window, {1.0f, 1.0f, 1.0f, 1.0f}); test_bitmaps( &window, 1); } - - if (drawing_test_run & TEST_INPUT) + + if (drawing_test_run & TEST_INPUT) { test_input(&window, 1); } + if (drawing_test_run & TEST_DIRECT_PIXSPEED) + { + test_direct_pixel_speed(&window, 1); + } + + if (drawing_test_run & TEST_PIXBUF) + { + test_pixbuf(&window, 1); + } + _sg_functions->graphics.close_drawing_surface(&window); - + return false == _sg_functions->has_error; } @@ -993,22 +1086,22 @@ bool test_window_operations() { cout << "Testing Window Operations!" << endl; _sg_functions->input.process_events(); - + sg_drawing_surface w[2]; w[0] = _sg_functions->graphics.open_window("Window 1", 800, 600); w[1] = _sg_functions->graphics.open_window("Window 2", 300, 300); - + _sg_functions->input.move_window(&w[1], 0, 0); - + _sg_functions->graphics.show_border(&w[0], false); - + if ( w[0].width != 800 ) cout << " >> Error with w[0] width! " << w[0].width << endl; if ( w[1].width != 300 ) cout << " >> Error with w[1] width! " << w[1].width << endl; - + if ( w[0].height != 600 ) cout << " >> Error with w[0] height! " << w[0].height << endl; if ( w[1].height != 300 ) cout << " >> Error with w[1] height! " << w[1].height << endl; - + test_colors(w, 2); test_clip(w, 2); test_pixels(w, 2); @@ -1018,7 +1111,7 @@ bool test_window_operations() test_ellipses(w, 2); test_lines(w, 2); test_bitmaps(w, 2); - + test_input(w, 2); _sg_functions->graphics.close_drawing_surface(&w[0]); @@ -1030,51 +1123,51 @@ bool test_window_operations() bool test_bitmap_dest_drawing() { cout << "Testing Drawing to Bitmap!" << endl; - + sg_drawing_surface window; window = _sg_functions->graphics.open_window("Drawing to Bitmap", 800, 600); _bmp_wnd = &window; - + sg_drawing_surface bmp = _sg_functions->image.create_bitmap(640, 480); - + float src_data[] = {0, 0, static_cast(img.width), static_cast(img.height)}; float dst_data[] = {0, 0, 0, 0, 0, 1, 1}; - + _sg_functions->image.draw_bitmap( &img, &bmp, src_data, 4, dst_data, 7, SG_FLIP_NONE); - + refresh_or_draw(&bmp); _sg_functions->utils.delay(3000); - + test_colors(&bmp, 1); test_positions(&bmp, 1); test_alpha(&bmp, 1); - + test_clip( &bmp, 1); test_pixels( &bmp, 1); - + test_rects( &bmp, 1); - + test_triangles( &bmp, 1); test_circles( &bmp, 1); - + test_ellipses( &bmp, 1); test_lines( &bmp, 1); dst_data[0] = 50; dst_data[1] = 50; - + src_data[2] = img2.width; src_data[3] = img2.height; - - + + _sg_functions->image.draw_bitmap( &img, &bmp, src_data, 4, dst_data, 7, SG_FLIP_NONE); refresh_or_draw(&bmp); _sg_functions->utils.delay(3000); - + _sg_functions->graphics.close_drawing_surface(&bmp); _sg_functions->graphics.close_drawing_surface(&window); _bmp_wnd = NULL; - + return false == _sg_functions->has_error; } @@ -1083,11 +1176,11 @@ void test_bitmap_loading_saving() sg_drawing_surface lines = _sg_functions->image.load_bitmap("Lines.png"); int sz = lines.width * lines.height; int pixels[sz]; - + for (int i = 0; i < sz; i++) pixels[i] = 0; - + _sg_functions->graphics.to_pixels(&lines, pixels, sz); - + for (int i = 0; i < sz; i++) { cout << std::hex << pixels[i] << std::dec << " "; @@ -1096,12 +1189,12 @@ void test_bitmap_loading_saving() cout << endl; } } - + sg_color clr = _sg_functions->graphics.read_pixel(&lines, 0, 0); cout << "Lines color is : " << clr.r << ":" << clr.g << ":" << clr.b << ":" << clr.a << endl; - + _sg_functions->graphics.save_png(&lines, "/Users/acain/Desktop/test.png"); - + _sg_functions->graphics.close_drawing_surface(&lines); } @@ -1109,9 +1202,9 @@ void test_bitmap_loading_saving() void output_system_details() { sg_system_data *data = _sg_functions->read_system_data(); - + cout << "Display count: " << data->num_displays << endl; - + for (int i = 0; i < data->num_displays; i++) { cout << " -> Display[" << i << "] = " << data->displays[i].name << endl; @@ -1122,7 +1215,7 @@ void output_system_details() cout << " " << data->displays[i].modes[m].width << " x " << data->displays[i].modes[m].height << endl; } } - + cout << "Time is " << _sg_functions->utils.get_ticks() << endl; } @@ -1130,41 +1223,41 @@ void test_fullscreen() { cout << "Calling load_sg..." << endl; _sg_functions = sg_load(get_input_callbacks()); - + if ( !_sg_functions ) { cout << "Failed to load functions!" << endl; return; } - + cout << "Calling init..." << endl; _sg_functions->init(); sg_drawing_surface window; window = _sg_functions->graphics.open_window("Test Basic Drawing", 800, 600); - + _sg_functions->graphics.show_fullscreen(&window, false); - + _sg_functions->graphics.clear_drawing_surface(&window, {1.0f, 1.0f, 1.0f, 1.0f}); _sg_functions->graphics.refresh_window(&window); _sg_functions->input.process_events(); _sg_functions->utils.delay(2000); - + _sg_functions->graphics.show_fullscreen(&window, true); - + // test_rects( &window, 1); _sg_functions->graphics.clear_drawing_surface(&window, {1.0f, 1.0f, 1.0f, 1.0f}); _sg_functions->graphics.refresh_window(&window); _sg_functions->input.process_events(); _sg_functions->utils.delay(2000); - + _sg_functions->graphics.show_fullscreen(&window, false); - + _sg_functions->graphics.clear_drawing_surface(&window, {1.0f, 0.0f, 0.0f, 1.0f}); _sg_functions->graphics.refresh_window(&window); _sg_functions->input.process_events(); _sg_functions->utils.delay(2000); - + _sg_functions->graphics.close_drawing_surface(&window); } @@ -1182,57 +1275,57 @@ int main(int argc, const char * argv[]) test_bitmap_loading_saving(); - cout << " Which tests do you want to run? " << endl; - print_options(); + cout << " Which tests do you want to run? " << endl; + print_options(); - int test_run = 0; - int test_drawing_run = INT_MAX; + int test_run = 0; + int test_drawing_run = INT_MAX; scanf("%d", &test_run); - if (test_run == 0) + if (test_run == 0) { - test_run |= 255; + test_run |= 255; } - else if (test_run & BASIC_DRAWING) + else if (test_run & BASIC_DRAWING) { - cout << "Which drawing functions would you like to run? " << endl; - print_drawing_options(); - scanf("%d", &test_drawing_run); + cout << "Which drawing functions would you like to run? " << endl; + print_drawing_options(); + scanf("%d", &test_drawing_run); } output_system_details(); - + if (test_run & BASIC_DRAWING && ! test_draw_bitmap_without_window() ) { cout << "Drawing to bitmap without window failed..." << endl; return -1; } - + if (test_run & BASIC_DRAWING && ! test_basic_drawing(test_drawing_run) ) { cout << "Basic drawing failed with error: " << endl; //cout << _sg_functions->current_error << endl; return -1; } - + _sg_functions->input.process_events(); - - if (test_run & WINDOW_OPERATIONS) + + if (test_run & WINDOW_OPERATIONS) { test_window_operations(); } - - if (test_run & BITMAP_DRAWING) + + if (test_run & BITMAP_DRAWING) { test_bitmap_dest_drawing(); test_bitmap_loading_saving(); } - + _sg_functions->graphics.close_drawing_surface(&img); _sg_functions->graphics.close_drawing_surface(&img2); - - if (test_run & AUDIO) + + if (test_run & AUDIO) { test_audio(); } @@ -1244,19 +1337,19 @@ int main(int argc, const char * argv[]) test_input(w, 1); } - if (test_run & TEXT) + if (test_run & TEXT) { test_text(); } - + if (test_run & NETWORK) { test_network(); } - + _sg_functions->finalise(); cout << "Success" << endl; - + return 0; }