dynamic texture

Started by
4 comments, last by siddim 20 years ago
hi, I want to use a array of integer to create a texture, but this array will be pretty big ( 2048*2048) and will probably change at every frame. What''s the best way to do that? Should I delete and recreate the textures at everyframe? siddim
Advertisement
does each integer stand for 4 btyes (red,green,blue,alpha) or does each integer stand for a single color? Cus if each integer stands for a color, then you will have to convert the integer array into a character array & then you can do pixel operations with it.

I''m sure there is a symetric function to glreadpixels()
(I think thats what its called) where you can feed it a stream of bytes & it will create a texture for you. so look for glwritepixels() or something stupid like that.
Read\write pixel directly on the backbuffer is a solution, but I am reading on the net that it''s not really fast.
let say i have my array of integer (4 integer for one color) = data
I create my texture and pass the array directly:
gluBuild2DMipmaps (GL_TEXTURE_2D, GL_RGBA, 2048, 2048, GL_RGBA, GL_UNSIGNED_BYTE, data);
and now on the next frame, I want to change a few pixel of that texture, if I change the integer in the data array, it won''t change the texture right? I will have to recreate the texture is''n?
You will have to reload the image data using glTexImage2d which is indeed pretty slow, look at this dynamic lightmap tutorial for more information on dynamic textures if you need it: click me
why do you need it at 2048x2048? At that size it either won''t all fit on the screen or be smaller that it''s true size. Which means you can split it up into smaller textures and make smaller versions of it, so only have to update one of the smaller textures (which may be a part of the larger texture or a smaller version of it) and hence will be faster.
Also, I''m not sure you wanna use the GL_UNSIGNED_BYTE flag if you are passing in the integer array, because a byte is 8 bits & an integer is 32 bits (on most machines). If it does what I think it will do... you will end up using only 1/4 of your array, because each integer will count for 3 colors & the alpha value. Good luck !!! : )

This topic is closed to new replies.

Advertisement