Sign in to follow this  
fsforall

OpenGL FBO-Problem

Recommended Posts

Hello, here is an updated to my previous post. Let me explain again what I have to do. I have a game which creates a bitmap in RAM. I need to draw with OpenGL on it. I can draw with PFD_DRAW_TO_BITMAP, but it is way too slow. That is why I need to create a FBO and then render to it. Since I can not create a FBO on the bitmap because OpenGL is initialised in software mode, so without extensions, I create a hidden window and initialise the FBO in there. I make the context of the window current, I then render to the FBO, I make the bitmap context current (software only, unfortunately) and then I draw the FBO as a texture in there using a quad. I do not use a depth buffer, just a simple FBO with only one bitmap, no mipmaps. This results in the quad being all white. However, the code works perfectly. If I do not make the context of the bitmap current, I draw on the window (which I can unhide) and the exact same code works perfectly, but it just fails on the bitmap. Is this a limitation ? Can somebody please help me ? Thank you very much in advance. Here is the code : //Start wglMakeCurrent(hDC,hRC); //Make current the window where the pbuffer is created glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb); glPushAttrib(GL_VIEWPORT_BIT); glViewport(0,0,width,height); glClearColor(0.0f, 0.0f, 0.0f, 0.5f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth Buffer glLoadIdentity(); /////////// //Draw Something /////////// glPopAttrib(); glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); aa = wglMakeCurrent(hdc,hrcb);//Make current the bitmap where we want this to be drawn glClearColor(0.0f, 0.0f, 0.2f, 0.5f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth Buffer glLoadIdentity(); glBindTexture(GL_TEXTURE_2D, img); glEnable(GL_TEXTURE_2D); glTranslatef(0.0f,0.0f,-2.0f); glColor4f(1.0f,1.0f,1.0f,1.0f); ////// //Draw a quad with the texture data, as described above ////// glDisable(GL_TEXTURE_2D); glFlush(); //END

Share this post


Link to post
Share on other sites
Quote:
Original post by fsforall
I make the context of the window current, I then render to the FBO, I make the bitmap context current (software only, unfortunately) and then I draw the FBO as a texture in there using a quad.
This doesn't work because the textures (and other OpenGL objects) are specific to the context they were created in. You can use wglShareLists to share the display list space (includes all OpenGL objects, not just display lists) between one or more contexts, however in this case I'm pretty sure you won't be able to do that because of the following line from the Remarks section...
Quote:
Rendering contexts can share display lists only if they use the same implementation of OpenGL functions.
... and one of your contexts uses your graphics driver's implementation while the other uses Microsoft's.

Unfortunately, I don't think you'll be able to do any better than manually reading the data from the FBO and copying it to the bitmap. But hey, I've been wrong before! [grin]

Share this post


Link to post
Share on other sites
Kalidor,

Thank you for your reply. Unless there is somebody else that can point to a solution, the only alternative is to read the FBO pixel by pixel.

I know and I can use the function glReadPixels without a problem, but it is way too slow for what I am trying to do. For a 512*512 bitmap, it takes about 12ms, which is way too much.

Is there any alternative to get the pixel data from a FBO ? Are there any faster functions ?

Thank you in advance.

Share this post


Link to post
Share on other sites
Quote:
Original post by fsforall
Kalidor,

Thank you for your reply. Unless there is somebody else that can point to a solution, the only alternative is to read the FBO pixel by pixel.

I know and I can use the function glReadPixels without a problem, but it is way too slow for what I am trying to do. For a 512*512 bitmap, it takes about 12ms, which is way too much.

Is there any alternative to get the pixel data from a FBO ? Are there any faster functions ?

Thank you in advance.
Reading the data from the FBO pixel by pixel will be much worse than reading the entire thing in one glReadPixels call. You may be able to use the GL_ARB_pixel_buffer_object (PBO) extension to speed it up a bit however, if your card supports it.

For your purposes it is essentially an asynchronous glReadPixels. So instead of the pipeline stall usually involved with glReadPixels and then having to wait for the data to actually be returned before your application continues, you issue one (or more) glReadPixels commands and then continue on doing something else with your application, then when the transfer is finished you copy it over to the bitmap. Speed-ups from this depend on what else you're doing in your app (ie: if you issue the async glReadPixels then immediately try to use the results it doesn't gain you anything).

If you can live with the image in your bitmap being a frame or two behind what's in the FBO you can probably get a decent speed-up with multiple PBOs. The idea here is do your rendering as usual, then issue an async read with one PBO, then continue onto rendering the next frame, then do another async read with a second PBO, then get the results from the first PBO and send that to your bitmap, then continue onto the next frame, etc. You can buffer that even more if you use more PBOs and wait more frames before sending the results to the bitmap.

For more information check out Fast Texture Transfers.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  

  • Partner Spotlight

  • Forum Statistics

    • Total Topics
      627636
    • Total Posts
      2978331
  • Similar Content

    • 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.
      Thank you in advance!
    • 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:
       
    • By Defend
      I've had a Google around for this but haven't yet found some solid advice. There is a lot of "it depends", but I'm not sure on what.
      My question is what's a good rule of thumb to follow when it comes to creating/using VBOs & VAOs? As in, when should I use multiple or when should I not? My understanding so far is that if I need a new VBO, then I need a new VAO. So when it comes to rendering multiple objects I can either:
      * make lots of VAO/VBO pairs and flip through them to render different objects, or
      * make one big VBO and jump around its memory to render different objects. 
      I also understand that if I need to render objects with different vertex attributes, then a new VAO is necessary in this case.
      If that "it depends" really is quite variable, what's best for a beginner with OpenGL, assuming that better approaches can be learnt later with better understanding?
       
    • By test opty
      Hello all,
       
      On my Windows 7 x64 machine I wrote the code below on VS 2017 and ran it.
      #include <glad/glad.h>  #include <GLFW/glfw3.h> #include <std_lib_facilities_4.h> using namespace std; void framebuffer_size_callback(GLFWwindow* window , int width, int height) {     glViewport(0, 0, width, height); } //****************************** void processInput(GLFWwindow* window) {     if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS)         glfwSetWindowShouldClose(window, true); } //********************************* int main() {     glfwInit();     glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);     glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);     glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);     //glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);     GLFWwindow* window = glfwCreateWindow(800, 600, "LearnOpenGL", nullptr, nullptr);     if (window == nullptr)     {         cout << "Failed to create GLFW window" << endl;         glfwTerminate();         return -1;     }     glfwMakeContextCurrent(window);     if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress))     {         cout << "Failed to initialize GLAD" << endl;         return -1;     }     glViewport(0, 0, 600, 480);     glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);     glClearColor(0.2f, 0.3f, 0.3f, 1.0f);     glClear(GL_COLOR_BUFFER_BIT);     while (!glfwWindowShouldClose(window))     {         processInput(window);         glfwSwapBuffers(window);         glfwPollEvents();     }     glfwTerminate();     return 0; }  
      The result should be a fixed dark green-blueish color as the end of here. But the color of my window turns from black to green-blueish repeatedly in high speed! I thought it might be a problem with my Graphics card driver but I've updated it and it's: NVIDIA GeForce GTX 750 Ti.
      What is the problem and how to solve it please?
  • Popular Now