///////////////////////////////////////// // M A I N // int main(int argc, char **argv) { srand(time(NULL)); mouse_x = 0; old_mouse_x = 0; mouse_y = 0; old_mouse_y = 0; m_angle = -300*M_PI; //FOULHACK! glutInit(&argc, argv); initKeymapManager(); glutPassiveMotionFunc(mouse); //glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH); glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GL_MULTISAMPLE); glutInitWindowSize(800, 600); glutInitContextVersion(3, 2); // Might not be needed in Linux glutCreateWindow("Farm Escape"); glutDisplayFunc(DisplayWindow); create_floor(&f); //create_plank(&p, SetVector(4,4,0), SetVector(0,5,0)); create_fence(&ff, 14, SetVector(0,0,0)); //f.model = generate_terrain(32); create_ball(&ball, SetVector(5,0,0)); create_wall(&wall, SetVector(0,10,0), SetVector(2,5,2)); create_joint(&legbase_joint[0], SetVector(-2.2, 3.8, .7), "legjoint0", "legcurrpos0", "legbonepos0", 0); create_joint(&legbase_joint[1], SetVector(-2.2, 3.8, -.7), "legjoint1", "legcurrpos1", "legbonepos1", 0); create_joint(&legbase_joint[2], SetVector(.2, 3.9, -.7), "legjoint2", "legcurrpos2", "legbonepos2", 0); create_joint(&legbase_joint[3], SetVector(.2, 3.9, .7), "legjoint3", "legcurrpos3", "legbonepos3", 0); create_joint(&thigh_joint[0], SetVector(-2.3, 1.8, .4), NULL, NULL, NULL, 0); create_joint(&thigh_joint[1], SetVector(-2.3, 1.8, -.4), NULL, NULL, NULL, 0); create_joint(&thigh_joint[2], SetVector(.1, 2, -.4), NULL, NULL, NULL, 0); create_joint(&thigh_joint[3], SetVector(.1, 2.0, .4), NULL, NULL, NULL, 0); create_joint(&knee_joint[0], SetVector(-2.6, .9, .4), NULL, NULL, NULL, 0); create_joint(&knee_joint[1], SetVector(-2.6, .9, -.4), NULL, NULL, NULL, 0); create_joint(&knee_joint[2], SetVector(.4, .9, -.4), NULL, NULL, NULL, 0); create_joint(&knee_joint[3], SetVector(.4, .9, .4), NULL, NULL, NULL, 0); create_joint(&foot_joint[0], SetVector(-2.75, 0, .4), NULL, NULL, NULL, 0); create_joint(&foot_joint[1], SetVector(-2.75, 0, -.4), NULL, NULL, NULL, 0); create_joint(&foot_joint[2], SetVector(.34, 0, -.4), NULL, NULL, NULL, 0); create_joint(&foot_joint[3], SetVector(.34, 0, .4), NULL, NULL, NULL, 0); //BODY JOINTS create_joint(&body_joint[0], SetVector(-1.8, 3.6, 0), "bodyjoint", "bodycurrpos", "bodybonepos", 0); create_joint(&body_joint[1], SetVector(-1, 3.3, 0), NULL, NULL, NULL, 0); create_joint(&body_joint[2], SetVector(.14, 3.9, 0), NULL, NULL, NULL, 0); //TAIL JOINTS create_joint(&tail_joint[0], SetVector(.7+.3, 3.75, 0), "tailjoint", "tailcurrpos", "tailbonepos", 0); create_joint(&tail_joint[1], SetVector(2.2, 3.8, 0), NULL, NULL, NULL, 0); create_joint(&tail_joint[2], SetVector(3.0, 3.75, 0), NULL, NULL, NULL, 0); create_joint(&tail_joint[3], SetVector(3.9, 3.65, 0), NULL, NULL, NULL, 0); //HEAD JOINTS create_joint(&head_joint[0], SetVector(-2.9, 3.2, 0), "headjoint", "headcurrpos", "headbonepos", 0); create_joint(&head_joint[1], SetVector(-3.85, 4, 0), NULL, NULL, NULL, 0); create_joint(&head_joint[2], SetVector(-4.7, 3, 0), NULL, NULL, NULL, 0); //EAR JOINTS //create_joint(&left_ear_joint[0], SetVector(-2.9, 3.2, -.4), //"leftearjoint", "leftearcurrpos", "leftearbonepos", 0); create_joint(&left_ear_joint[0], SetVector(-2.9, 3.2, .6), NULL, NULL, NULL, 0); create_joint(&right_ear_joint[0], SetVector(-2.9, 3.2, -.6), NULL, NULL, NULL, 0); //create_joint(&left_ear_joint[1], SetVector(-2.9, 3.2, .6), //NULL, NULL, NULL, 0); //create_joint(&right_ear_joint[1], SetVector(-2.9, 3.2, -.6), //NULL, NULL, NULL, 0); //create_joint(&right_ear_joint[0], SetVector(-2.9, 3.2, -.6), //"rightearjoint", "rightearcurrpos", "rightearbonepos", 0); //create_joint(&right_ear_joint[1], SetVector(-2.9, 3.2, -.8), //"rightearjoint", "rightearcurrpos", "rightearbonepos", 0); //SET CHILDREN! body_joint[0].child[0] = &body_joint[1]; body_joint[1].child[0] = &body_joint[2]; body_joint[2].child[0] = &tail_joint[0]; body_joint[2].child[1] = &legbase_joint[2]; body_joint[2].child[2] = &legbase_joint[3]; tail_joint[0].child[0] = &tail_joint[1]; tail_joint[1].child[0] = &tail_joint[2]; tail_joint[2].child[0] = &tail_joint[3]; tail_joint[3].child[0] = NULL; head_joint[0].child[0] = &head_joint[1]; head_joint[1].child[0] = &head_joint[2]; head_joint[2].child[0] = NULL; //head_joint[2].child[0] = &right_ear_joint[1]; head_joint[2].child[1] = &left_ear_joint[0]; head_joint[2].child[2] = &right_ear_joint[0]; //left_ear_joint[0].child[0] = &left_ear_joint[1]; //right_ear_joint[0].child[0] = &right_ear_joint[1]; //left_ear_joint[1].child[0] = NULL; //right_ear_joint[1].child[0] = NULL; //head_joint[0].child = &legbase_joint[0]; int i; for(i=0;i<4;i++) { legbase_joint[i].child[0] = &thigh_joint[i]; thigh_joint[i].child[0] = &knee_joint[i]; knee_joint[i].child[0] = &foot_joint[i]; foot_joint[i].child[0] = NULL; } //SET PARENTS legbase_joint[2].parent = &body_joint[2]; legbase_joint[3].parent = &body_joint[2]; //left_ear_joint[1].parent = &left_ear_joint[0]; left_ear_joint[0].parent = &head_joint[2]; //right_ear_joint[1].parent = &right_ear_joint[0]; right_ear_joint[0].parent = &head_joint[2]; create_cow(&cow); create_farmer(&farmer, SetVector(0,0,0)); create_ragdoll(&ragdoll); g_shader = loadShaders("shader.vert" , "shader.frag"); glUseProgram(g_shader); // Set up depth buffer glEnable(GL_DEPTH_TEST); //glEnable (GL_BLEND); //glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // initiering //#ifdef WIN32 // glewInit(); //#endif //glutSetCursor(0); //terr = generate_terrain(512); glutTimerFunc(20, &OnTimer, 0); glutMainLoop(); exit(0); }
static int atomic_run(const struct gbm *gbm, const struct egl *egl) { struct gbm_bo *bo = NULL; struct drm_fb *fb; uint32_t i = 0; uint32_t flags = DRM_MODE_ATOMIC_NONBLOCK; struct timeval timeout; fd_set fds; int ret; if (egl_check(egl, eglDupNativeFenceFDANDROID) || egl_check(egl, eglCreateSyncKHR) || egl_check(egl, eglDestroySyncKHR) || egl_check(egl, eglWaitSyncKHR) || egl_check(egl, eglClientWaitSyncKHR)) return -1; /* Allow a modeset change for the first commit only. */ flags |= DRM_MODE_ATOMIC_ALLOW_MODESET; while (1) { struct gbm_bo *next_bo; EGLSyncKHR gpu_fence = NULL; /* out-fence from gpu, in-fence to kms */ EGLSyncKHR kms_fence = NULL; /* in-fence to gpu, out-fence from kms */ if (drm.kms_out_fence_fd != -1) { kms_fence = create_fence(egl, drm.kms_out_fence_fd); assert(kms_fence); /* driver now has ownership of the fence fd: */ drm.kms_out_fence_fd = -1; /* wait "on the gpu" (ie. this won't necessarily block, but * will block the rendering until fence is signaled), until * the previous pageflip completes so we don't render into * the buffer that is still on screen. */ egl->eglWaitSyncKHR(egl->display, kms_fence, 0); } egl->draw(i++); /* insert fence to be singled in cmdstream.. this fence will be * signaled when gpu rendering done */ gpu_fence = create_fence(egl, EGL_NO_NATIVE_FENCE_FD_ANDROID); assert(gpu_fence); eglSwapBuffers(egl->display, egl->surface); /* after swapbuffers, gpu_fence should be flushed, so safe * to get fd: */ drm.kms_in_fence_fd = egl->eglDupNativeFenceFDANDROID(egl->display, gpu_fence); egl->eglDestroySyncKHR(egl->display, gpu_fence); assert(drm.kms_in_fence_fd != -1); next_bo = gbm_surface_lock_front_buffer(gbm->surface); if (!next_bo) { printf("Failed to lock frontbuffer\n"); return -1; } fb = drm_fb_get_from_bo(next_bo); if (!fb) { printf("Failed to get a new framebuffer BO\n"); return -1; } if (kms_fence) { EGLint status; /* Wait on the CPU side for the _previous_ commit to * complete before we post the flip through KMS, as * atomic will reject the commit if we post a new one * whilst the previous one is still pending. */ do { status = egl->eglClientWaitSyncKHR(egl->display, kms_fence, 0, EGL_FOREVER_KHR); } while (status != EGL_CONDITION_SATISFIED_KHR); egl->eglDestroySyncKHR(egl->display, kms_fence); } /* * Here you could also update drm plane layers if you want * hw composition */ ret = drm_atomic_commit(fb->fb_id, flags); if (ret) { printf("failed to commit: %s\n", strerror(errno)); return -1; } /* release last buffer to render on again: */ if (bo) gbm_surface_release_buffer(gbm->surface, bo); bo = next_bo; /* Allow a modeset change for the first commit only. */ flags &= ~(DRM_MODE_ATOMIC_ALLOW_MODESET); /* watch for user interruption */ FD_ZERO(&fds); FD_SET(0, &fds); memset(&timeout, 0, sizeof(timeout)); ret = select(1, &fds, NULL, NULL, &timeout); if (ret < 0) { printf("select() failed: %s\n", strerror(errno)); break; } /* * select() will immediately timeout if there was no user * interrupt because of the 0 timeout. However, that's an * expected situation, not an error, so we just ignore it * here. */ if (FD_ISSET(0, &fds)) { printf("user interrupted!\n"); break; } } return ret; }