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


getting pixel from texture x,y

Recommended Posts

Glak    315
I am making a game with a map similar to RISK or Europa Universalis. This means that I have a bunch of 2d shapes that cannot be modeled with any sort of math equation. You need to be able to select them though. My solution is to make a second map where every country is a unique color. Then when you click the mouse it will take the x,y coordinates and check on the secret map to see what color it is. Each color is an id number for that territory. However it doesn''t work, it always gives 0xCDCDCDCD, which means that my values aren''t writing to the memory. Ok here is what I have:
if(FAILED( D3DXCreateTextureFromFileEx( renderer,"texture2.bmp", 0, 0, 1, 0, 
          /*colorkey*/0, 0 , NULL, &texture2) ) )
	{	 Write("texture didn''t load");	  

	image_data = (unsigned int (*)[1024][768])malloc(1024*768*sizeof(unsigned int));

		1024*768*sizeof(unsigned int),
Write("Graphics::Startup get image failed");
and it prints that last error message, the get image part. Am I even using the right function? Also I normally use new for memory allocation, but I am not sure how to do it with my 2d array. My books are back home. Thanks for any help

Share this post

Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
You have to do more locking, etc. to get the bits (basically, your code is very wrong). This can be relatively heavy for what you really want to do.

Why store it as a *texture* at all? Just load the bitmap into system memory and bypass the texture thing altogether. The texture gives you all sorts of problems. (I bet the result to the D3DXCreate... function is NOT a 1024 x ***768*** texture...)

Even better, store an simple 2D array of bytes. Yes, you might need to distill that from a bmp, but only deal with the smaller representation at runtime.

Share this post

Link to post
Share on other sites