2

My Android app needs to display a full-screen bitmap as a background, then on top of that display some dynamic 3D graphics using OpenGL ES (either 1.1. or 2.0 - not decided yet). The background image is a snapshot of a WebView component in the same app, so its dimensions already fit the screen perfectly.

I'm new to OpenGL, but I know that the regular way to display a bitmap involve scaling it into a POT texture (glTexImage2D), configuring the matrices, creating some vertices for the rectangle and displaying that with glDrawArrays. Seems to be a lot of extra work (with loss of quality when down-scaling the image to POT size) when all that's needed is just to draw a bitmap to the screen, in 1:1 scale.

The "desktop" GL has glDrawPixels(), which seems to do exactly what's needed in this situation, but that's apparently missing in GLES. Is there any way to copy pixels to the screen buffer in GLES, circumventing the 3D pipeline? Or is there any way to draw OpenGL graphics on top of a "flat" background drawn by regular Android means? Or making a translucent GLView (there is RSTextureView for Renderscript-based display, but I couldn't find an equivalent for GL)?

1 Answer 1

1

but I know that the regular way to display a bitmap involve scaling it into a POT texture (glTexImage2D)

Then your knowledge is outdated. Modern OpenGL (version 2 and later) are fine with arbitrary image dimensions for their textures.

The "desktop" GL has glDrawPixels(), which seems to do exactly what's needed in this situation, but that's apparently missing in GLES.

Well, modern "desktop" OpenGL, namely version 3 core and later don't have glDrawPixels either.

However appealing this function is/was, it offers only poor performance and has so many caveats, that it's rarely used, whenever it's use can be avoided.

Just upload your unscaled image into a texture, disable mipmapping and draw it onto a fullscreen quad.

Sign up to request clarification or add additional context in comments.

5 Comments

Thank you for the clarification. If NPOT textures are indeed supported, that would solve the problem. However, how can I be sure that is the case on various devices running various versions of Android (at least from 2.3 and newer)?
It's not so much the version of Android running, which determines which version of OpenGL is available, but the GPU used by the device. Use glGetString(GL_VERSION) to retrieve the version strin in your program. Note that most Android devices (if not all of them) do support OpenGL ES-2.
I found some answers here that GL2.0 is definitely required and "GL_OES_texture_npot" extension is recommended (?). As an example, my ASUS TF-101, which isn't a terribly old device, doesn't seem to show that extension.
I´ve programmed OpenGL on Android and displaying non-POT textures renders only white on most devices and the emulator. I've also read that using NPOT textures is slower that using POT, in case the extension is used, although I haven't checked on that.
I've had the same experience than @RedOrav

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.