3
我在這裏讀過這個問題:Can example "GLImageProcessing" work with multi filters但是,我仍然不明白如何編輯GLImageProcessing的示例代碼來支持多個過濾器。這裏是我現在在ImageGL的drawGL中做的代碼。GLImageProcessing多個過濾器?
任何幫助?
void drawGL(int wide, int high, float val, int mode)
{
GLuint ResultFBO;
GLuint ResultTexture;
static int prevmode = -1;
typedef void (*procfunc)(V2fT2f *, float);
typedef struct {
procfunc func;
procfunc degen;
} Filter;
const Filter filter[] = {
{ brightness },
{ contrast },
{ extrapolate, greyscale },
{ hue },
{ extrapolate, blur }, // The blur could be exaggerated by downsampling to half size
};
#define NUM_FILTERS (sizeof(filter)/sizeof(filter[0]))
rt_assert(mode < NUM_FILTERS);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrthof(0, wide, 0, high, -1, 1);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glScalef(wide, high, 1);
glBindTexture(GL_TEXTURE_2D, Input.texID);
// Remember the FBO being used for the display framebuffer
glGetIntegerv(GL_FRAMEBUFFER_BINDING_OES, (GLint *)&SystemFBO);
// Create the texture and the FBO the will hold the result of applying the first filter
glGenTextures(1, &ResultTexture);
glBindTexture(GL_TEXTURE_2D, ResultTexture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, wide, high, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
glGenFramebuffersOES(1, &ResultFBO);
glBindFramebufferOES(GL_FRAMEBUFFER_OES, ResultFBO);
glFramebufferTexture2DOES(GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES, GL_TEXTURE_2D, ResultTexture, 0);
// bind the result FBO
glBindFramebufferOES(GL_FRAMEBUFFER_OES, ResultFBO);
// apply 1st filter
glViewport(0, 0, wide, high);
filter[mode].func(flipquad, val);
// restore original frame buffer object
glBindFramebufferOES(GL_FRAMEBUFFER_OES, SystemFBO);
// use ResultTexture as input for the 2nd filter
glBindTexture(GL_TEXTURE_2D, ResultTexture);
// apply 2nd filter
glViewport(0, 0, wide, high);
filter[2].func(flipquad, val);
glCheckError();
}
那麼究竟該去哪裏呢?我從「//記住用於顯示幀緩衝區的FBO」開始取代所有內容,然後放在我的代碼中,但仍然沒有運氣。 – Flipper
在最後一步中,您必須繪製到屏幕上,而不是幀緩衝區。我編輯了這個代碼示例。 – datenwolf
當我第一次加載它時,我仍然會看到一個黑色的黑色圖像,然後當我將滑塊向左移動到黑色時,它就會變成白色。在像Hue這樣的其他設置中,圖像在那裏,但顯示兩次......其中一個被翻轉。任何想法發生了什麼? – Flipper