0

I am new to openGL so having some issues figure out how to modify grafika texture2dProgram so that I can get a picture in picture effect (or texture in texture). Here is my understanding so far from all the examples:

(after surface is ready)

  1. Setup Viewport

    GLES20.glViewport(0, 0, width, height);
    
  2. Setup Drawable2d which has texture and vertices coordinates

    new Drawable2d(RECTANGLE)
    
  3. On new frame, use the Texture2dProgram to draw into the viewport with the texture

I want to take my understanding and modify so that I get a picture in picture output on the screen. How do I achieve this?

My understanding is that I should do the following: create two Texture2dPrograms and assign different texture id and pass different the projection matrix so that one texture2dprogram draws only on a smaller portion. Is that correct or am I missing something?

kungfoo
  • 597
  • 5
  • 16

1 Answers1

1

The Texture2dProgram class just abstracts the GLES program, encapsulating a vertex shader and a pixel shader. You only need more than one of them if you need different shaders, e.g. you want to use both "normal" and "external" textures.

If you look at HardwareScalerActivity, you can see it drawing both of shapes with the same program. You want to do something similar. (It also creates a FlatShadedProgram because it allows you to flip between them in the UI.)

The Drawable2d defines the shape, the Program defines how it's rendered, and Sprite2d defines position, size, and appearance. You set the texture ID on the Sprite2d object (see surfaceChanged() in HardwareScalerActivity).

This decomposition may seem a little strange at first, but it fits well with the way OpenGL ES works.

As far as rendering one thing on top of another thing goes, the GLES code in Grafika is pretty limited -- just 2D rendering in a single plane parallel to the display. Whatever you draw first will be overwritten by the things you draw after. Don't mess with the viewport, just set position and size on the Sprite2d object.

fadden
  • 51,356
  • 5
  • 116
  • 166