我用NDK制作了一个bin代码,通过ffmpeg解码获取视频帧,并渲染到opengles,但是屏幕没有任何改变,它仍然显示了启动器。
* 但是 当我发布apk时,它总是显示黑色。 *
我的opengles2.0 ini代码如下:
static int window_init_display(void)
{
EGLint attribs [] = {
EGL_RED_SIZE, 8,
EGL_GREEN_SIZE, 8,
EGL_BLUE_SIZE, 8,
EGL_ALPHA_SIZE, 8,
EGL_DEPTH_SIZE, 16,
EGL_STENCIL_SIZE, 0,
EGL_SAMPLE_BUFFERS, 0,
EGL_SAMPLES, 0,
EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
EGL_NONE
};
EGLint w, h, format;
EGLint numConfigs;
EGLConfig config;
EGLSurface surface;
EGLContext context;
EGLDisplay display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
eglInitialize(display, 0, 0);
eglChooseConfig(display, attribs, &config, 1, &numConfigs);
eglGetConfigAttrib(display, config, EGL_NATIVE_VISUAL_ID, &format);
ANativeWindow_setBuffersGeometry(g_application->window, 0, 0, format);
surface = eglCreateWindowSurface(display, config, g_application->window, NULL);
eglQuerySurface(display, surface, EGL_WIDTH, &w);
eglQuerySurface(display, surface, EGL_HEIGHT, &h);
LOGI("EGL_WIDTH=%d, EGL_HEIGHT=%d",w,h);
eglBindAPI(EGL_OPENGL_ES_API);
EGLint contextAttrs[] =
{
EGL_CONTEXT_CLIENT_VERSION, 2,
EGL_NONE
};
context = eglCreateContext(display, config, NULL, contextAttrs);
if (eglMakeCurrent(display, surface, surface, context) == EGL_FALSE)
{
LOGW("Unable to eglMakeCurrent");
return -1;
}
LOGI("OK init EGL !!!!");
}
我的渲染代码如下:
int m_rgbBufferSize = pPicture->iDisplayWidth*pPicture->iDisplayHeight*4;
m_rgbBuffer = new unsigned char[m_rgbBufferSize];
struct SwsContext *m_sw_context=NULL;
m_sw_context = m_dllSwScale.sws_getCachedContext(m_sw_context,
pPicture->iWidth, pPicture->iHeight, PIX_FMT_YUV420P,
pPicture->iWidth, pPicture->iHeight, PIX_FMT_RGBA,
SWS_FAST_BILINEAR, NULL, NULL, NULL);
uint8_t *psrc[] = { pPicture->data[0], pPicture->data[1], pPicture->data[2], 0 };
int srcStride[] = { pPicture->iLineSize[0], pPicture->iLineSize[1], pPicture->iLineSize[2], 0 };
uint8_t *dst[] = { m_rgbBuffer, 0, 0, 0 };
int dstStride[] = { pPicture->iDisplayWidth*4, 0, 0, 0 };
m_dllSwScale.sws_scale(m_sw_context, psrc, srcStride, 0, pPicture->iDisplayHeight, dst, dstStride);
//LOGV("swscale OK");
glEnable(GL_TEXTURE_2D);
glPixelStorei(GL_UNPACK_ALIGNMENT,1);
if(textureid == 0)
glGenTextures(1, &textureid);
glActiveTexture(GL_TEXTURE2);
glBindTexture(GL_TEXTURE_2D, textureid);
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0,
pPicture->iDisplayWidth, pPicture->iDisplayHeight, GL_RGBA, GL_UNSIGNED_BYTE, m_rgbBuffer);
为什么没有显示?我应该使用abk not bin文件来运行吗?
答案 0 :(得分:0)
Surface默认隐藏在其他一些视图中。检查是否在表面上放置了一些视图。或者在上面设置surfaceZOrder。