//media_gl.h
#ifndef MEDIA_GL_H
#define MEDIA_GL_H//type:没使用,x,y为视口坐标,w,h为视口宽和高
int init_view(int x,int y,int w,int h,int type);
void uninit_view();
//type:3 RGB格式,4 RGBA格式,w 图片宽度,h图片高度,imgdata图片内存格式数据(rgb数组)
void update_texture(int type,int w,int h,void* imgdata);
//
void update_draw();
//x,y为视口坐标,w,h为视口宽和高,需要配合窗口一起调用
void update_viewsize(int x,int y,int w,int h);
//turn:顺时针旋转角度 0,90,180,270
void update_viewturn(int turn);
#endif
//media_gl.c
#include "media_gl.h"
#if defined( __APPLE__ ) && !defined(__MACOSX)
#include <OpenGLES/ES2/gl.h>
#import <OpenGLES/ES2/glext.h>
#elif defined(linux) || defined(__linux) || defined(__linux__)
#include <GLES2/gl2.h>
#include <GLES2/gl2ext.h>
#else
#include <GL/glew.h>
#endif
struct media_point
{
float _x;
float _y;
float _tx;
float _ty;
};
struct media_view
{
GLuint _prpgram;
GLuint _vexctbuf;
GLuint _textureid;
int _vexctbuf_index;
};
#define shader_vs " \
attribute vec4 position;\n \
attribute vec2 texcoord;\n \
varying vec2 v_texcoord;\n \
void main() {\n \
gl_Position = position;\n \
v_texcoord = texcoord;\n \
}"
#define shader_fs " \
varying vec2 v_texcoord;\n \
uniform sampler2D texture0;\n \
void main() {\n \
gl_FragColor= texture2D(texture0, v_texcoord);\n \
}"
struct media_view _g_view = {0,0,0,0};
static GLuint _compile(const char * source, int type)
{
GLint status;
GLuint shader = glCreate