Advertisement

Regenerate only part of an image?

Started by July 19, 2004 03:50 PM
1 comment, last by MarauderIIC 20 years, 4 months ago
I have the following code:

	} else {
		for (unsigned int pixelYFill = bottom;pixelYFill <= top;pixelYFill++) {
			for (unsigned int pixelXFill = left;pixelXFill <= right;pixelXFill++) {
//				getRGBA(landRes[pixelYFill][pixelXFill], r, g, b, a);
				getRGBA(landRes.at(pixelYFill).at(pixelXFill), r, g, b, a);
				pixelDataRes[pixelYFill][pixelXFill][0] = (float)r/255.0;
				pixelDataRes[pixelYFill][pixelXFill][1] = (float)g/255.0;
				pixelDataRes[pixelYFill][pixelXFill][2] = (float)b/255.0;
				pixelDataRes[pixelYFill][pixelXFill][3] = (float)a/255.0;
			}
		}
	}

	GLuint temp;
	glGenTextures(1, &temp);
	glBindTexture(GL_TEXTURE_2D, temp);
	landGen->setTexture(temp);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
	gluBuild2DMipmaps(GL_TEXTURE_2D, 4, resWidth, resHeight, GL_RGBA, GL_FLOAT, pixelDataRes);


Of course, it lags like crap, which is my problem. Is it possible to only regenerate the part of the image contained within (bottom, left) (top, right) ? I mipmap because the image is 640x480 (at the moment) and it's not powers of two. This function is called whenever part of the image changes (it's "destroyable" terrain-like stuff).
"Is that a snow-globe in your fire blanket,or are you just stark naked?" --RavenBlack Surrealism
gluBuildMipmaps uses gluScale internally to scale the image to a power of two, so you can just use that to scale the image, then use glTexImage2D. To change just a part of the texture, use glSubTexImage2D ( I think thats the name - similar anyway ).
If at first you don't succeed, redefine success.
Advertisement
Ah, it's glTexSubImage2D.
"Is that a snow-globe in your fire blanket,or are you just stark naked?" --RavenBlack Surrealism

This topic is closed to new replies.

Advertisement