0

I need to draw a specific shape using OpenGL, but the thing is that I don't want it to display inside the application window, but to save it as a 24-bit .bmp file. I can create the .bmp file header myself, and given some sort of an image array I can generate the entire .bmp file.

My questions are:

  1. Can this be done automatically? Meaning, is there a command in OpenGL where instead of displaying the graphic, it saves it as a data array? Or even better, as a .bmp file?
  2. If #1 is not possible, how do I access the buffer where OpenGL stores my drawing data, and what is the format of this data?
  3. In addition, can I avoid displaying the image? Or do I have to display the image, because the buffer needs to be created?
user35443
  • 6,309
  • 12
  • 52
  • 75
yossi
  • 1
  • What makes you think that you need opengl then? – eldo Jun 06 '17 at 10:57
  • 1
    [`glReadPixels`](https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/glReadPixels.xhtml)? How you prevent the image from beeing displayed depends on your windowing system. – BDL Jun 06 '17 at 11:22
  • @eldo i need to draw certain shapes, it'll be easier using the opengl functions – yossi Jun 06 '17 at 11:30
  • @BDL thank you, i'll dig into it – yossi Jun 06 '17 at 11:32
  • And for your question 3 - the image can be rendered offscreen using _framebuffer objects_. – radical7 Jun 06 '17 at 14:54
  • 1. you can render then use glReadPixels then clear or not swaping buffers at all ... 2. OpenGL support rendering to bitmap instead of to window. 3. FBO and rendering to texture can be used too but you may have problems with Intel gfx drivers ... The texture can be then loaded back into CPU side memory ... see [OpenGL Scale Single Pixel Line](https://stackoverflow.com/a/43654398/2521214) and [Render OpenGL scene to texture using FBO in fixed function pipeline drawing](https://stackoverflow.com/a/43930271/2521214) – Spektre Jun 15 '17 at 06:40

0 Answers0