Skip to content

Instantly share code, notes, and snippets.



Last active Dec 24, 2017
What would you like to do?
使用OpenGL ES以双目渲染和显示360度视频。博文地址:
#ifndef GLHELPER_H
#define GLHELPER_H
#include <EGL/egl.h>
#include <EGL/eglext.h>
#include <GLES2/gl2.h>
#include <GLES2/gl2ext.h>
#include <vector>
#include <pthread.h>
#include "MyGLCamera.h"
struct FramebufferDesc {
// Depth Buffer Index used to represent depth component.
GLuint m_nDepthBufferID;
// Render Buffer Index used to represent color component.
GLuint m_nRenderTextureID;
// FrameBuffer object Index used to represent framebuffer object.
GLuint m_nRenderFramebufferID;
enum EYE {
class GLHelper {
bool init();
void setWindow(ANativeWindow *window);
void drawFrame(int frameWidth, int frameHeight, unsigned char *YData, unsigned char *UData,
unsigned char *VData);
void setRotationMatrix(float *rotation, int length);
ANativeWindow *_window;
// Display
EGLint w = 0;
EGLint h = 0;
EGLDisplay dpy;
EGLSurface surface;
EGLContext context;
// OpenGL
GLuint gProgram;
unsigned int vertexCount;
int numberOfPatches;
float *vertexCoordinates;
float *uvCoordinates;
// Camera
float FOVY = 60.0f;
float zNear = 0.1f;
float zFar = 20.0f;
GLuint sphereProgram;
// program used to draw half of screen
GLuint leftScreenProgram;
GLuint rightScreenProgram;
// pointers to indicate where the sphere data is.
GLuint gSpherePositionAttribPointer;
GLuint gSphereSamplerAttribPointer;
GLuint gSphereMatrixUniformPointer;
// pointers to indicate where the plane data is.
GLuint gLeftScreenPositionAttribPointer;
GLuint gRightScreenPositionAttribPointer;
GLuint gLeftScreenSamplerAttribPointer;
GLuint gRightScreenSamplerAttribPointer;
// FramebufferDesc struct for left and right eye.
FramebufferDesc leftEyeFrameBufferDesc;
FramebufferDesc rightEyeFrameBufferDesc;
MyGLCamera *myCamera;
bool setupMemories();
bool setupGraphics();
bool setupTextures();
bool setupVertices();
bool setupMatrix();
bool setupFrameBuffer(int screenWidth, int screenHeight, FramebufferDesc &framebufferDesc);
void renderToTexture(int yuvFrameWidth, int yuvFrameHeight, unsigned char *YData, unsigned char *UData,
unsigned char *VData, EYE eye);
void renderToScreen();
void close();
} ;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment