I have been searching around for a simple solution, but I have not found anything. Currently I am loading a texture from a file and rendering it into the buffer using C++ 2012 Express DirectX9. But what I want to do is be able to copy parts of the buffer, and use the part that is copied as the texture, instead of the loaded texture.
I want to be able to copy/select like a map-editor would do.
EDIT: Problem Solves 🙂 It was just dumb mistakes.
You can use the
StretchRectfunction (see documentation).You should copy a subset of the source buffer into the whole destination buffer (which is the new texture’s buffer in your case). Something like this:
EDIT:
OK, I’ve just got through the tones of your code and I think the best solution would be to use uv coordinates instead of copying subsets of the palette texture. You should calculate the appropriate uv coordinates for a given tile in
game_class:: game_gui_add_current_graphicand use them in theCUSTOMVERTEXstructure:Example: Your palette consists of 3 rows and 4 columns with the 12 possible cell textures. Each texture is 32 x 32. So
tex_w = tex_h = 32;,width = 4 * tex_w;andheight = 3 * tex_h;. Suppose you want to calculate uv coordinates for a tile which should be textured with the image in the second row and the third column of the palette. Thentex_x = (3-1)*tex_w;andtex_y = (2-1)*tex_h;. Finally, you calculate the UVs as in the code above (in this example you’ll get {u0,v0,u1,v1} = {(3-1)/4, (2-1)/3, 3/4, 2/3} = {0.5, 0.33, 0.75, 0.66}).