Exemple #1
0
static unsigned long
compass_draw (Display *dpy, Window window, void *closure)
{
  struct state *st = (struct state *) closure;
  XFillRectangle (st->dpy, st->b, st->erase_gc, 0, 0, st->xgwa.width, st->xgwa.height);

  draw_compass (st);
  draw_pointer (st);

#ifdef HAVE_DOUBLE_BUFFER_EXTENSION
  if (st->backb)
    {
      XdbeSwapInfo info[1];
      info[0].swap_window = st->window;
      info[0].swap_action = XdbeUndefined;
      XdbeSwapBuffers (st->dpy, info, 1);
    }
  else
#endif /* HAVE_DOUBLE_BUFFER_EXTENSION */
    if (st->dbuf)
      {
        XCopyArea (st->dpy, st->b, st->window, st->erase_gc, 0, 0,
                   st->size2, st->size2,
                   st->xgwa.width/2 - st->x,
                   st->xgwa.height/2 - st->y);
        st->b = (st->b == st->ba ? st->bb : st->ba);
      }

  return st->delay;
}
Exemple #2
0
/**
* "Got frame" callback.
* Fills the texture with the given frame, and displays it on the window.
*/
int video_display_frame(uint8_t* frame, int width, int height, int size) {

	//if we get a NULL frame, stop displaying.
	if(frame == NULL) {
		video_display_clean();
		return 0;
	}

	//first time called ? Initialize things.
	if(!initialized) {
		if(video_display_init_size(width, height) < 0) {
			fprintf(stderr, "Display : Failed initialization.\n");
			return -1;
		}
		if(video_display_set_size(width, height) < 0)
			return -1;

		initialized = 1;
	}

	//check whether the size of the video has changed
	if(width != current_width || height != current_height)
		if(video_display_set_size(width, height) < 0)
			return -1;
			
	//check whether there's new stuff in the input com buffer
	double new_update = jakopter_com_get_timestamp(com_in);
	if(new_update > prev_update) {
		update_infos();
		prev_update = new_update;
	}

	//update the texture with our new frame
	if(SDL_UpdateTexture(frameTex, NULL, frame, width) < 0) {
		fprintf(stderr, "Display : failed to update frame texture : %s\n", SDL_GetError());
		return -1;
	}

	//clear the renderer, then update it so that we get the new frame displayed.
	SDL_RenderClear(renderer);
	SDL_RenderCopy(renderer, frameTex, NULL, NULL);
	//SDL_RenderFillRect(renderer, &rectangle);
	//draw all overlay elements, when they exist
	int i=0;
	for(i=0 ; i<VIDEO_NB_NAV_INFOS ; i++)
		if(graphs[i].tex != NULL)
			SDL_RenderCopy(renderer, graphs[i].tex, NULL, &graphs[i].pos);
	draw_attitude_indic();
	draw_compass();
	SDL_RenderPresent(renderer);

	return 0;
}
Exemple #3
0
int display_minimap_handler(window_info *win)
{
	float zoom_multip;
	float size_x = float_minimap_size / (tile_map_size_x * 6);
	float size_y = float_minimap_size / (tile_map_size_y * 6);
	float px = 0.0f, py = 0.0f;
	actor *me;
	float x,y;
	int i;

	if(win->pos_x > window_width - 50)
		move_window(minimap_win,win->pos_id,win->pos_loc,window_width-minimap_size,win->pos_y);
	if(win->pos_y > window_height - 50)
		move_window(minimap_win,win->pos_id,win->pos_loc,win->pos_x,window_height-minimap_size);

	if (enable_controls)
	{
		draw_minimap_title_bar(win);
		enable_controls = 0;
	}
	
	zoom_multip = minimap_get_zoom();

	if(!minimap_texture) 
	{
		//there's no minimap for this map :( draw a X
		glTranslatef(0.0f, 16.0f, 0.0f);
		glPushMatrix(); 
		glDisable(GL_TEXTURE_2D);
		//draw black background
		glColor3f(0.0f,0.0f,0.0f);
		glBegin(GL_POLYGON);
		for (i=0; i<=360; i +=10) 
		{
			x = sin((i)*0.0174532925f)/2*float_minimap_size+float_minimap_size/2;
			y = cos((i)*0.0174532925f)/2*float_minimap_size+float_minimap_size/2;
			glVertex2f(x, y);	
		}
		glEnd();

		glPopMatrix();
		draw_compass();
		return 0;
	}
	//draw minimap

	//get player position in window coordinates
	if( (me = get_our_actor ()) == NULL)
	{
		//Don't know who we are? can't draw then
		return 0;
	}
	px = me->x_tile_pos * size_x;
	py = float_minimap_size - (me->y_tile_pos * size_y);

	glTranslatef(0.0f, 16.0f, 0.0f);

	glDisable(GL_TEXTURE_2D);
	//draw black background
	glColor3f(0.0f,0.0f,0.0f);
	glBegin(GL_POLYGON);
	for (i=0; i<=360; i +=10) 
	{
		x = sin((i)*0.0174532925f)/2*float_minimap_size+float_minimap_size/2;
		y = cos((i)*0.0174532925f)/2*float_minimap_size+float_minimap_size/2;
		glVertex2f(x, y);	
	}
	glEnd();

	draw_map(win,zoom_multip, px, py);
	draw_actor_points(zoom_multip, px, py);


#ifdef OPENGL_TRACE
CHECK_GL_ERRORS();
#endif //OPENGL_TRACE

	return 0;
}
Exemple #4
0
static __inline__ void draw_map(window_info *win,float zoom_multip, float px, float py)
{
	float sx = 0.0f, sy = 0.0f;
	int i;
	float x, y;

	glPushMatrix();

	sx = float_minimap_size/2;
	sy = float_minimap_size/2;

	glTranslatef(sx, sy, 0.0f);

	glClearStencil(0);
	glClear(GL_STENCIL_BUFFER_BIT);
	glEnable(GL_STENCIL_TEST);
	glStencilFunc(GL_ALWAYS, 1, 1); 
	glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
	glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
	glDepthMask(GL_FALSE);

	glColor3f(0.0f,0.0f,0.0f);
	glBegin(GL_POLYGON);
		for (i=0; i<=360; i +=10) 
		{
			x = sin((i)*0.0174532925f)/2*float_minimap_size;
			y = cos((i)*0.0174532925f)/2*float_minimap_size;
			glVertex2f(x, y);	
		}
		glEnd();

	glStencilFunc(GL_EQUAL, 1, 1);
	glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);

	// re-enable the drawing in the current buffer
	glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
	glDepthMask(GL_TRUE);

	glEnable(GL_TEXTURE_2D);

	//draw the map
#ifdef	NEW_TEXTURES
	bind_texture(minimap_texture);
#else	/* NEW_TEXTURES */
	bind_texture_id(minimap_texture);
#endif	/* NEW_TEXTURES */
	glColor4f(1.0f,1.0f,1.0f,1.0f);

	rotate_at_player(zoom_multip,px,py);
	glBegin(GL_QUADS);
#ifdef	NEW_TEXTURES
		glTexCoord2f(0.0f, 1.0f);
		glVertex2f(-float_minimap_size/2, float_minimap_size/2);
		glTexCoord2f(1.0f, 1.0f);
		glVertex2f(float_minimap_size/2, float_minimap_size/2);
		glTexCoord2f(1.0f, 0.0f);
		glVertex2f(float_minimap_size/2, -float_minimap_size/2);
		glTexCoord2f(0.0f, 0.0f);
		glVertex2f(-float_minimap_size/2, -float_minimap_size/2);
#else	/* NEW_TEXTURES */
		glTexCoord2f(0.0f, 0.0f);
		glVertex2f(-float_minimap_size/2, float_minimap_size/2);
		glTexCoord2f(1.0f, 0.0f);
		glVertex2f(float_minimap_size/2, float_minimap_size/2);
		glTexCoord2f(1.0f, 1.0f);
		glVertex2f(float_minimap_size/2, -float_minimap_size/2);
		glTexCoord2f(0.0f, 1.0f);
		glVertex2f(-float_minimap_size/2, -float_minimap_size/2);
#endif	/* NEW_TEXTURES */
	glEnd();

	glDisable(GL_STENCIL_TEST);

	glPopMatrix();
	if (compass_tex) 
	{
		//draw the compass texture
		draw_compass();
	}
}
Exemple #5
0
int video_display_process(uint8_t* frame, int width, int height, int size) {

	//if we get a NULL frame, stop displaying.
	if(frame == NULL) {
		video_display_destroy();
		return 0;
	}

	//first time called ? Initialize things.
	if(!initialized) {
		if(video_display_init_size(width, height) < 0) {
			fprintf(stderr, "[~][Display] Failed initialization.\n");
			return -1;
		}
		if(video_display_set_size(width, height) < 0)
			return -1;
		initialized = 1;
	}

	//check whether the size of the video has changed
	if (width != current_width || height != current_height)
		if (video_display_set_size(width, height) < 0)
			return -1;

	//check whether there's new stuff in the input com buffer
	double new_update = jakopter_com_get_timestamp(com_in);
	if (new_update > prev_update) {
		update_infos();
		if (want_screenshot) {
			take_screenshot(frame, size);
			want_screenshot = 0;
			jakopter_com_write_int(com_in, 24, 0);
		}
		prev_update = new_update;
	}
	pthread_mutex_lock(&mutex_process);

	if (current_process != NULL) {
		current_process(frame, width, height, size);
	}
	pthread_mutex_unlock(&mutex_process);

	unload_element();

	if (load_element() < 0)
		fprintf(stderr, "Couldn't load graphic element\n");

	// update the texture with our new frame
	if (SDL_UpdateTexture(frameTex, NULL, frame, width) < 0) {
		fprintf(stderr, "[~][Display] Failed to update frame texture : %s\n", SDL_GetError());
		return -1;
	}

	//clear the renderer, then update it so that we get the new frame displayed.
	SDL_RenderClear(renderer);
	SDL_RenderCopy(renderer, frameTex, NULL, NULL);
	//SDL_RenderFillRect(renderer, &rectangle);
	//draw all overlay elements, when they exist
	int i = 0;
	for (i = 0 ; i < VIDEO_NB_NAV_INFOS ; i++)
		if (graphs[i].tex != NULL)
			SDL_RenderCopy(renderer, graphs[i].tex, NULL, &graphs[i].pos);

	pthread_mutex_lock(&mutex_graphics_list);
	struct graphics_list *current = icon_registry;
	while (current != NULL) {
		if (current->graphic != NULL && current->graphic->tex != NULL){
			int ret = SDL_RenderCopy(renderer, current->graphic->tex, NULL, &current->graphic->pos);
			if (ret < 0)
				fprintf(stderr, "[~][display] RenderCopy() failed: %s\n", SDL_GetError());
		}

		current = current->next;
	}
	pthread_mutex_unlock(&mutex_graphics_list);

	draw_attitude_indic();
	draw_compass();
	SDL_RenderPresent(renderer);

	return 0;
}