/***************************************************************************
 *            gl_port.h
 *
 *  Thu Jul 19 19:00:10 2007
 *  Copyright  2007  Steffen Pohle
 *  steffen@gulpe.de
 ****************************************************************************/

/*
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */
 
 
#ifndef _ANDROID_PORT_H_
#define _ANDROID_PORT_H_

#include <android/sensor.h>
#include <android/log.h>
#include <android_native_app_glue.h>

#define GL_GLEXT_PROTOTYPES 1
#include <GLES2/gl2.h>
#include <GLES2/gl2ext.h>
#include <EGL/egl.h>
#include <EGL/eglext.h>
#include <ft2build.h>
#include FT_FREETYPE_H

/*****************************************************************************
 * gfx stuff... 
 */
struct color {
	unsigned short int r;
	unsigned short int g;
	unsigned short int b;
	union {
		struct {
			float r;
			float g;
			float b;
			float a;
		} elements;
		float array[4];
	} c;
	int alloc;
};


struct image {
	int width;
	int height;
	GLuint txt_id;	// texture id
	GLuint rbo_id;	// renderbuffer object id
	GLuint fbo_id;	// framebuffer id
	GLuint srb_id;
	int img_id;		// internal gfx value for setting glViweport and glOrtho
	uint8_t *data;	// raw pixeldata (mostly used on opengl)
	int data_fmt;	// raw data format		
};


struct font {
	FT_Face face;
	char *buffer;
	int buffersize;
};


/**
 * internal structure for android
 */
struct saved_state {
    float angle;
    int32_t x;
    int32_t y;
};


struct engine {
    struct android_app* app;

    ASensorManager* sensorManager;
    const ASensor* accelerometerSensor;
    ASensorEventQueue* sensorEventQueue;

    int animating;
    EGLDisplay display;
    EGLSurface surface;
    EGLContext context;
    int32_t width;
    int32_t height;
    struct saved_state state;
	GLuint gles_prgobject;
	GLuint gles_pos;
	GLuint gles_color;
	GLuint gles_umvp;
	GLuint gles_txcoord;
	GLuint gles_txenabled;	// 0 - no texture, 1 - normal text, 2 - blendfunc
	GLuint gles_txsampler;
};

extern struct engine engine;
extern int font_init ();
extern struct font *font_load (char *fname);
extern void font_draw (struct font *f, char *text, float x, float y, float sx, float sy);

#include "draw.h"

#endif



