开发者

Drawing a smaller texture on a larger OpenGL texture on iPhone

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

  1. Load a texture from an image.
  2. Load another texture which is much smaller than the first one.
  3. 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 2开发者_如何学GoD.

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!


Others may find this sample from Apple useful: GLPaint

Hope it helps!


  1. Draw the large texture into the frame buffer,
  2. Paint on it with the small texture as you wish,
  3. 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜