/*==========================================================
  File:  gl.c
  Author:  _pragma

  Description:  Initializes and queries OpenGL.
  ==========================================================*/


#include <SDL/SDL.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <GL/gl.h>
#include <GL/glu.h>

#include "util.h"
#include "gl.h"
#include "lights.h"
#include "texture.h"
#include "console.h"

#ifndef HAS_MULTITEXTURE
PFNGLACTIVETEXTUREARBPROC        glActiveTextureARB       = NULL;
PFNGLCLIENTACTIVETEXTUREARBPROC  glClientActiveTextureARB = NULL;
#endif

void G_initGL(int widthint height)
{
  CON_printf("------------ Init GL ---------------");
  glShadeModel(GL_SMOOTH);

  glClearColor(0.00.00.00.0);

  glEnable(GL_DEPTH_TEST);
  glDepthFunc(GL_LESS);
  glClearDepth(1.0);

  L_initLights();  
  glBlendFunc(GL_SRC_ALPHA,GL_ONE);

  glViewport (00, (GLsizeiwidth, (GLsizeiheight); 
  glMatrixMode (GL_PROJECTION);
  glLoadIdentity ();

  glMatrixMode (GL_MODELVIEW);
  glEnable(GL_COLOR_MATERIAL);

  G_queryGL();

#ifndef HAS_MULTITEXTURE
  glActiveTextureARB = (PFNGLACTIVETEXTUREARBPROCSDL_GL_GetProcAddress("glActiveTextureARB");
  glClientActiveTextureARB = (PFNGLACTIVETEXTUREARBPROCSDL_GL_GetProcAddress("glClientActiveTextureARB");

  // Here we make sure that the functions were loaded properly
  if(!glActiveTextureARB || !glClientActiveTextureARB)
    CON_printf("Warning: no multitexture support");
#endif

  CON_printf("------------------------------------");
}

void G_queryGL(void)
{
  char string[1024];

  CON_printf("VENDOR:     %s"glGetString(GL_VENDOR));
  CON_printf("RENDERER:   %s"glGetString(GL_RENDERER));
  CON_printf("VERSION:    %s"glGetString(GL_VERSION));

  strncpy(stringglGetString(GL_EXTENSIONS), 1024);
  string[1024] = 0;
  CON_printf("EXTENSIONS: %s"string);
}