I am new to OpenGL. I am trying to use pyopengl to do some graphics, but I find OpenGL very complicated and frightening. I am OK with replies in C++, and I don’t think this is specific to Python OpenGL. Also, I am doing 2D graphics.
Here is a description of what I think I want to do. Terminology may be misunderstood on my side. The TLDR of it is that I want to draw graphics off screen, for caching, and then later copy into the window.
Help to implement any of following functions would very useful to me:
def open_window() :
# Initialize the window and its framebuffer object.
def close_window() :
# Clean up everything.
def render_offscreen( height, width, draw_function ) :
# Initialize a new framebuffer object.
draw_function() # Do the drawing.
# The drawing can involve pasting other renderbuffers into current framebuffer object using the draw_from_renderbuffer mentioned next.
# Clean up framebuffer, but keep the renderbuffer.
return renderbuffer
def draw_from_renderbuffer( renderbuffer, x, y, width, height ) :
# Draw renderbuffer into the current framebuffer object at x, y with given width and height.
def renderbuffer_to_ram( renderbuffer ) :
# If renderbuffer is in VRAM, move it to RAM, and free the VRAM it occupied.
# Wait for transfere to finnish.
return width, height, data
def renderbuffer_to_vram( width, height, data ) :
# If renderbuffer is in RAM, move it to VRAM, and free the RAM it occupied.
# Wait for transfer to finish.
return renderbuffer
I am aware that I may need to render to a texture instead of a renderbuffer. I have tried to do this, but with no luck. I followed some tutorials and got the following to attach a texture to a framebuffer object:
texture = glGenTextures( 1 )
glBindTexture( GL_TEXTURE_2D, texture )
glTexStorage2D( GL_TEXTURE_2D, 1, GL_RGBA, w, h ) # This fails, with 'invalid argument'.
glFramebufferTexture2D( GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, texturebuffer )
I am sorry if this is trivial stuff that I should be able to figure out my self ( and also, it is Python and not C++ ), but I need this for a project. I need it a lot!