from OpenGL.GL import *
from OpenGL.GLU import *
import pygame, pygame.image
from pygame.locals import *

import math
import texMgr


def draw_quad(texname, left, top, right, bottom):
    glBindTexture(GL_TEXTURE_2D, texMgr.tex_id(texname))

    glBegin(GL_QUADS)
    glTexCoord2f(0.0, 1.0); glVertex2f(  left, top)
    glTexCoord2f(1.0, 1.0); glVertex2f( right, top)
    glTexCoord2f(1.0, 0.0); glVertex2f( right, bottom)
    glTexCoord2f(0.0, 0.0); glVertex2f(  left, bottom)
    glEnd()


def draw_rot_quad(texname, left, top, right, bottom, angle):

    cx=(right+left)/2.0
    cy=(top+bottom)/2.0

    x_len=right-cx
    y_len=top-cy

    glPushMatrix()
    glTranslate(cx,cy,0.0)
    glRotate(math.degrees(angle),0.0,0.0,1.0)

    glBindTexture(GL_TEXTURE_2D, texMgr.tex_id(texname))

    glBegin(GL_QUADS)
    glTexCoord2f(0.0, 1.0); glVertex2f( -x_len, y_len)
    glTexCoord2f(1.0, 1.0); glVertex2f(  x_len, y_len)
    glTexCoord2f(1.0, 0.0); glVertex2f(  x_len,-y_len)
    glTexCoord2f(0.0, 0.0); glVertex2f( -x_len,-y_len)
    glEnd()


    glPopMatrix()
