Ejemplo n.º 1
0
Archivo: draw.cpp Proyecto: kekimmo/tuk
void draw_tile (const Level& level, int x, int y, const Textures& tex, int texture_size) {
  const Tile& tile = level.tile(x, y);

  // Draw floor underneath anyway
  draw_texture(texture_size * x, texture_size * y, tex.floor, texture_size);

  if (tile.type == Tile::WALL) {
    auto w = [&level](int x, int y) {
      return level.valid(x, y) && level.tile(x, y).type == Tile::WALL;
    };

    struct { int x; int y; } c[4][3] = {
      {
        { -1,  0 },
        { -1, -1 },
        {  0, -1 },
      },
      {
        {  0, -1 },
        {  1, -1 },
        {  1,  0 },
      },
      {
        {  1,  0 },
        {  1,  1 },
        {  0,  1 },
      },
      {
        {  0,  1 },
        { -1,  1 },
        { -1,  0 },
      },
    };

    struct { int dx; int dy; } where[4] = {
      { 0, 0 },
      { 1, 0 },
      { 1, 1 },
      { 0, 1 },
    };

    for (int i = 0; i < 4; ++i) {
      int p = 0;
      int bit = 1;
      for (int j = 0; j < 3; ++j) {
        if (w(x + c[i][j].x, y + c[i][j].y)) {
          p |= bit;
        }
        bit <<= 1;
      }

      const int tx = x * texture_size + where[i].dx * texture_size / 2;
      const int ty = y * texture_size + where[i].dy * texture_size / 2;

      draw_texture(tx, ty, tex.wall_parts[p], texture_size / 2, false, i * 90);
    }
  }
}
Ejemplo n.º 2
0
void player_draw(Player* plr) {
	draw_enemies(plr->slaves);
	
	glPushMatrix();
		glTranslatef(creal(plr->pos), cimag(plr->pos), 0);
		
		if(plr->focus != 0) {
			glPushMatrix();
				glRotatef(global.frames*10, 0, 0, 1);
				glScalef(1, 1, 1);
				glColor4f(1,1,1,0.2);
				draw_texture(0, 0, "fairy_circle");
				glColor4f(1,1,1,1);
			glPopMatrix();
		}
					
		glDisable(GL_CULL_FACE);
		if(plr->dir) {
			glPushMatrix();
			glScalef(-1,1,1);
		}
		
		int clr_changed = 0;
		
		if(global.frames - abs(plr->recovery) < 0 && (global.frames/8)&1) {
			glColor4f(0.4,0.4,1,0.9);
			clr_changed = 1;
		}
				
		draw_animation_p(0, 0, !plr->moving, player_get_ani(plr->cha));
		
		if(clr_changed)
			glColor3f(1,1,1);
		
		if(plr->dir)
			glPopMatrix();
		
		glEnable(GL_CULL_FACE);
		
		if(plr->focus != 0) {
			glPushMatrix();
				glColor4f(1,1,1,fabs((float)plr->focus/30.0f));
				glRotatef(global.frames, 0, 0, -1);
				draw_texture(0, 0, "focus");
				glColor4f(1,1,1,1);
			glPopMatrix();
		}
		
	glPopMatrix();
}
Ejemplo n.º 3
0
//Draw textures within the m_texture_planes[plane_id].
void mgTLData::drawt_texture_image_part(
	const MGTextureImages& teximage,	//texture image data.
	const double back_color[4],	//back ground color data.
	int plane_id	//indicates if only parts of texture data be drawn.
		//let i1=m_texture_planes[plane_id]->index(), and i2=m_texture_planes[plane_id+1]->index().
		//Then rects of m_rects[i1] to m_rects[i2-1] are to be drawn.
)const{
	mgGDL::draw_texture_image_set_up(back_color);

	const mgTLTriangles& tris=triangles();
	mgTLTriangles::const_triIterator first=tris.begin(), last=tris.end();;
	const std::vector<mgTLTexPlane*>& texplanes=tlrects().texture_planes();
	int ntpls=texplanes.size();
	if(plane_id<ntpls){
		int i1=texplanes[plane_id]->index();
		const mgTLRect& recti=rect(i1);
		int tri_id1=rect(i1).triangle_id();
		first+=tri_id1;
		if(plane_id<ntpls-1){
			int i2=texplanes[plane_id+1]->index();
			int tri_id2=rect(i2).triangle_id();
			last=first+(tri_id2-tri_id1);
		}
	}
	draw_texture(teximage,first,last);

	mgGDL::draw_texture_image_end_up();
}
Ejemplo n.º 4
0
/** @brief Main in-game rendering routine.
 *
 *  @param b Board configuration to render.
 */
void draw_scene(board_t *b, GLuint fb, int reflections) {
	char temp[80];
	int clock_seconds = 0;
	int clock_minutes = 0;

	glBindFramebuffer(GL_FRAMEBUFFER, fb);

	transition_update();

	gg_dialog_cleanup();

	glDisable(GL_BLEND);
	glDepthFunc(GL_ALWAYS);

	draw_backdrop();

	glEnable(GL_BLEND);
	glDepthFunc(GL_LEQUAL);

	go_3d(get_screen_width(), get_screen_height());

	render_scene_3d(b, fb, reflections);
	mouse_square = find_square(get_true_mouse_x(), get_true_mouse_y());

	glBindFramebuffer(GL_FRAMEBUFFER, fb);
	resize_window(get_screen_width(), get_screen_height());

	glPushMatrix();

	draw_ui_elements();

	// draw_move_list(get_col(COL_WHITE), get_col(COL_YELLOW));
	// draw_capture_list(get_col(COL_WHITE));

	clock_minutes = (((SDL_GetTicks() - get_turn_counter()) / 1000) / 60);
	clock_seconds = ((SDL_GetTicks() - get_turn_counter()) / 1000) - (clock_minutes * 60);
	snprintf(temp, sizeof(temp), "%i:%02i", clock_minutes, clock_seconds);
	/*text_draw_string( 303, 440, temp, 1, &col_black);*/
	glPopMatrix();

	/*if ( get_white_in_check() == TRUE )
		text_draw_string_bouncy( 180, 420, "White is in check!", 1, get_col(COL_WHITE));
	else if ( get_black_in_check() == TRUE )
		text_draw_string_bouncy( 180, 420, "Black is in check!", 1, get_col(COL_WHITE));*/

	gg_dialog_render_all();

	if (get_fading_out()) {
		if (!draw_fade(FADE_OUT))
			set_switch_to_menu(TRUE);
	} else {
		if (get_show_egg())
			draw_sonic_fade(FADE_IN);
		else
			draw_fade(FADE_IN);
	}

	/* Draw mouse cursor.. */
	draw_texture(get_mouse_cursor(), get_mouse_x(), (479 - get_mouse_y() - 32), 32, 32, 1.0f, get_col(COL_WHITE));
}
Ejemplo n.º 5
0
void App::render_bloom_combine(clan::Canvas &canvas, clan::Texture2D &tex_base, clan::Texture2D &tex_bloom, clan::ProgramObject &program_object)
{
	canvas.flush();
	clan::GraphicContext gc = canvas.get_gc();

	gc.set_texture(0, tex_base);
	gc.set_texture(1, tex_bloom);

	gc.set_program_object(program_object);
	program_object.set_uniform1i(("BaseTexture"), 0);
	program_object.set_uniform1f(("BaseIntensity"), base_intensity);
	program_object.set_uniform1f(("BaseSaturation"), base_saturation);

	program_object.set_uniform1i(("BloomTexture"), 1);
	program_object.set_uniform1f(("BloomIntensity"), bloom_intensity);
	program_object.set_uniform1f(("BloomSaturation"), bloom_saturation);

	program_object.set_uniform_matrix("cl_ModelViewProjectionMatrix", canvas.get_projection() * canvas.get_transform());

	draw_texture(gc, clan::Rectf(0,0,canvas.get_width(),canvas.get_height()), clan::Rectf(0.0f, 0.0f, 1.0f, 1.0f));

	gc.reset_program_object();
	gc.reset_texture(0);
	gc.reset_texture(1);

}
Ejemplo n.º 6
0
void GLAPIENTRY
_mesa_DrawTexi(GLint x, GLint y, GLint z, GLint width, GLint height)
{
   GET_CURRENT_CONTEXT(ctx);
   draw_texture(ctx, (GLfloat) x, (GLfloat) y, (GLfloat) z,
                (GLfloat) width, (GLfloat) height);
}
Ejemplo n.º 7
0
void App::draw_cpu(clan::Canvas &canvas, clan::PixelBuffer &cpu_buffer, clan::PixelBuffer &tux, clan::Texture2D &texture_to_write_into, clan::Texture2D &texture_to_draw)
{
	upload_pixel_buffer(canvas, tux, cpu_buffer);
	texture_to_write_into.set_subimage(canvas, 0, 0, cpu_buffer, cpu_buffer.get_size());

	draw_texture(canvas, texture_to_draw, 32, 32);
}
Ejemplo n.º 8
0
void GLAPIENTRY
_mesa_DrawTexsOES(GLshort x, GLshort y, GLshort z, GLshort width, GLshort height)
{
   GET_CURRENT_CONTEXT(ctx);
   draw_texture(ctx, (GLfloat) x, (GLfloat) y, (GLfloat) z,
                (GLfloat) width, (GLfloat) height);
}
Ejemplo n.º 9
0
void GLAPIENTRY
_mesa_DrawTexsvOES(const GLshort *coords)
{
   GET_CURRENT_CONTEXT(ctx);
   draw_texture(ctx, (GLfloat) coords[0], (GLfloat) coords[1],
                (GLfloat) coords[2], (GLfloat) coords[3], (GLfloat) coords[4]);
}
Ejemplo n.º 10
0
void Renderer::draw_texture(TextureRef texture, const Vector2i &dst_pos, float angle)
{
    const Vector2i& size = texture->size();
    Recti src(size);
    Recti dst(dst_pos, size);

    draw_texture(texture, src, dst, angle);
}
Ejemplo n.º 11
0
void TouchScreenButton::_notification(int p_what) {

	switch(p_what) {

		case NOTIFICATION_DRAW: {

			if (!is_inside_tree())
				return;
			if (!get_tree()->is_editor_hint() && !OS::get_singleton()->has_touchscreen_ui_hint() && visibility==VISIBILITY_TOUCHSCREEN_ONLY)
				return;

			if (finger_pressed!=-1) {

				if (texture_pressed.is_valid())
					draw_texture(texture_pressed,Point2());
				else if (texture.is_valid())
					draw_texture(texture,Point2());

			} else {
				if (texture.is_valid())
					draw_texture(texture,Point2());
			}

		} break;
		case NOTIFICATION_ENTER_TREE: {

			if (!get_tree()->is_editor_hint() && !OS::get_singleton()->has_touchscreen_ui_hint() && visibility==VISIBILITY_TOUCHSCREEN_ONLY)
				return;
			update();

			if (!get_tree()->is_editor_hint())
				set_process_input(true);

			if (action.operator String()!="" && InputMap::get_singleton()->has_action(action)) {
				action_id=InputMap::get_singleton()->get_action_id(action);
			} else {
				action_id=-1;
			}
		} break;
		case NOTIFICATION_EXIT_TREE: {
			if (is_pressed())
				Input::get_singleton()->action_release(action);
		} break;
	}
}
Ejemplo n.º 12
0
void youmu_common_particle_slice_draw(Projectile *p, int t) {
    float f = p->args[1]/p->args[0]*20.0;
    glPushMatrix();
    glTranslatef(creal(p->pos), cimag(p->pos),0);
    glRotatef(p->angle/M_PI*180,0,0,1);
    glScalef(f,1,1);
    draw_texture(0,0,"part/youmu_slice");
    ProjDrawCore(p, p->color);
    glPopMatrix();
}
Ejemplo n.º 13
0
extern "C" void capture_dump_frames() {
  int i;
  for (i = 0; i < 10; i++) {
    fprintf(stderr, "capture_dump() %d\n", i);
    draw_texture(texids[i]);

    glReadPixels(0, 0, 1280, 720, GL_RGBA, GL_UNSIGNED_BYTE, pixelbuffer);
    framecapture_capframe(pixelbuffer);
  }
}
Ejemplo n.º 14
0
void SplitContainer::_notification(int p_what) {

	switch(p_what) {

		case NOTIFICATION_SORT_CHILDREN: {

			_resort();
		} break;
		case NOTIFICATION_MOUSE_ENTER: {
			mouse_inside=true;
			update();
		} break;
		case NOTIFICATION_MOUSE_EXIT: {
			mouse_inside=false;
			update();
		} break;
		case NOTIFICATION_DRAW: {

			if (!_getch(0) || !_getch(1))
				return;

			if (collapsed || (!mouse_inside && get_constant("autohide")))
				return;
			int sep=dragger_visible?get_constant("separation"):0;
			Ref<Texture> tex = get_icon("grabber");
			Size2 size=get_size();
			if (vertical) {

				//draw_style_box( get_stylebox("bg"), Rect2(0,middle_sep,get_size().width,sep));
				if (dragger_visible)
					draw_texture(tex,Point2i((size.x-tex->get_width())/2,middle_sep+(sep-tex->get_height())/2));

			} else {

				//draw_style_box( get_stylebox("bg"), Rect2(middle_sep,0,sep,get_size().height));
				if (dragger_visible)
					draw_texture(tex,Point2i(middle_sep+(sep-tex->get_width())/2,(size.y-tex->get_height())/2));

			}

		} break;
	}
}
Ejemplo n.º 15
0
void GLAPIENTRY
_mesa_DrawTexx(GLfixed x, GLfixed y, GLfixed z, GLfixed width, GLfixed height)
{
   GET_CURRENT_CONTEXT(ctx);
   draw_texture(ctx,
                (GLfloat) x / 65536.0f,
                (GLfloat) y / 65536.0f,
                (GLfloat) z / 65536.0f,
                (GLfloat) width / 65536.0f,
                (GLfloat) height / 65536.0f);
}
Ejemplo n.º 16
0
void GLAPIENTRY
_mesa_DrawTexxv(const GLfixed *coords)
{
   GET_CURRENT_CONTEXT(ctx);
   draw_texture(ctx,
                (GLfloat) coords[0] / 65536.0f,
                (GLfloat) coords[1] / 65536.0f,
                (GLfloat) coords[2] / 65536.0f,
                (GLfloat) coords[3] / 65536.0f,
                (GLfloat) coords[4] / 65536.0f);
}
Ejemplo n.º 17
0
void dc_capture_render(struct dc_capture *capture, effect_t effect)
{
	int last_tex = (capture->cur_tex > 0) ?
		capture->cur_tex-1 : capture->num_textures-1;

	if (!capture->valid)
		return;

	if (capture->textures_written[last_tex])
		draw_texture(capture, last_tex, effect);
}
Ejemplo n.º 18
0
	void View_list::draw(View* v, size_t slot_idx){
		Rect f = frame();

		const size_t text_size = slot_height;
		const size_t mark_width = 8;

		Text_texture *tex_gen = shared_text_texture();
		Size ts(list_width-mark_width, text_size);

		GLuint tex = tex_gen->generate(ts, v->name().c_str());

		if (is_visible(v)){
			color::hilight();
			draw_texture(0, 0, slot_idx*text_size+1, mark_width, ts.h-2);
		}

		color::text();
		draw_texture(tex, mark_width, slot_idx*text_size, ts.w, ts.h);

		glDeleteTextures(1,&tex);
	}
Ejemplo n.º 19
0
void GraphNode::_notification(int p_what) {

	if (p_what==NOTIFICATION_DRAW) {

		Ref<StyleBox> sb=get_stylebox("frame");
		Ref<Texture> port =get_icon("port");
		Ref<Texture> close =get_icon("close");
		int close_offset = get_constant("close_offset");
		Ref<Font> title_font = get_font("title_font");
		int title_offset = get_constant("title_offset");
		Color title_color = get_color("title_color");
		Point2i icofs = -port->get_size()*0.5;
		int edgeofs=get_constant("port_offset");
		icofs.y+=sb->get_margin(MARGIN_TOP);
		draw_style_box(sb,Rect2(Point2(),get_size()));

		int w = get_size().width-sb->get_minimum_size().x;

		if (show_close)
			w-=close->get_width();

		draw_string(title_font,Point2(sb->get_margin(MARGIN_LEFT),-title_font->get_height()+title_font->get_ascent()+title_offset),title,title_color,w);
		if (show_close) {
			Vector2 cpos = Point2(w+sb->get_margin(MARGIN_LEFT),-close->get_height()+close_offset);
			draw_texture(close,cpos);
			close_rect.pos=cpos;
			close_rect.size=close->get_size();
		} else {
			close_rect=Rect2();
		}

		for (Map<int,Slot>::Element *E=slot_info.front();E;E=E->next()) {

			if (E->key() < 0 || E->key()>=cache_y.size())
				continue;
			if (!slot_info.has(E->key()))
				continue;
			const Slot &s=slot_info[E->key()];
			//left
			if (s.enable_left)
				port->draw(get_canvas_item(),icofs+Point2(edgeofs,cache_y[E->key()]),s.color_left);
			if (s.enable_right)
				port->draw(get_canvas_item(),icofs+Point2(get_size().x-edgeofs,cache_y[E->key()]),s.color_right);

		}
	}

	if (p_what==NOTIFICATION_SORT_CHILDREN) {

		_resort();
	}

}
Ejemplo n.º 20
0
	bool CSurface::draw_sprite(const char* p_name, float x, float y, float sub_x, float sub_y, float sub_width, float sub_height)
	{
		glEnable(GL_ALPHA_TEST);
		glAlphaFunc(GL_GREATER, 0);		// alpha 值大于 0 的像素才会被绘制
		if (!draw_texture(p_name, x, y, sub_x, sub_y, sub_width, sub_height))
		{
			glDisable(GL_ALPHA_TEST);
			return false;
		}
		glDisable(GL_ALPHA_TEST);
		return true;
	}
Ejemplo n.º 21
0
void VFrame::draw_texture(int flip_y)
{
	draw_texture(0, 
		0,
		get_w(),
		get_h(),
		0,
		0,
		get_w(),
		get_h(),
		flip_y);
}
Ejemplo n.º 22
0
void DungeonMap::draw(sf::RenderTarget& target)
{
  const int mapPosX = config::GAME_RES_X / 2 - m_mapTexture->getSize().x / 2;
  const int mapPosY = config::GAME_RES_Y / 2 - m_mapTexture->getSize().y / 2;

  draw_frame(target, 0, 0, config::GAME_RES_X, config::GAME_RES_Y);
  draw_texture(target, m_mapTexture, mapPosX, mapPosY);
  m_minimap.draw(target);

  int left  = POS_X - 19;
  int right = POS_X + WIDTH + 19;
  int top   = POS_Y - 19;
  int bottom = POS_Y + HEIGHT + 19;

  int middle_x = config::GAME_RES_X / 2;
  int middle_y = config::GAME_RES_Y / 2;

  sf::Sprite sprite;
  sprite.setTexture(*m_arrowTexture);
  sprite.setOrigin(m_arrowTexture->getSize().x / 2, m_arrowTexture->getSize().y / 2);

  // RIGHT
  sprite.setPosition(right, middle_y);
  if (m_centerX < (m_map->getWidth() - 1))
  {
    target.draw(sprite);
  }

  // DOWN
  sprite.rotate(90);
  sprite.setPosition(middle_x, bottom);
  if (m_centerY < (m_map->getHeight() - 1))
  {
    target.draw(sprite);
  }

  // LEFT
  sprite.rotate(90);
  sprite.setPosition(left, middle_y);
  if (m_centerX > 0)
  {
    target.draw(sprite);
  }

  // UP
  sprite.rotate(90);
  sprite.setPosition(middle_x, top);
  if (m_centerY > 0)
  {
    target.draw(sprite);
  }
}
Ejemplo n.º 23
0
static void
render_fire (uint32_t time_offset, void *params, int iparam, viewpoint *view,
	     lighting *lights, int pass)
{
  if (pass == PVR_LIST_OP_POLY)
    draw_backdrop ();
  if (pass == PVR_LIST_TR_POLY)
    {
      draw_texture ();

      warp_active = 1 - warp_active;
    }
}
Ejemplo n.º 24
0
void SplitContainer::_notification(int p_what) {

	switch (p_what) {

		case NOTIFICATION_SORT_CHILDREN: {

			_resort();
		} break;
		case NOTIFICATION_MOUSE_ENTER: {

			mouse_inside = true;
			update();
		} break;
		case NOTIFICATION_MOUSE_EXIT: {

			mouse_inside = false;
			update();
		} break;
		case NOTIFICATION_DRAW: {

			if (!_getch(0) || !_getch(1))
				return;

			if (collapsed || (!mouse_inside && get_constant("autohide")))
				return;

			int sep = dragger_visibility != DRAGGER_HIDDEN_COLLAPSED ? get_constant("separation") : 0;
			Ref<Texture> tex = get_icon("grabber");
			Size2 size = get_size();
			if (dragger_visibility == DRAGGER_VISIBLE) {

				if (vertical)
					draw_texture(tex, Point2i((size.x - tex->get_width()) / 2, middle_sep + (sep - tex->get_height()) / 2));
				else
					draw_texture(tex, Point2i(middle_sep + (sep - tex->get_width()) / 2, (size.y - tex->get_height()) / 2));
			}
		} break;
	}
}
Ejemplo n.º 25
0
extern "C" void capture_dump_textures() {
  int i;
  for (i = 0; i < 100; i++) {
    if (glIsTexture(i)) {
      fprintf(stderr, "capture_dump_textures() %d\n", i);
      draw_texture(i);

      glReadPixels(0, 0, 1280, 720, GL_RGBA, GL_UNSIGNED_BYTE, pixelbuffer);

      texturecapture_captexture(i, PARENT, 10, 0, 0, 1280, 720, GL_RGBA,
                                GL_UNSIGNED_BYTE, pixelbuffer);
    }
  }
}
Ejemplo n.º 26
0
void App::draw_image(GraphicContext &gc, Texture &image, float xpos, float ypos, ProgramObject &program_object, Vec4f &draw_color_offset)
{
	program_object.set_uniform1i("SourceTexture", 0);
	program_object.set_uniform4f("color_offset", draw_color_offset);

	gc.set_texture(0, image);
	gc.set_program_object(program_object, cl_program_matrix_modelview_projection);

	draw_texture(gc, Rectf(xpos, ypos, Sizef(image.get_width(), image.get_height())), Colorf::white, Rectf(0.0f, 0.0f, 1.0f, 1.0f));

	gc.reset_program_object();
	gc.reset_texture(0);

}
Ejemplo n.º 27
0
void App::render_gaussian_blur(clan::Canvas &canvas, float blur_amount, clan::Texture2D &source_texture, clan::ProgramObject &program_object, float dx, float dy)
{
    uniforms.sample[0].weight = compute_gaussian(0, blur_amount);
    uniforms.sample[0].offset_x = 0.0f;
    uniforms.sample[0].offset_y = 0.0f;

    float totalWeights = uniforms.sample[0].weight;

    for (int i = 0; i < sampleCount / 2; i++)
    {
        float weight = compute_gaussian(i + 1.0f, blur_amount);

        uniforms.sample[i * 2 + 1].weight = weight;
        uniforms.sample[i * 2 + 2].weight = weight;

        totalWeights += weight * 2;

        float sampleOffset = i * 2 + 1.5f;

        clan::Vec2f delta(dx * sampleOffset, dy * sampleOffset);

        uniforms.sample[i * 2 + 1].offset_x = delta.x;
        uniforms.sample[i * 2 + 1].offset_y = delta.y;
        uniforms.sample[i * 2 + 2].offset_x = -delta.x;
        uniforms.sample[i * 2 + 2].offset_y = -delta.y;
    }

    for (int i = 0; i < sampleCount; i++)
    {
        uniforms.sample[i].weight /= totalWeights;
    }

    canvas.flush();
    clan::GraphicContext gc = canvas.get_gc();

    gc.set_texture(0, source_texture);
    gc.set_program_object(program_object);

    uniforms.cl_ModelViewProjectionMatrix = canvas.get_projection() * canvas.get_transform();
    gpu_uniforms.upload_data(gc, &uniforms, 1);
    gc.set_uniform_buffer(0, gpu_uniforms);

    draw_texture(gc, clan::Rectf(0,0,canvas.get_width(),canvas.get_height()), clan::Rectf(0.0f, 0.0f, 1.0f, 1.0f));

    gc.reset_program_object();
    gc.reset_texture(0);

}
Ejemplo n.º 28
0
bool App::update()
{
	clan::InputDevice keyboard = window.get_keyboard();

	if (keyboard.get_keycode(clan::keycode_escape))
		quit = true;
	uniforms.timer = (System::get_time() - startTime) / 1000.0f;

	// Uncomment this to make ball jump silly
	//float scale = (sinf(timer * 2.0f) + 1.1f);
	//ball.set_scale(scale, scale);

	// Render standard image to offscreen buffer

	background.draw(canvas_offscreen, 0, 0);
	ball.draw(canvas_offscreen, canvas.get_width() / 2 + 200 * sinf(uniforms.timer / 2.0f), canvas.get_height() / 2 + 200 * cosf(uniforms.timer / 2.0f));
	canvas_offscreen.flush();

	// Render offscreen buffer to screen using post process shader

	canvas.flush();
	clan::GraphicContext gc = canvas.get_gc();

	gc.set_texture(0, texture_offscreen);
	gc.set_program_object(shader);

	uniforms.cl_ModelViewProjectionMatrix = canvas.get_projection() * canvas.get_transform();
	gpu_uniforms.upload_data(gc, &uniforms, 1);
	gc.set_uniform_buffer(0, gpu_uniforms);

	draw_texture(gc, clan::Rectf(0,0,canvas.get_width(),canvas.get_height()), clan::Rectf(0.0f, 0.0f, 1.0f, 1.0f));

	gc.reset_program_object();
	gc.reset_texture(0);


	if(uniforms.timer > 2.0f)
	{
		uniforms.amount += 0.005f;
		if(uniforms.amount > 1.0f)
			uniforms.amount = 1.0f;
	}

	window.flip(1);

	return !quit;
}
Ejemplo n.º 29
0
void App::render_shockwave(clan::Canvas &canvas, clan::Texture2D &source_texture, clan::ProgramObject &program_object)
{
	canvas.flush();
	clan::GraphicContext gc = canvas.get_gc();

	gc.set_texture(0, source_texture);
	gc.set_program_object(program_object);

	uniforms.cl_ModelViewProjectionMatrix = canvas.get_projection() * canvas.get_modelview();
	gpu_uniforms.upload_data(gc, &uniforms, 1);
	gc.set_uniform_buffer(0, gpu_uniforms);

	draw_texture(gc, clan::Rectf(0,0,canvas.get_width(),canvas.get_height()), clan::Rectf(0.0f, 0.0f, 1.0f, 1.0f));

	gc.reset_program_object();
	gc.reset_texture(0);
}
Ejemplo n.º 30
0
void App::render_gaussian_blur(CL_GraphicContext &gc, float blur_amount, CL_Texture &source_texture, CL_ProgramObject &program_object, float dx, float dy)
{
	int sampleCount = 15;

	float *sampleWeights = new float[sampleCount];
	CL_Vec2f *sampleOffsets = new CL_Vec2f[sampleCount];

	sampleWeights[0] = compute_gaussian(0, blur_amount);
	sampleOffsets[0] = CL_Vec2f(0.0, 0.0);

	float totalWeights = sampleWeights[0];

	for (int i = 0; i < sampleCount / 2; i++)
	{
		float weight = compute_gaussian(i + 1.0f, blur_amount);

		sampleWeights[i * 2 + 1] = weight;
		sampleWeights[i * 2 + 2] = weight;

		totalWeights += weight * 2;

		float sampleOffset = i * 2 + 1.5f;

		CL_Vec2f delta = CL_Vec2f(dx * sampleOffset, dy * sampleOffset);

		sampleOffsets[i * 2 + 1] = delta;
		sampleOffsets[i * 2 + 2] = CL_Vec2f(-delta.x, -delta.y);
	}

	for (int i = 0; i < sampleCount; i++)
	{
		sampleWeights[i] /= totalWeights;
	}

	program_object.set_uniform1i("SourceTexture", 0);
	program_object.set_uniformfv("SampleOffsets", 2, sampleCount, (float *)sampleOffsets);
	program_object.set_uniformfv("SampleWeights", 1, sampleCount, sampleWeights);

	gc.set_texture(0, source_texture);
	gc.set_program_object(program_object, cl_program_matrix_modelview_projection);

	draw_texture(gc, CL_Rectf(0,0,gc.get_width(),gc.get_height()), CL_Colorf::white, CL_Rectf(0.0f, 0.0f, 1.0f, 1.0f));

	gc.reset_program_object();
	gc.reset_texture(0);
}