Generating textures on the fly
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
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.
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.
Modify the texture data in host memory, and update the texture on the 3D card with glTexSubImage2D().
(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]
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]
As Yann says, keep a copy of your texture in a buffer (e.g):
Hopefully that will give the idea.
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.
>>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
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
Got another problem. I can update the image, but only once, after the first update it refuses to draw the updated texture.. Any suggestions?
WDA
WDA
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
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
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[z][1]=testno;<br> //my_dynamic_texture[z][2]=testno;<br> //my_dynamic_texture[z][3]=255;<br> <br> my_dynamic_texture[z][0]=curno;<br> my_dynamic_texture[z][1]=curno;<br> my_dynamic_texture[z][2]=curno;<br> my_dynamic_texture[z][3]=curno;<br><br> <br> }<br> }<br> curno–;<br> if(curno < 0)<br> curno=255;<br>glBindTexture(GL_TEXTURE_2D, texture[0]);<br> glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 256, 256, GL_RGB, GL_UNSIGNED_BYTE, my_dynamic_texture);<br> </pre> <br>That only updates it once for some reason, prior to initial draw, then the drawing routine fails to update it again<br><br>WDA </i>
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement