Bitblit from buffer to screen

Started by
2 comments, last by dgcoventry 9 years, 5 months ago

I've been reading up on OpenGL, but I'm particularly interested in swapping out bitmaps from a buffer onto a screen and visa versa.

My main function is as follows:


int main(int argc, char** argv)
{
  init_font();
  glutInit(&argc, argv);
  glutInitDisplayMode(GLUT_SINGLE);
  glutInitWindowSize(500,500);
  glutInitWindowPosition(0,0);
  glutCreateWindow("Griddle");
  glutDisplayFunc(renderFunction);
  glutMainLoop();    
  return 0;
}

void renderFunction()
{
  glClearColor(0.0, 0.0, 0.0, 0.0);
  glClear(GL_COLOR_BUFFER_BIT);
  glColor3f(1.0, 1.0, 1.0);
  glFlush();
}

This opens a window with a black backgound.

My understanding is that I should define a Framebuffer:


glGenFramebuffers(1, &frameBufferID);

and then bind it:


glBindFramebuffer(GL_FRAMEBUFFER, frameBuffer);

Am I correct in thinking that anything drawn on the FBO is rendered on the screen?

How can I assign a 2D array to a buffer and then render it to the screen?

Advertisement

To get data from a bitmap to the screen, copy the data into a texture using glTexImage2D. Then draw that texture to the screen on a quad

To get the data from the buffer you can use glReadPixels

My current game project Platform RPG

Am I correct in thinking that anything drawn on the FBO is rendered on the screen?

You are not. Firstly, you created a FBO, but you have given it no place to actually store pixel data. FBOs are just state holding objects, similar to VAOs. To create storage for your FBO you can first create a Renderbuffer Object using glRenderbufferStorage, and then attach it to the FBO using glFramebufferRenderbuffer?. Alternatively you can create a texture and then attach that to the FBO using glFramebufferTexture2D. Either way what you render to the FBO will not appear on screen. FBOs are for off screen rendering, so you can implement things like render to texture. GLUT will create a default framebuffer (not a FBO) for you when it creates a window. This is where you want to render to if you want something to show up on the screen.

Thanks for the responses.

Here's what I have:


#include <GL/glut.h>
void display(void)
{
 glClear(GL_COLOR_BUFFER_BIT);
 glFlush();
}
int main(int argc, char** argv)
{
 glutInit(&argc, argv);
 glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
 glutInitWindowSize(600, 600);
 glutInitWindowPosition(100, 10);
 glutCreateWindow(argv[0]);
 glutDisplayFunc(display);
 glutMainLoop();
 return 0;
}

This produces a black window.

What I want is to be able to have a white block at the bottom of the window in which to draw text.

I also want to be able to draw lines and text in the black area as depicted in the attached image.

[attachment=24729:opengl.png]

I want both areas to be drawn to off screen and to be bit blitted onto the screen as needed, so I need 2 (or more) separate scratch areas to draw to.

This topic is closed to new replies.

Advertisement