# OpenGL Bit help to improve my Offscreen renderer?

## Recommended Posts

Hello I am porting an old game and currently I try to get some stuff working with OpenGL. I wrote an Offscreen renderer for some special parts, but I fear this code is still too slow and sometimes it creates some ugly glitches with several graphic cards settings. I am still sort of a Noob in OpenGL (have not much time to care about it as I would wish to) and I hope someone may be able to help. this is the code for now: [CODE] GLubyte *pixels = NULL; void ogl_start_offscreen_render(int x, int y, int w, int h) { int y2; if (offscreen_canv) Error("ogl_start_offscreen_render: offscreen_canv!=NULL"); offscreen_save_canv = grd_curcanv; glDrawBuffer(GL_BACK); offscreen_canv = gr_create_sub_canvas(grd_curcanv, x, y, w, h); gr_set_current_canvas(offscreen_canv); y2 = last_height - offscreen_canv->cv_bitmap.bm_y - offscreen_canv->cv_bitmap.bm_h; glReadPixels(offscreen_canv->cv_bitmap.bm_x,y2,w,h,GL_RGBA,GL_UNSIGNED_BYTE,pixels); } void ogl_end_offscreen_render(void) { int y; if (!offscreen_canv) Error("ogl_end_offscreen_render: no offscreen_canv"); glDrawBuffer(GL_FRONT); glReadBuffer(GL_BACK); glDisable(GL_TEXTURE_2D); y = last_height - offscreen_canv->cv_bitmap.bm_y - offscreen_canv->cv_bitmap.bm_h; glRasterPos2f(offscreen_canv->cv_bitmap.bm_x/(float)last_width, y/(float)last_height); glDrawPixels(offscreen_canv->cv_bitmap.bm_w, offscreen_canv->cv_bitmap.bm_h,GL_RGBA,GL_UNSIGNED_BYTE,pixels); gr_free_sub_canvas(offscreen_canv); gr_set_current_canvas(offscreen_save_canv); offscreen_canv=NULL; } [/CODE] I suspect, that glDrawPixels is very slow but I am not sure where the glitches may come from. Here is an example image (I hope this works this way): http://www.descentforum.de/forum/useruploads/scrn0000.jpg Thanks :)

##### Share on other sites
Why do you need copy whole buffer to you local memory and then draw it back??If you not using any kind of special effects you can just load everything you need as textures.. And ofcourse problem is in readpixels/drawpixels, because each call makes ur card transfer GPU memory to local memory and back.

##### Share on other sites
Okay admitted, this is sorta hack.
On that screen you see a spinning object. I just try to prevent the flickering since this animation is not going trough the backbuffer.

EDIT: Probably I should also say that this code is a leftover from this unfinished port I just continue. Probably I should solve that whole problem in a different order.

[Edited by - zico on March 4, 2007 3:44:04 PM]

##### Share on other sites
You could use FBOs or pbuffers for offscreen rendering so that you could eliminate making a copy of the backbuffer and restoring it back. Most likely, glReadPixels is the one that is bringing down your performance.

##### Share on other sites
I now moved on to solve this problem from another side.

briefing()
{

draw_briefing_bitmap();

while (!key_pressed())
rotate_object();

}

All this "briefing" stuff normally gets drawed one time on the FRONT-buffer.

This way the object shown with rotate_object() flickers very heavy due to the clearing of the canvas it get's drawn to.

So I made the following (note again: I am still a noob):

while (!key_pressed()) {
glDrawBuffer(GL_BACK);
rotate_object();
SDL_GL_Swap_buffers();
}

glDrawBuffer(GL_FRONT);

This now works outstanding ... but with one single problem:
the briefing bitmap, that is shown above disappears from the screen. That is already the point that I am out of ideas again. :/

The code itself is a bit more complex and all the functions are very seperated. I would probably think I need to call draw_briefing_bitmap() withing this while loop, but is it also possible, to get it stored and shown otherwise?

EDIT:

Ah, I see now. I solved it. :)

All my menus are drawn by glDrawBuffer(GL_FRONT).
I now changed this at init to GL_BACK, flip at drawing and done. :)

[Edited by - zico on March 8, 2007 11:14:37 AM]

## Create an account

Register a new account

• ### Forum Statistics

• Total Topics
627701
• Total Posts
2978709
• ### Similar Content

• A friend of mine and I are making a 2D game engine as a learning experience and to hopefully build upon the experience in the long run.

-What I'm using:
C++;. Since im learning this language while in college and its one of the popular language to make games with why not.     Visual Studios; Im using a windows so yea.     SDL or GLFW; was thinking about SDL since i do some research on it where it is catching my interest but i hear SDL is a huge package compared to GLFW, so i may do GLFW to start with as learning since i may get overwhelmed with SDL.
-Questions
Knowing what we want in the engine what should our main focus be in terms of learning. File managements, with headers, functions ect. How can i properly manage files with out confusing myself and my friend when sharing code. Alternative to Visual studios: My friend has a mac and cant properly use Vis studios, is there another alternative to it?

• Both functions are available since 3.0, and I'm currently using glMapBuffer(), which works fine.
But, I was wondering if anyone has experienced advantage in using glMapBufferRange(), which allows to specify the range of the mapped buffer. Could this be only a safety measure or does it improve performance?
Note: I'm not asking about glBufferSubData()/glBufferData. Those two are irrelevant in this case.
• By xhcao
Before using void glBindImageTexture(    GLuint unit, GLuint texture, GLint level, GLboolean layered, GLint layer, GLenum access, GLenum format), does need to make sure that texture is completeness.
• By cebugdev
hi guys,
are there any books, link online or any other resources that discusses on how to build special effects such as magic, lightning, etc. in OpenGL? i mean, yeah most of them are using particles but im looking for resources specifically on how to manipulate the particles to look like an effect that can be use for games,. i did fire particle before, and I want to learn how to do the other 'magic' as well.
Like are there one book or link(cant find in google) that atleast featured how to make different particle effects in OpenGL (or DirectX)? If there is no one stop shop for it, maybe ill just look for some tips on how to make a particle engine that is flexible enough to enable me to design different effects/magic
let me know if you guys have recommendations.
• By dud3
How do we rotate the camera around x axis 360 degrees, without having the strange effect as in my video below?
Mine behaves exactly the same way spherical coordinates would, I'm using euler angles.
Tried googling, but couldn't find a proper answer, guessing I don't know what exactly to google for, googled 'rotate 360 around x axis', got no proper answers.

References:
Code: https://pastebin.com/Hcshj3FQ
The video shows the difference between blender and my rotation:

• 21
• 14
• 12
• 10
• 12