PDA

View Full Version : Texture Generation



convict@large
12-04-2000, 09:37 AM
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

12-04-2000, 12:53 PM
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.

Don't Disturb
12-05-2000, 06:29 AM
You could use new instead of malloc().
Which you should do if you're using C++.

convict@large
12-07-2000, 09:01 AM
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?

rangaroek
12-08-2000, 12:39 AM
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