Archived

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

Raloth

glTexSubImage2D

Recommended Posts

glTexSubImage2D doesn''t seem to do exactly what it says. The following code works correctly, but only when I update the entire texture at once.
	for(int i=0;i);
		glTexSubImage2D(GL_TEXTURE_2D,0,x,y,sizex,sizey,GL_ALPHA,GL_FLOAT,textureWeights[i]);
		//glTexImage2D(GL_TEXTURE_2D,0,GL_ALPHA,size*2,size*2,0,GL_ALPHA,GL_FLOAT,textureWeights[i]);
	} 
The commented out line is what I used to use. Obviously this is inefficient with larger textures. Has anyone gotten glTexSubImage2D to work correctly?

Share this post


Link to post
Share on other sites
It seems that you''re passing the exact same data to both glTexSubImage2D and glTexImage2D. glTexSubImage2D does not automatically offset the data and apply a stride to it, if you''re expecting it to. You can still pass glTexSubImage2D an address of a buffer holding a "full image" if you inform it of what you''re doing (call glPixelStore with at least GL_PACK_ROW_LENGTH) and pass it a proper offset into that buffer.

Share this post


Link to post
Share on other sites
I still can't get it to work .

for(int i=0;i<NUM_LAND_TEXTURES;i++) {
glBindTexture(GL_TEXTURE_2D,alphamaps[i]);
glPixelStorei(GL_PACK_ROW_LENGTH,size*2);
glTexSubImage2D(GL_TEXTURE_2D,0,x,y,sizex,sizey,GL_ALPHA,GL_FLOAT,textureWeights[ i ]+y*size*2+x);
}
[edit] The size*2 things are in there because I have two pixels per tile on my terrain.

[edited by - Raloth on October 22, 2003 10:09:55 PM]

Share this post


Link to post
Share on other sites
I finally got it fixed (not exactly sure what I changed...but it works) but now I have an equally annoying problem. It seems to only update the texture when it feels like it. Nothing will happen, and then all of a sudden everything snaps at once. What''s going on now?

Share this post


Link to post
Share on other sites