Rpi3, GLES2, OF_PIXELS_NATIVE and Textures


#1

Hi,

I’m running an application on a Rpi3.

I’m switching to GLES2 in main.cpp:

settings.setGLESVersion(2);

So I can load videos with OF_PIXELS_NATIVE, which runs smooth and fast on the Pi.

Now the problem arises when I want to do something with the texture, like:

player.getTexture().drawSubsection(...)

Nothing is displayed then. Just a blank screen.

Disabling GLES2, disabling OF_PIXELS_NATIVE solves the (visual) problem, but CPU usage makes the application unusable.

Any hints? Also just drawing a primitive ofDrawRectangledoes not work.


#2

when OF_PIXELS_NATIVE is enabled OF uses internally up to 3 textures, one per yuv channel to draw the video frame. each texture is then combined through a shader to get the rgb value for each pixel. that’s why getting a reference to only 1 of those textures will at most give you a black and white one.

the easiest is to draw the frame first into an fbo and then draw a subsection of that fbo


#3

Thanks, I’ll give that a try. The bigger problem was, that with GLES2 I was not able to draw a single thing like a rectangle. Does GLES2 on a Rpi need some special treatment when drawing something?


#4

can you put an example of something that doesn’t work? except for lights and materials everything should work the same even if internally the code is different

also please post which version of OF you are using


#5

I’m using git master, running on a Rpi3:

main.cpp:

#include "ofMain.h"
#include "ofApp.h"
int main( ){
    ofGLESWindowSettings settings;
    settings.setGLESVersion(2);
    settings.windowMode = OF_FULLSCREEN;
    ofCreateWindow(settings);
    ofRunApp(new ofApp);
}

ofApp.cpp

void ofApp::setup(){
   ofBackground(0);
   ofSetVerticalSync(false);
   ofEnableAlphaBlending();
   font.load("type/VCR_OSD_MONO_1.001.ttf", 10, true, false, true, 0.4, 72);
}

void ofApp::update(){}

void ofApp::draw(){
    ofSetColor(0,255,0,255);
    font.drawStringAsShapes(
        "TEST", 
        50, 
        50
    );
}

I’m getting just a blank screen.
If I’m commenting out settings.setGLESVersion(2); I see the green “test” in the upper left corner.

Here’s the output after running with GLES2 activated:

make RunRelease
HOST_OS=Linux
PLATFORM_ARCH=armv6l
PLATFORM_OS=Linux
HOST_ARCH=armv6l
HOST_OS=Linux
CROSS_COMPILING=
PLATFORM_VARIANT=default
IS_RASPBIAN=1
checking pkg-config libraries:   cairo zlib gstreamer-app-1.0 gstreamer-1.0 gstreamer-video-1.0 gstreamer-base-1.0 libudev freetype2 fontconfig sndfile openal openssl libcurl glfw3 rtaudio gtk+-3.0 libmpg123
with PKG_CONFIG_LIBDIR=
[notice ] ofAppEGLWindow: setupRPiNativeWindow(): screenRect: 1680x1050
[notice ] ofAppEGLWindow: setupRPiNativeWindow(): windowRect: 1680x1050
[notice ] ofAppEGLWindow: createSurface(): setting up EGL Display
[notice ] ofAppEGLWindow: createSurface(): EGL Display correctly set 0x1
[notice ] ofAppEGLWindow: createSurface(): no current renderer selected
[notice ] ofAppEGLWindow: createSurface(): GLES2 renderer detected
[notice ] ofAppEGLWindow: createSurface(): surface created correctly
[notice ] ofAppEGLWindow: createSurface(): API bound correctly
[notice ] ofAppEGLWindow: createSurface(): -----EGL-----
[notice ] ofAppEGLWindow: createSurface(): EGL_VERSION_MAJOR = 1
[notice ] ofAppEGLWindow: createSurface(): EGL_VERSION_MINOR = 4
[notice ] ofAppEGLWindow: createSurface(): EGL_CLIENT_APIS = OpenGL_ES OpenVG
[notice ] ofAppEGLWindow: createSurface(): EGL_VENDOR = Broadcom
[notice ] ofAppEGLWindow: createSurface(): EGL_VERSION = 1.4
[notice ] ofAppEGLWindow: createSurface(): EGL_EXTENSIONS = EGL_KHR_image EGL_KHR_image_base EGL_KHR_image_pixmap EGL_KHR_vg_parent_image EGL_KHR_gl_texture_2D_image EGL_KHR_gl_texture_cubemap_image EGL_KHR_lock_surface
[notice ] ofAppEGLWindow: createSurface(): GL_RENDERER = VideoCore IV HW
[notice ] ofAppEGLWindow: createSurface(): GL_VERSION  = OpenGL ES 2.0
[notice ] ofAppEGLWindow: createSurface(): GL_VENDOR   = Broadcom
[notice ] ofAppEGLWindow: createSurface(): -------------
[notice ] ofAppEGLWindow: setupPeripherals(): peripheral setup complete
[notice ] ofAppEGLWindow: setupNativeUDev(): created udev object
[notice ] ofAppEGLWindow: setupMouse(): mouse_fd=5 devicePath=/dev/input/event0
[notice ] ofAppEGLWindow: setupMouse(): mouse device name = NOVATEK USB Keyboard
[ error ] ofAppEGLWindow: ioctl GABS failed
[ error ] ofAppEGLWindow: ioctl GABS failed
[notice ] ofAppEGLWindow: setupKeyboard(): keyboard_fd=6 devicePath=/dev/input/by-path/platform-3f980000.usb-usb-0:1.2.3:1.0-event-kbd
[notice ] ofAppEGLWindow: setupKeyboard(): keyboard device name = NOVATEK USB Keyboard
[notice ] ofAppEGLWindow: setupPeripherals(): native event setup complete
[warning] ofShader: GL_VERTEX_SHADER shader reports:
Compiled
[warning] %extensions%
precision highp float;
#define IN attribute
#define OUT varying
#define TEXTURE texture2D
#define TARGET_OPENGLES
uniform mat4 modelViewMatrix; uniform mat4 projectionMatrix; uniform mat4 textureMatrix; uniform mat4 modelViewProjectionMatrix; uniform float usingTexture; uniform float usingColors; uniform vec4 globalColor; IN vec4 position; IN vec4 color; IN vec4 normal; IN vec2 texcoord; OUT vec4 colorVarying; OUT vec2 texCoordVarying; void main(){ gl_Position = modelViewProjectionMatrix * position; if(usingTexture>.5) texCoordVarying = (textureMatrix*vec4(texcoord.x,texcoord.y,0,1)).xy; if(usingColors>.5) colorVarying = color; else colorVarying = globalColor; }

[warning] ofShader: GL_FRAGMENT_SHADER shader reports:
Compiled
[warning] %extensions%
precision highp float;
#define IN varying
#define OUT
#define TEXTURE texture2D
#define FRAG_COLOR gl_FragColor
#define TARGET_OPENGLES
uniform sampler2D src_tex_unit0; uniform float usingTexture; uniform float bitmapText; IN vec4 colorVarying; IN vec2 texCoordVarying; void main(){ vec4 tex; if(usingTexture>.5){ tex = TEXTURE(src_tex_unit0, texCoordVarying); if(bitmapText>.5 && tex.a < 0.5){ discard; }else{ FRAG_COLOR = colorVarying*tex; } }else{ FRAG_COLOR = colorVarying; } }

[ error ] ofShader: checkProgramLinkStatus(): program failed to link
[ error ] ofShader: ofShader: program reports:
ERROR:LEX/PARSE-1 (vertex shader, line 1) Syntax error

Thanks!
Urs


#6

at the end of the output you can see there’s an error in the shader. we fixed this some weeks ago so if you pull again from master it should work


#7

thanks arturo - git pull did the trick ; )