How do I create textures on the fly?

Started by
6 comments, last by Fugitive 14 years, 10 months ago
I've seen a number of OpenGL progams where the creator describes creating textures on the fly during runtime instead of having the application load a texture from an external jpeg or bitmap. Anyone know where I can find some good examples or tutorials that show how this is done? Neither of my OpenGL books even mention it and I'm having a hard finding any information. Thanks!
Advertisement
I can only think of two ways. One is to actually create the texture-data yourself and send it in using glTexImage2D, and the other is to render stuff using a FBO (or pbuffers depending on your hardware).
The first one probably isn't realtime and is probably best for procedurally generated textures.
The old red book had an example at the start of the texture mapping section.

e.g., http://glprogramming.com/red/chapter09.html#name2
Thanks, I'll take a look. Would taking a solid external texture and letting the program manipulate the color be easier?
Quote:Original post by pjyelton
Would taking a solid external texture and letting the program manipulate the color be easier?


Procedurally generating textures is not complicated. It's the coming up with interesting procedural content that is complicated. I recommend you look at Perlin noise.

Apart from that, if you provide more info on what it is you actually want to do, I'm sure we can come up with some better advice.
there is zero difference between the two

A/ read image data from file then call
glTexImage(...., data );

B/ create data procedurally + then call
glTexImage(...., data );
Quote:Apart from that, if you provide more info on what it is you actually want to do, I'm sure we can come up with some better advice.

Thanks, I really don't have a specific issue I am trying to solve, I'm basically teaching myself OpenGL through a couple pet projects like a terrain editor and a city skyline editor and I've just seen a few places where this idea is discussed and I'd like to try it out. For example, on the terrain editor I've seen where someone mentioned creating a cloud texture dynamically using the same height map that I create the terrain with. Or it would be nice to create a large texture that covers the terrain where high elevation is snow, steep cliffs are brown, etc but since the terrain is always randomly generated everytime the program is run it would be nice if I could randomly generate this texture as well. The last example I saw talked about creating random window lights that were textured onto city skyscrapers so basically take a solid dark color and randomly place dark and light windows. Hope this makes sense.
You can also create textures on the fly using shaders. The 'Orange Book' (Opengl Shading Language by Randi Rost) is the place to go for examples. Chapter 6 has a basic 'brick' texture, created on the fly.

This topic is closed to new replies.

Advertisement