int main() { int ok; allegro_init(); install_timer(); do { set_color_depth(8); if (set_gfx_mode (GFX_AUTODETECT, 640, 480, 0, 0) < 0) { allegro_message ("Error setting plain graphics mode:\n%s\n", allegro_error); return -1; } install_allegro_gl(); install_keyboard(); install_mouse(); ok = setup(); remove_keyboard(); remove_mouse(); if (ok) run_demo(); remove_allegro_gl(); } while (ok); return 0; }
int main(int argc, char *argv[]) { allegro_init(); install_allegro_gl(); install_keyboard(); install_mouse(); try { Juego::Inicializar() ; Juego *juego = new Juego(); juego->BuclePrincipal(); delete juego ; Juego::Cerrar(); } catch ( Excepcion &ex ) { set_gfx_mode(GFX_TEXT, 0, 0, 0, 0); allegro_message("%s\n", ex.GetMensajeDeError().c_str()); } catch ( exception &ex ) { set_gfx_mode(GFX_TEXT, 0, 0, 0, 0); allegro_message("%s\n", ex.what() ); } }
/** * Initialises the OpenGL and Allegro application. This function creates the global * Gui object that can be populated by various examples. */ void init() { // We simply initialise OpenGL and Allegro as we would do with any OpenGL // and Allegro application. allegro_init(); install_allegro_gl(); allegro_gl_clear_settings(); allegro_gl_set (AGL_COLOR_DEPTH, 32); allegro_gl_set (AGL_Z_DEPTH, 24); allegro_gl_set (AGL_FULLSCREEN, TRUE); allegro_gl_set (AGL_DOUBLEBUFFER, 1); allegro_gl_set (AGL_SUGGEST, AGL_COLOR_DEPTH | AGL_Z_DEPTH | AGL_DOUBLEBUFFER); set_gfx_mode(GFX_OPENGL_WINDOWED, 640, 480, 0, 0); install_keyboard(); install_mouse(); install_timer(); glViewport(0, 0, 640, 480); glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // Now it's time to initialise the Guichan OpenGL back end // and the Guichan Allegro back end. imageLoader = new gcn::OpenGLAllegroImageLoader(); // The ImageLoader Guichan should use needs to be passed to the Image object // using a static function. gcn::Image::setImageLoader(imageLoader); graphics = new gcn::OpenGLGraphics(); // We need to tell the OpenGL Graphics object how big the screen is. graphics->setTargetPlane(640, 480); input = new gcn::AllegroInput(); // Now we create the Gui object to be used with this OpenGL // and Allegro application. globals::gui = new gcn::Gui(); // The Gui object needs a Graphics to be able to draw itself and an Input // object to be able to check for user input. In this case we provide the // Gui object with OpenGL and Allegro implementations of these objects hence // making Guichan able to utilise OpenGL and Allegro. globals::gui->setGraphics(graphics); globals::gui->setInput(input); }
int main () { allegro_init(); install_allegro_gl(); allegro_gl_clear_settings(); allegro_gl_set (AGL_COLOR_DEPTH, 32); allegro_gl_set (AGL_Z_DEPTH, 24); allegro_gl_set (AGL_FULLSCREEN, TRUE); allegro_gl_set (AGL_DOUBLEBUFFER, 1); allegro_gl_set (AGL_SUGGEST, AGL_COLOR_DEPTH | AGL_Z_DEPTH | AGL_DOUBLEBUFFER | AGL_FULLSCREEN); if (set_gfx_mode(GFX_OPENGL, 640, 480, 0, 0) < 0) { allegro_message ("Error setting OpenGL graphics mode:\n%s\n" "Allegro GL error : %s\n", allegro_error, allegro_gl_error); return -1; } install_keyboard(); install_timer(); LOCK_FUNCTION(secs_timer); LOCK_VARIABLE(secs); glShadeModel (GL_FLAT); glEnable (GL_DEPTH_TEST); glCullFace (GL_BACK); glEnable (GL_CULL_FACE); install_int (secs_timer, 1000); do { keyboard(); } while (!key[KEY_ESC]); set_gfx_mode (GFX_TEXT, 0, 0, 0, 0); allegro_message("Frames: %i, Seconds: %i, FPS: %f\n", frames, secs, (float)frames / (float)secs); return 0; }
void init() { allegro_init(); install_allegro_gl(); allegro_gl_set(AGL_Z_DEPTH, 16); allegro_gl_set(AGL_COLOR_DEPTH, 32); allegro_gl_set(AGL_SUGGEST, AGL_Z_DEPTH | AGL_COLOR_DEPTH); set_gfx_mode(GFX_OPENGL_WINDOWED, 1024, 1024, 0, 0); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0, SCREEN_W, SCREEN_H, 0, -10.0, 10.0); glEnable(GL_TEXTURE_2D); install_keyboard(); install_mouse(); }
void init() { allegro_init(); install_allegro_gl(); allegro_gl_set(AGL_Z_DEPTH, 16); allegro_gl_set(AGL_COLOR_DEPTH, 32); allegro_gl_set(AGL_SUGGEST, AGL_Z_DEPTH | AGL_COLOR_DEPTH); set_gfx_mode(GFX_OPENGL, 640, 480, 0, 0); install_keyboard(); install_mouse(); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glFrustum(-1.0 * ASPECT_RATIO, 1.0 * ASPECT_RATIO, -1.0, 1.0, 2.0, 1000.0); glEnable(GL_DEPTH_TEST); disable_hardware_cursor(); }
int main() { FONT *lucidia_fnt; FONT *allegro_fnt; DATAFILE *dat; struct { float x, y, z; int c; } coord[NUM_STRINGS]; char *string = STRING; int i; allegro_init(); install_allegro_gl(); install_timer(); LOCK_FUNCTION(the_timer); LOCK_VARIABLE(chrono); install_int(the_timer, 2); allegro_gl_clear_settings(); allegro_gl_set(AGL_COLOR_DEPTH, 32); allegro_gl_set(AGL_Z_DEPTH, 24); allegro_gl_set(AGL_WINDOWED, TRUE); allegro_gl_set(AGL_DOUBLEBUFFER, 1); allegro_gl_set(AGL_RENDERMETHOD, 1); allegro_gl_set(AGL_SUGGEST, AGL_COLOR_DEPTH | AGL_DOUBLEBUFFER | AGL_RENDERMETHOD | AGL_Z_DEPTH | AGL_WINDOWED); if (set_gfx_mode(GFX_OPENGL, 640, 480, 0, 0)) { allegro_message("Error initializing OpenGL!\n"); return -1; } install_keyboard(); /* Load 2 copies of the datafile */ dat = load_datafile("lucidia.dat"); if (!dat) { set_gfx_mode(GFX_TEXT, 0, 0, 0, 0); allegro_message("Unable to load lucidia.dat\n"); return -2; } lucidia_fnt = allegro_gl_convert_allegro_font((FONT*)dat[0].dat, AGL_FONT_TYPE_TEXTURED, 16.0); if (!lucidia_fnt) { unload_datafile(dat); set_gfx_mode(GFX_TEXT, 0, 0, 0, 0); allegro_message("Unable to convert font!\n"); return -3; } allegro_fnt = allegro_gl_convert_allegro_font(font, AGL_FONT_TYPE_TEXTURED, 16.0); if (!allegro_fnt) { allegro_gl_destroy_font(lucidia_fnt); unload_datafile(dat); set_gfx_mode(GFX_TEXT, 0, 0, 0, 0); allegro_message("Unable to convert font!\n"); return -4; } srand(time(NULL)); for (i = 0; i < NUM_STRINGS; i++) { coord[i].z = 0; coord[i].c = 0; } i = 0; /* Start nice text demo */ /* Setup OpenGL like we want */ glEnable(GL_TEXTURE_2D); glEnable(GL_BLEND); glViewport(0, 0, SCREEN_W, SCREEN_H); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glFrustum(-1.0, 1.0, -1.0, 1.0, 1, 60.0); /* Set culling mode - not that we have anything to cull */ glEnable(GL_CULL_FACE); glFrontFace(GL_CCW); glMatrixMode(GL_MODELVIEW); do { int c; /* Update rotation angle of text */ glLoadIdentity(); glTranslatef(0, 0, -30); glRotatef(-45, 1, 0, 0); glRotatef(-30, 0, 1, 0); /* Clear the screen and set a nice blender mode */ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_COLOR); /* Print the text wheel */ for (i = 0; i < NUM_STRINGS; i++) { allegro_gl_printf(lucidia_fnt, coord[i].x, coord[i].y, coord[i].z, coord[i].c, string); } /* Update the text wheel's position */ for (i = 0; i < NUM_STRINGS; i++) { int r, g, b; float angle2 = angle + i * M_PI * 2 / NUM_STRINGS; coord[i].x = 10 * cos(angle2) - 10; coord[i].y = 10 * sin(angle2); angle2 = angle2 * 180.0 / M_PI; #if ((((ALLEGRO_VERSION) << 16) | ((ALLEGRO_SUB_VERSION) << 8) | (ALLEGRO_WIP_VERSION)) == 0x40200) /* Work around an Allegro bug that's only in 4.2.0 */ while (angle2 > 360.0f) angle2 -= 360.0f; while (angle2 < 0) angle2 += 360.0f; #endif hsv_to_rgb(angle2, 1, 1, &r, &g, &b); coord[i].c = makeacol(r, g, b, 255); } /* Draw "AllegroGL" */ glLoadIdentity(); c = MID(0, (int)(255 - chrono / 100), 255); allegro_gl_printf(allegro_fnt, -(strlen(STRING0) * 1 / 2.0f) / 2, -3.0f, -chrono / 200.0 + 0, makecol(c, c, c), STRING0); c = MID(0, (int)(255 - chrono / 100) + 24, 255); allegro_gl_printf(allegro_fnt, -(strlen(STRING1) * 1 / 2.0f) / 2, -3.0f, -chrono / 200.0 + 12, makecol(c, c, c), STRING1); c = MID(0, (int)(255 - chrono / 100) + 48, 255); allegro_gl_printf(allegro_fnt, -(strlen(STRING2) * 1 / 2.0f) / 2, -3.0f, -chrono / 200.0 + 24, makecol(c, c, c), STRING2); c = MID(0, (int)(255 - chrono / 100) + 72, 255); allegro_gl_printf(allegro_fnt, -(strlen(STRING3) * 1 / 2.0f) / 2, -3.0f, -chrono / 200.0 + 36, makecol(c, c, c), STRING3); c = MID(0, (int)(255 - chrono / 100) + 96, 255); allegro_gl_printf(allegro_fnt, -(strlen(STRING4) * 1 / 2.0f) / 2, -3.0f, -chrono / 200.0 + 48, makecol(c, c, c), STRING4); c = MID(0, (int)(255 - chrono / 100) + 120, 255); allegro_gl_printf(allegro_fnt, -(strlen(URL) * 1 / 2.0f) / 2, -3.0f, -chrono / 200.0 + 60, makecol(c, c, c), URL); allegro_gl_flip(); rest(2); } while (!key[KEY_ESC]); return 0; }
int main() { /* Setup Allegro/AllegroGL */ if (allegro_init()) return 1; if (install_allegro_gl()) return 1; if (install_keyboard() < 0) { allegro_message("Unable to install keyboard\n"); return 1; } if (install_mouse() == -1) { allegro_message("Unable to install mouse\n"); return 1; } if (install_timer() < 0) { allegro_message("Unable to install timers\n"); return 1; } /* lock timer */ LOCK_VARIABLE(rotation_counter); LOCK_FUNCTION(rotation_counter_handler); /* set desktop resolution */ DESKTOP_W = GetSystemMetrics(SM_CXVIRTUALSCREEN); DESKTOP_H = GetSystemMetrics(SM_CYVIRTUALSCREEN); /* get monitor resolution/count */ int monitor_count; MONITOR *monitors = get_monitors(&monitor_count); /* generate point data */ PLACE places[POINT_COUNT]; int c; for (c = 1; c < POINT_COUNT - 1; c++) { places[c].x = sin((M_PI * (GLfloat)c) / 10.0f) * 200.0f; places[c].y = cos((M_PI * (GLfloat)c) / 10.0f) * 200.0f; } places[0].x = 0.01; places[0].y = 200.0f; places[POINT_COUNT - 1].x = 0.01; places[POINT_COUNT - 1].y = -200.0f; /* setup display */ allegro_gl_set(AGL_Z_DEPTH, 8); allegro_gl_set(AGL_COLOR_DEPTH, 16); allegro_gl_set(AGL_SUGGEST, AGL_Z_DEPTH | AGL_COLOR_DEPTH); glDepthFunc(GL_LEQUAL); if (set_gfx_mode(GFX_OPENGL_WINDOWED_BORDERLESS, DESKTOP_W, DESKTOP_H, 0, 0)) { set_gfx_mode(GFX_TEXT, 0, 0, 0, 0); allegro_message("Unable to set graphic mode\n%s\n", allegro_error); return 1; } /* move window so it covers the desktop */ position_window(0, 0); /* fake information to use if only 1 monitor */ MONITOR fake = {0, 512, 512, 512}; /* setup lighting model */ glShadeModel(GL_FLAT); glEnable(GL_LIGHT0); glEnable(GL_COLOR_MATERIAL); GLfloat light_position[] = { 1.0, 1.0, 1.0, 0.0 }; glLightfv(GL_LIGHT0, GL_POSITION, light_position); GLfloat ambient[] = { 0.1f, 0.1f, 0.1f }; glLightfv(GL_LIGHT0, GL_AMBIENT, ambient); int selected = -1; /* the point currently being moved */ GLfloat rotation[3] = {0, 0, 0}; /* the rotation of the mesh */ install_int(rotation_counter_handler, 20); /* install the rotation handler */ /* enter main program loop */ while(!key[KEY_ESC]) { while (rotation_counter > 0) { /* rotate the mesh */ rotation[0] += M_PI / 24.0f; rotation[1] += M_PI / 16.0f; rotation[2] += M_PI / 8.0f; rotation_counter--; } /* clear the buffers */ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); /* process monitor 0 */ MONITOR *m = &monitors[0]; /* adjust mouse so its relative to the monitor */ int mx = (mouse_x - m->x) - (m->w / 2); int my = (mouse_y - m->y) - (m->h / 2); /* if the left mouse is pushed, find a close point */ if (mouse_b & 1) { if (selected == -1) { GLfloat distance = 10; for (c = 0; c < POINT_COUNT; c++) { GLfloat dx = mx - places[c].x; GLfloat dy = my - places[c].y; GLfloat d = sqrt(dx * dx + dy * dy); if (d < distance) { distance = d; selected = c; } } } } else selected = -1; /* move selected point */ if (selected >= 0) { places[selected].x = mx; places[selected].y = my; } /* center the viewport on monitor */ glViewport(m->x, DESKTOP_H - m->h - m->y, m->w, m->h); /* setup viewport projection */ glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluOrtho2D(-m->w / 2, m->w / 2, m->h / 2, -m->h / 2); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); /* draw points */ glColor3ub(0, 255, 0); glBegin(GL_LINE_STRIP); for (c = 0; c < POINT_COUNT; c++) { glVertex2f(places[c].x, places[c].y); } glEnd(); glColor3ub(255, 255, 255); for (c = 0; c < POINT_COUNT; c++) { draw_square(places[c].x, places[c].y, 10); } /* draw vertical line */ glBegin(GL_LINE_STRIP); glVertex2f(0.0f, -m->h); glVertex2f(0.0f, m->h); glEnd(); /* draw the mouse */ glColor3ub(255, 255, 255); draw_square(mx, my, 20); /* process viewport 1 */ /* select second monitor */ if (monitor_count > 1) { /* if 2nd monitor exists use it */ m = &monitors[1]; } else { /* use fake monitor */ m = &fake; } /* adjust mouse so its relative to the monitor*/ mx = (mouse_x - m->x) - (m->w / 2); my = (mouse_y - m->y) - (m->h / 2); /* center the viewport on the monitor*/ glViewport(m->x, DESKTOP_H - m->h - m->y, m->w, m->h); /* setup viewport projection */ glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(45.0f, (float)m->w / (float)m->h, 0.1f, 2000.0f); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); /* turn on lighting and depth testing */ glEnable(GL_LIGHTING); glEnable(GL_DEPTH_TEST); /* move mesh so its visible */ glTranslatef(0.0f, 0.0f, -1000.0f); /* rotate mesh */ glRotatef(rotation[0], 1.0f, 0.0f, 0.0f); glRotatef(rotation[1], 0.0f, 1.0f, 0.0f); glRotatef(rotation[2], 0.0f, 0.0f, 1.0f); GLfloat p1[3] = {0, 0, 0}; GLfloat p2[3] = {0, 0, 0}; GLfloat p3[3] = {0, 0, 0}; GLfloat p4[3] = {0, 0, 0}; GLfloat vec1[3]; GLfloat vec2[3]; GLfloat normal[3]; /* draw mesh to screen */ glColor3ub(0, 255, 0); for (c = 0; c < (POINT_COUNT - 1); c++) { GLfloat a1 = 0; GLfloat a2 = M_PI / 16.0f; GLfloat d1 = places[c].x; GLfloat d2 = places[c + 1].x; p1[0] = sin(a1) * d1; p1[1] = places[c].y; p1[2] = cos(a1) * d1; p2[0] = sin(a2) * d1; p2[1] = places[c].y; p2[2] = cos(a2) * d1; p3[0] = sin(a2) * d2; p3[1] = places[c + 1].y; p3[2] = cos(a2) * d2; p4[0] = sin(a1) * d2; p4[1] = places[c + 1].y; p4[2] = cos(a1) * d2; buildVector(vec1, p1, p2); buildVector(vec2, p1, p4); cross_product_f(vec2[0], vec2[1], vec2[2], vec1[0], vec1[1], vec1[2], &normal[0], &normal[1], &normal[2]); normalize_vector_f(&normal[0], &normal[1], &normal[2]); glBegin(GL_QUAD_STRIP); glNormal3fv(normal); glVertex3fv(p1); glVertex3fv(p4); int s = 0; for (s = 1; s < 32; s++) { a2 = (M_PI * (GLfloat)(s + 1)) / 16.0f; d1 = places[c].x; d2 = places[c + 1].x; copyPoint(p1, p2); copyPoint(p4, p3); p2[0] = sin(a2) * d1; p2[1] = places[c].y; p2[2] = cos(a2) * d1; p3[0] = sin(a2) * d2; p3[1] = places[c + 1].y; p3[2] = cos(a2) * d2; buildVector(vec1, p1, p2); buildVector(vec2, p1, p4); cross_product_f(vec2[0], vec2[1], vec2[2], vec1[0], vec1[1], vec1[2], &normal[0], &normal[1], &normal[2]); normalize_vector_f(&normal[0], &normal[1], &normal[2]); glNormal3fv(normal); glVertex3fv(p2); glVertex3fv(p3); } glEnd(); } /* turn off lighting and depth testing */ glDisable(GL_DEPTH_TEST); glDisable(GL_LIGHTING); /* if not using the fake monitor */ if (m != &fake) { /* setup viewport projection */ glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluOrtho2D(-m->w / 2, m->w / 2, m->h / 2, -m->h / 2); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); /* draw the mouse */ glColor3ub(255, 255, 255); draw_square(mx, my, 20); } /* flip the contents to the screen */ allegro_gl_flip(); } free(monitors); return 0; }
int install() { int screen_mode; if(IsInstalled) return 0; if(allegro_init()) return 1; if(install_allegro_gl()) return 1; set_window_title("Sharp Fighters"); Resolutions=get_gfx_mode_list(GFX_OPENGL_FULLSCREEN); LoadSettings(); LoadCollisionData(); if(install_keyboard()) return 1; if(install_timer()) return 1; if(install_sound(DIGI_AUTODETECT, MIDI_NONE, NULL)) return 1; JoyStickEnabled=(install_joystick(JOY_TYPE_AUTODETECT)==0); JoyStickEnabled=JoyStickEnabled && num_joysticks; LoadInput(); if(install_fonts()) printf("One or more font files were not loaded.\n"); allegro_gl_set(AGL_COLOR_DEPTH, depth); allegro_gl_set(AGL_RENDERMETHOD, 1); allegro_gl_set(AGL_DOUBLEBUFFER, 1); allegro_gl_set(AGL_SUGGEST, AGL_COLOR_DEPTH | AGL_DOUBLEBUFFER | AGL_RENDERMETHOD); if(Fullscreen) screen_mode=GFX_OPENGL_FULLSCREEN; else screen_mode=GFX_OPENGL_WINDOWED; if (set_gfx_mode(screen_mode, Width,Height, 0, 0)) { set_gfx_mode(GFX_TEXT, 0, 0, 0, 0); allegro_message("Unable to set graphic mode\n%s\n", allegro_error); return 1; } set_close_button_callback(close_button_handler); SetOpenGL2D(); screenimage=(IMAGE*)malloc(sizeof(IMAGE)); screenimage->ID=0; AspectRatio=(float)SCREEN_W/(float)SCREEN_H; if(install_int(Ticks,1)) return 1; if(install_int(ProcessKeys,25)) return 1; IsInstalled=1; return 0; }