Texture Generation

Hi folks,

I’ve got a heightfield I want to use as the base for a sky texture in opengl. How do I go about creating a texture on the fly in OpenGL? How do I write the colour values etc for the texture? I can do the texture co-ordinate stuff just not the texture generation.

Cheers,

Daniel

You just put the data in malloc()-ed memory
just as if you loaded a bitmap from disk,
and call glTex(Sub)Image2D on it. GL doesn’t
care whether the data came from disk or was
calculated on the fly, as long as it’s in the
right RGB pixel format.

You could use new instead of malloc().
Which you should do if you’re using C++.

Originally posted by Don’t Disturb:
You could use new instead of malloc().
Which you should do if you’re using C++.

Does anyone know where I could find some sample could for this? Do I just create an 2d array of structs of 4 chars (RGBA) and then feed that data into the malloced address?

Originally posted by convict@large:
Does anyone know where I could find some sample could for this? Do I just create an 2d array of structs of 4 chars (RGBA) and then feed that data into the malloced address?

WIDTH -> ImageWidth
HEIGHT-> ImageHeight
CCOMPONENTS->for RGBA 4
int WIDTH = 256, HEIGHT = 256, COMPONENTS = 4;
unsigned char *pixels =
malloc(WIDTH * HEIGHT * COMPONENTS);
unsigned char *pixelAt;

… Pixel at (X,Y)
pixelAt = pixels + (X * COMPONENTS) +
(Y * WIDTH * COMPONENTS);

Red = *pixelAt;
Blue = *(pixelAt +1);
Green = *(pixelAt +2);
Alpha = *(pixelAt +3);


free(pixels;

adios