2
\$\begingroup\$

I have an object made up of many vertices that changes very rare (for the most part of time, it looks the same) and I'm trying to figure out a way to avoid rendering all its vertices every frame. However, being a OpenGL beginner I have no idea how to do it. I was thinking I could render it to a texture and only show the texture every frame. But I don't know if it's possible or if there are better ways.

\$\endgroup\$

3 Answers 3

7
\$\begingroup\$

The technical term for rendering a model into a texture once and then just drawing that texture to the screen in place of the model is called the "imposter" technique. That is, the texture is an imposter for the model. In the old days, this was a common technique for filling out large crowds -- render textures of a few character models, and then draw lots of copies of that texture. And the game Trespasser went so far as to use it for most of its game objects.

In practice, there are a lot of problems with imposters, so it's unusual for them to be used in games these days (though they were quite common in the PS2 era). Being a static texture, they don't animate well (every copy of each imposter will be showing the same pose, for members of a crowd), they don't show correct perspective effects, etc.

It sounds like what you're really asking for is a way to avoid having to send your rarely-changing vertices to the graphics card every frame. To do that, you want to put the vertices into a Vertex Buffer Object (VBO, for short). Once you've done that, the vertices will remain in memory managed by the GPU driver, so that all you'll have to do is tell OpenGL to render using the vertices you've already stored in that VBO.

Exactly what functions you use to create and reference VBOs will vary a bit based on whether you're writing for an OpenGL 2.x or OpenGL >=3.x context. But this is the general concept. :)

\$\endgroup\$
1
\$\begingroup\$

This is a common thing, generally you use either vertex arrays or VBO's (Vertex Buffer Objects) to render large objects (vertices numbering in the millions). What VBO's do is make use of the graphics processor by loading the vertices into high powered GPU memory.

The classic NeHe tutorials describe how to do this and there are many examples (of varying quality) of code around the web, check these other links out:

  • Simple Tutorial on VBO's: This tutorial gives a good overview of the commands needed.
  • This tutorial is somewhat dated but has good info. Especially if your graphics card is a little low down on the food chain.
\$\endgroup\$
0
\$\begingroup\$

If you have a stationary object and the camera doesn't move, you can render the object to an off-screen texture - a frame buffer object (FBO) - and then you just have to blit that texture each frame.

In general you should assume that the contents of the frame-buffer before each frame are garbage, and always clear it. But in OpenGLES on many platforms you can control if the last frame remains in the buffer when you draw the next frame and this may be an alternative to using an explicit FBO.

However, if you have a scene too complex to draw each frame at a reasonable rate, and you ever need to actually redraw the scene completely (as simple as the camera moving, even if the objects in the scene do not) then you'll get choppy frame-rates.

I've used the build-scene-over-many-frames and change-level-of-detail-when-panning for things like fractal viewers where choppiness can be forgiven. In more mainstream use-cases, hmm.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .