एक बनावट आप एक बनावट के साथ जुड़े फ्रेमबफर का उपयोग करना चाहिए करने के लिए दृश्य प्रस्तुत करना करने के लिए। अपने ड्रा में _texture में दृश्य प्रस्तुत करना
GLuint _texture, _framebuffer;
GLsizei w,h;
float scale = [UIScreen mainScreen].scale;
w = self.view.bounds.size.width * scale;
h = self.view.bounds.size.height * scale;
glGenTextureFromFramebuffer(&_texture, &_framebuffer, w, h);
आप बाद में _framebuffer उपयोग कर सकते हैं:
void glGenTextureFromFramebuffer(GLuint *t, GLuint *f, GLsizei w, GLsizei h)
{
glGenFramebuffers(1, f);
glGenTextures(1, t);
glBindFramebuffer(GL_FRAMEBUFFER, *f);
glBindTexture(GL_TEXTURE_2D, *t);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, *t, 0);
GLuint depthbuffer;
glGenRenderbuffers(1, &depthbuffer);
glBindRenderbuffer(GL_RENDERBUFFER, depthbuffer);
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, w, h);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depthbuffer);
GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
if(status != GL_FRAMEBUFFER_COMPLETE)
NSLog(@"Framebuffer status: %x", (int)status);
}
आप फ्रेम बफर और आसानी से बनावट बना सकते हैं: यहाँ एक विधि है कि मैं इसे आसान बनाने के लिए बनाया है विधि:
glBindFramebuffer(GL_FRAMEBUFFER, _framebuffer);
//draw here the content you want in the texture
//_texture is now a texture with the drawn content
//bind the base framebuffer
glBindFramebuffer(GL_FRAMEBUFFER, 0);
//or if you use GLKit
[view bindDrawable];
//draw normaly
अब आप बनावट के साथ जो भी चाहते हैं वह कर सकते हैं। यदि आप कुछ पोस्ट प्रोसेसिंग (ब्लर, ब्लूम, छाया इत्यादि ...) करना चाहते हैं तो आप कर सकते हैं!
मार्को, तुम्हें पता है कितना भूमि के ऊपर प्रत्येक बनावट आप में प्रस्तुत करने के लिए की जरूरत के लिए एक फ्रेमबफर और renderbuffer रखने में शामिल है क्या ज़रूरत है? मेरे पास कई बड़े बनावट हैं जिनके लिए मेरे ऐप को आकर्षित करने की ज़रूरत है, और मैं glframebufferTexture2DOES का उपयोग करके अलग-अलग "अतिरिक्त" फ्रेमबफर में घुमावदार रूप से संलग्न कर रहा हूं। प्रत्येक के लिए एक अलग फ्रेमबफर रखना बेहतर होगा? –
क्या आप अपना कोड संपादित कर सकते हैं ताकि initWithData: ... कॉल स्क्रॉल किए बिना फिट बैठे? – nornagon
ठीक है, संपादित, अब बेहतर दिखता है। –