Drawing a smaller texture on a larger OpenGL texture on iPhone

I am very new to OpenGL and this is what my goal is...

  • Load a texture from an image.
  • Load another texture which is much smaller than the first one.
  • Now keep drawing the smaller texture on the larger one on some chain of events, like painting on the larger texture.
  • Can somebody point me to some material which might help do this?

    I looked into some book, but they are mostly into 3D animation kind of stuff and I do not want to go to that dept, I just need the texture manipulation stuff in 2D.

    I am following the example...

    http://developer.apple.com/library/ios/#samplecode/GLImageProcessing/index.html

    For my experiments, I am modifying the drawGL() function in the example to do this...

    First time when drawGL() is called, nothing changes, so that the full texture is drawn on the view.

    In the next draw onwards, I change the flipquad array to...

    V2fT2f flipquad[4] = {
     { 0, .5, 0, .5 },
     { .5, .5, .5, .5 },
     { 0, 1, 0, 0 },
     { .5, 1, .5, 0 },
    };
    

    So that only the top left quadrant is modified. This works fine on the simulator, but when I run it on device, except for the top left quadrant the rest of the view flickers, that is every alternate draw makes it black!


  • Draw the large texture into the frame buffer,
  • Paint on it with the small texture as you wish,
  • Call glCopyTexImage2D or glCopyTexSubImage2D to copy the painted texture from the frame buffer back to the texture object.
  • The above method will work with OpenGL 1.1 or higher. However it may be not as efficient as you want. Possible optimization (depends on you OpenGL version) is to create an off-screen frame buffer bound directly to the large texture and paint there. See glGenFramebuffers.


    Others may find this sample from Apple useful: GLPaint

    Hope it helps!

    链接地址: http://www.djcxy.com/p/33966.html

    上一篇: 无法在OpenGL中的2D(Ortho)上绘制3D(Frustum)

    下一篇: 在iPhone上的较大的OpenGL纹理上绘制较小的纹理