/*------------------------------------------------------------------------------
 src/lib/djWidget/ogl.cxx

 Copyright (c) 2004-2006 Darby Johnston.
 All rights reserved.
 Use is subject to license terms.
------------------------------------------------------------------------------*/

//#define DJ_DBG
#include "djOgl.h"

namespace dj {

void oglOrtho(int width, int height, double min, double max)
{
  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();
  glOrtho(0.0, width, 0.0, height, min, max);
  glMatrixMode(GL_MODELVIEW);
  glLoadIdentity();
}

void oglPoints(const Box2i & in)
{
  glVertex2i(in.p0().x(), in.p0().y());
  glVertex2i(in.p0().x(), in.p0().y() + in.size().y());
  glVertex2i(in.p0().x() + in.size().x(), in.p0().y() + in.size().y());
  glVertex2i(in.p0().x() + in.size().x(), in.p0().y());
}

GLenum oglFormat(PIXEL_FORMAT in)
{
  switch (in) {
    case PIXEL_L: return GL_LUMINANCE;
    case PIXEL_LA: return GL_LUMINANCE_ALPHA;
    case PIXEL_RGB: return GL_RGB;
    case PIXEL_RGBA: return GL_RGBA;
  }
  return 0;
}

GLenum oglType(PIXEL_TYPE in)
{
  switch (in) {
    case PIXEL_U8: return GL_UNSIGNED_BYTE;
    case PIXEL_U16: return GL_UNSIGNED_SHORT;
    case PIXEL_F32: return GL_FLOAT;
  }
  return 0;
}

}
