bool graphics_init(gfx_t* gfx) { memset(gfx, 0, sizeof *gfx); if (SDL_InitSubSystem(SDL_INIT_VIDEO) < 0) { return false; } if (!window_init(&gfx->window, "Spielbub", SCREEN_WIDTH, SCREEN_HEIGHT)) { return false; } gfx->background = create_surface(); gfx->sprites_bg = create_surface(); gfx->sprites_fg = create_surface(); if (!gfx->background || !gfx->sprites_bg || ! gfx->sprites_fg) { goto error; } gfx->layers[0] = gfx->background; gfx->layers[1] = gfx->sprites_bg; gfx->layers[2] = gfx->sprites_fg; gfx->state = OAM; window_clear(&gfx->window); window_draw(&gfx->window); return true; error: { graphics_destroy(gfx); return false; } }
boolean la_t_edge_connector(uint *vertex) { double *vertex_array; uint *edge, edge_length, *crease, create_final[8] = { -1, -1, -1, -1, -1, -1, -1, -1 }, crease_final[8] = {0, 0, 0, 0, 0, 0, 0, 0}; uint *ref, ref_length, vertex_length; udg_get_geometry(&vertex_length, &ref_length, &vertex_array, &ref, &crease); if(crease_edge(crease, vertex, ref, ref_length)) return FALSE; edge = udg_get_edge_data(&edge_length); // print_edge_list(edge, edge_length); GlobalSurfaceCreate.list_length[0] = 0; GlobalSurfaceCreate.list_length[1] = 0; GlobalSurfaceCreate.create_length = 0; find_neighbor_polygon(ref, ref_length, vertex_length, vertex); find_neighbor_edges(edge, edge_length, vertex); // print_neighbor(); find_triangles(vertex); find_quads(vertex, ref, ref_length, edge, edge_length); if(GlobalSurfaceCreate.create_length == 0) return TRUE; select_found(vertex_array, vertex, create_final); destroy_edges(edge, edge_length, create_final); destroy_surface(ref, crease, vertex_length, ref_length, create_final, crease_final); create_surface(create_final, crease_final); return FALSE; }
static gboolean create_surface_when_idle (PhotosPrintPreview *preview) { create_surface (preview); return FALSE; }
int main() { { TimeCheck time; auto surface = create_surface(CAIRO_FORMAT_ARGB32, SURFACE_SIZE{ 256, 256 }); auto cr = create(surface); line_width(cr, 30.0); line_cap(cr, CAIRO_LINE_CAP_BUTT); /* default */ move_to(cr, POINT{ 64.0, 50.0 }); line_to(cr, POINT{ 64.0, 200.0 }); stroke(cr); line_cap(cr, CAIRO_LINE_CAP_ROUND); move_to(cr, POINT{ 128.0, 50.0 }); line_to(cr, POINT{ 128.0, 200.0 }); stroke(cr); line_cap(cr, CAIRO_LINE_CAP_SQUARE); move_to(cr, POINT{ 192.0, 50.0 }); line_to(cr, POINT{ 192.0, 200.0 }); stroke(cr); /* draw helping lines */ source(cr, RGB{ 1, 0.2, 0.2 }); line_width(cr, 2.56); move_to(cr, POINT{ 64.0, 50.0 }); line_to(cr, POINT{ 64.0, 200.0 }); move_to(cr, POINT{ 128.0, 50.0 }); line_to(cr, POINT{ 128.0, 200.0 }); move_to(cr, POINT{ 192.0, 50.0 }); line_to(cr, POINT{ 192.0, 200.0 }); stroke(cr); write_to_png(surface, "image.png"); } return 0; }
CParticle::CParticle(CDisplay& Display, CTimer& Timer, const SDL_Color& color, int x, int y): CEntity(Display, Timer) { this->Move_Force(x, y); /* Choose either neg or pos direction */ int sign = rand() % 2; if(sign == 1) { this->dx = 5 + rand() % 15; } else { this->dx = -5 - (rand() % 15); } sign = rand() % 2; if(sign == 1) { this->dy = -5 - rand() % 15; } else { this->dy = 5 + rand() % 15; } this->lifetime = 100 + rand() % 100; this->SetEntity(create_surface(5, 5, color)); }
// draw_menu - draws menu centered on surface void draw_menu(struct Menu* menu, SDL_Surface* destination, int oldx, int oldy) { struct MenuElement* element; int i; int x = 0; int y = 0; int w = 200; int h = menu->length*25; SDL_Surface* menusurf = create_surface(w, h); SDL_Surface* menutextsurf; for (i = 0; i < menu->length; i++) { element = &menu->elements[i]; if (element->active) { // draw active element red menutextsurf = draw_text(0, 0, NULL, element->text, 255, 0, 0); draw_surface(x, y, menutextsurf, menusurf, NULL); SDL_FreeSurface(menutextsurf); } else { menutextsurf = draw_text(0, 0, NULL, element->text, 255, 255, 255); draw_surface(x, y, //draw inactive element white menutextsurf, menusurf, NULL); SDL_FreeSurface(menutextsurf); } y += 25; } draw_surface_centered(menusurf, destination); SDL_FreeSurface(menusurf); }
/* Draw a rectangle on the screen */ static void draw_brush (GtkWidget *widget, gdouble x, gdouble y) { GdkRectangle update_rect; cairo_t *cr; if (surface == NULL || cairo_image_surface_get_width (surface) != gtk_widget_get_width (widget) || cairo_image_surface_get_height (surface) != gtk_widget_get_height (widget)) create_surface (widget); update_rect.x = x - 3; update_rect.y = y - 3; update_rect.width = 6; update_rect.height = 6; /* Paint to the surface, where we store our state */ cr = cairo_create (surface); gdk_cairo_rectangle (cr, &update_rect); cairo_fill (cr); cairo_destroy (cr); gtk_widget_queue_draw (widget); }
int main() { { TimeCheck time; auto surface = create_surface(CAIRO_FORMAT_ARGB32, SURFACE_SIZE{ 256, 256 }); auto cr = create(surface); arc(cr, POINT{ 128.0, 128.0 }, 76.8, DEGRESS{ 0 }, DEGRESS{ 360 }); clip(cr); new_path(cr); /* current path is not consumed by cairo_clip() */ rectangle(cr, POINT{ 0, 0 }, SIZE{ 255, 255 }); fill(cr); source(cr, RGB{ 0, 1, 0 }); move_to(cr, POINT{ 0, 0 }); line_to(cr, POINT{ 256, 256 }); move_to(cr, POINT{ 256, 0 }); line_to(cr, POINT{ 0, 256 }); line_width(cr, 10.0); stroke(cr); write_to_png(surface, "image.png"); } return 0; }
static cairo_test_status_t draw (cairo_t *cr, int width, int height) { cairo_content_t contents[] = { CAIRO_CONTENT_COLOR_ALPHA, CAIRO_CONTENT_COLOR, CAIRO_CONTENT_ALPHA }; unsigned int content, type, ops; cairo_set_source_rgb (cr, 0.5, 0.5, 0.5); cairo_paint (cr); cairo_translate (cr, SPACE, SPACE); for (type = 0; type <= PAINTED; type++) { for (content = 0; content < ARRAY_LENGTH (contents); content++) { cairo_surface_t *surface; surface = create_surface (cr, contents[content], type); cairo_save (cr); for (ops = 0; ops < ARRAY_LENGTH (operations); ops++) { cairo_save (cr); operations[ops] (cr, surface); cairo_restore (cr); cairo_translate (cr, 0, SIZE + SPACE); } cairo_restore (cr); cairo_translate (cr, SIZE + SPACE, 0); cairo_surface_destroy (surface); } } return CAIRO_TEST_SUCCESS; }
void floating_label::draw(surface screen) { if(!visible_) { buf_.assign(nullptr); return; } if(screen == nullptr) { return; } create_surface(); if(surf_ == nullptr) { return; } if(buf_ == nullptr) { buf_.assign(create_compatible_surface(screen, surf_->w, surf_->h)); if(buf_ == nullptr) { return; } } SDL_Rect rect = sdl::create_rect(xpos(surf_->w), ypos_, surf_->w, surf_->h); const clip_rect_setter clip_setter(screen, &clip_rect_); sdl_copy_portion(screen,&rect,buf_,nullptr); sdl_blit(surf_,nullptr,screen,&rect); }
void image_new_blank(image_t *image, gdouble rel_w, gdouble rel_h) { double w, h; get_abs_pos(rel_w, rel_h, &w, &h); image->layer = create_layer(w, h); image->rotation = 0; image->surface = create_surface(w, h); image->pbuf = NULL; add_layer(image->layer); }
/** * @param w šířka surface * @param h výška surface * @param transparent pokud TRUE, bude nastavena poloprůhlednost surface * @return Vrací vytvořené SDL_Surface. */ SDL_Surface* create_transparent_surface(Uint16 w, Uint16 h, bool transparent){ // vytvorim surface SDL_Surface *sur=create_surface(w, h, Color::transparent); // nastavim transparentni barvu set_transparent_color(sur, Color::transparent); //nastavim pruhlednost if(transparent) SDL_SetAlpha(sur, SDL_SRCALPHA | SDL_RLEACCEL, 128); return sur; }
// TODO: This will be less awkward with the ApplicationWindow class. bool mtc::SessionManagementContext::open_window_consuming(std::string const& window_name) { auto const params = mf::a_surface().of_name(window_name); auto session = shell->open_session(window_name); auto const surface_id = session->create_surface(params); open_windows[window_name] = std::make_tuple(session, surface_id); return true; }
void DisplayChannel::handle_surface_create(RedPeer::InMessage* message) { SpiceMsgSurfaceCreate* surface_create = (SpiceMsgSurfaceCreate*)message->data(); if (surface_create->flags == SPICE_SURFACE_FLAGS_PRIMARY) { create_primary_surface(surface_create->width, surface_create->height, surface_create->format); } else { create_surface(surface_create->surface_id, surface_create->width, surface_create->height, surface_create->format); } }
int main(int argc, char** argv){ int i; int j; int* score = (int*) malloc(sizeof(int)); if (SDL_Init(SDL_INIT_EVERYTHING) == -1){ printf("SDL_Init: %s\n", SDL_GetError()); return 1; } // Unicode support for hiscore table SDL_EnableUNICODE(1); if(TTF_Init()==-1) { printf("TTF_Init: %s\n", TTF_GetError()); return 1; } SDL_Surface* screen = SDL_SetVideoMode(608, 640, 32, SDL_SWSURFACE); SDL_WM_SetCaption("martet", "martet"); SDL_Surface* board = create_surface(320, 640); SDL_Surface* border = load_image("../data/tetborder.png"); draw_surface(321, 0, border, screen, NULL); draw_text(390, 35, screen, "Next tetromino:", 255, 255, 255); draw_text(330, 200, screen, "Score: ", 255, 255, 255); // create menu struct Menu* menu = menu_create(); menu_addelement(menu, "Start Game"); menu_addelement(menu, "Quit"); menu->active_element = &menu->elements[0]; menu->active_element->active = 1; bool running = true; while (running){ if (menu_martet(screen, board, menu, score) == KEYEVENT_EXIT) break; // fill the board with blocks on game over for (i = 0; i < BOARD_HEIGHT; i++) { char* line = get_board_line(i); for (j = 0; j < BOARD_WIDTH; j++) { line[j] = rand() % 7 + '0'; } draw_board(board); draw_surface(0, 0, board, screen, NULL); SDL_Flip(screen); SDL_Delay(50); } manage_hiscores(screen, board, score); board_delete(); } menu_destroy(menu); SDL_FreeSurface(border); SDL_FreeSurface(board); free(score); SDL_Quit(); return 0; }
int main(int argc, char *argv[]) { struct display *display; char buf[256], *p; int ret, fd; display = malloc(sizeof *display); assert(display); display->display = wl_display_connect(NULL); assert(display->display); display->registry = wl_display_get_registry(display->display); wl_registry_add_listener(display->registry, ®istry_listener, display); wl_display_dispatch(display->display); wl_display_dispatch(display->display); fd = 0; p = getenv("TEST_SOCKET"); if (p) fd = strtol(p, NULL, 0); while (1) { ret = read(fd, buf, sizeof buf); if (ret == -1) { fprintf(stderr, "test-client: read error: fd %d, %m\n", fd); return -1; } fprintf(stderr, "test-client: got %.*s\n", ret - 1, buf); if (strncmp(buf, "bye\n", ret) == 0) { return 0; } else if (strncmp(buf, "create-surface\n", ret) == 0) { create_surface(fd, display); } else if (strncmp(buf, "send-state\n", ret) == 0) { send_state(fd, display); } else if (strncmp(buf, "send-button-state\n", ret) == 0) { send_button_state(fd, display); } else if (strncmp(buf, "send-keyboard-state\n", ret) == 0) { send_keyboard_state(fd, display); } else { fprintf(stderr, "test-client: unknown command %.*s\n", ret, buf); return -1; } } assert(0); }
extern SkinSurface* skin_surface_create_window(int x, int y, int w, int h, int original_w, int original_h, int is_fullscreen) { D("skin_surface_create_window %d, %d, %d, %d, %d, %d, fullscreen: %d", x, y, w, h, original_w, original_h, is_fullscreen); QSemaphore semaphore; EmulatorWindow *window = EmulatorWindow::getInstance(); if (window == NULL) return NULL; SkinSurface *surface = create_surface(w, h, original_w, original_h); QRect rect(x, y, w, h); window->showWindow(surface, &rect, is_fullscreen, &semaphore); semaphore.acquire(); D("ID of backing bitmap surface is %d", surface->id); return surface; }
int main(int argc, char **argv) { struct sigaction sigint; struct display display = { 0 }; struct window window = { 0 }; window.display = &display; window.geometry.width = 250; window.geometry.height = 250; display.display = wl_display_connect(NULL); assert(display.display); wl_display_add_global_listener(display.display, display_handle_global, &display); wl_display_get_fd(display.display, event_mask_update, &display); wl_display_iterate(display.display, WL_DISPLAY_READABLE); init_egl(&display); create_surface(&window); init_gl(&window); sigint.sa_handler = signal_int; sigemptyset(&sigint.sa_mask); sigint.sa_flags = SA_RESETHAND; sigaction(SIGINT, &sigint, NULL); redraw(&window, NULL, 0); while (running) wl_display_iterate(display.display, display.mask); fprintf(stderr, "simple-egl exiting\n"); destroy_surface(&window); fini_egl(&display); if (display.shell) wl_shell_destroy(display.shell); if (display.compositor) wl_compositor_destroy(display.compositor); wl_display_flush(display.display); wl_display_disconnect(display.display); return 0; }
static SURFACE* _createsurf_copy_internal_yx(SURFACE* src) { SURFACE* surface = create_surface(src->h,src->w,src->bpp); if(surface==0) return 0; surface->pixtype = src->pixtype; if(src->pal) { surface->pal->colorkey = src->pal->colorkey; surface->pal->nColors = src->pal->nColors; memcpy(surface->pal->colors,src->pal->colors,src->pal->nColors*4); } return surface; }
extern SkinSurface* skin_surface_create_argb32_from(int w, int h, int pitch, uint32_t *pixels) { D("skin_surface_create_argb32_from %d, %d, pitch %d (%d)", w, h, pitch); SkinSurface* s = create_surface(w, h, w, h); SkinRect rect; rect.size.h = h; rect.size.w = w; rect.pos.x = 0; rect.pos.y = 0; SkinSurfacePixels p; skin_surface_lock(s, &p); skin_surface_upload(s, &rect, pixels, pitch); skin_surface_unlock(s); return s; }
bool init(const char* pipeline, core::c_window *window, bool validation) { VERIFY(graphics::render3d::resources::load_pipeline(pipeline)); VERIFY(create_instance("appname")); VERIFY(create_surface(window)); VERIFY(create_device()); VERIFY(create_device_queue()); VERIFY(graphics::render3d::resources::create_pipeline()); vk_globals::is_init = true; flag_needs_recreate_swapchain.store(false); flag_needs_shutdown.store(false); on_window_resize_listener = window->add_event_listener(core::e_window_event::ON_RESIZE, on_window_resize); return true; }
void Shell::create_swapchain() { ctx_.surface = create_surface(ctx_.instance); VkBool32 supported; vk::assert_success(vk::GetPhysicalDeviceSurfaceSupportKHR(ctx_.physical_dev, ctx_.present_queue_family, ctx_.surface, &supported)); // this should be guaranteed by the platform-specific can_present call assert(supported); std::vector<VkSurfaceFormatKHR> formats; vk::get(ctx_.physical_dev, ctx_.surface, formats); ctx_.format = formats[0]; // defer to resize_swapchain() ctx_.swapchain = VK_NULL_HANDLE; ctx_.extent.width = (uint32_t) -1; ctx_.extent.height = (uint32_t) -1; }
gboolean image_new(image_t *image, const char *filename) { GError **error = NULL; image->pbuf = gdk_pixbuf_new_from_file(filename, error); if (!image->pbuf) return FALSE; image->layer = create_layer(gdk_pixbuf_get_width(image->pbuf), gdk_pixbuf_get_height(image->pbuf)); image->rotation = 0; image->surface = create_surface(image->layer->width, image->layer->height); cairo_t *cr = cairo_create(image->surface); cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); gdk_cairo_set_source_pixbuf(cr, image->pbuf, 0, 0); cairo_paint(cr); cairo_destroy(cr); add_layer(image->layer); return TRUE; }
SDL_Surface* DrawingContext::get_surface(const Rect& rect) { SDL_Surface* region = create_surface(rect.get_width(), rect.get_height()); // Fill with white (FIXME: should be alpha or background color) SDL_FillRect(region, NULL, SDL_MapRGB(region->format, 255, 255, 255)); SDL_Rect source_pos; // FIXME: Do we need to clip those? source_pos.x = rect.left; source_pos.y = rect.top; source_pos.w = rect.get_width(); source_pos.h = rect.get_height(); SDL_Rect target_pos; target_pos.x = 0; target_pos.y = 0; SDL_BlitSurface(drawable, &source_pos, region, &target_pos); return region; }
int main() { { TimeCheck time; constexpr int WIDTH = 175; constexpr int HEIGHT = 175; constexpr int STRIDE = WIDTH * 4; std::vector<unsigned char> datas(HEIGHT*STRIDE); auto surface = create_surface(datas, CAIRO_FORMAT_ARGB32, SURFACE_SIZE{ WIDTH, HEIGHT }, STRIDE); auto cr = create(surface); rectangle(cr, POINT{ 0,0 }, SIZE{ WIDTH, HEIGHT }); source(cr, RGB{ 0,0,0 }); fill(cr); draw(cr, WIDTH, HEIGHT); write_to_png(surface, "image.png"); } return 0; }
/// this will render a block and store a pointer to the rendered texture in the blockData itself. // this is useful when you don't want to render a block every time you print the screen. // this can be used to only re-render the block when a change in the block elevation occurs. // returns 0 on success // returns 1 on invalid block // returns 2 if blockRenderer is NULL short block_render(struct blockData *block, SDL_Renderer *blockRenderer){ // quit and report error if you were given a bad block. if(block == NULL){ error("block_render() was sent NULL block."); return 1; } // quit and report error if you were given a bad block. if(blockRenderer == NULL){ error("block_render() was sent invalid blockRenderer. blockRenderer = NULL"); return 2; } // this is a pointer to where surface data is stored. // the data will stay here (we can use the same surface data over and over again to render any block, because the surface is only needed temporarily. static SDL_Surface *blockSurface; static int firstTimeThrough = 1; if(firstTimeThrough) { blockSurface = create_surface(BLOCK_WIDTH, BLOCK_HEIGHT); firstTimeThrough = 0; } // if the block texture is valid, destroy it. This frees up the memory that was used to render the last texture. We no longer need it. if(block->texture != NULL) SDL_DestroyTexture(block->texture); int i, j; for(i=0; i<BLOCK_WIDTH; i++){ for(j=0; j<BLOCK_HEIGHT; j++){ set_pixel(blockSurface, i, j, ((int)(block->elevation[i][j])) | 0xff000000); } } // copy surface to texture block->texture = SDL_CreateTextureFromSurface(blockRenderer, blockSurface); // success! return 0; }
static gboolean gst_gl_window_wayland_egl_open (GstGLWindow * window, GError ** error) { GstGLWindowWaylandEGL *window_egl = GST_GL_WINDOW_WAYLAND_EGL (window); window_egl->display.display = wl_display_connect (NULL); if (!window_egl->display.display) { g_set_error (error, GST_GL_WINDOW_ERROR, GST_GL_WINDOW_ERROR_RESOURCE_UNAVAILABLE, "Failed to connect to Wayland display server"); goto error; } window_egl->display.registry = wl_display_get_registry (window_egl->display.display); wl_registry_add_listener (window_egl->display.registry, ®istry_listener, window_egl); wl_display_dispatch (window_egl->display.display); create_surface (window_egl); window_egl->display.cursor_surface = wl_compositor_create_surface (window_egl->display.compositor); window_egl->wl_source = wayland_event_source_new (window_egl->display.display); window_egl->main_context = g_main_context_new (); window_egl->loop = g_main_loop_new (window_egl->main_context, FALSE); g_source_attach (window_egl->wl_source, window_egl->main_context); return TRUE; error: return FALSE; }
/* This returns a referenced object via resultptr. */ bool apple_glx_surface_create(Display * dpy, int screen, GLXDrawable drawable, struct apple_glx_drawable ** resultptr) { struct apple_glx_drawable *d; if (apple_glx_drawable_create(dpy, screen, drawable, &d, &callbacks)) return true; /* apple_glx_drawable_create creates a locked and referenced object. */ if (create_surface(dpy, screen, d)) { d->unlock(d); d->destroy(d); return true; } *resultptr = d; d->unlock(d); return false; }
void style_set(const gchar *font, gint x, gint y, gint off_x, gint off_y, gint width, gint height, gdouble r, gdouble g, gdouble b, gdouble a, const gchar *bg, const gchar *border, gdouble border_width) { if (font) { pango_font_description_free(lualock.style.font_desc); lualock.style.font_desc = pango_font_description_from_string(font); } lualock.style.x = x; lualock.style.y = y; lualock.style.off_x = off_x; lualock.style.off_y = off_y; lualock.style.width = width; lualock.style.height = height; lualock.style.r = r; lualock.style.g = g; lualock.style.b = b; lualock.style.a = a; GdkRGBA bg_color, border_color; gdk_rgba_parse(&bg_color, bg ? bg : "white"); lualock.style.bg_color = bg_color; gdk_rgba_parse(&border_color, border ? border : "rgba(0, 0, 0, 0.6)"); lualock.style.border_color = border_color; lualock.style.border_width = border_width; cairo_surface_t *old_pw_surface = lualock.pw_surface; lualock.pw_surface = create_surface(width, height); cairo_surface_destroy(old_pw_surface); }
void menu_create_buffer(menu_t *menu){ #ifdef DEBUG if(menu->buffer != NULL){ printf("MEMORY LEAK: MENU BUFFER OVER-WRITE\n"); } #endif int32_t x = 0; int32_t w = 0; int32_t h = 0; for(uint32_t i=0; i<MENU_MAX_OPTIONS; i++){ if(menu->options[i] != NULL){ x = font_get_width(menu->font, menu->options[i]->label); if(x > w){ w = x; } h += font_get_height(menu->font); } } w += 20; h += 8; menu->buffer = create_surface(w,h); }