void RGBHistogram::display() { #ifdef ALLEGRO int winwid=640,winhei=480; set_color_depth(24); allegrosetup(winwid,winhei); PALETTE pal; generate_332_palette(pal); set_palette(pal); float rot=pi/4,elev=pi/8,rotspeed=pi/64; int smallize=largest(); PPsetup(winwid,winhei,3); BITMAP *b=create_bitmap(winwid,winhei); do { clear(b); Matrix m1=Matrix(); m1.makerotation(V3d(0,1,0),rot); Matrix m2=Matrix(); m2.makerotation(V3d(1,0,0),elev); for (int i=0;i<quant;i++) { for (int j=0;j<quant;j++) { for (int k=0;k<quant;k++) { V3d c=V3d(i,j,k); c=c/c.getlongestside(); c=c*(float)rgb[i][j][k]/smallize*255; // c=c*255; c.chop(0,255); if (c.getlongestside()>64) { V3d v=2*(V3d(i,j,k)/quant-V3d(.5,.5,.5)); // v=V3d::rotate(v,V3d(0,1,0),rot); // v=V3d::rotate(v,V3d(1,0,0),elev); v=m1*v; v=m2*v; V3d u=v+V3d(.02,0,0); int x,y,rx,dx; PPgetscrpos(v,&x,&y); PPgetscrpos(u,&rx,&dx); dx=rx-x; circle(b,x,y,dx,makecol(c.x,c.y,c.z)); } } } } blit(b,screen,0,0,0,0,winwid,winhei); if (key[KEY_LEFT]) rot-=rotspeed; if (key[KEY_RIGHT]) rot+=rotspeed; if (key[KEY_UP]) elev-=rotspeed; if (key[KEY_DOWN]) elev+=rotspeed; if (key[KEY_Z]) smallize=smallize*1.2; if (key[KEY_X]) smallize=smallize/1.2; } while (!key[KEY_ESC]); #endif }
int main(int argc, char *argv[]) { int ret = 0; int i; allegro_init(); install_keyboard(); install_mouse(); install_timer(); srand(time(NULL)); for (i=1; i<argc; i++) { if (stricmp(argv[i], "-bpp") == 0) { if ((i >= argc-1) || (bpp > 0)) { usage(); return 1; } bpp = atoi(argv[++i]); } else if (stricmp(argv[i], "-frames") == 0) { if ((i >= argc-1) || (frames > 0)) { usage(); return 1; } frames = atoi(argv[++i]); } else if (stricmp(argv[i], "-size") == 0) { if ((i >= argc-2) || (size_x > 0) || (size_y > 0)) { usage(); return 1; } size_x = atoi(argv[++i]); size_y = atoi(argv[++i]); } else if (stricmp(argv[i], "-mode") == 0) { if ((i >= argc-2) || (mode_x > 0) || (mode_y > 0)) { usage(); return 1; } mode_x = atoi(argv[++i]); mode_y = atoi(argv[++i]); } else if (stricmp(argv[i], "-step") == 0) { step = TRUE; } else if (stricmp(argv[i], "-modesel") == 0) { modesel = TRUE; } else if (stricmp(argv[i], "-pregen") == 0) { pregen = TRUE; } else if (stricmp(argv[i], "-o") == 0) { if ((i >= argc-1) || (out_file)) { usage(); return 1; } out_file = argv[++i]; } else if (stricmp(argv[i], "-pal") == 0) { if ((i >= argc-1) || (pal_file)) { usage(); return 1; } pal_file = argv[++i]; } else { if ((*argv[i] == '-') || (in_file)) { usage(); return 1; } in_file = argv[i]; } } if (!in_file) { usage(); return 1; } if ((pregen) && ((frames <= 0) || (step))) { allegro_message("The '-pregen' option requires '-frames num' to be specified,\nand cannot be used at the same time as '-step'\n"); return 1; } if (!set_video_mode()) { ret = 1; goto getout; } the_egg = load_egg(in_file, error); if (!the_egg) { set_gfx_mode(GFX_TEXT, 0, 0, 0, 0); allegro_message("%s", error); return 1; } if (size_x <= 0) size_x = 128; if (size_y <= 0) size_y = 128; if (pal_file) { BITMAP *tmp = load_bitmap(pal_file, pal); if (!tmp) { set_gfx_mode(GFX_TEXT, 0, 0, 0, 0); allegro_message("Error reading palette from '%s'\n", pal_file); ret = 1; goto getout; } destroy_bitmap(tmp); } else generate_332_palette(pal); clear(screen); set_palette(pal); text_mode(0); do { if (pregen) { textprintf_centre(screen, font, SCREEN_W/2, SCREEN_H/2-24, makecol(128, 128, 128), "Rendering frame %d/%d", the_egg->frame+1, frames); textprintf_centre(screen, font, SCREEN_W/2, SCREEN_H/2+24, makecol(128, 128, 128), "Please Wait"); } if (update_egg(the_egg, error) != 0) { allegro_exit(); printf("Error running EGG script:\n%s\n\n", error); ret = 1; goto getout; } bmp[frame] = create_bitmap(size_x, size_y); lay_egg(the_egg, bmp[frame]); if (!pregen) { vsync(); blit(bmp[frame], screen, 0, 0, (SCREEN_W-size_x)/2, (SCREEN_H-size_y)/2, size_x, size_y); textprintf(screen, font, 0, 0, makecol(128, 128, 128), "Frame %d, %d particles ", the_egg->frame, the_egg->part_count); } if ((!pregen) && (!out_file)) { destroy_bitmap(bmp[frame]); bmp[frame] = NULL; } frame++; if ((step) || (keypressed())) { if ((readkey()&0xFF) == 27) break; clear_keybuf(); } } while (((frames <= 0) || (frame < frames)) && (frame < 4096)); if (pregen) view_animation(); if (out_file) save_animation(); getout: if (the_egg) destroy_egg(the_egg); for (i=0; i<frame; i++) if (bmp[frame]) destroy_bitmap(bmp[frame]); return ret; }
void TextureUtil::initGrx() { Config * config = Config::getInstance(); #if EM_USE_SDL cerr << "Initing SDL" << endl << endl; if (SDL_InitSubSystem(SDL_INIT_VIDEO) < 0) { cerr << "Couldn't initialize SDL video" << SDL_GetError() << endl; exit(1); } if (SDL_InitSubSystem(SDL_INIT_JOYSTICK) < 0) { cerr << "Couldn't initialize SDL joystick: " << SDL_GetError() << endl << endl; } else { int njoystick = SDL_NumJoysticks(); cerr << njoystick << " joysticks were found." << endl; if (njoystick != 0) { cerr << "The names of the joysticks are:" << endl; for(int a=0; a<njoystick; a++ ) { cerr << " " << SDL_JoystickName(a) << endl; } cerr << "Using " << SDL_JoystickName(0) << endl << endl; SDL_JoystickOpen(0); SDL_JoystickEventState(SDL_ENABLE); } } // See if we should detect the display depth if ( SDL_GetVideoInfo()->vfmt->BitsPerPixel <= 8 ) { SDL_GL_SetAttribute( SDL_GL_RED_SIZE, 2 ); SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, 3 ); SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, 3 ); } else if ( SDL_GetVideoInfo()->vfmt->BitsPerPixel <= 16 ) { SDL_GL_SetAttribute( SDL_GL_RED_SIZE, 5 ); SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, 5 ); SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, 5 ); } else { SDL_GL_SetAttribute( SDL_GL_RED_SIZE, 8 ); SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, 8 ); SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, 8 ); } SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, 16 ); SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 ); /* Initialize the display */ SDL_Surface* screen = SDL_SetVideoMode(config->getWidth(), config->getHeight(), config->getBpp(), SDL_OPENGL | (config->useFullScreen() ? SDL_FULLSCREEN : 0)); // if (config->useFullScreen()) { SDL_ShowCursor(SDL_DISABLE); // } SDL_WM_SetCaption("Emilia Pinball", NULL); if (screen == NULL) { cerr << "Couldn't set video mode: " << SDL_GetError() << endl; exit(1); } cerr << "Vendor : " << glGetString( GL_VENDOR ) << endl; cerr << "Renderer : " << glGetString( GL_RENDERER ) << endl; cerr << "Version : " << glGetString( GL_VERSION ) << endl; cerr << "Extensions : " << glGetString( GL_EXTENSIONS ) << endl << endl; //TODO: that would be usefull to report CPU/RAM specs also //!rzr int value; SDL_GL_GetAttribute( SDL_GL_RED_SIZE, &value ); cerr << "SDL_GL_RED_SIZE: " << value << endl; SDL_GL_GetAttribute( SDL_GL_GREEN_SIZE, &value ); cerr << "SDL_GL_GREEN_SIZE: " << value << endl; SDL_GL_GetAttribute( SDL_GL_BLUE_SIZE, &value ); cerr << "SDL_GL_BLUE_SIZE: " << value << endl; SDL_GL_GetAttribute( SDL_GL_DEPTH_SIZE, &value ); cerr << "SDL_GL_DEPTH_SIZE: " << value << endl; SDL_GL_GetAttribute( SDL_GL_DOUBLEBUFFER, &value ); cerr << "SDL_GL_DOUBLEBUFFER: " << value << endl << endl; this->resizeView(config->getWidth(), config->getHeight()); #endif // EM_USE_SDL #if EM_USE_ALLEGRO //config->setSize(320, 240); allegro_init(); install_keyboard(); install_timer(); install_mouse(); COLOR_MAP colorMap; RGB_MAP rgbMap; COLOR_MAP transMap; RGB* paPalette = (RGB*) calloc(256, sizeof(RGB)); generate_332_palette(paPalette); // create rgb table create_rgb_table(&rgbMap, paPalette, NULL); rgb_map = &rgbMap; // create light table and setup the truecolor blending functions. create_light_table(&colorMap, paPalette, 0, 0, 0, NULL); color_map = &colorMap; // texture and flat polygons are 50% transparent create_trans_table(&transMap, paPalette, 128, 128, 128, NULL); set_trans_blender(0, 0, 0, 128); // set the graphics mode int tc = GFX_AUTODETECT_WINDOWED, tw = config->getWidth(); int th = config->getHeight(), tbpp = 16; /* set_gfx_mode(GFX_SAFE, 320, 200, 0, 0); set_palette(desktop_palette); if (!gfx_mode_select_ex(&tc, &tw, &th, &tbpp)) { allegro_exit(); cerr << "Error setting safe graphics mode" << endl; } */ set_color_depth(tbpp); if (set_gfx_mode(tc, tw, th, 0, 0) != 0) { allegro_exit(); cerr << "Error setting graphics mode " << endl << allegro_error << endl; } set_palette(paPalette); config->setSize(tw, th); set_projection_viewport(0, 0, tw, th); // Create back buffer. backbuffer = create_bitmap(tw, th); clear(backbuffer); zbuffer = create_zbuffer(backbuffer); set_zbuffer(zbuffer); clear_zbuffer(zbuffer, 0); #endif // EM_USE_ALLEGRO }