PDA

View Full Version : GL_INVALID_OPERATION at glFramebufferTexture2DEXT



PP2005
06-26-2012, 10:49 AM
I'm trying to get a basic FBO up and running, but I'm getting a GL_INVALID_OPERATION error when trying to assign a texture to the FBO. I'm on WindowsXP and am programming in Freepascal with SDL as the context wrapper. Here's a code snippet:



glEnable(GL_TEXTURE_2D);
glClearColor(0.0, 0.0, 0.0, 0.0);
glViewport(0, 0, 800, 600);
glClear(GL_COLOR_BUFFER_BIT);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0.0, 800, 600, 0.0, -1.0, 1.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glDisable(GL_LIGHTING);
glShadeModel(GL_SMOOTH);

[...]

TempSurface := IMG_Load('gfx/logo.png');
glGenTextures(1, @TexID);
glBindTexture(GL_TEXTURE_2D, TexID);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, 4, 512, 512, 0, GL_RGBA, GL_UNSIGNED_BYTE, TempSurface^.pixels);
SDL_FreeSurface(TempSurface);

[...]

IF glext_LoadExtension('GL_EXT_framebuffer_object') THEN BEGIN
glGenFramebuffersEXT(1, @FBO);
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, FBO);
// NO ERROR HERE
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, TexID, 0);
// GL_INVALID_OPERATION RETURNED HERE!
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
END;


I can't figure out what I'm doing wrong here...

PP2005
06-26-2012, 02:22 PM
I've narrowed it down to being an issue with the texture being assigned to the FBO. If I assign zero instead of a texture, I don't get the error. And then there's this (http://www.opengl.org/wiki/GLAPI/glFramebufferTexture):

GL_INVALID_OPERATION​ is generated if textarget​ and texture​ are not compatible.
Anybody have any idea how textarget and the texture are incompatible?

kowal
06-26-2012, 03:12 PM
glTexImage2D(GL_TEXTURE_2D, 0, 4, 512, 512, 0, GL_RGBA, GL_UNSIGNED_BYTE, TempSurface^.pixels);


Which version of OpenGL are You using?
Afaik old internal texture formats (1,2,3,4) are deprecated by GL 3.0, try GL_RGBA, or GL_RGB instead (third argument),
also see paragraph 4.4.4 (Framebuffer completness and internal formats) of
http://www.opengl.org/registry/specs/EXT/framebuffer_object.txt

PP2005
06-26-2012, 03:53 PM
Yes, that did it! Thanks a bunch! :D