views:

32

answers:

2

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 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!

+1  A: 
  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.

ybungalobill
Thanks a lot for the response. While I understand the concept, I am struggling on the step 2. Say, I load large texture in GL_TEXTURE0 and smaller one in GL_TEXTURE1. Now I am not able to successfully draw these textures one on top another on FBO using the combinations of glVertexPointer(), glVertexPointer(), glTexEnvi() and glDrawArrays() functions. Can you please explain how do i achive this?
Pankaj
@Pankaj: Why do you try to bind both of them at the same time? Can't you see that step 1 is separated from step 2?
ybungalobill
Well i am very new to OpenGL, started just this weekend. Let me get some more understanding of things and i will try again.
Pankaj
Finally it seems to working and without glCopyTexImage2D, using off-screen frame buffer as you suggested. Thanks for your response.
Pankaj
@Pankaj: congrats!
ybungalobill
+1  A: 

Others may find this sample from Apple useful: GLPaint

Hope it helps!

ayreguitar