树莓派raspberry pi3使用opengl渲染图片

本文介绍了如何在树莓派3上利用FFMPEG解码视频,获取图片帧,并通过OpenGL进行显示。示例代码中创建了GlPlayer对象,用以绘制图像地址,最后释放资源。
摘要由CSDN通过智能技术生成


运行环境:raspberry pi3 官方jessie系统,QT 5.3.2

本文应用场景:FFMPEG解码视频获得图片帧,使用opengl进行显示。

代码:glplayer.h

#ifndef GLPLAYER_H
#define GLPLAYER_H

#include <QObject>
#include <stdio.h>
#include <math.h>
#include <sys/time.h>

#include <EGL/egl.h>
#include <EGL/eglext.h>
#include <GLES2/gl2.h>
#include <cassert>
#include "bcm_host.h"

typedef struct
{
    // Handle to a program object
    GLuint programObject;
   // Attribute locations
   GLint  positionLoc;
   GLint  texCoordLoc;
   // Sampler location
   GLint samplerLoc;
   // Texture handle
   GLuint textureId;
} UserData;

typedef struct CUBE_STATE_T
{
    uint32_t width;
    uint32_t height;

    EGLDisplay display;
    EGLSurface surface;
    EGLContext context;

    EGL_DISPMANX_WINDOW_T nativewindow;
    UserData *user_data;

    DISPMANX_ELEMENT_HANDLE_T dispman_element;
    DISPMANX_DISPLAY_HANDLE_T dispman_display;
    DISPMANX_UPDATE_HANDLE_T dispman_update;
} CUBE_STATE_T;

class GlPlayer{
private:

    GLuint createSimpleTexture2D();
    GLuint loadShader(GLenum type, const char *shaderSrc);
    GLuint loadProgram (const char *vertShaderSrc, const char *fragShaderSrc);
    void initEGL( int width, int height);
    int init();
    void releaseEGL();
public:
    GlPlayer(int width, int height);
    ~GlPlayer();
    void draw(char * image);

public:
    int m_width;
    int m_height;
    CUBE_STATE_T *p_state;
    UserData *user_data;
};

#endif // GLPLAYER_H


GlPlayer.cpp
#include "glplayer.h"
#include <QApplication>
#include <QDesktopWidget>
#include <QTime>

GlPlayer::GlPlayer(int width, int height) :
    user_data(new UserData()),
    p_state(new CUBE_STATE_T()),
    m_width(width),
    m_height(height)
{
    p_state->user_data = user_data;
    initEGL(m_width, m_height);
    if(!init()) exit(1);
}

GlPlayer::~GlPlayer(){
    fprintf(stderr, "~GlPlayer()\n");
    releaseEGL();
    if(user_data != NULL) delete user_data;
    if(p_state != NULL) delete p_state;
}

// Create a simple width x height texture image with four different colors
//
GLuint GlPlayer::creat
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值