Beispiel #1
0
/*
// on_expose_event : draw the background and the cards and if needed rescale them
// 
*/
bool Table::on_expose_event(GdkEventExpose* event)
{	
	back=Gdk::Pixmap::create(get_window(),get_width(),get_height(),get_window()->get_depth()); 
	back_drag=Gdk::Pixmap::create(get_window(),get_width(),get_height(),get_window()->get_depth()); 

	//Rescale only if the size has changed
	if(get_width()!=width || get_height()!=height)
	{	
		std::cout<<"Resize"<<std::endl;			
		width=get_width();
		height=get_height();		
		
		//Scale the background
		double ratio = std::min(1.*get_width()/background.source->get_width(),1.*get_height()/background.source->get_height());	
		background.scaled = background.source->scale_simple(ratio*background.source->get_width()+1,ratio*background.source->get_height()+1,Gdk::INTERP_BILINEAR);
				
		for (card_it=card_list.begin();card_it!=card_list.end();card_it++)
		{
			//Scale the cards
			ratio = std::min(0.15*get_width()/(*card_it)->card_f->source->get_width(),0.15*get_height()/(*card_it)->card_f->source->get_height());
			(*card_it)->card_f->scaled =(*card_it)->card_f->source->scale_simple(ratio*(*card_it)->card_f->source->get_width(),ratio*(*card_it)->card_f->source->get_height(),Gdk::INTERP_BILINEAR);
			
		}

			
		
	}
	
	std::cout<<"Redraw"<<std::endl;

	//Draw the table
	draw_table();
	
	return true;
}
Beispiel #2
0
bool Table::on_motion_notify_event(GdkEventMotion* event)
{
	//std::cout<<"Move"<<std::endl;
	if(!card_drag)
	{
		int c=on_deck();
		//If true
		if(c!=-1)
		{
			card_quit=true;			
			
			//If not the current pointed card, update
			if(card_list[c] != card_pointed)
			{
				card_pointed->pointed=false;
				card_list[c]->pointed=true;
				card_pointed = card_list[c];
				draw_table();
			}						
		}
		//Or not
		else
		{
			if(card_quit)
			{
				for (card_it=card_list.begin();card_it!=card_list.end();card_it++)
				{			
					(*card_it)->pointed=false;
				}
				//Force the table to be drawn again to put back the card in the deck
				card_quit=false;
				card_pointed = new card;
				draw_table();			
			}
			
		}
	}
	else
	{
		draw_table();
	}
	return true;	
}
// Draw everything
void draw_all_objects(
	int* room_display_lists,
	float lid_degrees,
	float* dancer_angles, float dancer_angle,float dancer_y,
	float door_angle
) {
	// int* room_display_lists = all_display_lists[0];

	// Room walls and door
	draw_room(room_display_lists, door_angle);

	// Box and dancer
	glPushMatrix();
		// glTranslatef(0,2.6001,1.7);
		glTranslatef(-2,2.1+.001,-1);
		draw_box(room_display_lists ,lid_degrees);
	glPopMatrix();
	glPushMatrix();
		glTranslatef(-2,dancer_y,-2.7);
		draw_dancer(room_display_lists, dancer_angles, dancer_angle);
	glPopMatrix();

	// Furniture
	glPushMatrix();
		glTranslatef(-2,-1,-2.7);
		draw_table(room_display_lists);
	glPopMatrix();
	glPushMatrix();
		glTranslatef(5,-2.05,0);
		draw_one_legged_table(room_display_lists);
	glPopMatrix();
	glPushMatrix();
		glTranslatef(4.5,-2,-2.5);
		glRotatef(-90,0,1,0);
		draw_chair(room_display_lists);
	glPopMatrix();
	glPushMatrix();
		glTranslatef(0,-2,0);
		draw_stool(room_display_lists);
	glPopMatrix();

	// Lights
	// lamp
	glPushMatrix();
		glTranslatef(-3,-1.5,0);
		draw_lamp(room_display_lists);
	glPopMatrix();
	// wall light
	glPushMatrix();
		glTranslatef(4,2,-5);
		glRotatef(-90,0,1,0);
		draw_wall_light(room_display_lists);
	glPopMatrix();
}
Beispiel #4
0
extern int table_reset(void)
{
        int result = SUCCESS;

        if (Table_state != TABLE_INITIALIZED) {
                result = -1;
        } else {
                Next_card_dealer = STARTING_CARD_ROW;
                Next_card_player = STARTING_CARD_ROW;

                draw_table();
        }

        return result;
} // table_reset()
Beispiel #5
0
bool Table::on_button_release_event(GdkEventButton* event)
{
	if(event->button==1)
	{
		//End of a drag, end all the process
		if(card_drag)
		{
			card_dragged->moving=false;					
			card_list.erase(std::find(card_list.begin(),card_list.end(),card_dragged)); //erase the card from the list
			drag_save=false;
			card_drag=false;
			draw_table();
			std::cout<<"La carte "<<card_dragged->value<<" a été jouée."<<std::endl;
		}
	}
	
	return true;	
}
Beispiel #6
0
/**
 * draw_area:
 *
 * Draw the game area with its players and their cards
 */
void draw_area(void)
{
    gint i;
    cairo_t *cr;
    player *player;

    GdkRectangle rect =
    {
        0, 0,
        gskat.area->allocation.width,
        gskat.area->allocation.height
    };

    gdk_window_begin_paint_rect(gskat.area->window, &rect);

    cr = gdk_cairo_create(gskat.area->window);

    draw_table(gskat.area, cr);

    if (gskat.skat)
        draw_cards(gskat.skat, cr);

    if (gskat.table)
        draw_cards(gskat.table, cr);

    if (gskat.players)
    {
        for (i=0; i<3; ++i)
        {
            player = gskat.players[i];
            draw_cards(player->cards, cr);
            draw_player(player, cr);
        }
    }

    /* draw bid values during provoke phase only */
    if (gskat.state >= PROVOKE1 && gskat.state <= PROVOKE4 &&
            get_prop_bool("provoke_values"))
        draw_provoke_value(cr);

    cairo_destroy(cr);

    gdk_window_end_paint(gskat.area->window);
}
Beispiel #7
0
void AI( void )
{

  register unsigned int x=0,
                        y=0;
  
  for( y; y<(strlen(*table)/3); y++ )
  {
    for( x; x<(strlen(*table)/3); x++ )
    {    
      if( table[y][x] != 'O' && table[y][x] != 'X' )
      {
        table[y][x] = 'X';
        system("tput reset");draw_table();
        printf("Computer plays in : %d %d\n", x, y);
        return;
      }
      else{ continue; }
    }
  }

}
Beispiel #8
0
/**
 * draw_tricks_area:
 * @area: #GtkDrawingArea widget the cards are drawn on
 * @sv:   trick (three cards) to draw
 *
 * Draw the tricks in the show last tricks dialog window
 */
void draw_tricks_area(GtkWidget *area, stich_view *sv)
{
    gint i, x, y, winner;
    gchar *caption = NULL;
    cairo_t *cr;
    trick *stich = sv->stich;
    card **cards = stich->cards;

    GdkRectangle rect =
    {
        0, 0,
        area->allocation.width,
        area->allocation.height
    };

    /* begin drawing process
     * used for double buffering */
    gdk_window_begin_paint_rect(area->window, &rect);

    cr = gdk_cairo_create(area->window);

    /* draw table background */
    draw_table(area, cr);

    /* draw current stich */
    caption = g_strdup_printf(_("Trick %d"), sv->cur + 1);

    cairo_set_source_rgb(cr, 0.1, 0.1, 0.1);
    cairo_select_font_face(cr, "sans-serif",
            CAIRO_FONT_SLANT_NORMAL,
            CAIRO_FONT_WEIGHT_BOLD);
    cairo_set_font_size(cr, 12);
    cairo_move_to(cr, area->allocation.width / 2 - 25, 25);
    cairo_show_text(cr, caption);

    /* draw cards of the given stich */
    x = 5;
    y = 40;
    winner = get_trick_winner(cards);

    for (i=0; i<3; ++i)
    {
        if (cards[i])
        {
            /* draw card image */
            cairo_set_source_surface(cr, cards[i]->img, x, y);
            cairo_paint(cr);

            /* darken the non-winning cards */
            if (cards[i]->owner != winner)
            {
                cairo_set_source_rgba(cr, 0.1, 0.1, 0.1, 0.2);
                cairo_rectangle(cr, x, y, cards[i]->dim.w, cards[i]->dim.h);
                cairo_fill(cr);
            }

            /* draw card owner's name */
            cairo_set_source_rgb(cr, 0.1, 0.1, 0.1);
            cairo_select_font_face(cr, "sans-serif",
                    CAIRO_FONT_SLANT_NORMAL,
                    CAIRO_FONT_WEIGHT_BOLD);
            cairo_set_font_size(cr, 12);
            cairo_move_to(cr, x, y + cards[i]->dim.h + 15);
            cairo_show_text(cr, gskat.players[cards[i]->owner]->name);

            x += cards[i]->dim.w + 5;
        }
    }

    cairo_destroy(cr);
    g_free(caption);

    /* end drawing process
     * used for double buffering */
    gdk_window_end_paint(area->window);
}
Beispiel #9
0
static void 
draw_scene(void)
{
  GLfloat dist = 20.0;
  GLfloat eyex, eyey, eyez;

  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);

  eyex = dist * cos(yrot * DEG2RAD) * cos(xrot * DEG2RAD);
  eyez = dist * sin(yrot * DEG2RAD) * cos(xrot * DEG2RAD);
  eyey = dist * sin(xrot * DEG2RAD);

  /* view from top */
  glPushMatrix();
  gluLookAt(eyex, eyey, eyez, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);

  glLightfv(GL_LIGHT0, GL_POSITION, light_pos);

  /* draw table into stencil planes */
  glEnable(GL_STENCIL_TEST);
#ifdef USE_ZBUFFER
  glDisable(GL_DEPTH_TEST);
#endif
  glStencilFunc(GL_ALWAYS, 1, 0xffffffff);
  glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE);
  glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
  draw_table();
  glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);

#ifdef USE_ZBUFFER
  glEnable(GL_DEPTH_TEST);
#endif

  /* render view from below (reflected viewport) */
  /* only draw where stencil==1 */
  if (eyey > 0.0) {
    glPushMatrix();

    glStencilFunc(GL_EQUAL, 1, 0xffffffff);  /* draw if ==1 */
    glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
    glScalef(1.0, -1.0, 1.0);

    /* Reposition light in reflected space. */
    glLightfv(GL_LIGHT0, GL_POSITION, light_pos);

    draw_objects(eyex, eyey, eyez);
    glPopMatrix();

    /* Restore light's original unreflected position. */
    glLightfv(GL_LIGHT0, GL_POSITION, light_pos);
  }
  glDisable(GL_STENCIL_TEST);

  glEnable(GL_BLEND);
  glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

#ifdef USE_TEXTURE
  glEnable(GL_TEXTURE_2D);
#endif
  draw_table();
  glDisable(GL_TEXTURE_2D);
  glDisable(GL_BLEND);

  /* view from top */
  glPushMatrix();

  draw_objects(eyex, eyey, eyez);

  glPopMatrix();

  glPopMatrix();

  glutSwapBuffers();
}
Beispiel #10
0
static void display(void)
{
  float x, y, z, c;

    calc_spline(view_from, view_from_spline, current_time);
    calc_spline(view_to, view_to_spline, current_time);
    calc_spline(light_pos, light_pos_spline, current_time);
    light_pos[3] = 0.0;
    calc_spline(logo_pos, logo_pos_spline, current_time);
    calc_spline(logo_rot, logo_rot_spline, current_time);
    
    tmplight[1] = light_pos[X] - logo_pos[X];
    tmplight[2] = light_pos[Y] - logo_pos[Y];
    tmplight[3] = light_pos[Z] - logo_pos[Z];
    
    glNewList(LIGHT_TMP, GL_COMPILE); 
    glMaterialf(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, * tmplight); 
    glEndList();
    
    tv[0][0] = tv[1][1] = tv[2][2] = light_pos[Y];
    
    glColor3ub(0,  0,  0);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 
    
    /*
     * SHADOW
     */
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    gluLookAt(view_from[X], view_from[Y], view_from[Z], 
	      view_to[X], view_to[Y], view_to[Z],
	      0.0, 1.0, 0.0);
    
    if (view_from[Y] > 0.0) draw_table();

    glEnable(GL_CULL_FACE); 
    glDisable(GL_DEPTH_TEST); 

    if (logo_pos[Y] < 0.0) {
      
      if (logo_pos[Y]>-0.33) {
	/* We're emerging from the table */
	c = 1.0 - (logo_pos[Y]) / -0.33;
	pca /= 4.0;
	glColor3ub((GLubyte)(128.0*(1.0-c)*0.5 + 255.0*pca*c),
		   (GLubyte)(102.0*(1.0-c)*0.5 + 255.0*pca*c),
		   (GLubyte)(179.0*(1.0-c)*0.5 + 200.0*pca*c));
      } else {
	/* Still under table */
	glColor3ub(128/2,  102/2,  179/2);
      }
      
      glPushMatrix();
      glScalef(0.04,  0.0,  0.04);
      glRotatef(0.1 * (-900), 1.0, 0.0, 0.0);
      glRotatef(0.1 * ((int)(10.0*logo_rot[Z])), 0.0, 0.0, 1.0);
      glRotatef(0.1 * ((int)(10.0*logo_rot[Y])), 0.0, 1.0, 0.0);
      glRotatef(0.1 * ((int)(10.0*logo_rot[X])), 1.0, 0.0, 0.0);
      glRotatef(0.1 * (353), 1.0, 0.0, 0.0);
      glRotatef(0.1 * (450), 0.0, 1.0, 0.0);
      draw_logo_shadow();
      glPopMatrix();
    }
    
    if (logo_pos[Y] > 0.0) {
      glPushMatrix();
      if (logo_pos[Y]<0.33) {
	pca /= 4.0;
	c = 1.0 - (logo_pos[Y])/0.33;
	glColor3ub((GLubyte)(255.0*pca*c),
		   (GLubyte)(255.0*pca*c),
		   (GLubyte)(200.0*pca*c));
      } else {
	glColor3ub(0, 0, 0);
      }
      
      glTranslatef(light_pos[X],  light_pos[Y],  light_pos[Z]);
      glMultMatrixf(&tv[0][0]);
      glTranslatef(-light_pos[X]+logo_pos[X],
		   -light_pos[Y]+logo_pos[Y],
		   -light_pos[Z]+logo_pos[Z]);
      glScalef(0.04,  0.04,  0.04);
      glRotatef (0.1 * (-900), 1.0, 0.0, 0.0);
      glRotatef (0.1 * ((int)(10.0*logo_rot[Z])), 0.0, 0.0, 1.0);
      glRotatef (0.1 * ((int)(10.0*logo_rot[Y])), 0.0, 1.0, 0.0);
      glRotatef (0.1 * ((int)(10.0*logo_rot[X])), 1.0, 0.0, 0.0);
      glRotatef (0.1 * (353), 1.0, 0.0, 0.0);
      glRotatef (0.1 * (450), 0.0, 1.0, 0.0);


      glEnable(GL_POLYGON_STIPPLE);
      glPolygonStipple(stipple);
      draw_logo_shadow();
      glDisable(GL_POLYGON_STIPPLE);
      glPopMatrix();
    }
    /*
     * DONE SHADOW 
     */


    glEnable(GL_DEPTH_TEST);
    glDisable(GL_CULL_FACE);
    glEnable(GL_LIGHTING);

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(.1*(450),  5.0/4.0,  0.5,  20.0);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    
    gluLookAt(view_from[X],  view_from[Y],  view_from[Z],
	      view_to[X],  view_to[Y],  view_to[Z], 
	      0.0, 1.0, 0.0);
    
    glCallList( MAT_HOLDER_RINGS); 
    
    glPushMatrix();
    glTranslatef(light_pos[X],  light_pos[Y],  light_pos[Z]);
    glScalef(0.1,  0.1,  0.1);
    
    x = light_pos[X] - logo_pos[X];
    y = light_pos[Y] - logo_pos[Y];
    z = light_pos[Z] - logo_pos[Z];
    
    if (x!=0.0) {
      a3 = -atan2(z, x)*10.0 RAD;
    } else a3 = 0.0;
    
    a4 = -atan2(sqrt(x*x + z*z), y)*10.0 RAD;
    
    glRotatef (0.1 * ((int)a3), 0.0, 1.0, 0.0);
    glRotatef (0.1 * ((int)a4), 0.0, 0.0, 1.0);
    glRotatef (0.1 * (-900), 1.0, 0.0, 0.0);
    
    glEnable(GL_LIGHT2);
    glEnable(GL_LIGHT3);
    glCallList(MAT_HEMISPHERE);
    glEnable(GL_NORMALIZE);
    draw_hemisphere();
    glDisable(GL_NORMALIZE);
    glPopMatrix();

    glDisable(GL_LIGHT2);
    glDisable(GL_LIGHT3); 
    glEnable(GL_LIGHT1);
    glLightfv(GL_LIGHT1, GL_POSITION, light_pos);
    
    if (logo_pos[Y] > -0.33) {

      glCallList(MAT_LOGO);
    
      glPushMatrix();
      glTranslatef(logo_pos[X],  logo_pos[Y],  logo_pos[Z]);
      glScalef(0.04,  0.04,  0.04);
      glRotatef (0.1 * (-900), 1.0, 0.0, 0.0);
      glRotatef (0.1 * ((int)(10.0*logo_rot[Z])), 0.0, 0.0, 1.0);
      glRotatef (0.1 * ((int)(10.0*logo_rot[Y])), 0.0, 1.0, 0.0);
      glRotatef (0.1 * ((int)(10.0*logo_rot[X])), 1.0, 0.0, 0.0);
      glRotatef (0.1 * (353), 1.0, 0.0, 0.0);
      glRotatef (0.1 * (450), 0.0, 1.0, 0.0);
      glEnable(GL_LIGHTING);
      draw_logo();
      glPopMatrix();
    }
    
    if (view_from[Y] < 0.0) draw_under_table();
    
    glutSwapBuffers();

    if(post_idle) do_post_idle();
}
static void
generate_bottle (ModeInfo *mi)
{
  lavalite_configuration *bp = &bps[MI_SCREEN(mi)];
  int wire = MI_IS_WIREFRAME(mi);
  int faces = resolution * 1.5;
  Bool smooth = do_smooth;
  Bool have_texture = False;

  const lamp_geometry *top_slice = bp->model;
  const char *current_texture = 0;
  lamp_part last_part = 0;

  if (faces < 3)  faces = 3;
  else if (wire && faces > 20) faces = 20;
  else if (faces > 60) faces = 60;

  bp->bottle_poly_count = 0;

  glNewList (bp->bottle_list, GL_COMPILE);
  glPushMatrix();

  glRotatef (90, 1, 0, 0);
  glTranslatef (0, -0.5, 0);

  /* All parts of the lamp use the same specularity and shininess. */
  glMaterialfv (GL_FRONT, GL_SPECULAR,  lava_spec);
  glMateriali  (GL_FRONT, GL_SHININESS, lava_shininess);

  while (1)
    {
      const lamp_geometry *bot_slice = top_slice + 1;

      const char *texture = 0;
      GLfloat *color = 0;
      GLfloat t0, t1;

      glDisable (GL_LIGHT2);

      switch (top_slice->part)
        {
        case CAP:
        case BASE:
          texture = base_tex;
          color   = base_color;
          break;
        case BOTTLE:
          texture = fluid_tex;
          color   = fluid_color;
          if (!wire) glEnable (GL_LIGHT2);   /* light2 affects only fluid */
          break;
        default:
          abort();
          break;
        }

      have_texture = False;
      if (!wire && texture && texture != current_texture)
        {
          current_texture = texture;
          have_texture = load_texture (mi, current_texture);
        }
        
      /* Color the discs darker than the tube walls. */
      glMaterialfv (GL_FRONT, GL_AMBIENT_AND_DIFFUSE, foot_color);

      /* Do a top disc if this is the first slice of the CAP or BASE.
       */
      if ((top_slice->part == CAP  && last_part == 0) ||
          (top_slice->part == BASE && last_part == BOTTLE))
        bp->bottle_poly_count +=
          draw_disc (top_slice->radius, top_slice->elevation, faces,
                     True, wire);

      /* Do a bottom disc if this is the last slice of the CAP or BASE.
       */
      if ((top_slice->part == CAP  && bot_slice->part == BOTTLE) ||
          (top_slice->part == BASE && bot_slice->part == 0))
        {
          const lamp_geometry *sl = (bot_slice->part == 0
                                     ? top_slice : bot_slice);
          bp->bottle_poly_count +=
            draw_disc (sl->radius, sl->elevation, faces, False, wire);
        }

      if (bot_slice->part == 0)    /* done! */
        break;

      /* Do a tube or cone
       */
      glMaterialfv (GL_FRONT, GL_AMBIENT_AND_DIFFUSE, color);

      t0 = top_slice->texture_elevation;
      t1 = bot_slice->texture_elevation;

      /* Restart the texture coordinates for the glass.
       */
      if (top_slice->part == BOTTLE)
        {
          Bool first_p = (top_slice[-1].part != BOTTLE);
          Bool last_p  = (bot_slice->part    != BOTTLE);
          if (first_p) t0 = 0;
          if (last_p)  t1 = 1;
        }

      bp->bottle_poly_count +=
        draw_tube (top_slice->radius, bot_slice->radius,
                   top_slice->elevation, bot_slice->elevation,
                   t0, t1,
                   faces,
                   (top_slice->part == BOTTLE),
                   smooth, wire);

      last_part = top_slice->part;
      top_slice++;
    }

  if (bp->style == ROCKET)
    {
      int i;
      for (i = 0; i < 3; i++)
        {
          glPushMatrix();
          glRotatef (120 * i, 0, 1, 0);
          glTranslatef (0.14, -0.05, 0);
          bp->bottle_poly_count += draw_wing (0.4, 0.95, 0.02, wire);
          glPopMatrix();
        }
      glTranslatef (0, -0.1, 0);  /* move floor down a little */
    }


  have_texture = !wire && load_texture (mi, table_tex);
  glMaterialfv (GL_FRONT, GL_AMBIENT_AND_DIFFUSE, table_color);
  bp->bottle_poly_count += draw_table (top_slice->elevation, wire);


  glPopMatrix ();
  glDisable (GL_TEXTURE_2D);   /* done with textured objects */
  glEndList ();
}
Beispiel #12
0
int your_test(int argc, char **argv)
{
    int done=0;

    /* check args */
    if(argc!=2)
    {
        fprintf(stderr,"%s file.ttf\n",argv[0]);
        return 1;
    }

    /* initialize the cache to NULL */
    memset(text,0,sizeof(text));

    /* start SDL video */
    if(SDL_Init(SDL_INIT_VIDEO)==-1)
    {
        printf("SDL_Init: %s\n",SDL_GetError());
        return 1;
    }
    atexit(SDL_Quit); /* remember to quit SDL */

    /* open the screen */
    if(!(screen=SDL_SetVideoMode(1200,1000,0,0)))
    {
        printf("SDL_SetVideoMode: %s\n",SDL_GetError());
        return 1;
    }

    /* allow for key repeat (so the user can hold down a key...) */
    SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);

    /* start SDL_ttf */
    if(TTF_Init()==-1)
    {
        printf("TTF_Init: %s\n", TTF_GetError());
        return 2;
    }
    atexit(TTF_Quit); /* remember to quit SDL_ttf */
    atexit(free_font); /* remember to free any loaded font and glyph cache */

    while(!done)
    {
        SDL_Event event;
        static int x=0, y=0, need_draw=1,last_size=0, last_start_glyph=-1;

        /* smartly load font and generate new glyph cache (font_size change) */
        if(last_size!=font_size)
        {
            if(font_size<1)
                font_size=1;
            load_font(argv[1], font_size);
            need_draw=1;
            last_size=font_size;
        }
        /* smartly generate new glyph cache (page change) */
        if(last_start_glyph!=start_glyph)
        {
            cache_glyphs();
            need_draw=1;
            last_start_glyph=start_glyph;
        }
        /* smartly redraw as needed */
        if(need_draw)
        {
            SDL_FillRect(screen,0,~0);
            draw_table(x,y);
            SDL_Flip(screen);
            need_draw=0;
        }
        /* wait for events and handle them */
        /* this waits for one, then handles all that are queued before finishing */
        if(SDL_WaitEvent(&event))
            do {
                switch(event.type)
                {
                case SDL_QUIT:
                    done=1;
                    break;
                case SDL_KEYDOWN:
                    switch(event.key.keysym.sym)
                    {
                    case '0':
                        start_glyph=0;
                        break;
                    case SDLK_LEFT:
                        start_glyph=(start_glyph+0x10000-0x80)&0xffff;
                        break;
                    case SDLK_RIGHT:
                        start_glyph=(start_glyph+0x80)&0xffff;
                        break;
                    case SDLK_UP:
                        font_size++;
                        break;
                    case SDLK_DOWN:
                        font_size--;
                        break;
                    case 'n':
                        style=TTF_STYLE_NORMAL;
                        last_start_glyph=-1;
                        break;
                    case 'b':
                        style^=TTF_STYLE_BOLD;
                        last_start_glyph=-1;
                        break;
                    case 'i':
                        style^=TTF_STYLE_ITALIC;
                        last_start_glyph=-1;
                        break;
                    case 'u':
                        style^=TTF_STYLE_UNDERLINE;
                        last_start_glyph=-1;
                        break;
                    case 's':
                        style^=TTF_STYLE_STRIKETHROUGH;
                        last_start_glyph=-1;
                        break;
                    case 'k':
                        kerning=!kerning;
                        printf("kerning=%d\n",kerning);
                        last_start_glyph=-1;
                        break;
                    case 'h':
                        hinting=(hinting+1)%4;
                        printf("hinting=%s\n",
                            hinting==0?"Normal":
                        hinting==1?"Light":
                        hinting==2?"Mono":
                        hinting==3?"None":
                        "Unknonwn");
                        last_start_glyph=-1;
                        break;
                    case '=':
                        ++outline;
                        printf("outline=%d\n",outline);
                        last_start_glyph=-1;
                        break;
                    case '-':
                        if(outline>0)
                            --outline;
                        printf("outline=%d\n",outline);
                        last_start_glyph=-1;
                        break;
                    case 'q':
                    case SDLK_ESCAPE:
                        done=1;
                        break;
                    default:
                        break;
                    }
                    break;
                case SDL_MOUSEMOTION:
                    if(event.motion.state)
                    {
                        x=event.motion.x;
                        y=event.motion.y;
                        need_draw=1;
                    }
                    break;
                case SDL_MOUSEBUTTONDOWN:
                    x=event.button.x;
                    y=event.button.y;
                    need_draw=1;
                    break;
                }
            } while(SDL_PollEvent(&event));
    } /* main loop */

    return 0;
}
Beispiel #13
0
GLvoid init_scene(GLvoid) {
  u_int* temp;

  temp = (u_int*) calloc(DIMS, sizeof(u_int));
  //  printf("allocated initial [%x]\n", temp);
  temp[0] = 0;
  temp[1] = 0;

  view_main = view_new(0,
		       VIEW_NONE,
		       GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT,
		       0, 0,
		       1, 1);
  view_main->draw_func = draw_scene;

  /*
    view_main->subviews[0] = view_new(0,
				    VIEW_FG | VIEW_BG | VIEW_ASPECT,
				    GL_DEPTH_BUFFER_BIT,
				    0.0, 0.0,
				    0.3, 0.3);
  view_main->subviews[0]->alpha = 0.5f;
  view_main->subviews[0]->draw_func = draw_static_board;
  */
  

  board* b11;
  board* b12;
  board* b13;
  board* b21;
  board* b22;
  board* b23;
  board* b31;
  board* b32;
  board* b33;

  b11 = read_2d("boards/red-star-p.board");
  b21 = read_2d("boards/red-saturn-p.board");
  //b31 = read_2d("boards/red-gear-p.board");
  b12 = read_2d("boards/red-gear-p.board");

  b22 = read_2d("boards/red-moon-p.board");

  //b32 = read_2d("boards/red-saturn-np.board");
  //b13 = read_2d("boards/red-star-p.board");
  //b23 = read_2d("boards/red-gear-np.board");
  //b33 = read_2d("boards/red-moon-p.board");

  //  board_rotate_2d(b2, 1);
  //  board_rotate_2d(b3, 3);
  //  board_rotate_2d(b4, 2);

  boards_stich_2d(b11, DIR_RIGHT, b12);
  // boards_stich_2d(b12, DIR_RIGHT, b13);
  boards_stich_2d(b21, DIR_RIGHT, b22);
  //boards_stich_2d(b22, DIR_RIGHT, b23);
  //boards_stich_2d(b31, DIR_RIGHT, b32);
  //boards_stich_2d(b32, DIR_RIGHT, b33);

  boards_stich_2d(b11, DIR_DOWN, b21);
  //boards_stich_2d(b21, DIR_DOWN, b31);
  boards_stich_2d(b12, DIR_DOWN, b22);
  //boards_stich_2d(b22, DIR_DOWN, b32);
  //boards_stich_2d(b13, DIR_DOWN, b23);
  //boards_stich_2d(b23, DIR_DOWN, b33);

  board_clean_stich(b11);
  board_clean_stich(b12);
  //board_clean_stich(b13);
  board_clean_stich(b21);
  board_clean_stich(b22);
  //board_clean_stich(b23);
  //board_clean_stich(b31);
  //board_clean_stich(b32);
  //board_clean_stich(b33);

  tile_clear_flag(b11->origin, TILE_CHECKED);
  tile_fill_coord(b11->origin, temp);

  //  exit(0);

  robots   = robots_new();
  robots_v = robots_new();

  origin = b11->origin;
  cursor = origin;

  place_robot(COLOR_RED, origin);
  place_robot(COLOR_GREEN, origin->tile_p[DIR_RIGHT]);
  place_robot(COLOR_BLUE, origin->tile_p[DIR_DOWN]);
  place_robot(COLOR_YELLOW, origin->tile_p[DIR_RIGHT]->tile_p[DIR_RIGHT]);
  place_robot(COLOR_BLACK, origin->tile_p[DIR_DOWN]->tile_p[DIR_DOWN]);

  textures = (GLuint*) calloc(TEXTURES, sizeof(GLuint));
  if (textures == NULL)
    pexit(errno, "init_scene: can't allocate texture array");

  textures[TEXTURE_TILE] = gl_load_texture_png("gfx/tile.png", 0);
  textures[TEXTURE_MARK_MOON_RED]    = gl_load_texture_png("gfx/mark_moon_red.png", 1);
  textures[TEXTURE_MARK_MOON_GREEN]  = gl_load_texture_png("gfx/mark_moon_green.png", 1);
  textures[TEXTURE_MARK_MOON_BLUE]   = gl_load_texture_png("gfx/mark_moon_blue.png", 1);
  textures[TEXTURE_MARK_MOON_YELLOW] = gl_load_texture_png("gfx/mark_moon_yellow.png", 1);
  textures[TEXTURE_MARK_STAR_RED]    = gl_load_texture_png("gfx/mark_star_red.png", 1);
  textures[TEXTURE_MARK_STAR_GREEN]  = gl_load_texture_png("gfx/mark_star_green.png", 1);
  textures[TEXTURE_MARK_STAR_BLUE]   = gl_load_texture_png("gfx/mark_star_blue.png", 1);
  textures[TEXTURE_MARK_STAR_YELLOW] = gl_load_texture_png("gfx/mark_star_yellow.png", 1);
  textures[TEXTURE_MARK_SATURN_RED]    = gl_load_texture_png("gfx/mark_saturn_red.png", 1);
  textures[TEXTURE_MARK_SATURN_GREEN]  = gl_load_texture_png("gfx/mark_saturn_green.png", 1);
  textures[TEXTURE_MARK_SATURN_BLUE]   = gl_load_texture_png("gfx/mark_saturn_blue.png", 1);
  textures[TEXTURE_MARK_SATURN_YELLOW] = gl_load_texture_png("gfx/mark_saturn_yellow.png", 1);
  textures[TEXTURE_MARK_GEAR_RED]    = gl_load_texture_png("gfx/mark_gear_red.png", 1);
  textures[TEXTURE_MARK_GEAR_GREEN]  = gl_load_texture_png("gfx/mark_gear_green.png", 1);
  textures[TEXTURE_MARK_GEAR_BLUE]   = gl_load_texture_png("gfx/mark_gear_blue.png", 1);
  textures[TEXTURE_MARK_GEAR_YELLOW] = gl_load_texture_png("gfx/mark_gear_yellow.png", 1);
  textures[TEXTURE_MARK_WARP]        = gl_load_texture_png("gfx/mark_warp.png", 1);

  glNewList(DRAW_LIST_TABLE, GL_COMPILE);
  draw_table();
  glEndList();

  tile_clear_flag(origin, TILE_DRAWN);
  glNewList(DRAW_LIST_TILE, GL_COMPILE);
  draw_tile(origin, DIR_LEFT, DRAW_TILE, 1.0f);
  glEndList();

  tile_clear_flag(origin, TILE_DRAWN);
  glNewList(DRAW_LIST_TILE_TRANS, GL_COMPILE);
  draw_tile(origin, DIR_LEFT, DRAW_TILE, 0.75f);
  glEndList();

  tile_clear_flag(origin, TILE_DRAWN);
  glNewList(DRAW_LIST_MARK, GL_COMPILE);
  glDisable(GL_DEPTH_TEST);
  draw_tile(origin, DIR_LEFT, DRAW_MARK, 1.0f);
  glEnable(GL_DEPTH_TEST);
  glEndList();

  tile_clear_flag(origin, TILE_DRAWN);
  glNewList(DRAW_LIST_MARK_TRANS, GL_COMPILE);
  glDisable(GL_DEPTH_TEST);
  draw_tile(origin, DIR_LEFT, DRAW_MARK, 0.75f);
  glEnable(GL_DEPTH_TEST);
  glEndList();

  tile_clear_flag(origin, TILE_DRAWN);
  glNewList(DRAW_LIST_WALL, GL_COMPILE);
  draw_tile(origin, DIR_LEFT, DRAW_WALL, 1.0f);
  glEndList();

  tile_clear_flag(origin, TILE_DRAWN);
  glNewList(DRAW_LIST_PRISM, GL_COMPILE);
  draw_tile(origin, DIR_LEFT, DRAW_PRISM, 1.0f);
  glEndList();

  compile_robots();
}
Beispiel #14
0
ENTRYPOINT void 
init_sonar (ModeInfo *mi)
{
  sonar_configuration *sp;
  int wire = MI_IS_WIREFRAME(mi);

  if (!sps) {
    sps = (sonar_configuration *)
      calloc (MI_NUM_SCREENS(mi), sizeof (sonar_configuration));
    if (!sps) {
      fprintf(stderr, "%s: out of memory\n", progname);
      exit(1);
    }
  }
  sp = &sps[MI_SCREEN(mi)];
  sp->glx_context = init_GL(mi);

  reshape_sonar (mi, MI_WIDTH(mi), MI_HEIGHT(mi));
  clear_gl_error(); /* WTF? sometimes "invalid op" from glViewport! */

  if (!wire)
    {
      GLfloat pos[4] = {0.05, 0.07, 1.00, 0.0};
      GLfloat amb[4] = {0.2, 0.2, 0.2, 1.0};
      GLfloat dif[4] = {1.0, 1.0, 1.0, 1.0};
      GLfloat spc[4] = {0.0, 1.0, 1.0, 1.0};

      glEnable(GL_TEXTURE_2D);
      glEnable(GL_LIGHTING);
      glEnable(GL_LIGHT0);
      glEnable(GL_CULL_FACE);
      glEnable(GL_DEPTH_TEST);
      glEnable(GL_NORMALIZE);
      glEnable(GL_LINE_SMOOTH);
      glEnable(GL_BLEND);
      glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
      glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
      glShadeModel(GL_SMOOTH);

      glLightfv(GL_LIGHT0, GL_POSITION, pos);
      glLightfv(GL_LIGHT0, GL_AMBIENT,  amb);
      glLightfv(GL_LIGHT0, GL_DIFFUSE,  dif);
      glLightfv(GL_LIGHT0, GL_SPECULAR, spc);
    }

  sp->trackball = gltrackball_init ();
  sp->rot = make_rotator (0, 0, 0, 0, speed * 0.003, True);

  sp->texfont = load_texture_font (MI_DISPLAY(mi), "font");
  check_gl_error ("loading font");

  sp->table_list = glGenLists (1);
  glNewList (sp->table_list, GL_COMPILE);
  sp->table_polys = draw_table (mi);
  glEndList ();

  sp->screen_list = glGenLists (1);
  glNewList (sp->screen_list, GL_COMPILE);
  sp->screen_polys = draw_screen (mi, False, False);
  glEndList ();

  sp->grid_list = glGenLists (1);
  glNewList (sp->grid_list, GL_COMPILE);
  sp->grid_polys = draw_screen (mi, True,  False);
  glEndList ();

  sp->sweep_list = glGenLists (1);
  glNewList (sp->sweep_list, GL_COMPILE);
  sp->sweep_polys = draw_screen (mi, False, True);
  glEndList ();

  sp->start_time = double_time ();
  sp->sweep_offset = random() % 60;
  sp->sweep_th = -1;
}