Re: Using framebuffers

Uğur Güney <[email protected]> Sat, 28 May 2016 15:34:41 -0400
Newsgroups gmane.comp.python.opengl.user
Message-ID <CALr+-4wnFeOny6WzVihu5Bk9wrpnwYbGKUcJeetVe0VAaTKxQg@mail.gmail.com>
--===============1856177838538828298==
Content-Type: multipart/alternative; boundary=089e0116067a8e8c950533ec1e27

--089e0116067a8e8c950533ec1e27
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

I did some more research.

It looks like the EXT-framebuffer is deprecated:
https://www.opengl.org/wiki/Framebuffer_Object#EXT_Framebuffer_object
"EXT_Framebuffer_object Warning: This section describes legacy OpenGL APIs
that have been removed from core OpenGL 3.1 and above" Hence, I assume that
I should be good to go with non-EXT version.

I also tried GLUT instead of GLFW, but that didn't solve my problem. I
guess the library to create the window is not related to the framebuffer
issue.

I uploaded a newer version where you can choose between GLFW and GLUT, and
between using offscreen framebuffer or not (via global variables
WINDOW_LIBRARY and TRY_FRAMEBUFFER) here:
https://gist.github.com/vug/2c7953d5fdf750c727af249ded3e9018

This is how I generate the framebuffer.

fbo =3D GLuint()
glGenFramebuffers(1, fbo)
glBindFramebuffer(GL_FRAMEBUFFER, fbo)

texture =3D GLuint()
glGenTextures(1, texture)
glBindTexture(GL_TEXTURE_2D, texture)
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_RGB, SIDE, SIDE, 0, GL_RGB,
GL_UNSIGNED_BYTE, None)
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
texture, 0)

rbo =3D GLuint()
glGenRenderbuffers(1, rbo)
glBindRenderbuffer(GL_RENDERBUFFER, rbo)
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, SIDE, SIDE)
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT,
GL_RENDERBUFFER, rbo)

if not glCheckFramebufferStatus(GL_FRAMEBUFFER) =3D=3D GL_FRAMEBUFFER_COMPL=
ETE:
    print('framebuffer binding failed')
    exit()
glBindFramebuffer(GL_FRAMEBUFFER, 0)
glBindTexture(GL_TEXTURE_2D, 0)
glBindRenderbuffer(GL_RENDERBUFFER, 0)

Best,
u

On Sat, May 28, 2016 at 1:10 PM, U=C4=9Fur G=C3=BCney <[email protected]>=
 wrote:

> Thanks for your response and sharing your code!
>
> I started looking at your code. You are using from OpenGL.GL.EXT
> extensions by importing
>
> from OpenGL.GL.EXT.framebuffer_object import *
>
> I don't know what GL extensions are for in pyopengl, however, I tried to
> move from non-extension version to EXT versions of GL functions.
> Unfortunately, just at the beginning, calling the glGenFramebuffersEXT vi=
a
>
> fbo =3D glGenFramebuffersEXT(1)
>
> generates this error:
>
> OpenGL.error.NullFunctionError: Attempt to call an undefined function
> glGenFramebuffersEXT, check for bool(glGenFramebuffersEXT) before calling
>
> Also bool(glGenFramebuffersEXT) return False,
> whereas bool(glGenFramebuffers) is True.
>
> I am using GLFW to generate the window, and my opengl version on OSX is
> 4.1. You are using pygame for that purpose. Do you think that might be th=
e
> source of my problem?
>
> I wasn't able to "pip install pygame" to install pygame, hence I am
> hesitant to use it. But I'll try glut and other window generation options
> to see whether framebuffer's work in them, or whether EXT functions can b=
e
> called. Does this make sense?
>
> PS:
> By the way, I saw your amazing explanation on why y-axis should mean
> upwards direction on your website: "Part of the problem was that Blender,
> like many other modeling softwares use z  for up, which is morally wrong
> (TL;DR: If y  is "up" in 2D (clue: it is), then it should also be "up" in
> 3D; it's demented to redefine it to mean something literally orthogonal t=
o
> its original meaning when you simply add a new coordinate)" Even though, =
as
> a physicist, I am in the "z is up" camp, I appreciated the persuasion pow=
er
> and simplicity of your argument. Also, my girlfriend agrees with you. :-)
>
> Have a good day!
> u
>
> On Fri, May 27, 2016 at 8:44 PM, Ian Mallett <[email protected]> wrote:
>
>> On Fri, May 27, 2016 at 5:35 PM, U=C4=9Fur G=C3=BCney <[email protected]=
om> wrote:
>>
>>> I am a beginner who studies OpenGL using PyOpenGL. I want to learn
>>> post-processing effects and as the first step I want to be able to rend=
er a
>>> scene into a FBO and then render that FBO on a quad that cover the whol=
e
>>> screen.
>>>
>>> The python code I am running is this:
>>> https://gist.github.com/vug/2c7953d5fdf750c727af249ded3e9018 I combined
>>> parts from several tutorials I found on the internet.
>>>
>>
>>
>>> I appreciate if anyone can direct me on how to render on an offscreen
>>> framebuffer via PyOpenGL.
>>>
>>
>> =E2=80=8BAs another reference, you may like to consider some of my code.=
 For
>> example, I wrote a Game of Life simulator
>> <http://geometrian.com/programming/projects/index.php?project=3DGame%20o=
f%20Life>
>> that uses FBOs (it actually uses two IIRC; feedback requires ping-pongin=
g).
>> The code is well-abstracted and reasonably well-tested, so it should ser=
ve
>> as a good example.
>>
>> Ian=E2=80=8B
>>
>
>

--089e0116067a8e8c950533ec1e27
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">I did some more research.<div><br></div><div>It looks like=
 the EXT-framebuffer is deprecated:=C2=A0<a href=3D"https://www.opengl.org/=
wiki/Framebuffer_Object#EXT_Framebuffer_object">https://www.opengl.org/wiki=
/Framebuffer_Object#EXT_Framebuffer_object</a> &quot;EXT_Framebuffer_object=
 Warning: This section describes legacy OpenGL APIs that have been removed =
from core OpenGL 3.1 and above&quot; Hence, I assume that I should be good =
to go with non-EXT version.</div><div><br></div><div>I also tried GLUT inst=
ead of GLFW, but that didn&#39;t solve my problem. I guess the library to c=
reate the window is not related to the framebuffer issue.</div><div><br></d=
iv><div>I uploaded a newer version where you can choose between GLFW and GL=
UT, and between using offscreen framebuffer or not (via global variables WI=
NDOW_LIBRARY and TRY_FRAMEBUFFER) here:=C2=A0<a href=3D"https://gist.github=
.com/vug/2c7953d5fdf750c727af249ded3e9018">https://gist.github.com/vug/2c79=
53d5fdf750c727af249ded3e9018</a></div><div><br></div><div>This is how I gen=
erate the framebuffer.</div><div><br></div><div><div>fbo =3D GLuint()</div>=
<div>glGenFramebuffers(1, fbo)</div><div>glBindFramebuffer(GL_FRAMEBUFFER, =
fbo)<br></div><div><br></div><div>texture =3D GLuint()</div><div>glGenTextu=
res(1, texture)</div><div>glBindTexture(GL_TEXTURE_2D, texture)</div><div>g=
lTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST)</div><div>=
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST)</div><div=
>glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, SIDE, SIDE, 0, GL_RGB, GL_UNSIGNED_=
BYTE, None)</div><div>glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTAC=
HMENT0, GL_TEXTURE_2D, texture, 0)<br></div><div><br></div><div>rbo =3D GLu=
int()</div><div>glGenRenderbuffers(1, rbo)</div><div>glBindRenderbuffer(GL_=
RENDERBUFFER, rbo)</div><div>glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPT=
H24_STENCIL8, SIDE, SIDE)</div><div>glFramebufferRenderbuffer(GL_FRAMEBUFFE=
R, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, rbo)</div></div><div><br><=
/div><div><div>if not glCheckFramebufferStatus(GL_FRAMEBUFFER) =3D=3D GL_FR=
AMEBUFFER_COMPLETE:</div><div>=C2=A0 =C2=A0 print(&#39;framebuffer binding =
failed&#39;)</div><div>=C2=A0 =C2=A0 exit()</div><div>glBindFramebuffer(GL_=
FRAMEBUFFER, 0)</div><div>glBindTexture(GL_TEXTURE_2D, 0)</div><div>glBindR=
enderbuffer(GL_RENDERBUFFER, 0)</div></div><div><br></div><div>Best,</div><=
div>u</div></div><div class=3D"gmail_extra"><br><div class=3D"gmail_quote">=
On Sat, May 28, 2016 at 1:10 PM, U=C4=9Fur G=C3=BCney <span dir=3D"ltr">&lt=
;<a href=3D"mailto:[email protected]" target=3D"_blank">[email protected]=
om</a>&gt;</span> wrote:<br><blockquote class=3D"gmail_quote" style=3D"marg=
in:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr"=
>Thanks for your response and sharing your code!<div><br></div><div>I start=
ed looking at your code. You are using=C2=A0from OpenGL.GL.EXT extensions b=
y importing=C2=A0</div><div><br></div><div>from OpenGL.GL.EXT.framebuffer_o=
bject import *</div><div><br></div><div>I don&#39;t know what GL extensions=
 are for in pyopengl, however, I tried to move from non-extension version t=
o EXT versions of GL functions. Unfortunately, just at the beginning, calli=
ng the glGenFramebuffersEXT via</div><div><br></div>fbo =3D glGenFramebuffe=
rsEXT(1)<br><br><div>generates this error:<br><br>OpenGL.error.NullFunction=
Error: Attempt to call an undefined function glGenFramebuffersEXT, check fo=
r bool(glGenFramebuffersEXT) before calling</div><div><br></div><div>Also b=
ool(glGenFramebuffersEXT) return False, whereas=C2=A0bool(glGenFramebuffers=
) is True.</div><div><br></div><div>I am using GLFW to generate the window,=
 and my opengl version on OSX is 4.1. You are using pygame for that purpose=
. Do you think that might be the source of my problem?=C2=A0</div><div><br>=
</div><div>I wasn&#39;t able to &quot;pip install pygame&quot; to install p=
ygame, hence I am hesitant to use it. But I&#39;ll try glut and other windo=
w generation options to see whether framebuffer&#39;s work in them, or whet=
her EXT functions can be called. Does this make sense?</div><div><br></div>=
<div>PS:</div><div>By the way, I saw your amazing explanation on why y-axis=
 should mean upwards direction on your website: &quot;Part of the problem w=
as that Blender, like many other modeling softwares use z =C2=A0for up, whi=
ch is morally wrong (TL;DR: If y =C2=A0is &quot;up&quot; in 2D (clue: it is=
), then it should also be &quot;up&quot; in 3D; it&#39;s demented to redefi=
ne it to mean something literally orthogonal to its original meaning when y=
ou simply add a new coordinate)&quot; Even though, as a physicist, I am in =
the &quot;z is up&quot; camp, I appreciated the persuasion power and simpli=
city of your argument. Also, my girlfriend agrees with you. :-)</div><div><=
br></div><div>Have a good day!</div><span class=3D"HOEnZb"><font color=3D"#=
888888"><div>u</div></font></span></div><div class=3D"HOEnZb"><div class=3D=
"h5"><div class=3D"gmail_extra"><br><div class=3D"gmail_quote">On Fri, May =
27, 2016 at 8:44 PM, Ian Mallett <span dir=3D"ltr">&lt;<a href=3D"mailto:ia=
[email protected]" target=3D"_blank">[email protected]</a>&gt;</span> wrote=
:<br><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-le=
ft:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr"><div class=3D"gmail_ex=
tra"><span>On Fri, May 27, 2016 at 5:35 PM, U=C4=9Fur G=C3=BCney <span dir=
=3D"ltr">&lt;<a href=3D"mailto:[email protected]" target=3D"_blank">ugurg=
[email protected]</a>&gt;</span> wrote:<br></span><div class=3D"gmail_quote"><=
span><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-le=
ft:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr">I am a beginner who st=
udies OpenGL using PyOpenGL. I want to learn post-processing effects and as=
 the first step I want to be able to render a scene into a FBO and then ren=
der that FBO on a quad that cover the whole screen.<div><br></div><div>The =
python code I am running is this:=C2=A0<a href=3D"https://gist.github.com/v=
ug/2c7953d5fdf750c727af249ded3e9018" target=3D"_blank">https://gist.github.=
com/vug/2c7953d5fdf750c727af249ded3e9018</a> I combined parts from several =
tutorials I found on the internet.</div></div></blockquote><div>=C2=A0</div=
></span><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border=
-left:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr"><div>I appreciate i=
f anyone can direct me on how to render on an offscreen framebuffer via PyO=
penGL.<br></div></div></blockquote><div><br><div class=3D"gmail_default" st=
yle=3D"font-family:times new roman,serif;display:inline">=E2=80=8BAs anothe=
r reference, you may like to consider some of my code. For example, I wrote=
 <a href=3D"http://geometrian.com/programming/projects/index.php?project=3D=
Game%20of%20Life" target=3D"_blank">a Game of Life simulator</a> that uses =
FBOs (it actually uses two IIRC; feedback requires ping-ponging). The code =
is well-abstracted and reasonably well-tested, so it should serve as a good=
 example.<span><font color=3D"#888888"><br><br></font></span></div><span><f=
ont color=3D"#888888"><div class=3D"gmail_default" style=3D"font-family:tim=
es new roman,serif;display:inline">Ian=E2=80=8B</div></font></span></div></=
div></div></div>
</blockquote></div><br></div>
</div></div></blockquote></div><br></div>

--089e0116067a8e8c950533ec1e27--


--===============1856177838538828298==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

------------------------------------------------------------------------------
What NetFlow Analyzer can do for you? Monitors network bandwidth and traffic
patterns at an interface-level. Reveals which users, apps, and protocols are 
consuming the most bandwidth. Provides multi-vendor support for NetFlow, 
J-Flow, sFlow and other flows. Make informed decisions using capacity 
planning reports. https://ad.doubleclick.net/ddm/clk/305295220;132659582;e
--===============1856177838538828298==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
PyOpenGL Homepage
http://pyopengl.sourceforge.net
_______________________________________________
PyOpenGL-Users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/pyopengl-users

--===============1856177838538828298==--