Advertisement

Texture Generation @ Runtime

Started by May 16, 2002 02:58 PM
0 comments, last by stryx 22 years, 9 months ago
Hi, I want to code an Screensaver and generate my own textures while starting up. How to create an Texture manually ? Is there any code ? Code would be nice Thanks StryX PS: I need it in an NeHe Basecode like Code
Anything that requires finding convex hulls in realtime isstarting to sound like a bad idea. -- John Carmack
for generating a texture, you have to send gl as normally a data-array..

glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA8,width,height,GL_RGBA,GL_UNSIGNED_BYTE,data);

now how to generate "data"?


  unsigned char* data = new unsigned char[width*height*4]; //or 3 if you don't want alpha// if you don't have an alpha, replace all the *4 with *3..for(int x=0;x<width;x++) { for(int y=0;y<height;y++) {  data[(x+width*y)*4+0] = red_at_pixel(x,y);  data[(x+width*y)*4+1] = green_at_pixel(x,y);  data[(x+width*y)*4+2] = blue_at_pixel(x,y);  data[(x+width*y)*4+3] = alpha_at_pixel(x,y); }}glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA8,width,height,GL_RGBA,GL_UNSIGNED_BYTE,data);delete [] data;data = 0;  


well.. its quite easy, isn't it? simple array filling..

good luck (you find some loadtime-texture-generation code possibly in the bumpmapping-tutorial if he didn't replaced it, there he adds the alpha component manually at loadtime..)

"take a look around" - limp bizkit
www.google.com

[edited by - davepermen on May 16, 2002 5:20:32 PM]

[edited by - davepermen on May 16, 2002 5:21:51 PM]
If that's not the help you're after then you're going to have to explain the problem better than what you have. - joanusdmentia

My Page davepermen.net | My Music on Bandcamp and on Soundcloud

This topic is closed to new replies.

Advertisement