예제 #1
0
/**
 * Create new draw module context with gallivm state for LLVM JIT.
 */
static struct draw_context *
draw_create_context(struct pipe_context *pipe, void *context,
                    boolean try_llvm)
{
   struct draw_context *draw = CALLOC_STRUCT( draw_context );
   if (!draw)
      goto err_out;

   /* we need correct cpu caps for disabling denorms in draw_vbo() */
   util_cpu_detect();

#if HAVE_LLVM
   if (try_llvm && draw_get_option_use_llvm()) {
      draw->llvm = draw_llvm_create(draw, (LLVMContextRef)context);
   }
#endif

   draw->pipe = pipe;

   if (!draw_init(draw))
      goto err_destroy;

   draw->ia = draw_prim_assembler_create(draw);
   if (!draw->ia)
      goto err_destroy;

   return draw;

err_destroy:
   draw_destroy( draw );
err_out:
   return NULL;
}
예제 #2
0
파일: draw_context.c 프로젝트: nikai3d/mesa
/**
 * Create new draw module context with gallivm state for LLVM JIT.
 */
struct draw_context *
draw_create_gallivm(struct pipe_context *pipe, struct gallivm_state *gallivm)
{
   struct draw_context *draw = CALLOC_STRUCT( draw_context );
   if (draw == NULL)
      goto fail;

#if HAVE_LLVM
   if (draw_get_option_use_llvm()) {
      if (!gallivm) {
         gallivm = gallivm_create();
         draw->own_gallivm = gallivm;
      }

      if (gallivm)
         draw->llvm = draw_llvm_create(draw, gallivm);
   }
#endif

   if (!draw_init(draw))
      goto fail;

   draw->pipe = pipe;

   return draw;

fail:
   draw_destroy( draw );
   return NULL;
}
예제 #3
0
파일: nbody.c 프로젝트: crypt3lx2k/nbody
int main (int argc, char * argv[]) {
  bool restart;
  unsigned long int particles_n;

  if (argc < 2) {
    particles_n = NUMBER_OF_PARTICLES;
  } else {
    errno = 0;

    particles_n = strtoul(argv[1], NULL, 0);

    if (errno) {
      perror(__func__);
      exit(EXIT_FAILURE);
    }
  }

  n = particles_n;

  px =
    align_padded_malloc(ALIGN_BOUNDARY, n*sizeof(value), ALLOC_PADDING);
  py =
    align_padded_malloc(ALIGN_BOUNDARY, n*sizeof(value), ALLOC_PADDING);

  vx =
    align_padded_malloc(ALIGN_BOUNDARY, n*sizeof(value), ALLOC_PADDING);
  vy =
    align_padded_malloc(ALIGN_BOUNDARY, n*sizeof(value), ALLOC_PADDING);

  m  =
    align_padded_malloc(ALIGN_BOUNDARY, n*sizeof(value), ALLOC_PADDING);

  if (px == NULL || py == NULL ||
      vx == NULL || vy == NULL || m == NULL) {
    perror("main");
    exit(EXIT_FAILURE);
  }

  draw_init(SCREEN_WIDTH, SCREEN_HEIGHT, FRAME_RATE, n);
  physics_init(n);
  rng_init();

  do {
    draw_reset(n);
    physics_reset(n);
    restart = main_loop();
  } while (restart);

  rng_free();
  physics_free();
  draw_free();

  align_free(m);
  align_free(vy);
  align_free(vx);
  align_free(py);
  align_free(px);

  exit(EXIT_SUCCESS);
}
PROCESS_THREAD(oled_temp_process, ev, data)
{
  static struct etimer sensors_timer;

  PROCESS_BEGIN();

  draw_init();

  draw_clear();

  onewire_init();

  etimer_set(&sensors_timer, READ_INTERVAL);
  timer_callback();
  while(1)
    {
      PROCESS_YIELD();
      if(etimer_expired(&sensors_timer))
        {
          timer_callback();
          etimer_set(&sensors_timer, READ_INTERVAL);
        }
    }

  PROCESS_END();
}
예제 #5
0
파일: viewer.cpp 프로젝트: nelk/cs488
bool Viewer::on_expose_event(GdkEventExpose* event) {
  Glib::RefPtr<Gdk::GL::Drawable> gldrawable = get_gl_drawable();

  if (!gldrawable) return false;

  if (!gldrawable->gl_begin(get_gl_context()))
    return false;

  draw_init(get_width(), get_height());

  // Transforms each point by matrix m_perspective * m_view * m_model.
  std::vector<LineSegment4D> lineSegments = rootNode->getTransformedLineSegments();

  renderHomogenousLines(lineSegments);

  // Draw viewport box.
  const Colour BLACK(0);
  set_colour(BLACK);
  const Point2D viewportBL = Point2D(viewportTL[0], viewportBR[1]);
  const Point2D viewportTR = Point2D(viewportBR[0], viewportTL[1]);
  draw_line(viewportTL, viewportBL);
  draw_line(viewportBL, viewportBR);
  draw_line(viewportBR, viewportTR);
  draw_line(viewportTR, viewportTL);

  draw_complete();

  // Swap the contents of the front and back buffers so we see what we
  // just drew. This should only be done if double buffering is enabled.
  gldrawable->swap_buffers();

  gldrawable->gl_end();

  return true;
}
예제 #6
0
파일: wterm.c 프로젝트: hchunhui/myos
int main()
{
	draw_init();
	draw_set_canvas(canv, (void *)buff);
	if(w_connect(&priv_fd, &ifd, &ofd))
		return -1;

	poll_fd = open("/dev/poll/0", 0);
	pipe_in = open("/dev/pipe/0", 0);
	pipe_out = open("/dev/pipe/0", 0);
	poll_set_event(poll_fd, pipe_out, POLL_TYPE_READ);
	if(fork() == 0)
	{
		dup2(pipe_in, 0);
		dup2(pipe_out, 1);
		dup2(pipe_out, 2);
		_exit(execl("/bin/sh", "*sh*", NULL));
	}

	w_send_wcreate(ofd, 0, 0, 0, C*FW, (R+1)*FH, "WTerm");
	w_wait_reply(ifd, &hwnd, &shm_key);
	shm_at(shm_key, buff, SHM_RW);
	printf("hwnd: %x\n",hwnd);
	poll_set_event(poll_fd, ifd, POLL_TYPE_READ);

	draw_title();
	term_init();
	main_loop();

	w_disconnect(priv_fd, ifd, ofd);
	shm_dt(shm_key, buff);
	printf("exit with exit code 0\n");
	return 0;
}
예제 #7
0
/**
 * Create new draw module context with gallivm state for LLVM JIT.
 */
static struct draw_context *
draw_create_context(struct pipe_context *pipe, boolean try_llvm)
{
   struct draw_context *draw = CALLOC_STRUCT( draw_context );
   if (draw == NULL)
      goto err_out;

#if HAVE_LLVM
   if (try_llvm && draw_get_option_use_llvm()) {
      draw->llvm = draw_llvm_create(draw);
      if (!draw->llvm)
         goto err_destroy;
   }
#endif

   draw->pipe = pipe;

   if (!draw_init(draw))
      goto err_destroy;

   return draw;

err_destroy:
   draw_destroy( draw );
err_out:
   return NULL;
}
int screen_init(void)
{
    if (draw_init())
        goto err1;
    if (fb_open(fb))
        goto err2;
    return 0;

err2:
    draw_uninit();
err1:
    return -1;
}
예제 #9
0
파일: bspline.cpp 프로젝트: llevar/uoft
BSpline::BSpline(const Matrix mat)
{
	int N, j, i;
	RowVector first(2), last(2);

	// specify default parameters in case the matrix
	// passed as argument is incorrect
	_d = 3;
	_k = 0;
	_done = false;
	draw_init(); 


	// check that the matrix has two rows
	if (mat.ncols() != 2) {
		cerr << "BSpline::BSpline(): Error: Knot matrix must have two columns" << endl
		 	 << "BSpline::BSpline(): Creating empty B-spline" << endl;
		return;
	}

	// check that the number of interior knot intervals is a power of two
	N = mat.nrows();
	j = (int) ceil(log((double)N-2*_d-1)/log(2.0));
	if ((N-2*_d-1) != (1<<j)) {
		cerr << "BSpline::BSpline(): Error: Incorrect number of interior knots" << endl
		 	 << "BSpline::BSpline(): Creating empty B-spline" << endl;
		return;
	}

	// check that the first and last d+1 columns are identical
	first = mat.Row(1);
	last = mat.Row(N);
	for (i=1; i<_d; i++) {
		if ((first(1) != mat(i+1,1)) ||
			(first(2) != mat(i+1,2)) ||
			(last(1) != mat(N-i,1)) ||
			(last(2) != mat(N-i,2))) {
			cerr << "BSpline::BSpline(): Error: Matrix is not an endpoint-interpolating bspline" 
			     << endl << "BSpline::BSpline(): Creating empty B-spline" << endl;
			return;
		}
	}
    
	// matrix is in correct format, so create the knots
	for (i=1; i<=N; i++)
	     add_knot((int)rint(mat(i,1)), (int)rint(mat(i,2)));
	// update the internal bspline parameters
	_j = j;
	_done = true;
	update_matrix();
}
예제 #10
0
void configure_system() {
	    
	kill_interrupts();	// turn off interrupts just in case

	turn_analog_inputs_off();	// kill those pesky analogue inputs
	
	
	serial_setup(BRGH_HIGH_SPEED, SPBRG_19200);

	turn_peripheral_ints_on();
	turn_global_ints_on();

	draw_setup_io();
	draw_init();

}
예제 #11
0
static void choose_font(void)
{
    CHOOSEFONT cf;

    memset(&cf, 0, sizeof(CHOOSEFONT));
    cf.lStructSize=sizeof(CHOOSEFONT);
    cf.hwndOwner=wndMain;
    cf.Flags=CF_FIXEDPITCHONLY|CF_NOSCRIPTSEL|CF_SCREENFONTS|CF_INITTOLOGFONTSTRUCT;
    cf.lpLogFont=&df;
    if (!ChooseFont(&cf))
        return;
    save_font();
    draw_free();
    draw_init(&df);
    InvalidateRect(termwnd, 0, 1);
}
예제 #12
0
void main_loops_init(void) {
    system_init();
    debug_init();
    input_init();
    button_init();
    comm_init();
    draw_init(TGL_UPDATE_RATE);
    pacer_init(DISPLAY_TASK_RATE);

    tinygl_font_set (TGL_FONT);
    tinygl_text_speed_set (TGL_TEXT_SPEED);
    tinygl_text_dir_set (TINYGL_TEXT_DIR_ROTATE);
    tinygl_text_mode_set (TINYGL_TEXT_MODE_SCROLL);
    
    TRACE("\n\n\n**UCFK initialised.**\n");
}
예제 #13
0
static void win32_init(void)
{
    WNDCLASS wc;

    INITCOMMONCONTROLSEX icex;

    icex.dwSize = sizeof(INITCOMMONCONTROLSEX);
    icex.dwICC = ICC_BAR_CLASSES;
    InitCommonControlsEx(&icex);

    wc.style = 0;
    wc.lpfnWndProc = (WNDPROC) MainWndProc;
    wc.cbClsExtra = 0;
    wc.cbWndExtra = 0;
    wc.hInstance = inst;
    wc.hIcon = LoadIcon(inst, MAKEINTRESOURCE(0));
    wc.hCursor = LoadCursor(NULL, IDC_ARROW);
    if (!(wc.hbrBackground = CreatePatternBrush(LoadBitmap(inst, "wood1"))))
        wc.hbrBackground=CreateSolidBrush(clWoodenDown);
    wc.lpszMenuName = 0;
    wc.lpszClassName = "MainWindow";

    if (!RegisterClass(&wc))
        die("RegisterClass");

    wc.style = 0;
    wc.lpfnWndProc = (WNDPROC) TermWndProc;
    wc.cbClsExtra = 0;
    wc.cbWndExtra = 0;
    wc.hInstance = inst;
    wc.hIcon = 0;
    wc.hCursor = LoadCursor(NULL, IDC_ARROW);
    wc.hbrBackground=0;
    wc.lpszMenuName = 0;
    wc.lpszClassName = "Term";

    if (!RegisterClass(&wc))
        die("RegisterClass");

    load_font();
    draw_init(&df);
    InitializeCriticalSection(&vt_mutex);
    if (!(timer=CreateWaitableTimer(0, 0, 0)))
        die("CreateWaitableTimer");
}
예제 #14
0
파일: draw.c 프로젝트: agadiffe/wolf3d
void			draw(t_env *e)
{
	e->x = 0;
	while (e->x < SCREEN_W)
	{
		draw_init(e);
		calculate_step_and_initial_side_dist(e);
		perform_dda(e);
		calculate_dist_projected(e);
		calculate_wall(e);
		if (e->textured_wall)
			texturing_calculations(e);
		else
			wall_color(e);
		draw_vertical_line(e);
		e->x++;
	}
	if (e->textured_wall && e->map.max_x > 25 && e->map.y > 25)
		draw_sprite(e);
}
예제 #15
0
파일: world.c 프로젝트: brownman/bastos85
int world_main_loop(int argc, char **argv, world_t *w){
	init_time();
	set_fps(90);
	world_set(w);
	/*printf("coucou2\n");	*/
	glutInit(&argc,argv);
	glutInitDisplayMode(GLUT_DEPTH|GLUT_DOUBLE|GLUT_RGB);
	glEnable(GL_DEPTH_TEST);
	glutInitWindowPosition(250,250);
	glutInitWindowSize(600,400);
	glutCreateWindow("BASTOS 85");
	draw_init();
	glutDisplayFunc(do_world);
	glutIdleFunc(do_world);
	glutReshapeFunc(draw_reshape);
	/*glutIgnoreKeyRepeat(1);*/
	glutKeyboardFunc(keyboard_down_func);
	glutKeyboardUpFunc(keyboard_up_func);
	glutMainLoop();
	return 0;
}
예제 #16
0
파일: kacbriK_v2.c 프로젝트: Wobow/Tek1
int	do_ball(t_ole *t)
{
  int	i;

  if (t->state == 0)
    {
      i = 0;
      usleep(NB_BALL * 4000 + 20000);
      draw_init(t);
      while (i < NB_BALL)
	{
	  move_ball(t, i);
	  i = i + 1;
	}
      expose(t);
    }
  else if (t->state == 1)
    {
      t->state = 2;
      usleep(1000000);
    }
}
예제 #17
0
파일: Frame.cpp 프로젝트: ETRu/Laura
//------------------------------------------------------------------------------
void Frame::draw() {
  if (!valid()) {
    glClearColor(0.0, 0.0, 0.0, 1);                        // Turn the background color black
    glViewport(0,0,w(),h());                               // Make our viewport the whole window
    glMatrixMode(GL_PROJECTION);                           // Select The Projection Matrix
    glLoadIdentity();                                      // Reset The Projection Matrix
    gluOrtho2D(framexmin,framexmax,frameymin,frameymax);                             // (xmin,xmax,ymin,ymax)
    //gluPerspective(45.0f,w()/h(), 1 ,150.0);
    glMatrixMode(GL_MODELVIEW);                            // Select The Modelview Matrix
    glLoadIdentity();                                      // Reset The Modelview Matrix
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);    // Clear The Screen And The Depth Buffer
    glLoadIdentity();                                      // Reset The View
    //gluLookAt( 0, 0, 10,     0, 0, 0,     0, 1, 0);         // Position - View  - Up Vector
    glEnable(GL_DEPTH_TEST);
    
	  
    valid(1);
  }
	
	if(newgraph==1){draw_init(); newgraph=0;}

  draw_scene();
}
예제 #18
0
파일: pong.c 프로젝트: anlif/micropong
void pong_init(){
	static int first_run = 1;
	score[PONG_PADDLE_LEFT] = score[PONG_PADDLE_RIGHT] = 0;

	point_t paddle_left_origin = {PADDLE_LEFT_X,
					YRES/2 - PADDLE_HEIGHT/2};
	paddle_left_state_y = paddle_left_origin.y;

	point_t paddle_right_origin = {PADDLE_RIGHT_X, 
					YRES/2 - PADDLE_HEIGHT/2};
	paddle_right_state_y = paddle_right_origin.y;

	point_t ball_origin = {XRES/2-3, YRES/2-3};
	ball_state.pos.x = ball_origin.x; 
	ball_state.pos.y = ball_origin.y;
	ball_state.dx = -1; 
	ball_state.dy = 0;
	
	point_t *points;
	if(first_run)
	{
		points = (point_t*)malloc(PONG_BUFFER_SIZE*sizeof(point_t));
	}
	else
	{
		points = draw_get_back_buffer();
	}

	for (uint8_t i = 0; i < PONG_BUFFER_SIZE; i++) 
	{
		points[i].x = 0;
		points[i].y = 0;
	}

	for(uint8_t i = 0; i < PADDLE_WIDTH; ++i){
		for(uint8_t j = 0; j < PADDLE_HEIGHT; j++){
			uint8_t x1 = paddle_left_origin.x + i;
			uint8_t y1 = paddle_left_origin.y + j;
			uint8_t x2 = paddle_right_origin.x + i;
			uint8_t y2 = paddle_right_origin.y + j;
			points[PADDLE_LEFT_OFFSET + i*PADDLE_HEIGHT+j].x = x1;
			points[PADDLE_LEFT_OFFSET + i*PADDLE_HEIGHT+j].y = y1;
			points[PADDLE_RIGHT_OFFSET + i*PADDLE_HEIGHT+j].x = x2;
			points[PADDLE_RIGHT_OFFSET + i*PADDLE_HEIGHT+j].y = y2;
		}
	}

	pong_place_ball(ball_origin, points);
	
	for(uint8_t i = 0; i < LINE_SIZE; ++i){
		points[LINE_OFFSET + i].x = XRES/2 - 1;
		points[LINE_OFFSET + i].y = (i/LINE_SEP_SIZE)*LINE_SEP_SIZE + i + LINE_SEP_SIZE/2;
	}
	
	pong_draw_number(&points[NUMBER1_OFFSET], 0, NUMBER1_X, NUMBER_Y);
	pong_draw_number(&points[NUMBER2_OFFSET], 0, NUMBER2_X, NUMBER_Y);

	if(first_run) {
		draw_init(PONG_BUFFER_SIZE,  points);
		free(points);
		first_run = 0;
	}
	
}
예제 #19
0
파일: menu.c 프로젝트: bogger33/gnuboy-gx
void OptionMenu ()
{
  int ret;
  int quit = 0;
  int filtering = config.usefilter + (config.filterdmg << 1);
  char optionmenu[7][20];
  int prevmenu = menu;
  u16 xscale, yscale;
  
  menu = 0;


  while (quit == 0)
  {
    strcpy (menutitle, "");

    if (config.aspect == 0)      sprintf (optionmenu[0], "Aspect: STRETCH");
    else if (config.aspect == 1) sprintf (optionmenu[0], "Aspect: ORIGINAL");
    else if (config.aspect == 2) sprintf (optionmenu[0], "Aspect: SCALED");
    sprintf (optionmenu[1], "Force Mono: %s",config.forcedmg ? "YES" : "NO");
    if (filtering == 1) sprintf (optionmenu[2], "Filtering: GBC");
    else if (filtering == 3) sprintf (optionmenu[2], "Filtering: ALL");
    else sprintf (optionmenu[2], "Filtering: OFF");
    sprintf (optionmenu[3], "GBA Features: %s",config.gbamode ? "YES" : "NO");
    sprintf (optionmenu[4], "Palette: %s", paltxt[config.paletteindex]);
    sprintf (optionmenu[5], "RTC Synchro: %s", config.syncrtc ? "YES" : "NO");
    sprintf(optionmenu[6], "Return to previous");

    ret = DoMenu (&optionmenu[0], 7);

    switch (ret)
    {
      case 0: /* Aspect ratio */
        config.aspect = (config.aspect + 1) % 3;
        if (config.aspect == 0)
        {
          xscale = 320;
          yscale = 224;
        }
        else if (config.aspect == 1)
        {
          xscale = 160;
          yscale = 144;
        }
        else
        {
          xscale = 250;
          yscale = 224;
        }
        
        square[6] = square[3]  =  xscale;
        square[0] = square[9]  = -xscale;
        square[4] = square[1]  =  yscale;
        square[7] = square[10] = -yscale;
        draw_init();
        break;

      case 1: /* Force Monochrome Display */
        config.forcedmg ^= 1;
        break;
      
      case 2: /* Graphics Filtering */
        filtering ++;
        if (filtering == 2) filtering = 3;
        if (filtering > 3) filtering = 0;
        config.usefilter = filtering & 1;
        config.filterdmg = (filtering >> 1) & 1;
        break;

      case 3: /* GBA-only features (used in some GB/GBC games) */
        config.gbamode ^= 1;
        break;

      case 4: /* Color Palettes */
      case -6:
        if (ret<0)
        {
          if (config.paletteindex == 0) config.paletteindex = 27;
          else  config.paletteindex --;
        }
        else
        {
          config.paletteindex++;
          if (config.paletteindex > 27) config.paletteindex = 0;
        }
        break;

      case 5: /* RTC synchro */
        config.syncrtc ^= 1;
        break;

      case -1:
      case 6:
        quit = 1;
        break;
     }
  }

  /* save Config File */
  config_save();

  /* update gnuboy defaults */
  usefilter     = config.usefilter;
  filterdmg     = config.filterdmg;
  syncrtc       = config.syncrtc;
  paletteindex  = config.paletteindex;
  forcedmg      = config.forcedmg;
  gbamode       = config.gbamode;
  u8 c = gbrom[0x0147];
  hw.cgb = ((c == 0x80) || (c == 0xc0)) && !forcedmg;
  hw.gba = (hw.cgb && gbamode);

  menu = prevmenu;
}
예제 #20
0
파일: viewer.cpp 프로젝트: jemartti/Cubes
bool Viewer::on_expose_event( GdkEventExpose* /*event*/ )
{
	Glib::RefPtr<Gdk::GL::Drawable> gldrawable = get_gl_drawable();

	if ( !gldrawable )
	{
		return false;
	}

	if ( !gldrawable->gl_begin(get_gl_context()) )
	{
		return false;
	}

	// Start drawing
	draw_init( get_width(), get_height() );

	// Transform the world gnomon
	for( int i = 0; i < 4; i += 1 )
	{
		m_gnomonTrans[i] = m_viewing * m_gnomon[i];
	}
	// Draw the world gnomon
	set_colour( Colour(0.1, 0.1, 1.0) );
	draw_line2D( m_gnomonTrans[0], m_gnomonTrans[1] );
	draw_line2D( m_gnomonTrans[0], m_gnomonTrans[2] );
	draw_line2D( m_gnomonTrans[0], m_gnomonTrans[3] );

	// Draw the modelling gnomon
	set_colour( Colour(0.1, 1.0, 0.1) );
	draw_modellingGnomon();

	// Draw the unit cube
	set_colour( Colour(0.1, 0.1, 0.1) );
	draw_unitCube();

	// Initialize the viewport
	if ( !m_viewflag )
	{
		m_viewport[0] = ( Point2D(get_width() * 0.05, get_height() * 0.05) );
		m_viewport[1] = ( Point2D(get_width() * 0.95, get_height() * 0.05) );
		m_viewport[2] = ( Point2D(get_width() * 0.95, get_height() * 0.95) );
		m_viewport[3] = ( Point2D(get_width() * 0.05, get_height() * 0.95) );
		m_viewflag    = true;
	}
	// Draw the viewport
	set_colour( Colour(0.1, 0.1, 0.1) );
	draw_line( m_viewport[0], m_viewport[1] );
	draw_line( m_viewport[1], m_viewport[2] );
	draw_line( m_viewport[2], m_viewport[3] );
	draw_line( m_viewport[3], m_viewport[0] );

	// Finish drawing
	draw_complete();

	// Update the information bar
	update_infobar();

	// Swap the contents of the front and back buffers so we see what we
	// just drew. This should only be done if double buffering is enabled.
	gldrawable->swap_buffers();

	gldrawable->gl_end();

	return true;
}
예제 #21
0
파일: game.c 프로젝트: poulenque/St_V_2014
Game* initGame(Camera* player){

	//no weapon
	trigger_value_MAX[0]=200;//avoid 1./0.
	fire_value_MAX[0]   =1;//avoid 1./0.
	//bow
	trigger_value_MAX[1]=200;
	fire_value_MAX[1]   =278;
	trigger_value_MAX[4]=200;
	fire_value_MAX[4]   =278;
	trigger_value_MAX[5]=200;
	fire_value_MAX[5]   =278;
	// fire_value_MAX[1]   =1800;
	// la sulfateuse
	trigger_value_MAX[2]=400;
	fire_value_MAX[2]   =100;
	// la sulfateuse BOURRIN
	trigger_value_MAX[3]=400;
	fire_value_MAX[3]   =10;
	// fire_value_MAX[3]   =1;

	draw_init();
	audio_init();


	str = new_string3d();
	glMatrixMode( GL_PROJECTION );
	glLoadIdentity();
	glMatrixMode( GL_MODELVIEW );
	glLoadIdentity();

	glEnable(GL_DEPTH_TEST);
	glEnable (GL_BLEND);
	glDisable(GL_CULL_FACE);

	glEnable(GL_TEXTURE_2D);

	glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	glDepthFunc(GL_LESS);//GL_NEVER, GL_LESS, GL_EQUAL, GL_LEQUAL, GL_GREATER, GL_NOTEQUAL, GL_GEQUAL, GL_ALWAYS, GL_LESS

	glEnable(GL_POINT_SMOOTH);
	glDisable( GL_LINE_SMOOTH );
	glDisable( GL_POLYGON_SMOOTH ); // THIS MAKES A NICE ARTEFACT :¬D

	
	glHint(GL_LINE_SMOOTH_HINT,GL_FASTEST);
	glHint(GL_POLYGON_SMOOTH_HINT,GL_FASTEST);
	// glHint(GL_TEXTURE_COMPRESSION_HINT,GL_FASTEST);
	// glHint(GL_FRAGMENT_SHADER_DERIVATIVE_HINT,GL_FASTEST);

	//GL_FASTEST, GL_NICEST, and GL_DONT_CARE
	// glHint( GL_LINE_SMOOTH_HINT, GL_NICEST );
	// glHint( GL_POLYGON_SMOOTH_HINT, GL_NICEST );

	// glEnable(GL_AUTO_NORMAL);
	// glEnable(GL_NORMALIZE);


	Game* game = malloc(sizeof(Game));


	game->player=player;

	game->HUD_render=HUD;

	game->color_debug=0;
	game->sorting=1;
	game->sorting_arrow=NULL;
	game->sorting_next=NULL;

	game->speed_custom=1;
	
	game->trigger=trigger;
	game->trigger_value=0;
	game->fire=fire;
	game->fire_value=0;
	game->weapon=0;
	game->FIRST_SHOT=0;

	game->mechants=NULL;
	game->particles=NULL;
	game->particles_update=NULL;

	game->arrows=NULL;
	game->arrows_last=NULL;
	game->arrows_to_update=NULL;
	game->audio= new_audioplayer();

	game->audio_amplitude=0;
	game->heart_beat=0;
	game->heart_beat_time=0;
	game->heart_beat_time_normalized=0;

	game->mechant_regeneration_type=mechant_regeneration_type_dummy;

	intro_setup(game);

	game->world_x_size=600;
	game->world_y_size=600;
	//===========================
	// 
	//  _|_|_|_|_|  _|_|_|_|    _|_|_|  _|_|_|_|_|  _|_|_|  _|      _|    _|_|_|  
	//      _|      _|        _|            _|        _|    _|_|    _|  _|        
	//      _|      _|_|_|      _|_|        _|        _|    _|  _|  _|  _|  _|_|  
	//      _|      _|              _|      _|        _|    _|    _|_|  _|    _|  
	//      _|      _|_|_|_|  _|_|_|        _|      _|_|_|  _|      _|    _|_|_|  
	//                                                                            
	//THIS IS FOR TESTING PURPOSE
	//===========================

	// audio_playMusic(game->audio,"music/Goto80_gopho_loop.ogg");
	// audio_playMusic(game->audio,"music/short_test.ogg");
	// audio_playMusic(game->audio,"music/INEXISTANT_FILE");
	// audio_playMusic(game->audio,"music/Goto80_gopho.ogg");

	// ingame_level4_setup(game);
	// ingame_level3_setup(game);
	// ingame_level2_setup(game);
	// ingame_level1_setup(game);
	// audioplayer_set_next(game->audio,"music/noise_test.ogg");
	// audioplayer_set_next(game->audio,"music/noise_test_2.ogg");
	// audioplayer_set_next(game->audio,"music/noise_test_3.ogg");
	// audioplayer_set_next(game->audio,"music/noise_test_4.ogg");
	// audioplayer_set_next(game->audio,"music/Goto80_gopho.ogg");
	// audioplayer_set_next(game->audio,"music/Goto80_gopho_level2.ogg");

	// int mechant_regeneration_test(){
	// 	return 2;
	// }
	// game->mechant_regeneration_type=mechant_regeneration_test;

	// level1_spawn_mechants(game);
	// audioplayer_set_next(game->audio,"music/Goto80_gopho_loop.ogg");

	// Mechant * mechant = malloc(sizeof(mechant));
	// mechant->x =0;
	// mechant->y =0;
	// mechant->z =0;
	// mechant->update =NULL;

	// game_insert_Mechant(game, mechant);


	// glClearColor( 1., 1., 1., 1. );
	// game->update=ingame_level1_update;
	// game->render=ingame_level1_render;

	// game->update=ingame_level3_update;
	// game->render=ingame_level3_render;

	//===========================
	//===========================


	return game;
}
예제 #22
0
파일: Boomdos.cpp 프로젝트: willy9561/Boom2
// application entry point
void main(int argc,char *argv[])
{
  int system_time=0;
  int frame_counter=0;
  int time0;
  char s[20]="";

  if (argc<2) {
    printusage();
    return;
  }

  // parses command line parameters
  parsecmdline(argc-2,argv+2);

  // initializes the video mode and geometry module
  int mode=-1;
  if (vbe_init()) {
    mode=vbe_findmode(scrwidth,scrheight,8);
    if (!mode) mode=-1;
  }
  if (mode==-1) vbe_done();
  if (!vbe_setmode(mode,backbuffl)) goto err;
  setscreensize(vbe_width,vbe_height);
  scr_cols=vbe_width;
  scr_bpp=vbe_bpp;

  // initializes the keyboard
  kbd_init();

  // initializes the timer
  timer_init();

  // initializes the mouse
  mouse_init();

  // reads the map
  if (!map_init(argv[1])) goto err;
  vbe_setpal((Tcolor *)palette,0,256);

  // main loop
  time0=timer_clocks;
  while(player_idle(timer_clocks)) {
    // draws the current frame
    draw_init(vbe_backbuffer,vbe_width,vbe_height);
    map_draw();

    // calculates the frame rate
    frame_counter++;
    int dt=timer_clocks-time0;
    if (dt>500) {
      float fps = (frame_counter*1000.)/dt;
      sprintf(s,"%.1f FPS",fps);
      time0 = timer_clocks;
      frame_counter = 0;
    }
    textout(vbe_backbuffer,0,0,s,255);

    // flips the video pages
    vbe_flip(waitfl);

    // applies the mouse movement
    if (player_keys & kRUN) player_rotate(-mousedy*0.01,0,-mousedx*0.01);
    else player_rotate(-mousedy*0.005,0,-mousedx*0.005);
    mousedx=0;mousedy=0;

    // clears the keyboard queue
    while (kbhit()) getch();
  }
 err:
  vbe_done();
  vbe_settext();
}
예제 #23
0
int main(int argc, char *argv[]) {
	int rc = 0, first = 1, c = 0, i = 0, l = 0;
	size_t length = 0;
	char *exec = NULL, *arg = NULL;
	char *client_id = NULL, *client_secret = NULL, *access_token = NULL;
	char *max_id = NULL, *id = NULL, *link = NULL;

	exec = argv[0];

	if (argc < 2) {
		usage(exec);

		rc = 1;
		goto cleanup;
	}

	for (i = 1, l = argc; i < l; i++) {
		arg = argv[i];
		length = strlen(arg);

		if (strncmp(arg, "--client_id", 11) == 0) {
			length -= 12;
			client_id = malloc(sizeof(char) * (length + 1));
			strncpy(client_id, arg + 12, length);
			client_id[length] = '\0';
		}

		if (strncmp(arg, "--client_secret", 15) == 0) {
			length -= 16;
			client_secret = malloc(sizeof(char) * (length + 1));
			strncpy(client_secret, arg + 16, length);
			client_secret[length] = '\0';
		}
	}

	if (get_access_token(&access_token, client_id, client_secret) != 0) {
		printf("Unable to get access_token\n");

		rc = 1;
		goto cleanup;
	}

	draw_init();

	while (1 == TRUE) {
		c = getch();

		draw_border();

		if ((photo_pos == 0 && first == 1) || photo_pos == photo_count - 1) {
			get_feed(access_token, &max_id);
			draw_instagram(&id, &link);

			if (first == 1) {
				first = 0;
			}
		}

		switch (c) {
		case '\033':
			getch();
			c = getch();

			switch (c) {
			case 'A':
				photo_pos--;

				if (photo_pos < 0) {
					photo_pos = 0;
				}

				break;
			case 'B':
				photo_pos++;

				if (photo_pos >= MAX) {
					goto cleanup;
				}

				break;
			default:
				break;
			}

			draw_instagram(&id, &link);

			break;
		case 'o':
			open_url(link);
			break;
		case 'q':
			goto cleanup;
			break;
		default:
			break;
		}
	}

cleanup:
	draw_clear();
	draw_end();

	if (client_id) {
		free(client_id);
	}

	if (client_secret) {
		free(client_secret);
	}

	if (access_token) {
		free(access_token);
	}

	if (id) {
		free(id);
	}

	if (link) {
		free(link);
	}

	return rc;
}
예제 #24
0
파일: main.c 프로젝트: Afinostux/stb
void draw(void)
{
   draw_init();
   draw_world();
   stbwingraph_SwapBuffers(NULL);
}
예제 #25
0
void
main_loop ()
{
#if HAVE_SDL
  SDL_Event event[1];
#endif

#if HAVE_FREEGLUT

  // Passing the GTK+ signals to the FreeGLUT main loop
  glutIdleFunc ((void (*)) gtk_main_iteration);
  // Setting our draw resize function as the FreeGLUT reshape function
  glutReshapeFunc (draw_resize);
  // Setting our draw function as the FreeGLUT display function
  glutDisplayFunc (draw);
  // FreeGLUT main loop
  glutMainLoop ();

#else

#if HAVE_SDL
  while (1)
    {
      while (gtk_events_pending ())
        gtk_main_iteration ();
      while (SDL_PollEvent (event))
        {
          if (event->type == SDL_QUIT)
            return;
          if (event->type == SDL_WINDOWEVENT
              && event->window.event == SDL_WINDOWEVENT_SIZE_CHANGED)
            draw_resize (event->window.data1, event->window.data2);
        }

#elif HAVE_GLFW

  while (!glfwWindowShouldClose (window))
    {
      while (gtk_events_pending ())
        gtk_main_iteration ();
      glfwPollEvents ();

#endif

      draw ();
    }

#endif
}

/**
 * \fn int main(int argn, char **argc)
 * \brief Main function
 * \param argn
 * \brief Arguments number.
 * \param argc
 * \brief Array of arguments.
 * \return 0 on success.
 */
int
main (int argn, char **argc)
{
  GLenum glew_status;

// PARALELLIZING INIT
#ifdef G_OS_WIN32
  SYSTEM_INFO sysinfo;
  GetSystemInfo (&sysinfo);
  nthreads = sysinfo.dwNumberOfProcessors;
#else
  nthreads = (int) sysconf (_SC_NPROCESSORS_CONF);
#endif
// END

  // Initing locales
#if DEBUG
  printf ("Initing locales\n");
  fflush (stdout);
#endif
  bindtextdomain ("fractal", "./po");
  bind_textdomain_codeset ("fractal", "UTF-8");
  textdomain ("fractal");

  // Initing graphic window
#if HAVE_FREEGLUT

#if DEBUG
  printf ("Initing FreeGLUT window\n");
  fflush (stdout);
#endif
  glutInit (&argn, argc);
  glutInitDisplayMode (GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
  glutInitWindowSize (window_width, window_height);
  glutCreateWindow ("fractal");

#elif HAVE_SDL

#if DEBUG
  printf ("Initing SDL window\n");
  fflush (stdout);
#endif
  SDL_Init (SDL_INIT_VIDEO);
  window = SDL_CreateWindow ("fractal",
                             SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
                             window_width, window_height,
                             SDL_WINDOW_RESIZABLE | SDL_WINDOW_OPENGL);
  if (!window)
    {
      printf ("ERROR! unable to create the window: %s\n", SDL_GetError ());
      return 1;
    }
  SDL_GL_SetAttribute (SDL_GL_CONTEXT_MAJOR_VERSION, 2);
  if (!SDL_GL_CreateContext (window))
    {
      printf ("ERROR! SDL_GL_CreateContext: %s\n", SDL_GetError ());
      return 1;
    }

#elif HAVE_GLFW

#if DEBUG
  printf ("Initing GLFW window\n");
  fflush (stdout);
#endif
  if (!glfwInit ())
    {
      printf ("ERROR! unable to init GLFW\n");
      return 1;
    }
  window
    = glfwCreateWindow (window_width, window_height, "fractal", NULL, NULL);
  if (!window)
    {
      printf ("ERROR! unable to open the window\n");
      glfwTerminate ();
      return 1;
    }
  glfwMakeContextCurrent (window);

#endif

  // Initing GLEW
#if DEBUG
  printf ("Initing GLEW\n");
  fflush (stdout);
#endif
  glew_status = glewInit ();
  if (glew_status != GLEW_OK)
    {
      printf ("ERROR! glewInit: %s\n", glewGetErrorString (glew_status));
      return 1;
    }

  // Initing FreeType
  if (FT_Init_FreeType (&ft))
  {
    printf("ERROR! could not init freetype library\n");
    return 1;
  }

  // Initing GTK+
#if DEBUG
  printf ("Initing GTK+\n");
  fflush (stdout);
#endif
  gtk_init (&argn, &argc);

  // Initing logo
#if DEBUG
  printf ("Initing logo\n");
  fflush (stdout);
#endif
  logo_new ("logo.png");

  // Initing drawing data
#if DEBUG
  printf ("Initing drawing data\n");
  fflush (stdout);
#endif
  if (!draw_init ())
    return 1;

  // Creating the main GTK+ window
#if DEBUG
  printf ("Creating simulator dialog\n");
  fflush (stdout);
#endif
  dialog_simulator_create (dialog_simulator);

#if DEBUG
  printf ("Main loop\n");
  fflush (stdout);
#endif
  main_loop ();

  // Freeing memory
#if HAVE_GLFW
  glfwDestroyWindow (window);
  glfwTerminate ();
#endif

  return 0;
}
예제 #26
0
파일: Viewer.cpp 프로젝트: WalrusCow/gfx
void Viewer::paintGL() {
  draw_init();

  auto viewM = viewPoint.getViewMatrix();
  auto perspectiveM = perspectiveMatrix();

  // Norms of clipping planes
  Vector3D nearNorm = {0, 0, 1};
  Vector3D farNorm = {0, 0, -1};
  Vector3D leftNorm = {1, 0, 0};
  Vector3D rightNorm = {-1, 0, 0};
  Vector3D topNorm = {0, -1, 0};
  Vector3D bottomNorm = {0, 1, 0};

  // Points on clipping planes
  Point3D nearPoint = {0, 0, near};
  Point3D farPoint = {0, 0, far};
  Point3D leftPoint = {-1, 0, 0};
  Point3D rightPoint = {1, 0, 0};
  Point3D topPoint = {0, 1, 0};
  Point3D bottomPoint = {0, -1, 0};

  // Convert vp1 and vp2 into points in range [-1, 1]
  Point2D vp1, vp2;
  getAdjustedViewportBounds(&vp1, &vp2);

  int idx = 0;
  for (const auto& model : {boxModel, boxGnomon, worldGnomon}) {
    idx += 1;
    auto v = model.getLines();

    int jdx = -1;
    for (auto& line : v) {
      jdx += 1;
      // Last minute colour additions lol
      if (idx == 1) {
        if (jdx < 4) {
          set_colour(QColor(0.0, 1.0, 1.0));
        }
        else {
          set_colour(QColor(1.0, 1.0, 1.0));
        }
      }
      else if (idx == 2) {
        // Draw box gnomon as some kind of red
        set_colour(QColor(1.0, 1.0, 0.0));
      }
      else {
        // Draw world gnomon in fancy colours
        set_colour(QColor(jdx == 0 ? 1.0 : 0.0,
                          jdx == 1 ? 1.0 : 0.0,
                          jdx == 2 ? 1.0 : 0.0));
      }
      // Now we have the view coordinates
      line.start = viewM * line.start;
      line.end = viewM * line.end;

      // Now we want to clip the line to the near and far planes first, to
      // avoid ambiguity. (Actually, we only need to do the near one, but
      // far is the same so why not do that too) :)
      if (!clipLine(&line, nearNorm, nearPoint) ||
          !clipLine(&line, farNorm, farPoint)) {
        continue;
      }

      // We need these because our vectors are 3D not 4D...
      auto startZ = line.start[2];
      auto endZ = line.end[2];

      // Now multiply to project it onto the near plane
      line.start = perspectiveM * line.start;
      line.end = perspectiveM * line.end;

      // We no longer care about depth
      // TODO: Convert to 2D
      for (int i = 0; i < 3; ++i) {
        line.start[i] /= startZ;
        line.end[i] /= endZ;
      }

      // We can clip these afterwards (in 2D, since we don't care about depth)
      // TODO: 2D
      if (!clipLine(&line, rightNorm, rightPoint) ||
          !clipLine(&line, leftNorm, leftPoint) ||
          !clipLine(&line, topNorm, topPoint) ||
          !clipLine(&line, bottomNorm, bottomPoint)) {
        continue;
      }

      const Line2D windowLine = {
        {line.start[0], line.start[1]},
        {line.end[0], line.end[1]}
      };

      const Line2D viewportLine = {
        adjustForViewport(windowLine.start, vp1, vp2),
        adjustForViewport(windowLine.end, vp1, vp2)
      };

      draw_line(viewportLine.start, viewportLine.end);
    }
  }

  // Finally, draw viewport lines
  set_colour(QColor(0.0, 0.0, 0.0));
  draw_line(vp1, {vp1[0], vp2[1]});
  draw_line(vp1, {vp2[0], vp1[1]});
  draw_line({vp1[0], vp2[1]}, vp2);
  draw_line({vp2[0], vp1[1]}, vp2);
}