Archived

This topic is now archived and is closed to further replies.

witchdrash

Generating textures on the fly

Recommended Posts

I want to modify a texture on the fly, I was working on the theory of creating bitmap data and rebinding the texture, but I can''t find anything on creating the bitmap data structure, which is a pain, does anyone know how I could do this, or a better way of approaching this situation? WDA

Share this post


Link to post
Share on other sites
GameDev''s resource section has several image related articles. Flipcode is good for reference too... best of all, do a search on google.
If u''re in good grips of MSDN, u have all the reference u need, too.

But thats if u wanted to do image manipulation using raw bitmap data. An alternative would be manipulating texture memory directly. The means of doing that is very API specific though. check out the Opengl or Directx sections of this forum for more info.

Share this post


Link to post
Share on other sites
(I'm am using OpenGL btw which is why it's in this forum)
Hmm still can't find anything, Google returns libaries that I could use to do it, but this is a learning project so using someone elses work is cheating..

Basically what I'm looking for is say I want to access pixel 1 and change it's RGB to 255,0,0 how would I do that?


[edited by - witchdrash on December 24, 2002 1:58:06 PM]

Share this post


Link to post
Share on other sites
As Yann says, keep a copy of your texture in a buffer (e.g):


  

char my_dynamic_texture[256*256*3];

void upload_texture(void)
{
// You''ll have to lookup the exact paramters coz I can''t remember off hand:

glTexSubImage2D(my_dynamic_texture,256,256,GL_RGB);
}

void modify_texture(void)
{
// do some weird stuff with my_dynamic_texture

// (set texel at (0,0) to green)

my_dynamic_texture[(0 + (0 * 256)) * 3] = 0;
my_dynamic_texture[((0 + (0 * 256)) * 3) + 1] = 255;
my_dynamic_texture[((0 + (0 * 256)) * 3) + 2] = 0;

}

// then each time you want to update the texture:


modify_texture()
upload_texture()



Hopefully that will give the idea.

Share this post


Link to post
Share on other sites
>>Basically what I''m looking for is say I want to access pixel 1 and change it''s RGB to 255,0,0 how would I do that?<<

to get a texture from opengl use glGetImage(..)
but to do what u want + just change the one pixel use as someone pointed out void glTexSubImage2D( GLenum target,
GLint level,
GLint xoffset,
GLint yoffset,
GLsizei width,
GLsizei height,
GLenum format,
GLenum type,
const GLvoid *pixels )

this will let u uipdate only the one pixel in the texture (+ leave the rest intact)

http://uk.geocities.com/sloppyturds/kea/kea.html
http://uk.geocities.com/sloppyturds/gotterdammerung.html

Share this post


Link to post
Share on other sites
youre not doing it correctly,
go
bind texture
use glTexSubImage
(now its updated for alltime)

to change it again repeat

http://uk.geocities.com/sloppyturds/kea/kea.html
http://uk.geocities.com/sloppyturds/gotterdammerung.html

Share this post


Link to post
Share on other sites

for(int i=0;i<256;i++)
{
for(int z=0;z<256;z++)
{
int testno = rand() % 255;
//my_dynamic_texture[z][0]=testno;
//my_dynamic_texture[i][z][1]=testno;
//my_dynamic_texture[i][z][2]=testno;
//my_dynamic_texture[i][z][3]=255;

my_dynamic_texture[i][z][0]=curno;
my_dynamic_texture[i][z][1]=curno;
my_dynamic_texture[i][z][2]=curno;
my_dynamic_texture[i][z][3]=curno;


}
}
curno--;
if(curno < 0)
curno=255;
glBindTexture(GL_TEXTURE_2D, texture[0]);
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 256, 256, GL_RGB, GL_UNSIGNED_BYTE, my_dynamic_texture);

That only updates it once for some reason, prior to initial draw, then the drawing routine fails to update it again

WDA

Share this post


Link to post
Share on other sites