1. Are you ready for the Galaxy S20? Here is everything we know so far!

Drawing an image with OpenGL ES?

Discussion in 'Android Development' started by cmh0114, Aug 10, 2010.

  1. cmh0114

    cmh0114 Well-Known Member
    Thread Starter

    Hey everyone,

    I'm trying to develop a game for Android, and I need to know how to draw an image onscreen using OpenGL - an image that I access from the resources, not created within the program. Any tips?

    Thanks.
     


  2. DiCon

    DiCon Newbie

    I'm not sure, if there is a way to directly copy some kind of image buffer into the active frame buffer, but if you want to manipulate your image (translating, scaling, rotating, placing it according to the z-buffer, etc.) you will want to go the usual way:
    Create two triangles forming a rectangle and apply your image as a texture - For example using the Bitmap class and GLUtils.texImage2D(...).

    Additionally, if you do not want to add a perspective, you should use gluOrtho2D(...) as your projection matrix.

    Now, if you want some code or more details on one of these steps, just ask for it - It's just a very general answer to a very general question ;)
     
  3. cmh0114

    cmh0114 Well-Known Member
    Thread Starter

    That's what I'm interested in - how do I apply an image to a texture to the triangles? And how do I use the gluOrtho2D() method?
     
  4. DiCon

    DiCon Newbie

    ok, so I can probably assume, that you are pretty new to OpenGL. In this case, I would recommend the NeHe tutorials that have been ported for Android (since OpenGL != OpenGL ES) -> INsanityDesign NeHe Android Ports

    If you already have an OpenGL environment running with your triangles already rendering, but without textures, you can skip to "Lesson 06". Set "gl.glEnable(GL10.GL_TEXTURE_2D)" and have a look at loadGLTexture(...) from the cube-class in this lesson.

    The gluOrtho2D just sets up a projection matrix with an orthographic projection. With this projection you can easily do 2D graphics in OpenGL as the z-coordinate does not affect the size of your graphics. gluOrtho2D is just like gluPerspective but "without depth".
     
  5. obviam

    obviam Lurker

    I have put up a tutorial describing exactly that.
    How to draw images with opengl.
    It explains triangle strips, how to create a square and how to create a texture from an image and how to bind it.
    You can find the article here.

    Good luck!
     
  6. jonbonazza

    jonbonazza Android Expert

    Depending on the complexity, you could just use glTexImage2D()... this can be kind of slow tho.
     
Loading...
Similar Threads - Drawing image OpenGL
  1. Samsung
    Replies:
    0
    Views:
    97
  2. App Update
    Replies:
    0
    Views:
    109
  3. dPRogerWilco
    Replies:
    1
    Views:
    119
  4. Bretwa
    Replies:
    0
    Views:
    277
  5. iTP
    Replies:
    0
    Views:
    209
  6. Rad Brothers
    Replies:
    1
    Views:
    724
  7. App Update
    Replies:
    0
    Views:
    133
  8. App Update
    Replies:
    0
    Views:
    117
  9. The_Chief
    Replies:
    9
    Views:
    1,413
  10. Muffi Zainu
    Replies:
    18
    Views:
    6,182

Share This Page

Loading...