X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?a=blobdiff_plain;f=src%2Fapp.c;h=87f3a1070c6cb6bef3aa38663a581b1d82f67a21;hb=86aa9bdd85243207bbd7e888d73c2b865d805265;hp=0a0af71e5d675c6d204769b2260b0b6bf48cf148;hpb=7fccf8b3543c8cdb993252f0cf9a6b9ed826408e;p=retroray diff --git a/src/app.c b/src/app.c index 0a0af71..87f3a10 100644 --- a/src/app.c +++ b/src/app.c @@ -23,10 +23,20 @@ along with this program. If not, see . #include #include "gaw/gaw.h" #include "app.h" +#include "rend.h" #include "options.h" #include "font.h" +#include "util.h" +#include "rtk.h" -static void txdraw(struct dtx_vertex *v, int vcount, struct dtx_pixmap *pixmap, void *cls); +#ifdef GFX_SW +#include "gaw/gaw_sw.h" +#endif + +static void gui_fill(rtk_rect *rect, uint32_t color); +static void gui_blit(int x, int y, rtk_icon *icon); +static void gui_drawtext(int x, int y, const char *str); +static void gui_textrect(const char *str, rtk_rect *rect); int mouse_x, mouse_y, mouse_state[3]; unsigned int modkeys; @@ -38,7 +48,11 @@ long time_msec; struct app_screen *cur_scr; -struct font *font; +struct font *uifont; + +uint32_t *framebuf; + +struct scene *scn; /* available screens */ #define MAX_SCREENS 8 @@ -50,12 +64,18 @@ int app_init(void) { int i; char *start_scr_name; + static rtk_draw_ops guigfx = {gui_fill, gui_blit, gui_drawtext, gui_textrect}; #if !defined(NDEBUG) && defined(DBG_FPEXCEPT) printf("floating point exceptions enabled\n"); enable_fpexcept(); #endif +#ifdef GFX_SW + gaw_sw_init(); +#endif + rend_init(); + load_options("retroray.cfg"); app_resize(opt.xres, opt.yres); app_vsync(opt.vsync); @@ -63,14 +83,22 @@ int app_init(void) app_fullscreen(1); } - dtx_target_user(txdraw, 0); + /*dtx_target_user(txdraw, 0);*/ + dtx_target_raster((unsigned char*)framebuf, win_width, win_height); + dtx_set(DTX_RASTER_THRESHOLD, 127); - font = malloc_nf(sizeof *font); - if(load_font(uifont, "data/uifont.gmp") == -1) { + uifont = malloc_nf(sizeof *uifont); + if(load_font(uifont, "data/uifont14.gmp") == -1) { free(uifont); return -1; } + rtk_setup(&guigfx); + + if(!(scn = create_scene())) { + return -1; + } + /* initialize screens */ screens[num_screens++] = &scr_model; screens[num_screens++] = &scr_rend; @@ -92,7 +120,7 @@ int app_init(void) } } if(!cur_scr) { - app_chscr(&scr_logo); + app_chscr(&scr_model); } return 0; @@ -104,7 +132,7 @@ void app_shutdown(void) putchar('\n'); - save_options(GAME_CFG_FILE); + save_options("retroray.cfg"); for(i=0; idestroy) { @@ -114,21 +142,43 @@ void app_shutdown(void) destroy_font(uifont); free(uifont); + +#ifdef GFX_SW + gaw_sw_destroy(); +#endif + + free_scene(scn); + + cleanup_logger(); } void app_display(void) { - static long nframes, interv, prev_msec; - time_msec = app_getmsec(); cur_scr->display(); - - app_swap_buffers(); } void app_reshape(int x, int y) { + int numpix = x * y; + int prev_numpix = win_width * win_height; + + printf("reshape(%d, %d)\n", x, y); + + if(!framebuf || numpix > prev_numpix) { + void *tmp; + if(!(tmp = realloc(framebuf, numpix * sizeof *framebuf))) { + errormsg("failed to resize framebuffer to %dx%d\n", x, y); + return; + } + framebuf = tmp; + } +#ifdef GFX_SW + gaw_sw_framebuffer(x, y, framebuf); +#endif + dtx_target_raster((unsigned char*)framebuf, x, y); + win_width = x; win_height = y; win_aspect = (float)x / (float)y; @@ -149,10 +199,17 @@ void app_keyboard(int key, int press) return; #endif + case 'q': + if(modkeys & KEY_MOD_CTRL) { + app_quit(); + return; + } + break; + case '\n': case '\r': - if(modkeys & GKEY_MOD_ALT) { - case GKEY_F11: + if(modkeys & KEY_MOD_ALT) { + case KEY_F11: app_fullscreen(-1); return; } @@ -227,55 +284,46 @@ void app_chscr(struct app_screen *scr) cur_scr = scr; } -static void txdraw(struct dtx_vertex *v, int vcount, struct dtx_pixmap *pixmap, void *cls) +static void gui_fill(rtk_rect *rect, uint32_t color) { - int i, aref, npix; - unsigned char *src, *dest; - struct texture *tex = pixmap->udata; - - if(!tex) { - struct img_pixmap *img = img_create(); - img_set_pixels(img, pixmap->width, pixmap->height, IMG_FMT_RGBA32, 0); - - npix = pixmap->width * pixmap->height; - src = pixmap->pixels; - dest = img->pixels; - for(i=0; iy * win_width + rect->x; - if(!(tex = tex_image(img))) { - return; + for(i=0; iheight; i++) { + for(j=0; jwidth; j++) { + fb[j] = color; } - pixmap->udata = tex; + fb += win_width; } +} - gaw_save(); - if(dtx_get(DTX_GL_BLEND)) { - gaw_enable(GAW_BLEND); - gaw_blend_func(GAW_SRC_ALPHA, GAW_ONE_MINUS_SRC_ALPHA); - } else { - gaw_disable(GAW_BLEND); - } - if((aref = dtx_get(DTX_GL_ALPHATEST))) { - gaw_enable(GAW_ALPHA_TEST); - gaw_alpha_func(GAW_GREATER, aref); - } else { - gaw_disable(GAW_ALPHA_TEST); +static void gui_blit(int x, int y, rtk_icon *icon) +{ + int i, j; + uint32_t *dest, *src; + + dest = framebuf + y * win_width + x; + src = icon->pixels; + + for(i=0; iheight; i++) { + for(j=0; jwidth; j++) { + int r = src[j] & 0xff; + int g = (src[j] >> 8) & 0xff; + int b = (src[j] >> 16) & 0xff; + dest[j] = 0xff000000 | (r << 16) | (g << 8) | b; + } + dest += win_width; + src += icon->scanlen; } +} - gaw_set_tex2d(tex->texid); - - gaw_begin(GAW_TRIANGLES); - for(i=0; is, v->t); - gaw_vertex2f(v->x, v->y); - v++; - } - gaw_end(); +static void gui_drawtext(int x, int y, const char *str) +{ +} - gaw_restore(); - gaw_set_tex2d(0); +static void gui_textrect(const char *str, rtk_rect *rect) +{ + rect->x = rect->y = 0; + rect->width = 20; + rect->height = 10;/* TODO */ }