Esempio n. 1
0
void  render_handler_nui::draw_bitmap(
                                      const gameswf::matrix& m,
                                      const gameswf::bitmap_info* bi,
                                      const gameswf::rect& coords,
                                      const gameswf::rect& uv_coords,
                                      gameswf::rgba color)
                                      // Draw a rectangle textured with the given bitmap, with the
                                      // given color.   Apply given transform; ignore any currently
                                      // set transforms.
                                      //
                                      // Intended for textured glyph rendering.
{
  assert(bi);
  const bitmap_info_nui* pbi = (bitmap_info_nui*)bi;

  apply_color(color);

  gameswf::point a, b, c, d;
  m.transform(&a, gameswf::point(coords.m_x_min, coords.m_y_min));
  m.transform(&b, gameswf::point(coords.m_x_max, coords.m_y_min));
  m.transform(&c, gameswf::point(coords.m_x_min, coords.m_y_max));
  d.m_x = b.m_x + c.m_x - a.m_x;
  d.m_y = b.m_y + c.m_y - a.m_y;

  mpContext->SetFillColor(nuiColor(color.m_r, color.m_g, color.m_b, color.m_a));
  mpContext->SetCurrentTexture(pbi->mpTexture);
  mpContext->EnableTexturing(true);
  nuiRect src(uv_coords.m_x_min, uv_coords.m_y_min, uv_coords.m_x_max, uv_coords.m_y_max, false);
  mpContext->DrawImageQuad(a.m_x, a.m_y, b.m_x, b.m_y, c.m_x, c.m_y, d.m_x, d.m_y, src);
/*
  glBindTexture(GL_TEXTURE_2D, bi->m_texture_id);
  glEnable(GL_TEXTURE_2D);
  glDisable(GL_TEXTURE_GEN_S);
  glDisable(GL_TEXTURE_GEN_T);

  glBegin(GL_TRIANGLE_STRIP);

  glTexCoord2f(uv_coords.m_x_min, uv_coords.m_y_min);
  glVertex2f(a.m_x, a.m_y);

  glTexCoord2f(uv_coords.m_x_max, uv_coords.m_y_min);
  glVertex2f(b.m_x, b.m_y);

  glTexCoord2f(uv_coords.m_x_min, uv_coords.m_y_max);
  glVertex2f(c.m_x, c.m_y);

  glTexCoord2f(uv_coords.m_x_max, uv_coords.m_y_max);
  glVertex2f(d.m_x, d.m_y);

  glEnd();
*/
}
	void	draw_bitmap(
		const gameswf::matrix& m,
		gameswf::bitmap_info* bi,
		const gameswf::rect& coords,
		const gameswf::rect& uv_coords,
		gameswf::rgba color)
	// Draw a rectangle textured with the given bitmap, with the
	// given color.	 Apply given transform; ignore any currently
	// set transforms.
	//
	// Intended for textured glyph rendering.
	{
		assert(bi);

		apply_color(color);

		gameswf::point a, b, c, d;
		m.transform(&a, gameswf::point(coords.m_x_min, coords.m_y_min));
		m.transform(&b, gameswf::point(coords.m_x_max, coords.m_y_min));
		m.transform(&c, gameswf::point(coords.m_x_min, coords.m_y_max));
		d.m_x = b.m_x + c.m_x - a.m_x;
		d.m_y = b.m_y + c.m_y - a.m_y;

		bi->layout();
//		glBindTexture(GL_TEXTURE_2D, bi->m_texture_id);
//		glEnable(GL_TEXTURE_2D);

		glDisable(GL_TEXTURE_GEN_S);
		glDisable(GL_TEXTURE_GEN_T);

		glBegin(GL_TRIANGLE_STRIP);

		glTexCoord2f(uv_coords.m_x_min, uv_coords.m_y_min);
		glVertex2f(a.m_x, a.m_y);

		glTexCoord2f(uv_coords.m_x_max, uv_coords.m_y_min);
		glVertex2f(b.m_x, b.m_y);

		glTexCoord2f(uv_coords.m_x_min, uv_coords.m_y_max);
		glVertex2f(c.m_x, c.m_y);

		glTexCoord2f(uv_coords.m_x_max, uv_coords.m_y_max);
		glVertex2f(d.m_x, d.m_y);

		glEnd();
	}
	void	draw_bitmap(
		const gameswf::matrix& m,
		gameswf::bitmap_info* bi,
		const gameswf::rect& coords,
		const gameswf::rect& uv_coords,
		gameswf::rgba color)
	// Draw a rectangle textured with the given bitmap, with the
	// given color.	 Apply given transform; ignore any currently
	// set transforms.
	//
	// Intended for textured glyph rendering.
	{
		assert(bi);
		bi->layout();

		apply_color(color);

		gameswf::point a, b, c, d;
		m.transform(&a, gameswf::point(coords.m_x_min, coords.m_y_min));
		m.transform(&b, gameswf::point(coords.m_x_max, coords.m_y_min));
		m.transform(&c, gameswf::point(coords.m_x_min, coords.m_y_max));
		d.m_x = b.m_x + c.m_x - a.m_x;
		d.m_y = b.m_y + c.m_y - a.m_y;

		GLfloat squareVertices[8];
		squareVertices[0] = a.m_x;
		squareVertices[1] = a.m_y;
		squareVertices[2] = b.m_x;
		squareVertices[3] = b.m_y;
		squareVertices[4] = c.m_x;
		squareVertices[5] = c.m_y;
		squareVertices[6] = d.m_x;
		squareVertices[7] = d.m_y;
	
		GLfloat squareTextureCoords[8];
		squareTextureCoords[0] = uv_coords.m_x_min;
		squareTextureCoords[1] = uv_coords.m_y_min;
		squareTextureCoords[2] = uv_coords.m_x_max;
		squareTextureCoords[3] = uv_coords.m_y_min;
		squareTextureCoords[4] = uv_coords.m_x_min;
		squareTextureCoords[5] = uv_coords.m_y_max;
		squareTextureCoords[6] = uv_coords.m_x_max;
		squareTextureCoords[7] = uv_coords.m_y_max;

		glEnableClientState(GL_TEXTURE_COORD_ARRAY);
		glTexCoordPointer(2, GL_FLOAT, 0, squareTextureCoords);

		glEnableClientState(GL_VERTEX_ARRAY);
		glVertexPointer(2, GL_FLOAT, 0, squareVertices);

		glEnable(GL_LINE_SMOOTH);
		glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
		glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);

		glDisable(GL_LINE_SMOOTH);

		glDisableClientState(GL_TEXTURE_COORD_ARRAY);
		glDisableClientState(GL_VERTEX_ARRAY);

		glDisable(GL_TEXTURE_2D);
	}