using opengl es to draw bitmaps

1,570 views
Skip to first unread message

guich

unread,
Dec 16, 2009, 10:19:54 AM12/16/09
to android-ndk
Hi,

I already lost a few hours trying to make this work, but all i'm
getting is a black screen. I'm changing the san-angeles sample to
create a bitmap in RGB form and draw it in screen. This is my code:

GLuint texture;
if (!data || dataLen != width*height)
{
if (data) free(data);
data = malloc(dataLen = width * height);
}
{
int i;
unsigned char *d = data;
for (i = 0; i < dataLen; i++)
*d++ = i & 0xFF;
}

prepareFrame(width, height);
glGenTextures(1, &texture); // Create The Texture
// Typical Texture Generation Using Data From The Bitmap
glBindTexture(GL_TEXTURE_2D, texture);
// Generate The Texture
glTexEnvi(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_MODULATE);
glTexImage2D(GL_TEXTURE_2D, 0, 0, width, height, 0, GL_RGB,
GL_UNSIGNED_BYTE, data);
glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

I placed this in the appRender function, and commented out the rest of
this function.

Can someone help? Note that i have a framework that draws everything
in a RGB buffer and then transfers that to screen. That's why i don't
want to use opengl drawing methods.

best regards

guich

David Given

unread,
Dec 16, 2009, 3:40:36 PM12/16/09
to andro...@googlegroups.com
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 16/12/09 15:19, guich wrote:
> Can someone help? Note that i have a framework that draws everything
> in a RGB buffer and then transfers that to screen. That's why i don't
> want to use opengl drawing methods.

It doesn't look like you're actually using your texture to draw anything...

You'll also need to put OpenGL into ortho mode, set the screen
dimensions, and draw an appropriately-sized poly in the right place so
that it fills the screen.

In general, this doesn't work very well. Trying to upload a full-screen
texture every frame is going to be dead slow --- these embedded GPUs
typically have really lousy texture upload speeds. (Go look at the grief
people have doing 2D on the iPhone, for example.) There's a Qualcomm
extension that *might* help, but it's totally undocumented and I haven't
reverse-engineered from the Android source yet, and I don't know if it
works.

OTOH you do get free scaling from the GPU, so provided you're willing to
take a resolution hit, you can reduce the bandwidth hugely and improve
the frame rate.

- --
???? ?????????????? ????? http://www.cowlark.com ?????
?
? "Under communism, man exploits man. Under capitalism, it's just the
? opposite." --- John Kenneth Galbrith
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iD8DBQFLKUXEf9E0noFvlzgRAmTSAJ9WrLFMcyx1YisRB6pk0YR1VU4evACg4PXA
nmy6bHMn7t9gDW5ODQk0X9o=
=uM3x
-----END PGP SIGNATURE-----

Clapfoot

unread,
Dec 17, 2009, 9:31:42 AM12/17/09
to android-ndk
I don't have access to the rest of the san-angeles at the moment, but
from that code fragment above you should probably be using GL_REPLACE
instead of GL_MODULATE unless you are specifying colors for your
primitives.

guich

unread,
Dec 18, 2009, 6:35:53 AM12/18/09
to android-ndk
Hi,

> In general, this doesn't work very well. Trying to upload a full-screen
> texture every frame is going to be dead slow --- these embedded GPUs
> typically have really lousy texture upload speeds. (Go look at the grief
> people have doing 2D on the iPhone, for example.) There's a Qualcomm
> extension that *might* help, but it's totally undocumented and I haven't
> reverse-engineered from the Android source yet, and I don't know if it
> works.

That's bad. Is there anything else i can do? In Windows CE i draw in a
bitmap and draw that bitmap to screen. It works very well and fast.

I only want to use official apis.

thanks

guich

Enderx

unread,
Dec 19, 2009, 12:29:53 PM12/19/09
to android-ndk
Could someone pls explain how to get the actual drawing to work. I
have a similar problem, nothing is getting drawn. This is my app
render.

float vertices[] =
{
0.0f, 0.0f,
512.0f, 0.0f,
0.0f, 1024.0f,
512.0f, 1024.0f
};

float texture[] =
{
0.0f, 0.0f,
1.0f, 0.0f,
0.0f, 1.0f,
1.0f, 1.0f
};

int indices[] =
{
0, 1, 3,
0, 3, 2
};

UpdateView();

//Check if this section even gets run
__android_log_print(ANDROID_LOG_INFO, "SanAngeles", "We have
arrived.");

//onDraw
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glOrthof(0.0f, 320.0f, 430.0f, 0.0f, 1.0f, -1.0f);

//texture stuff
glGenTextures(1,&textureID);
glBindTexture(GL_TEXTURE_2D, textureID);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

//Different possible texture parameters, e.g
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);

glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, 512, 1024, 0,
GL_RGB ,GL_UNSIGNED_BYTE, (GLvoid *) colors);

glEnableClientState(GL_VERTEX_ARRAY);
//glEnableClientState(GL_TEXTURE_COORD_ARRAY);

glVertexPointer(2, GL_FLOAT, 0, vertices);
//glTexCoordPointer(2, GL_FLOAT, 0, texture);

glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_BYTE, indices);

glDisableClientState(GL_VERTEX_ARRAY);
//glDisableClientState(GL_TEXTURE_COORD_ARRAY);


colors is an array that contains the bitmap colors.

David Given

unread,
Dec 19, 2009, 6:25:38 PM12/19/09
to andro...@googlegroups.com
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 18/12/09 11:35, guich wrote:
[...]


> That's bad. Is there anything else i can do? In Windows CE i draw in a
> bitmap and draw that bitmap to screen. It works very well and fast.
>
> I only want to use official apis.

You cannot do this with official APIs.

If you're a platform developer (that is, if you're building your app
with the platform SDK and planning on having your app included in the
firmware of a new phone), you can use Surface::lock() and
Surface::unlockAndPost(). But that's a story for another mailing list.

(If anyone who was actually developing the Android EGL implementation is
interested on making 2D stuff work, I would encourage them to go and
look at the EGL_KHR_locksurface extension, which is specifically
intended to allow this sort of thing:

http://www.khronos.org/registry/egl/extensions/KHR/EGL_KHR_lock_surface.txt

It ought to be dead easy to implement, too. Unfortunately Android
doesn't support it right now. In general I find the Android EGL
implementation is pretty dubious --- there's a lot of omissions and
stuff it does wrong.)

- --
???? ?????????????? ????? http://www.cowlark.com ?????
?
? "Under communism, man exploits man. Under capitalism, it's just the
? opposite." --- John Kenneth Galbrith
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iD8DBQFLLWDyf9E0noFvlzgRAtcwAKCsCVhpJrQxkNggA8k9C3aZ98JKswCgyyPE
oAmRpDvIzGT1a+u+NdH4OYE=
=RtCU
-----END PGP SIGNATURE-----

Reply all
Reply to author
Forward
0 new messages