viewing image generated runtime

Started by
3 comments, last by majak 19 years ago
Hi I hope someone can help me, I haven't been able to find anything on the net.. I have here an array of intensities I want to plot on the screen (like texturemapping just without having it as a bitmap). This is 16 bit format and a size og 512*512 pixels, I can't find any tutorials on this or examples. I have tried just to pass the values to a struct, taken from a tutorial "Vertices" from SDK homepage, but the tutorial works with 32bit and complaines about stack overflow when the arrays gets to 64K bytes. Does anyone have a good idea to how I can view this?

const static int width = 512;					//image width 
const static int hight = 512;					//image hight
const int numPixels = width*hight;				//total numbers of pixels in image

unsigned short *arrIn = new unsigned short[numPixels];	//Array containing intensities

int index = 0;											//index in my array
int _x,_y;												//x and y of image
unsigned short lightInt = 65535;						//white
unsigned short darkInt = 0;								//black


	for(int row = 0; row < hight; row++){				//for-loop counting y
		_y=row;												//y increases 1 everytime x has gone from 0 to 511

		for(int kolonne = 0; kolonne < width; kolonne++){		//for-loop counting x
			_x=kolonne;											//x increases 1 until 511 and starts over from 0

			if(_x == _y){										//whenever x and y are the same, we make the pixel white, wich result in a white line from (0,0) to (511,511)
				arrIn[index]=lightInt;							
			}//end if

			else(arrIn[index] = darkInt);						//otherwise the rest should be black
			
			index++;											//going through the array.
		
		}//end for	

	}//end for
	


Advertisement
Quote:I have here an array of intensities I want to plot on the screen

A very trivial method would be to use Win32/GDI if you're starting from scratch.

If you want to use Direct3D:

1. Create a texture (IDirect3DDevice9::CreateTexture())
2. Lock the texture (IDirect3DTexture9::LockRect())
3. Fill in the array with your values
4. Unlock the texture (IDirect3DTexture9::UnlockRect())

I can see one big problem though - the only direct match for unsigned short that you want to work with is D3DFMT_L16 - and I'm not sure what sort of support exists for that. You may well either have to up your system requirements (maybe use floating point textures), or scale back the resolution of your intensities to 8bit...

hth
Jack

<hr align="left" width="25%" />
Jack Hoxley <small>[</small><small> Forum FAQ | Revised FAQ | MVP Profile | Developer Journal ]</small>

Quote:

If you want to use Direct3D:

1. Create a texture (IDirect3DDevice9::CreateTexture())
2. Lock the texture (IDirect3DTexture9::LockRect())
3. Fill in the array with your values
4. Unlock the texture (IDirect3DTexture9::UnlockRect())



I do want to use D3D.
Can't I just pass the intensities from my array to the backbuffer or something, creating a texture takes time and my program will recieve this array from outside the computer real time.

If not, do you know any good tutorials on this?
Quote:Can't I just pass the intensities from my array to the backbuffer or something

Performance wise, its always dangerous to say with any certainty - but locking/accessing/writing directly to the backbuffer will likely destroy your performance.

If you know, for fact, that you'll be receiving a 512x512 buffer of data each time, you create the texture once and the lock/write/unlock it each time a new sample is delivered. Provided your new samples aren't delivered at anything much higher than 100hz (or, you're happy running on a supercomputer) this should work perfectly well.

Also, rendering from a texture using a TLQuad will almost certainly be faster than using CopyRects() to upload a part of a surface to the backbuffer. You also, for future possibilities, leave the door open for per-pixel processing in a PShader.

Quote:If not, do you know any good tutorials on this?

I wrote some articles on this a long time ago for VB6/D3D8, but sadly the website is offline atm [sad]. I have written this sort of code before so if you have any direct questions - feel free to ask [smile].

You still need to decide what you're doing about your 16bit incoming data. As I previously mentioned, 16bit single-channel intensities aren't commonly used - thus suffer from hardware support issues...

hth
Jack

<hr align="left" width="25%" />
Jack Hoxley <small>[</small><small> Forum FAQ | Revised FAQ | MVP Profile | Developer Journal ]</small>

Thanks I have now created my very first image =)

This topic is closed to new replies.

Advertisement