Пример #1
0
void Shape_Blitter::OGL_Draw(const Image_Rect& dst)
{
#ifdef HAVE_OPENGL
	// Set up texture
	TextureManager TMgr;
	TMgr.ShapeDesc = BUILD_DESCRIPTOR(m_coll, 0);
    TMgr.LowLevelShape = m_frame;
    extended_get_shape_bitmap_and_shading_table(m_coll, m_frame,  &TMgr.Texture, &TMgr.ShadingTables, _shading_normal);
	TMgr.IsShadeless = false;
	TMgr.TransferMode = _shadeless_transfer;
    
    switch (m_type)
    {
        case Shape_Texture_Wall:
            TMgr.TextureType = OGL_Txtr_Wall;
            break;
        case Shape_Texture_Landscape:
	  {
            TMgr.TextureType = OGL_Txtr_Landscape;
            LandscapeOptions *LandOpts = View_GetLandscapeOptions(TMgr.ShapeDesc);	
            TMgr.LandscapeVertRepeat = LandOpts->VertRepeat;
            TMgr.Landscape_AspRatExp = LandOpts->OGL_AspRatExp;
	  }
            break;
        case Shape_Texture_Sprite:
            TMgr.TextureType = OGL_Txtr_Inhabitant;
            break;
        case Shape_Texture_WeaponInHand:
        case Shape_Texture_Interface:
            TMgr.TextureType = OGL_Txtr_WeaponsInHand;
            break;
    }
	if (!TMgr.Setup())
		return;
    
	// Get dimensions
	GLdouble U_Scale = TMgr.U_Scale;
	GLdouble V_Scale = TMgr.V_Scale;
	GLdouble U_Offset = TMgr.U_Offset;
	GLdouble V_Offset = TMgr.V_Offset;
    
	// Draw shape
	if (Wanting_sRGB && TMgr.TextureType != OGL_Txtr_WeaponsInHand)
	{
		glEnable(GL_FRAMEBUFFER_SRGB_EXT);
		Using_sRGB = true;
	}
	SglColor4f(tint_color_r, tint_color_g, tint_color_b, tint_color_a);
	glEnable(GL_TEXTURE_2D);
    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	TMgr.SetupTextureMatrix();
	TMgr.RenderNormal();
    
    bool rotating = (rotation > 0.1 || rotation < -0.1);
	if (rotating)
	{
		glMatrixMode(GL_MODELVIEW);
		glPushMatrix();
		glTranslatef((dst.x + dst.w/2.0), (dst.y + dst.h/2.0), 0.0);
		glRotatef(rotation, 0.0, 0.0, 1.0);
		glTranslatef(-(dst.x + dst.w/2.0), -(dst.y + dst.h/2.0), 0.0);
	}

    if (m_type == Shape_Texture_Interface)
    {
        if (crop_rect.x > 0)
            U_Offset += crop_rect.x * U_Scale / static_cast<double>(m_scaled_src.w);
        if (crop_rect.y > 0)
            V_Offset += crop_rect.y * V_Scale / static_cast<double>(m_scaled_src.h);
        if (crop_rect.w < m_scaled_src.w)
            U_Scale *= crop_rect.w / static_cast<double>(m_scaled_src.w);
        if (crop_rect.h < m_scaled_src.h)
            V_Scale *= crop_rect.h / static_cast<double>(m_scaled_src.h);

		OGL_RenderTexturedRect(dst.x, dst.y, dst.w, dst.h,
							   U_Offset, V_Offset,
							   U_Offset + U_Scale,
							   V_Offset + V_Scale);
    }
    else if (m_type == Shape_Texture_Landscape)
    {
        U_Scale = -TMgr.Texture->width / static_cast<double>(TMgr.Texture->height);
        U_Offset = 0.5 - U_Scale/2.0;
        
        if (crop_rect.x > 0)
            V_Offset += crop_rect.x * V_Scale / static_cast<double>(m_scaled_src.w);
        if (crop_rect.y > 0)
            U_Offset += crop_rect.y * U_Scale / static_cast<double>(m_scaled_src.h);
        if (crop_rect.w < m_scaled_src.w)
            V_Scale *= crop_rect.w / static_cast<double>(m_scaled_src.w);
        if (crop_rect.h < m_scaled_src.h)
            U_Scale *= crop_rect.h / static_cast<double>(m_scaled_src.h);
		
		OGL_RenderTexturedRect(dst.x, dst.y, dst.w, dst.h,
							   V_Offset, U_Offset,
							   V_Offset + V_Scale,
							   U_Offset + U_Scale);
    }
    else
    {
        shape_information_data *info = extended_get_shape_information(m_coll, m_frame);
        if (info->flags & _X_MIRRORED_BIT)
        {
            V_Offset += V_Scale;
            V_Scale = -V_Scale;
        }
        if (info->flags & _Y_MIRRORED_BIT)
        {
            U_Offset += U_Scale;
            U_Scale = -U_Scale;
        }

        if (crop_rect.x > 0)
            V_Offset += crop_rect.x * V_Scale / static_cast<double>(m_scaled_src.w);
        if (crop_rect.y > 0)
            U_Offset += crop_rect.y * U_Scale / static_cast<double>(m_scaled_src.h);
        if (crop_rect.w < m_scaled_src.w)
            V_Scale *= crop_rect.w / static_cast<double>(m_scaled_src.w);
        if (crop_rect.h < m_scaled_src.h)
            U_Scale *= crop_rect.h / static_cast<double>(m_scaled_src.h);

		GLfloat texcoords[8] = {
			U_Offset, V_Offset,
			U_Offset, V_Offset + V_Scale,
			U_Offset + U_Scale, V_Offset + V_Scale,
			U_Offset + U_Scale, V_Offset
		};
		GLfloat vertices[8] = {
			dst.x, dst.y,
			dst.x + dst.w, dst.y,
			dst.x + dst.w, dst.y + dst.h,
			dst.x, dst.y + dst.h
		};
		glVertexPointer(2, GL_FLOAT, 0, vertices);
		glTexCoordPointer(2, GL_FLOAT, 0, texcoords);
		glDrawArrays(GL_POLYGON, 0, 4);
	}
    
    if (rotating)
        glPopMatrix();
    
	if (TMgr.IsGlowMapped()) TMgr.RenderGlowing();
	TMgr.RestoreTextureMatrix();
	if (Using_sRGB)
	{
		glDisable(GL_FRAMEBUFFER_SRGB_EXT);
		Using_sRGB = false;
	}
#endif
}
Пример #2
0
void Shape_Blitter::OGL_Draw(SDL_Rect& dst)
{
#ifdef HAVE_OPENGL
  // Set up texture
  TextureManager TMgr;
  TMgr.ShapeDesc = m_desc;
  get_shape_bitmap_and_shading_table(m_desc, &TMgr.Texture, &TMgr.ShadingTables,
                                     _shading_normal);
  TMgr.IsShadeless = false;
  TMgr.TransferMode = _shadeless_transfer;

  switch (m_type)
  {
  case Shape_Texture_Wall:
    TMgr.TextureType = OGL_Txtr_Wall;
    break;
  case Shape_Texture_Landscape:
  {
    TMgr.TextureType = OGL_Txtr_Landscape;
    LandscapeOptions *LandOpts = View_GetLandscapeOptions(TMgr.ShapeDesc);
    TMgr.LandscapeVertRepeat = LandOpts->VertRepeat;
    TMgr.Landscape_AspRatExp = LandOpts->OGL_AspRatExp;
  }
  break;
  case Shape_Texture_Sprite:
    TMgr.TextureType = OGL_Txtr_Inhabitant;
    break;
  case Shape_Texture_WeaponInHand:
  case Shape_Texture_Interface:
    TMgr.TextureType = OGL_Txtr_WeaponsInHand;
    break;
  }
  if (!TMgr.Setup()) {
    return;
  }

  // Get dimensions
  // DJB Doubles to floats...
  GLfloat U_Scale = TMgr.U_Scale;
  GLfloat V_Scale = TMgr.V_Scale;
  GLfloat U_Offset = TMgr.U_Offset;
  GLfloat V_Offset = TMgr.V_Offset;

  // Draw shape
  SglColor4f(tint_color_r, tint_color_g, tint_color_b, tint_color_a);
  glEnable(GL_TEXTURE_2D);
  glEnable(GL_BLEND);
  glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  TMgr.SetupTextureMatrix();
  TMgr.RenderNormal();

  bool rotating = (rotation > 0.1 || rotation < -0.1);
  if (rotating) {
    glMatrixMode(GL_MODELVIEW);
    glPushMatrix();
    glTranslatef((dst.x + dst.w/2.0), (dst.y + dst.h/2.0), 0.0);
    glRotatef(rotation, 0.0, 0.0, 1.0);
    glTranslatef(-(dst.x + dst.w/2.0), -(dst.y + dst.h/2.0), 0.0);
  }

  if (m_type == Shape_Texture_Interface) {
    if (crop_rect.x > 0) {
      U_Offset += crop_rect.x * U_Scale / static_cast<double>(m_scaled_src.w);
    }
    if (crop_rect.y > 0) {
      V_Offset += crop_rect.y * V_Scale / static_cast<double>(m_scaled_src.h);
    }
    if (crop_rect.w < m_scaled_src.w) {
      U_Scale *= crop_rect.w / static_cast<double>(m_scaled_src.w);
    }
    if (crop_rect.h < m_scaled_src.h) {
      V_Scale *= crop_rect.h / static_cast<double>(m_scaled_src.h);
    }

    // DJB OpenGL  Change from triangle fan
    GLfloat t[8] = {
      U_Offset, V_Offset,
      U_Offset + U_Scale, V_Offset,
      U_Offset + U_Scale, V_Offset + V_Scale,
      U_Offset, V_Offset + V_Scale
    };
    GLshort v[8] = {
      dst.x, dst.y,
      dst.x + dst.w, dst.y,
      dst.x + dst.w, dst.y + dst.h,
      dst.x, dst.y + dst.h
    };
    glVertexPointer(2, GL_SHORT, 0, v);
    glEnableClientState(GL_VERTEX_ARRAY);
    glTexCoordPointer(2, GL_FLOAT, 0, t);
    glEnableClientState(GL_TEXTURE_COORD_ARRAY);
    glDrawArrays(GL_TRIANGLE_FAN, 0, 4);

    /*
    glBegin(GL_TRIANGLE_FAN);
    glTexCoord2d(U_Offset, V_Offset);
    glVertex2i(dst.x, dst.y);
    glTexCoord2d(U_Offset + U_Scale, V_Offset);
    glVertex2i(dst.x + dst.w, dst.y);
    glTexCoord2d(U_Offset + U_Scale, V_Offset + V_Scale);
    glVertex2i(dst.x + dst.w, dst.y + dst.h);
    glTexCoord2d(U_Offset, V_Offset + V_Scale);
    glVertex2i(dst.x, dst.y + dst.h);
    glEnd();
     */
  }
  else if (m_type == Shape_Texture_Landscape) {
    U_Scale = -TMgr.Texture->width / static_cast<double>(TMgr.Texture->height);
    U_Offset = 0.5 - U_Scale/2.0;

    crop_rect.x = m_scaled_src.w/4;
    crop_rect.w = m_scaled_src.w/2;
    crop_rect.y = m_scaled_src.h/4;
    crop_rect.h = m_scaled_src.h/2;
    if (crop_rect.x > 0) {
      V_Offset += crop_rect.x * V_Scale / static_cast<double>(m_scaled_src.w);
    }
    if (crop_rect.y > 0) {
      U_Offset += crop_rect.y * U_Scale / static_cast<double>(m_scaled_src.h);
    }
    if (crop_rect.w < m_scaled_src.w) {
      V_Scale *= crop_rect.w / static_cast<double>(m_scaled_src.w);
    }
    if (crop_rect.h < m_scaled_src.h) {
      U_Scale *= crop_rect.h / static_cast<double>(m_scaled_src.h);
    }

    // DJB OpenGL Change from glBegin/glEnd
    GLfloat t[8] = {
      V_Offset, U_Offset,
      V_Offset + V_Scale, U_Offset,
      V_Offset + V_Scale, U_Offset + U_Scale,
      V_Offset, U_Offset + U_Scale
    };
    GLshort v[8] = {
      dst.x, dst.y,
      dst.x + dst.w, dst.y,
      dst.x + dst.w, dst.y + dst.h,
      dst.x, dst.y + dst.h
    };
    glVertexPointer(2, GL_SHORT, 0, v);
    glEnableClientState(GL_VERTEX_ARRAY);
    glTexCoordPointer(2, GL_FLOAT, 0, t);
    glEnableClientState(GL_TEXTURE_COORD_ARRAY);
    glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
    /*
    glBegin(GL_TRIANGLE_FAN);
    glTexCoord2d(V_Offset, U_Offset);
    glVertex2i(dst.x, dst.y);
    glTexCoord2d(V_Offset + V_Scale, U_Offset);
    glVertex2i(dst.x + dst.w, dst.y);
    glTexCoord2d(V_Offset + V_Scale, U_Offset + U_Scale);
    glVertex2i(dst.x + dst.w, dst.y + dst.h);
    glTexCoord2d(V_Offset, U_Offset + U_Scale);
    glVertex2i(dst.x, dst.y + dst.h);
    glEnd();
     */
  }
  else
  {
    if (crop_rect.x > 0) {
      V_Offset += crop_rect.x * V_Scale / static_cast<double>(m_scaled_src.w);
    }
    if (crop_rect.y > 0) {
      U_Offset += crop_rect.y * U_Scale / static_cast<double>(m_scaled_src.h);
    }
    if (crop_rect.w < m_scaled_src.w) {
      V_Scale *= crop_rect.w / static_cast<double>(m_scaled_src.w);
    }
    if (crop_rect.h < m_scaled_src.h) {
      U_Scale *= crop_rect.h / static_cast<double>(m_scaled_src.h);
    }

    // DJB OpenGL 
    GLfloat t[8] = {
      U_Offset, V_Offset,
      U_Offset, V_Offset + V_Scale,
      U_Offset + U_Scale, V_Offset + V_Scale,
      U_Offset + U_Scale, V_Offset
    };
    GLshort v[8] = {
      dst.x, dst.y,
      dst.x + dst.w, dst.y,
      dst.x + dst.w, dst.y + dst.h,
      dst.x, dst.y + dst.h
    };
    glVertexPointer(2, GL_SHORT, 0, v);
    glEnableClientState(GL_VERTEX_ARRAY);
    glTexCoordPointer(2, GL_FLOAT, 0, t);
    glEnableClientState(GL_TEXTURE_COORD_ARRAY);
    glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
    /*
    glBegin(GL_TRIANGLE_FAN);
    glTexCoord2d(U_Offset, V_Offset);
    glVertex2i(dst.x, dst.y);
    glTexCoord2d(U_Offset, V_Offset + V_Scale);
    glVertex2i(dst.x + dst.w, dst.y);
    glTexCoord2d(U_Offset + U_Scale, V_Offset + V_Scale);
    glVertex2i(dst.x + dst.w, dst.y + dst.h);
    glTexCoord2d(U_Offset + U_Scale, V_Offset);
    glVertex2i(dst.x, dst.y + dst.h);
    glEnd();
    */
  }

  if (rotating) {
    glPopMatrix();
  }

  if (TMgr.IsGlowMapped()) {
    TMgr.RenderGlowing();
  }
  TMgr.RestoreTextureMatrix();
#endif
}