/* * Open the keyboard. * This is real simple, we just use a special file handle * that allows non-blocking I/O, and put the terminal into * character mode. */ static int allegro_Open(KBDDEVICE *pkd) { if (!init_allegro()) return -2; //no kbd //fprintf(stderr,"opened keyboard\n"); fflush(stderr); return 1; }
int main(void){ init_allegro(); bool redraw = true; bool done = false; al_clear_to_color(al_map_rgb(0,0,0)); al_flip_display(); al_start_timer(timer); init_stars(); while(!done){ ALLEGRO_EVENT event; al_wait_for_event(event_queue, &event); switch (event.type) { case ALLEGRO_EVENT_TIMER: redraw = true; break; case ALLEGRO_EVENT_DISPLAY_CLOSE: done = true; break; case ALLEGRO_EVENT_KEY_UP: switch(event.keyboard.keycode){ case ALLEGRO_KEY_MINUS: // decrease velocity of each plane velocity_1-=1; velocity_2-=2; velocity_3-=3; break; case ALLEGRO_KEY_EQUALS: // decrease velocity of each plane velocity_1+=1; velocity_2+=2; velocity_3+=3; break; case ALLEGRO_KEY_Q: done = true; break; } } if(redraw && al_is_event_queue_empty(event_queue)) { redraw = false; draw_stars(); } } return 0; }
int main(int argc, char **argv) { int i; Light light; const char *filename; Camera cam; Vec3 position = {0, 0, 150e9}; Vec3 up = {0, 1, 0}; Vec3 target = {0, 0, 0}; Shader *shader_light; Shader *shader_simple; Mesh *mesh; Renderable planet; if (argc < 2) filename = STRINGIFY(ROOT_PATH) "/data/teapot.ply"; else filename = argv[1]; solsys = solsys_load(STRINGIFY(ROOT_PATH) "/data/sol.ini"); if (solsys == NULL) return 1; mesh = mesh_import(filename); if (mesh == NULL) return 1; for (i = 0; i < mesh->num_vertices; i++) /* Blow up the teapot */ { mesh->vertex[i].x = mesh->vertex[i].x * 100; mesh->vertex[i].y = mesh->vertex[i].y * 100; mesh->vertex[i].z = mesh->vertex[i].z * 100; } cam.fov = M_PI/4; cam.left = 0; cam.bottom = 0; cam.width = 1024; cam.height = 768; cam.zNear = 1e6; cam.zFar = 4.5e15; init_allegro(&cam); cam_lookat(&cam, position, target, up); glewInit(); shader_light = shader_create(STRINGIFY(ROOT_PATH) "/data/lighting.v.glsl", STRINGIFY(ROOT_PATH) "/data/lighting.f.glsl"); if (shader_light == NULL) return 1; shader_simple = shader_create(STRINGIFY(ROOT_PATH) "/data/simple.v.glsl", STRINGIFY(ROOT_PATH) "/data/simple.f.glsl"); if (shader_simple == NULL) return 1; glmProjectionMatrix = glmNewMatrixStack(); glmViewMatrix = glmNewMatrixStack(); glmModelMatrix = glmNewMatrixStack(); light.position = light_pos; memcpy(light.ambient, light_ambient, sizeof(light_ambient)); memcpy(light.diffuse, light_diffuse, sizeof(light_diffuse)); memcpy(light.specular, light_specular, sizeof(light_specular)); glClearColor(20/255., 30/255., 50/255., 1.0); glEnable(GL_DEPTH_TEST); glEnable(GL_CULL_FACE); glCullFace(GL_BACK); glPointSize(2); planet.data = mesh; planet.upload_to_gpu = mesh_upload_to_gpu; planet.render = mesh_render; planet.shader = shader_light; renderable_upload_to_gpu(&planet); /* Transformation matrices */ cam_projection_matrix(&cam, glmProjectionMatrix); /* Start rendering */ while(handle_input(ev_queue, &cam)) { void *ctx; Entity *renderlist, *prev; t += 365*86400; /* Physics stuff */ solsys_update(solsys, t); ctx = ralloc_context(NULL); prev = NULL; for (i = 0; i < solsys->num_bodies; i++) { Entity *e; e = ralloc(ctx, Entity); e->orientation = (Quaternion) {1, 0, 0, 0}; e->renderable = &planet; e->position = solsys->body[i].position; e->radius = solsys->body[i].radius; e->prev = prev; e->next = NULL; if (prev != NULL) e->prev->next = e; prev = e; if (i == 0) renderlist = e; } /* Rendering stuff */ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glmLoadIdentity(glmModelMatrix); glmLoadIdentity(glmViewMatrix); cam_view_matrix(&cam, glmViewMatrix); /* view */ light_upload_to_gpu(&light, shader_light); render_entity_list(renderlist); al_flip_display(); calcfps(); ralloc_free(ctx); } ralloc_free(mesh); ralloc_free(solsys); shader_delete(shader_light); shader_delete(shader_simple); glmFreeMatrixStack(glmProjectionMatrix); glmFreeMatrixStack(glmViewMatrix); glmFreeMatrixStack(glmModelMatrix); al_destroy_display(dpy); return 0; }