Ejemplo n.º 1
0
void 
HaloRefImage::copy_to_scratch()
{
   check_resize();
   assert(_scratch_tex &&
          _scratch_tex->image().dims() == Point2i(VIEW::cur_size()));

   glPushAttrib(GL_ENABLE_BIT);

   // Specify texture
   _scratch_tex->apply_texture();   // GL_ENABLE_BIT

   glReadBuffer(GL_BACK);

   // Copies the frame buffer into a texture in gpu texture memory.
   glCopyTexImage2D(
      GL_TEXTURE_2D,  // The target to which the image data will be changed.
      0,              // Level of detail, 0 is base detail
      GL_RGBA,        // internal format
      0,              // x-coord of lower left corner of the window
      0,              // y-coord of lower left corner of the window
      _width,         // texture width
      _height,        // texture height
      0);             // border size, must be 0 or 1

   glPopAttrib();
}
Ejemplo n.º 2
0
int main(void)
{
	logOpen();
	initXWindows();
	init_opengl();
	Game game;
	init(&game);
	srand(time(NULL));
	clock_gettime(CLOCK_REALTIME, &timePause);
	clock_gettime(CLOCK_REALTIME, &timeStart);
	int done=0;
	while (!done) {
		while (XPending(dpy)) {
			XEvent e;
			XNextEvent(dpy, &e);
			check_resize(&e);
			check_mouse(&e);
			done = check_keys(&e);
		}
		clock_gettime(CLOCK_REALTIME, &timeCurrent);
		timeSpan = timeDiff(&timeStart, &timeCurrent);
		timeCopy(&timeStart, &timeCurrent);
		physicsCountdown += timeSpan;
		while (physicsCountdown >= physicsRate) {
			physics(&game);
			physicsCountdown -= physicsRate;
		}
		render(&game);
		glXSwapBuffers(dpy, win);
	}
	cleanupXWindows();
	cleanup_fonts();
	logClose();
	return 0;
}
Ejemplo n.º 3
0
void Player_ControlsGUI::set_screen_resize(int width_value,  int height_value)
{

// now we fool our selves that we could own large tvs

video_area.set_size_request(width_value, height_value);
resize(1,1);
check_resize();

}
Ejemplo n.º 4
0
int main(void)
{
	logOpen();
	initXWindows();
	init_opengl();
	init();
	init_sounds();
	clock_gettime(CLOCK_REALTIME, &timePause);
	clock_gettime(CLOCK_REALTIME, &timeStart);
	while(!done) {
		while(XPending(dpy)) {
			XEvent e;
			XNextEvent(dpy, &e);
			check_resize(&e);
			check_mouse(&e);
			check_keys(&e);
		}
		//
		//Below is a process to apply physics at a consistent rate.
		//1. Get the time right now.
		clock_gettime(CLOCK_REALTIME, &timeCurrent);
		//2. How long since we were here last?
		timeSpan = timeDiff(&timeStart, &timeCurrent);
		//3. Save the current time as our new starting time.
		timeCopy(&timeStart, &timeCurrent);
		//4. Add time-span to our countdown amount.
		physicsCountdown += timeSpan;
		//5. Has countdown gone beyond our physics rate? 
		//       if yes,
		//           In a loop...
		//              Apply physics
		//              Reducing countdown by physics-rate.
		//              Break when countdown < physics-rate.
		//       if no,
		//           Apply no physics this frame.
		while(physicsCountdown >= physicsRate) {
			//6. Apply physics
			physics();
			//7. Reduce the countdown by our physics-rate
			physicsCountdown -= physicsRate;
		}
		//Always render every frame.
		render();
		glXSwapBuffers(dpy, win);
	}
	cleanupXWindows();
	cleanup_fonts();
	#ifdef USE_SOUND
	fmod_cleanup();
	#endif //USE_SOUND
	logClose();
	return 0;
}
Ejemplo n.º 5
0
void 
HaloRefImage::copy_to_tex_aux()
{
   check_resize();
   assert(_texture && _texture->image().dims() == Point2i(VIEW::cur_size()));

   glPushAttrib(GL_ENABLE_BIT);

   // Specify texture
   _texture->apply_texture();   // GL_ENABLE_BIT

   if (use_fbos) {
      //copy contents of the frame buffer to output texture
      glBindFramebuffer(GL_READ_FRAMEBUFFER, _fbo);

      // Copies the frame buffer into a texture in gpu texture memory.
      glCopyTexImage2D(
         GL_TEXTURE_2D,  // The target to which the image data will be changed.
         0,              // Level of detail, 0 is base detail
         GL_RGBA,        // internal format
         0,              // x-coord of lower left corner of the window
         0,              // y-coord of lower left corner of the window
         _width,         // texture width
         _height,        // texture height
         0);             // border size, must be 0 or 1

      glBindFramebuffer(GL_FRAMEBUFFER, 0);

   } else {
      //copy contents of the aux0 buffer to output texture
      glReadBuffer(GL_AUX0);

      // Copies the frame buffer into a texture in gpu texture memory.
      glCopyTexImage2D(
         GL_TEXTURE_2D,  // The target to which the image data will be changed.
         0,              // Level of detail, 0 is base detail
         GL_RGBA,        // internal format
         0,              // x-coord of lower left corner of the window
         0,              // y-coord of lower left corner of the window
         _width,         // texture width
         _height,        // texture height
         0);             // border size, must be 0 or 1
   }

   glPopAttrib();
}
Ejemplo n.º 6
0
int main(void)
{
    int done=0;
    srand(time(NULL));
    initXWindows();
    init_opengl();
    init_sounds();

    clock_gettime(CLOCK_REALTIME, &timePause);
    clock_gettime(CLOCK_REALTIME, &timeStart);
    //declare game object
    Game game;

    fmod_playsound(1);
    //start animation
    while(!done) {
	while(XPending(dpy)) {
	    XEvent e;
	    XNextEvent(dpy, &e);
	    check_resize(&e);
	    check_mouse(&e, &game);
	    done = check_keys(&e, &game);
	}
	clock_gettime(CLOCK_REALTIME, &timeCurrent);
	timeSpan = timeDiff(&timeStart, &timeCurrent);
	timeCopy(&timeStart, &timeCurrent);
	movementCountdown += timeSpan;
	while(movementCountdown >= movementRate)
	{
	    movement(&game);
	    movementCountdown -= movementRate;
	}
	render(&game);
	glXSwapBuffers(dpy, win);
    }
    cleanupXWindows();
    cleanup_fonts();
#ifdef USE_SOUND
    fmod_cleanup();
#endif //USE_SOUND
    return 0;
}
Ejemplo n.º 7
0
int main(void)
{
    int done=0;
    srand(time(NULL));
    initXWindows();
    init_opengl();


    //declare game object
    Game game;
    game.n=0;

    // used to check if jumped, already in the air
    game.space = false; // deny jumping til collision on floor


    //declare a box shape
    game.box.width = BOX_WIDTH;
    game.box.height = BOX_HEIGHT;
    game.box.center.x = 20;//120 + 5*65;
    game.box.center.y = 10;//500 - 5*60;
    game.box.velocity.y = 0;
    game.box.velocity.x = 0;
    //start animation
    while(!done) {
        while(XPending(dpy)) {
            XEvent e;
            XNextEvent(dpy, &e);
            check_mouse(&e, &game);
            check_resize(&e);
            done = check_keys(&e, &game);
        }

        movement(&game);
        render(&game);
        glXSwapBuffers(dpy, win);
    }


    cleanupXWindows();
    return 0;
}
Ejemplo n.º 8
0
int main(void)
{
    logOpen();
    initXWindows();
    init_opengl();
    init();
    //buttonsInit();------------------------------------------------------------------
    init_sounds();
    clock_gettime(CLOCK_REALTIME, &timePause);
    clock_gettime(CLOCK_REALTIME, &timeStart);
    while(!done) {
        while(XPending(dpy)) {
            XEvent e;
            XNextEvent(dpy, &e);
            check_resize(&e);
            check_mouse(&e);
            GOcheck_mouse(&e);
            check_keys(&e);

        }
        clock_gettime(CLOCK_REALTIME, &timeCurrent);
        timeSpan = timeDiff(&timeStart, &timeCurrent);
        timeCopy(&timeStart, &timeCurrent);
        physicsCountdown += timeSpan;
        while(physicsCountdown >= physicsRate) {
            physics();
            physicsCountdown -= physicsRate;
        }
        render();
        glXSwapBuffers(dpy, win);
    }
    cleanupXWindows();
    cleanup_fonts();
#ifdef USE_SOUND
    fmod_cleanup();
#endif //USE_SOUND
    logClose();
    return 0;
}
Ejemplo n.º 9
0
int main(void)
{
    int done=0;
    srand(time(NULL));
    initXWindows();
    Game game;
    DefineRagdoll(&game);
    init_opengl(&game);
    create_sounds();
    play();
    //declare game object
    init_keys();
    clock_gettime(CLOCK_REALTIME, &timePause);
    clock_gettime(CLOCK_REALTIME, &timeStart);

    //start animation
    while(!done) {
	while(XPending(dpy)) {
	    XEvent e;
	    XNextEvent(dpy, &e);
	    check_mouse(&e, &game);
	    check_resize(&game, &e);
	    done = check_keys(&e);
	}
	clock_gettime(CLOCK_REALTIME, &timeCurrent);
	timeSpan = timeDiff(&timeStart, &timeCurrent);
	timeCopy(&timeStart, &timeCurrent);
	physicsCountdown += timeSpan;
	while(physicsCountdown >= physicsRate) {
	    movement(&game);
	    physicsCountdown -= physicsRate;
	}
	render(&game);
	glXSwapBuffers(dpy, win);
    }
    cleanupXWindows();
    cleanup_fonts();
    return 0;
}
Ejemplo n.º 10
0
int main(void)
{
	initXWindows();
    srand(time(NULL));
    clock_gettime(CLOCK_REALTIME, &timePause);
    clock_gettime(CLOCK_REALTIME, &timeStart);
    init_opengl();
    init_ship();
	//Do this to allow fonts
	glEnable(GL_TEXTURE_2D);
	initialize_fonts();
	init_textures();
	while(!done) {
		while(XPending(dpy)) {
			XEvent e;
			XNextEvent(dpy, &e);
			check_resize(&e);
			check_mouse(&e);
			check_keys(&e);
		}
        clock_gettime(CLOCK_REALTIME, &timeCurrent);
        timeSpan = timeDiff(&timeStart, &timeCurrent);
        timeCopy(&timeStart, &timeCurrent);
        physicsCountdown += timeSpan;
        while (physicsCountdown >= physicsRate) {
            physics();
            physicsCountdown -= physicsRate;
            render();
        }
		//physics();
		//render();
		glXSwapBuffers(dpy, win);
	}
	cleanupXWindows();
	cleanup_fonts();
	return 0;
}
Ejemplo n.º 11
0
int main(int argc, char *argv[])
{
	if(argc > 1) {
		if(argv[1] != NULL) {
			beginTesting();
		}
		return 0;
	}

	logOpen();
	initXWindows();
	init_opengl();
	Game game;
	init(&game);
	srand(time(NULL));
	clock_gettime(CLOCK_REALTIME, &timePause);
	clock_gettime(CLOCK_REALTIME, &timeStart);	

	hud = new Hud(xres ,yres);
	if (TEST_Hud){
		hud->testHUDAll();
		return 0;
	}
	//DEFUALT IS LEVEL 1 SELECTED:
	selected_screen = LEFT;    
	level =1;
	//--------------
	is_gameover = false;
	high_score = 0;
	gameStarted = false;
	lastPaddleHit = 'N';//'N' means no paddle hit

	bombBegin = time(NULL);
	bombRandom = random(7);

	beginSmallLeftPaddle = time(NULL);
	smallLeftPaddleTime = 7;
	beginSmallRightPaddle = time(NULL);
	smallRightPaddleTime = 7;
	hud->setAI(false);//DEFAULT: player2 is human	
	ball_saved_X_velocity = 8.0f * cos(30);
	ball_saved_Y_velocity = 8.0f * sin(90);    
	obstacle_saved_Y_velocity = -5.0;

	int min;
	if (xres<yres){
		min=xres;
	}
	else{
		min=yres;
	}
	bomb_radius = ((int)(3*min)/10);

	//MAIN MENU LOOP 
	while(intro != 0) {
		while (XPending(dpy)) {
			XEvent e;
			XNextEvent(dpy, &e);
			check_resize(&e);
			intro = check_keys(&e, &game);
		}
		render(&game);
		glXSwapBuffers(dpy, win);
	}


	//BEGIN MAIN GAME LOOP
	int done=0;
	while (!done) {        
		while (XPending(dpy)) {
			XEvent e;
			XNextEvent(dpy, &e);
			check_resize(&e);
			done = check_keys(&e, &game);
		}
		clock_gettime(CLOCK_REALTIME, &timeCurrent);
		timeSpan = timeDiff(&timeStart, &timeCurrent);
		timeCopy(&timeStart, &timeCurrent);
		physicsCountdown += timeSpan;
		while (physicsCountdown >= physicsRate) {
			physics(&game);
			physicsCountdown -= physicsRate;
		}        
		render(&game);
		glXSwapBuffers(dpy, win);
	}
	cleanupXWindows();
	cleanup_fonts();
	logClose();

	return 0;
}
Ejemplo n.º 12
0
void
HaloRefImage::update()
{
  // render the scene and read pixels to main memory
   // and/or texture memory

   if (!need_update())
      return;

   static bool debug = Config::get_var_bool("DEBUG_HALO_UPDATE",false);
   err_adv(debug, "HaloRefImage::update: updating...");

    check_resize();

   glPushAttrib(
      GL_LINE_BIT               |
      GL_DEPTH_BUFFER_BIT       |
      GL_ENABLE_BIT             |
      GL_LIGHTING_BIT           |
      GL_VIEWPORT               | // XXX - not needed
      GL_COLOR_BUFFER_BIT       | // XXX - not needed
      GL_TEXTURE_BIT              // XXX - not needed
      );

   // XXX - remove this:
   assert(_view && _view == VIEW::peek());

   // set up lights
   _view->setup_lights();

   // set default state
   // XXX - check
   glLineWidth(1.0);            // GL_LINE_BIT
   glDepthMask(GL_TRUE);        // GL_DEPTH_BUFFER_BIT
   glDepthFunc(GL_LESS);        // GL_DEPTH_BUFFER_BIT
   glEnable(GL_DEPTH_TEST);     // GL_DEPTH_BUFFER_BIT
   glDisable(GL_NORMALIZE);     // GL_ENABLE_BIT
   glDisable(GL_BLEND);         // GL_ENABLE_BIT
   glEnable(GL_CULL_FACE);      // GL_ENABLE_BIT

   glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
   glEnable(GL_COLOR_MATERIAL); // GL_ENABLE_BIT
   glShadeModel(GL_SMOOTH);     // GL_LIGHTING_BIT
  
   // set viewport to ref image size:
   glViewport(0,0,_width,_height); // GL_VIEWPORT_BIT
   draw_objects(_view->drawn());

   // copy image to main memory or texture memory
   // (or both) as requested:
   if (_update_main_mem) {
      if (use_fbos)
         glBindFramebuffer(GL_READ_FRAMEBUFFER, _fbo);
      else
         glReadBuffer(GL_AUX0); //because the image is constructed in aux0
      copy_to_ram();
      if (use_fbos)
         glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);
      else
         glReadBuffer(GL_BACK);
   }
   if (_update_tex_mem)
      copy_to_tex_aux(); //copies from aux0

   // clear update flags until next update request is made:
   _update_main_mem = _update_tex_mem = false;

   glPopAttrib();

   // restore viewport to window size:
   int w, h;
   _view->get_size(w,h);
   glViewport(0,0,w,h);
}
Ejemplo n.º 13
0
static int post_sleep_hook (pingobj_t *ping) /* {{{ */
{
	return (check_resize (ping));
} /* }}} int pre_sleep_hook */
Ejemplo n.º 14
0
void tasklist_window() /* {{{ */
{
	/* ncurses main function */
	int c;
	task *cur;
	char *uuid = NULL;

	/* get field lengths */
	cfg.fieldlengths.project = max_project_length();
	cfg.fieldlengths.date = DATELENGTH;

	/* create windows */
	rows = LINES;
	cols = COLS;
	tnc_fprintf(logfp, LOG_DEBUG_VERBOSE, "rows: %d, columns: %d", rows, cols);
	header = newwin(1, cols, 0, 0);
	tasklist = newwin(rows-2, cols, 1, 0);
	statusbar = newwin(1, cols, rows-1, 0);
	tnc_fprintf(logfp, LOG_DEBUG_VERBOSE, "ncurses windows: h:%p, t:%p, s:%p (%d,%d)", header, tasklist, statusbar, rows, cols);
	if (statusbar==NULL || tasklist==NULL || header==NULL)
	{
		tnc_fprintf(logfp, LOG_ERROR, "window creation failed (rows:%d, cols:%d)", rows, cols);
		ncurses_end(-1);
	}

	/* set curses settings */
	set_curses_mode(NCURSES_MODE_STD);

	/* print task list */
	check_screen_size();
	cfg.fieldlengths.description = COLS-cfg.fieldlengths.project-1-cfg.fieldlengths.date;
	task_count();
	print_header();
	tasklist_print_task_list();

	/* main loop */
	while (1)
	{
		/* set variables for determining actions */
		done = false;
		redraw = false;
		reload = false;

		/* check for an empty task list */
		if (head == NULL)
		{
			if (strcmp(active_filter,"") == 0){
				tnc_fprintf(logfp, LOG_ERROR, "it appears that your task list is empty. %s does not yet support empty task lists.", PROGNAME);
				ncurses_end(-1);
			}
			active_filter = strdup("");
			reload = true;
		}

		/* get the screen size */
		rows = LINES;
		cols = COLS;

		/* check for a screen thats too small */
		check_screen_size();

		/* check for size changes */
		check_resize();

		/* apply staged window updates */
		doupdate();

		/* get a character */
		c = wgetch(statusbar);

		/* handle the character */
		handle_keypress(c, MODE_TASKLIST);

		/* exit */
		if (done)
			break;
		/* reload task list */
		if (reload)
		{
			cur = get_task_by_position(selline);
			if (cur != NULL)
				uuid = strdup(cur->uuid);
			wipe_tasklist();
			reload_tasks();
			task_count();
			redraw = true;
			if (cfg.follow_task)
				set_position_by_uuid(uuid);
			check_free(uuid);
			uuid = NULL;
			tasklist_check_curs_pos();
		}
		/* redraw all windows */
		if (redraw)
		{
			cfg.fieldlengths.project = max_project_length();
			cfg.fieldlengths.description = cols-cfg.fieldlengths.project-1-cfg.fieldlengths.date;
			print_header();
			tasklist_print_task_list();
			tasklist_check_curs_pos();
			touchwin(tasklist);
			touchwin(header);
			touchwin(statusbar);
			wnoutrefresh(tasklist);
			wnoutrefresh(header);
			wnoutrefresh(statusbar);
			doupdate();
		}

		statusbar_timeout();
	}
} /* }}} */
Ejemplo n.º 15
0
void PlayGame()
{
	bool menuToggle = true;
	Game game;
	game.setResolution(window_width, window_height);

	if(window_height > 1080)
	{
		//game.gravity = 9;
		MAX_VELOCITY = 12;
		INITIAL_VELOCITY = 7;
	}

	srand(time(NULL));

	clock_gettime(CLOCK_REALTIME, &timePause);
	clock_gettime(CLOCK_REALTIME, &timeStart);
	clock_gettime(CLOCK_REALTIME, &start);
	while(game.run)
	{
		
		game = Game(); 			//reinitializes upon replay

		if(TOGGLE_SOUND)		//Sound switch so that the background music doesnt get recalled after the initial call
		{						//otherwise they loop over each other and it sounds bad, plus it created a memory leak
			Buffer = alutCreateBufferFromFile("./Sounds/music.wav");
			playBackgroundSound();
			TOGGLE_SOUND = false;
		}

		gutsToggle = true;
		bloodToggle = true;		//Reset switches to clear the prev game information. This includes the score and blood particles
		TOGGLE_PAUSE = true;	//basically reinitializing anything that didnt get reinitialized in the game = Game();
		numblood = 0;
		SCORE = 0;
		game.setMissiles = false;

		while(STATE == MAIN_MENU && game.run)
		{

			XEvent menu;
			while(XPending(dpy))
			{
				XNextEvent(dpy, &menu);
				check_keys(&menu, &game);											//Ahhh STATES, made this far easier to control.
				check_mouse(&menu, &game);											//Each while(STATE == X) loop renders a background and checks for input 
				game.setResolution(window_width, window_height);					//and the input functions all have checks to see what STATE is currently running
			}																		//and only allows proper input
			setMenuBackground();
			glXSwapBuffers(dpy, win);
		}

		while(STATE == HOW_TO && game.run && menuToggle)
		{

			XEvent howTo;
			while(XPending(dpy))
			{
				XNextEvent(dpy, &howTo);
				check_keys(&howTo, &game);
				check_mouse(&howTo, &game);
				game.setResolution(window_width, window_height);
			}
			setHowToBackground();
			glXSwapBuffers(dpy, win);
		}
		if(menuToggle)										//No one wants to see the how to menu over and over and over again.
			menuToggle = false;
		
		STATE = RUN_GAME; //gotta have this here, otherwise if the player clicks the green button after one game the STATE will be HOW_TO but it cant access it
		game.setResolution(window_width, window_height);
		game.setPos(window_width/2, window_height + game.player.height);	//this is when playforms are created and the players position is set to the top
		game.setGravity(GRAVITY);											//if this is called beforehand it wont take proper screen size into consideration
		makePlatform(5,&game);


		while(STATE == RUN_GAME && game.run)
		{

			// check input
			XEvent e;
			while(XPending(dpy))
			{
				if(TOGGLE_PAUSE)
				{
					TOGGLE_PAUSE = false;
					pausegame = false;
				}

				XNextEvent(dpy, &e);
				check_keys(&e, &game);
				check_resize(&e);
				game.setResolution(window_width, window_height);
			}


			if(game.guts && numblood <= 50)
			{
				STATE = DEATH;	//changes the game state to the death screen once the person has died and the blood particles are off the screen
			}

			clock_gettime(CLOCK_REALTIME, &timeCurrent);
			timeSpan = timeDiff(&timeStart, &timeCurrent);
			timeCopy(&timeStart, &timeCurrent);

			if(!pausegame && numblood < 1)
			{

				SCORE++;		//iterates the score every loop that the game is not paused and the player is not dead
			}

			physicsCountdown += timeSpan;

			// check for collisions, move player
			while(physicsCountdown >= physicsRate) {
				physics(&game);

				physicsCountdown -= physicsRate;
			}

			// used for sprite timing DON'T TOUCH
			if(frames > 2)
				frames = 0;
			frames++;

			// FPS COUNTER/RESET
			if(fps > 100)
			{
				clock_gettime(CLOCK_REALTIME, &start);
				fps = 0;
			}
			fps++;

			render(&game);
			glXSwapBuffers(dpy, win);

		}

		while(STATE == DEATH && game.run)
		{
			XEvent death;
			while(XPending(dpy))
			{
				XNextEvent(dpy, &death);
				check_keys(&death, &game);
				check_mouse(&death, &game);
				game.setResolution(window_width, window_height);
			}

			clock_gettime(CLOCK_REALTIME, &timeCurrent);
			timeSpan = timeDiff(&timeStart, &timeCurrent);
			timeCopy(&timeStart, &timeCurrent);
			physicsCountdown += timeSpan;
			while(physicsCountdown >= physicsRate)
			{
				physics(&game);
				physicsCountdown -= physicsRate;		//this will keep the game rendering so that the user can see the players full body explosion
			}
			render(&game);
			glXSwapBuffers(dpy, win);

		}

	}
	return;
}