English 中文(简体)
Using opengl, how do I combine a background image and a smaller distorted texture?
原标题:

I am attempting to make an image stretch effect on the iphone. I make a vertex array and shift the texture data for each indice within an arbitrary radius of a background image. Then make the following calls to display:

int n = gridSize_.x * gridSize_.y;
glEnableClientState( GL_VERTEX_ARRAY);
glEnableClientState( GL_TEXTURE_COORD_ARRAY );
glVertexPointer(3, GL_FLOAT, 0, vertices);
glTexCoordPointer(2, GL_FLOAT, 0, texCoordinates);
glDrawElements(GL_TRIANGLES, n*6, GL_UNSIGNED_SHORT, indices);

//if(num_myindices > 0)
// glDrawElements(GL_TRIANGLES, num_myindices*6, GL_UNSIGNED_SHORT, myindices);
glDisableClientState(GL_VERTEX_ARRAY );
glDisableClientState( GL_TEXTURE_COORD_ARRAY );

My problem is the edge of area that is stretched looks very choppy with a relatively small grid size like 32x32 or even 64x64. Any larger makes it smoother but much much slower.

So I tried adding a copy of the background image, and restricted the vertex array to only the affected indices. I use a much smaller grid size but for a smaller area. The drawing code above now looks like:

//glDrawElements(GL_TRIANGLES, n*6, GL_UNSIGNED_SHORT, indices);
if(num_myindices > 0)
glDrawElements(GL_TRIANGLES, num_myindices*6, GL_UNSIGNED_SHORT,myindices);

The affected area is displayed but the background image appears to flash and disappear, my stretched area is floating on a black background. Obviously my background is rendered first and then my code above overwrites and renders only the data in my vertex array.

Does anyone have advice on how to efficiently combine the drawing of the images?

I plan to make a 2nd simple vertex array for the background and make a call to glDrawArray just prior to my if statement so all the drawing is done in a single method. Is this the right way to go about this? Is there a better way? Should all the image data be combined into 1 simple vertex array somehow?

问题回答

Draw background on one set of primitives.

Draw "enchancments" on the second set of primitives, closer to the camera (if you use orthogonal projection, then its mater of changing value of one dimension).

Can t say why background flash and disappear. There may be many reasons. You forgot to clear opengl state correctly, there are depth conflicts, or any other large number of bugs.

But if you stick to drawing overlapping images on different sets of geometry on different "planes" then you should get effect you want.





相关问题
Code sign Error

I have created a new iPhone application.I have two mach machines. I have created the certificate for running application in iPhone in one mac. Can I use the other mac for running the application in ...

ABPersonViewController Usage for displaying contact

Created a View based Project and added a contact to the AddressBook using ABAddressBookRef,ABRecordRef now i wanted to display the added contact ABPersonViewController is the method but how to use in ...

将音频Clips从Peter改为服务器

我不禁要问,那里是否有任何实例表明从Peit向服务器发送音响。 I m不关心电话或SIP风格的解决办法,只是一个简单的袖珍流程......

• 如何将搜查线重新定位?

我正试图把图像放在搜索条左边。 但是,问题始于这里,搜索条线不能重新布署。

热门标签