简体   繁体   中英

OpenGL texture vs FBO

I am pretty new to OpenGL and just want some quick advice. I want to draw a tiled background for a game. I guess this means drawing a whole bunch of sprite like objects to the screen. I have about 48 columns to 30 rows, therefore 1440 tiles (tiles change depending on the game, so I can't pre-render the entire grid).

Currently on start up I create 6 different FBO (using the ofFbo class from OpenFrameworks) that act as 6 different tiles. I then draw these buffers, up to a maximum of 1400 times, selecting one for each tile. So there are only ever 6 fbos, just being draw a lot of times. (The buffers are drawn to on start up, and are never changed once created).

for (int x=0; x<columns; x++) {
  for (int y=0; y<rows; y++) {

  // Get tile type and rotation from tile struct.
  tileNum = tile.form
  rotNum = tile.rot

  // Draw image/texture/fbo that's stored in a std vector.
  tileSet->draw(x*TILESIZE, y*TILESIZE, TILESIZE, TILESIZE);

  }
}

I think I am going about this the wrong way, and was wondering if anyone new the best / optimal way to do this. Think something like an old school 8 bit video game background. Here is an image of my work in progress.

工作正在进行中

The structures in the background are the sprites i'm talking about, the different pieces are the inny corner, outty (concave) corner, square fill, and straight edge. Sorry for messing around with question.

I don't really understand your question. A texture is a (usually 2-dimensinal) image that can be applied to polygons, whereas an FBO (framebuffer object) is a kind of offscreen buffer that can be rendered into instead of the screen, usually used to render directly into textures. So I don't see where your question could be "textures vs FBOs" in any way, as they're quite orthogonal concepts and using FBOs doesn't make any sense in your example. Maybe you're messing up FBOs with VBOs (vertex buffer objects) or PBOs (pixel buffer objects) ? But then your question is still quite ill-posed.

EDIT: If you're really using FBOs, and that only because you think they magically make the texture they reference to be stored in video memory, then rest assured that textures are always stored in video memory and using an FBO in your case is completely useless.

for what your doing I would recommend you just use a standard OpenGL texture.

I think I understand what your trying to do, but FBO's retain far more information than you need and will thus take much longer to render onto your destination (which is an FBO).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM